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

Method reopenReplacedDatabase

src/index.ts:381–399  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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