예제 #1
0
        public ScavengeResult Scavenge <TStreamId>(Guid toScavenge, CancellationToken ct,
                                                   Func <TStreamId, ulong, ulong> upgradeHash,
                                                   Func <IndexEntry, bool> existsAt,
                                                   Func <IndexEntry, Tuple <TStreamId, bool> > recordExistsAt,
                                                   IIndexFilenameProvider filenameProvider,
                                                   byte version,
                                                   int indexCacheDepth  = 16,
                                                   bool skipIndexVerify = false,
                                                   bool useBloomFilter  = true,
                                                   int lruCacheSize     = 1_000_000)
        {
            var scavengedMap = CopyFrom(_map);

            for (int level = 0; level < scavengedMap.Count; level++)
            {
                for (int i = 0; i < scavengedMap[level].Count; i++)
                {
                    if (scavengedMap[level][i].Id == toScavenge)
                    {
                        long spaceSaved;
                        var  filename = filenameProvider.GetFilenameNewTable();
                        var  oldTable = scavengedMap[level][i];

                        PTable scavenged = PTable.Scavenged(oldTable, filename, upgradeHash, existsAt, recordExistsAt,
                                                            version, out spaceSaved, ESConsts.PTableInitialReaderCount, _pTableMaxReaderCount, indexCacheDepth, skipIndexVerify, useBloomFilter, lruCacheSize, ct);

                        if (scavenged == null)
                        {
                            return(ScavengeResult.Failed(oldTable, level, i));
                        }

                        scavengedMap[level][i] = scavenged;

                        var indexMap = new IndexMap(Version, scavengedMap, PrepareCheckpoint, CommitCheckpoint,
                                                    _maxTablesPerLevel, _maxTableLevelsForAutomaticMerge, _pTableMaxReaderCount);

                        return(ScavengeResult.Success(indexMap, oldTable, scavenged, spaceSaved, level, i));
                    }
                }
            }

            throw new ArgumentException("Unable to find table in map.", nameof(toScavenge));
        }
예제 #2
0
        public ScavengeResult Scavenge(Guid toScavenge, CancellationToken ct,
                                       Func <string, ulong, ulong> upgradeHash,
                                       Func <IndexEntry, bool> existsAt,
                                       Func <IndexEntry, Tuple <string, bool> > recordExistsAt,
                                       IIndexFilenameProvider filenameProvider,
                                       byte version,
                                       int indexCacheDepth  = 16,
                                       bool skipIndexVerify = false)
        {
            var scavengedMap = CopyFrom(_map);

            for (int level = 0; level < scavengedMap.Count; level++)
            {
                for (int i = 0; i < scavengedMap[level].Count; i++)
                {
                    if (scavengedMap[level][i].Id == toScavenge)
                    {
                        long spaceSaved;
                        var  filename = filenameProvider.GetFilenameNewTable();
                        var  oldTable = scavengedMap[level][i];

                        PTable scavenged = PTable.Scavenged(oldTable, filename, upgradeHash, existsAt, recordExistsAt, version, out spaceSaved, indexCacheDepth, skipIndexVerify, ct);

                        if (scavenged == null)
                        {
                            return(ScavengeResult.Failed(oldTable, level, i));
                        }

                        scavengedMap[level][i] = scavenged;

                        var indexMap = new IndexMap(Version, scavengedMap, PrepareCheckpoint, CommitCheckpoint, _maxTablesPerLevel);

                        return(ScavengeResult.Success(indexMap, oldTable, scavenged, spaceSaved, level, i));
                    }
                }
            }

            throw new ArgumentException("Unable to find table in map.", nameof(toScavenge));
        }