Search in sources :

Example 1 with HashedSetMap

use of com.ms.silverking.collection.HashedSetMap in project SilverKing by Morgan-Stanley.

the class NamespaceStore method singleReverseSegmentWalk.

public <T extends ValueRetentionState> void singleReverseSegmentWalk(ValueRetentionPolicy<T> vrp, T valueRetentionState, long curTimeNanos) {
    Set<Integer> deletedSegments;
    HashedSetMap<DHTKey, Triple<Long, Integer, Long>> removedEntries;
    removedEntries = new HashedSetMap<>();
    deletedSegments = new HashSet<>();
    for (int i = headSegment.getSegmentNumber() - 1; i >= 0; i--) {
        if (segmentExists(i)) {
            Triple<CompactionCheckResult, Set<Integer>, Set<Integer>> result;
            WritableSegmentBase segment;
            CompactionCheckResult ccr;
            try {
                Stopwatch sw;
                sw = new SimpleStopwatch();
                if (nsOptions.getStorageType() == StorageType.RAM) {
                    segment = getSegment(i, SegmentPrereadMode.Preread);
                } else {
                    segment = getSegment(i, SegmentPrereadMode.Preread);
                // segment = FileSegment.openReadOnly(nsDir, i, nsOptions.getSegmentSize(), nsOptions, SegmentIndexLocation.RAM, SegmentPrereadMode.Preread);
                }
                try {
                    result = segment.singleReverseSegmentWalk(vrp, valueRetentionState, curTimeNanos, ringMaster);
                    ccr = result.getV1();
                } finally {
                    if (nsOptions.getStorageType() == StorageType.FILE) {
                        if (segment.getSegmentNumber() != headSegment.getSegmentNumber()) {
                            ((FileSegment) segment).removeReference();
                        }
                    }
                }
                Log.warningAsyncf("Segment %3d CompactionCheckResult:\t%s", i, ccr.toString());
                if (segment.getSegmentNumber() == headSegment.getSegmentNumber()) {
                    Log.warningAsyncf("Retaining head segment");
                } else {
                    if (ccr.getValidEntries() == 0) {
                        try {
                            recentFileSegments.remove(i);
                            FileSegmentCompactor.delete(nsDir, i);
                            deletedSegments.add(i);
                            if (FileSegment.mapEverything) {
                                ((FileSegment) segment).close();
                            }
                        } catch (IOException ioe) {
                            Log.logErrorWarning(ioe, "Failed to delete segment: " + i);
                        }
                    } else if (ccr.getInvalidFraction() >= compactionThreshold) {
                        try {
                            HashedSetMap<DHTKey, Triple<Long, Integer, Long>> segmentRemovedEntries;
                            recentFileSegments.remove(i);
                            segmentRemovedEntries = FileSegmentCompactor.compact(nsDir, i, nsOptions, new RetainedOffsetMapCheck(result.getV2(), result.getV3()));
                            removedEntries.addAll(segmentRemovedEntries);
                        } catch (IOException ioe) {
                            Log.logErrorWarning(ioe, "IOException compacting segment: " + i);
                        }
                    }
                }
                sw.stop();
                Log.warningAsyncf("\t\t%d %f", i, sw.getElapsedSeconds());
            } catch (Exception e) {
                Log.logErrorWarning(e, "Skipping segment " + i + " due to Exception");
            }
        }
    }
    updateOffsetLists(deletedSegments, removedEntries);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) IOException(java.io.IOException) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) CorruptValueException(com.ms.silverking.cloud.dht.common.CorruptValueException) IOException(java.io.IOException) TableFullException(com.ms.silverking.cloud.dht.collection.TableFullException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyAndInteger(com.ms.silverking.cloud.dht.common.KeyAndInteger) Triple(com.ms.silverking.collection.Triple) HashedSetMap(com.ms.silverking.collection.HashedSetMap)

Aggregations

VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 TableFullException (com.ms.silverking.cloud.dht.collection.TableFullException)1 CorruptValueException (com.ms.silverking.cloud.dht.common.CorruptValueException)1 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)1 KeyAndInteger (com.ms.silverking.cloud.dht.common.KeyAndInteger)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 HashedSetMap (com.ms.silverking.collection.HashedSetMap)1 Triple (com.ms.silverking.collection.Triple)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1