private List <(IEnumerator <IndexEntry> Enumerator, long Count)> GetEnumerators() { var attempt = 0; while (attempt < 5) { attempt++; var enumerators = new List <(IEnumerator <IndexEntry> Enumerator, long Count)>(); try { var tables = _tableIndex.IterateAllInOrder(); foreach (var table in tables) { Log.Information("Found table {id}. Type: {type}. Count: {count:N0}. Version: {version}", table.Id, table.GetType(), table.Count, table.Version); if (table.Version == PTableVersions.IndexV1) { throw new NotSupportedException("The Stream Existence Filter is not supported with V1 index files. Please disable the filter by setting StreamExistenceFilterSize to 0, or rebuild the indexes."); } var enumerator = table.IterateAllInOrder().GetEnumerator(); // advance into the enumerator so that we obtain a workitem in each table // so that the ptables will definitely not be deleted until we are done. if (enumerator.MoveNext()) { // got workitem! enumerators.Add((enumerator, table.Count)); } else { enumerator.Dispose(); } } return(enumerators); } catch (NotSupportedException) { foreach (var pair in enumerators) { pair.Enumerator.Dispose(); } throw; } catch (FileBeingDeletedException) { foreach (var pair in enumerators) { pair.Enumerator.Dispose(); } Log.Debug("PTable is being deleted."); } } throw new InvalidOperationException("Failed to get enumerators for the index."); }
private void InitializeFromIndex(INameExistenceFilter filter) { if (filter.CurrentCheckpoint != -1L) { // can only use the index to build from scratch. if we have a checkpoint // we need to build from the log in order to make use of it. return; } Log.Information("Initializing from index"); // we have no checkpoint, build from the index. unfortunately there isn't // a simple way to checkpoint in the middle of the index. var tables = _tableIndex.IterateAllInOrder().ToList(); foreach (var table in tables) { if (table.Version == PTableVersions.IndexV1) { throw new NotSupportedException("The Stream Existence Filter is not supported with V1 index files. Please disable the filter by setting StreamExistenceFilterSize to 0, or rebuild the indexes."); } } ulong?previousHash = null; foreach (var table in tables) { foreach (var entry in table.IterateAllInOrder()) { if (entry.Stream == previousHash) { continue; } // add regardless of version because event 0 may be scavenged filter.Add(entry.Stream); previousHash = entry.Stream; } } // checkpoint at the end of the index. if (previousHash != null) { filter.CurrentCheckpoint = _tableIndex.CommitCheckpoint; } }