public IReadSession OpenReadSession() { var anchor = storageEngine.GetCurrentAnchor(); statistics.IncrementReadSessionsOpened(); lock (readSnapshotLock) { var documents = new DocumentSet(anchor); if (lastReadSnapshot != null && lastReadSnapshot.Anchor.Id == anchor.Id) { statistics.IncrementSnapshotReuse(); return new ReadSession(anchor, lastReadSnapshot, DisposeReadSession); } statistics.IncrementSnapshotRebuild(); if (lastReadSnapshot != null) { documents.InitializeFrom(lastReadSnapshot); } var visited = new HashSet<string>(StringComparer.OrdinalIgnoreCase); var visitor = new LoadEverythingVisitor(documents, encoders, visited); storageEngine.Visit(anchor, visitor); lastReadSnapshot = documents; if (lastReadSnapshot != null) { documents.RemoveExcept(visited); } return new ReadSession(anchor, documents, DisposeReadSession); } }