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

Method reopenReplacedDatabase

src/index.ts:387–405  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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