MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / reopenReplacedDatabase

Method reopenReplacedDatabase

src/index.ts:382–400  ·  view source on GitHub ↗

The body of reopenIfReplaced, without the in-flight-sync guard.

()

Source from the content-addressed store, hash-verified

380
381 /** The body of {@link reopenIfReplaced}, without the in-flight-sync guard. */
382 private reopenReplacedDatabase(): boolean {
383 if (!this.db.isReplacedOnDisk()) return false;
384 const dbPath = this.db.getPath();
385 // Open the live file FIRST — if that throws (e.g. mid-recreate), the old
386 // handle stays in place and the caller retries on the next query, rather
387 // than leaving this instance with no connection at all.
388 const fresh = DatabaseConnection.open(dbPath, { readOnly: this.db.readOnly });
389 const stale = this.db;
390 this.db = fresh;
391 this.queries = new QueryBuilder(fresh.getDb());
392 this.wireLayers();
393 // Whoever reopened — a sync, or a tool call's self-heal — the next sync
394 // must reconcile the whole tree (#1902).
395 this.pendingFullReconcile = true;
396 // Releasing the dead handle also frees the leaked db/-wal/-shm fds that were
397 // pinning the unlinked inode (#925).
398 try { stale.close(); } catch { /* the old inode is gone; closing just frees fds */ }
399 return true;
400 }
401
402 // ===========================================================================
403 // Lifecycle Methods

Callers 3

reopenIfReplacedMethod · 0.95
syncMethod · 0.95
runDeferredSynthesisMethod · 0.95

Calls 6

wireLayersMethod · 0.95
isReplacedOnDiskMethod · 0.80
getPathMethod · 0.80
getDbMethod · 0.80
openMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected