public void Scavenge(IIndexScavengerLog log, CancellationToken ct) { GetExclusiveBackgroundTask(ct); var sw = Stopwatch.StartNew(); try { Log.Info("Starting scavenge of TableIndex."); ScavengeInternal(log, ct); } finally { // Since scavenging indexes is the only place the ExistsAt optimization makes sense (and takes up a lot of memory), we can clear it after an index scavenge has completed. TFChunkReaderExistsAtOptimizer.Instance.DeOptimizeAll(); lock (_awaitingTablesLock) { _backgroundRunning = false; _backgroundRunningEvent.Set(); TryProcessAwaitingTables(); } Log.Info("Completed scavenge of TableIndex. Elapsed: {elapsed}", sw.Elapsed); } }
private void ScavengeInternal(IIndexScavengerLog log, CancellationToken ct) { var toScavenge = _indexMap.InOrder().ToList(); foreach (var pTable in toScavenge) { var startNew = Stopwatch.StartNew(); try { ct.ThrowIfCancellationRequested(); using (var reader = _tfReaderFactory()) { var indexmapFile = Path.Combine(_directory, IndexMapFilename); var scavengeResult = _indexMap.Scavenge(pTable.Id, ct, (streamId, currentHash) => UpgradeHash(streamId, currentHash), entry => reader.ExistsAt(entry.Position), entry => ReadEntry(reader, entry.Position), _fileNameProvider, _ptableVersion, _indexCacheDepth, _skipIndexVerify); if (scavengeResult.IsSuccess) { _indexMap = scavengeResult.ScavengedMap; _indexMap.SaveToFile(indexmapFile); scavengeResult.OldTable.MarkForDestruction(); var entriesDeleted = scavengeResult.OldTable.Count - scavengeResult.NewTable.Count; log.IndexTableScavenged(scavengeResult.Level, scavengeResult.Index, startNew.Elapsed, entriesDeleted, scavengeResult.NewTable.Count, scavengeResult.SpaceSaved); } else { log.IndexTableNotScavenged(scavengeResult.Level, scavengeResult.Index, startNew.Elapsed, pTable.Count, ""); } } } catch (OperationCanceledException) { log.IndexTableNotScavenged(-1, -1, startNew.Elapsed, pTable.Count, "Scavenge cancelled"); throw; } catch (Exception ex) { log.IndexTableNotScavenged(-1, -1, startNew.Elapsed, pTable.Count, ex.Message); throw; } } }
public void Scavenge(IIndexScavengerLog log, CancellationToken ct) { ScavengeCount++; }
public void Scavenge(IIndexScavengerLog log, CancellationToken ct) { throw new NotImplementedException(); }