MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / invalidate_sessions_for_graph

Method invalidate_sessions_for_graph

graphlite/src/session/manager.rs:237–302  ·  view source on GitHub ↗

Invalidate all sessions currently using the specified graph This is called when a graph is dropped to prevent stale data access Returns the number of sessions that were invalidated

(&self, graph_name: &str)

Source from the content-addressed store, hash-verified

235 /// This is called when a graph is dropped to prevent stale data access
236 /// Returns the number of sessions that were invalidated
237 pub fn invalidate_sessions_for_graph(&self, graph_name: &str) -> usize {
238 let mut invalidated_count = 0;
239
240 // Iterate through all partitions and invalidate sessions
241 for partition in &self.sessions {
242 let sessions_guard = match partition.read() {
243 Ok(guard) => guard,
244 Err(_) => {
245 log::error!("Failed to acquire partition read lock for graph invalidation");
246 continue;
247 }
248 };
249
250 // Iterate through all sessions in this partition
251 for (session_id, session_arc) in sessions_guard.iter() {
252 let mut session = match session_arc.write() {
253 Ok(guard) => guard,
254 Err(_) => {
255 log::warn!("Failed to acquire write lock for session {}", session_id);
256 continue;
257 }
258 };
259
260 // Check if this session is currently using the dropped graph
261 if let Some(current_graph) = &session.current_graph {
262 let current_graph_clone = current_graph.clone(); // Clone to avoid borrowing issues
263
264 // Handle both "/graph_name" and "graph_name" formats
265 let matches = current_graph == graph_name
266 || current_graph == &format!("/{}", graph_name)
267 || current_graph.strip_prefix('/') == Some(graph_name);
268
269 if matches {
270 // Clear only the graph context to prevent stale data access
271 // Keep the schema since it's independent of any particular graph
272 session.current_graph = None;
273
274 log::info!(
275 "Invalidated session {} using dropped graph '{}' (was: '{}')",
276 session_id,
277 graph_name,
278 current_graph_clone
279 );
280 invalidated_count += 1;
281 } else {
282 log::debug!(
283 "Session {} using different graph '{}', not invalidating for '{}'",
284 session_id,
285 current_graph_clone,
286 graph_name
287 );
288 }
289 }
290 }
291 }
292
293 if invalidated_count > 0 {
294 log::info!(

Callers 1

execute_ddl_operationMethod · 0.45

Calls 2

cloneMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected