Search in sources :

Example 1 with SegmentPrereadMode

use of com.ms.silverking.cloud.dht.daemon.storage.FileSegment.SegmentPrereadMode in project SilverKing by Morgan-Stanley.

the class NamespaceStore method recoverExisting.

static NamespaceStore recoverExisting(long ns, File nsDir, NamespaceStore parent, StoragePolicy storagePolicy, MessageGroupBase mgBase, NodeRingMaster2 ringMaster, ConcurrentMap<UUIDBase, ActiveProxyRetrieval> activeRetrievals, ZooKeeperExtended zk, String nsLinkBasePath, LinkCreationListener linkCreationListener) {
    NamespaceStore nsStore;
    NamespaceProperties nsProperties;
    int numSegmentsToPreread;
    int numSegmentsToSkipPreread;
    int segmentsPrereadSkipped;
    if (ns == NamespaceUtil.metaInfoNamespace.contextAsLong()) {
        nsProperties = NamespaceUtil.metaInfoNamespaceProperties;
    } else {
        try {
            nsProperties = NamespacePropertiesIO.read(nsDir);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
    nsStore = new NamespaceStore(ns, nsDir, NamespaceStore.DirCreationMode.DoNotCreateNSDir, nsProperties, parent, mgBase, ringMaster, true, activeRetrievals);
    if (nsProperties.getOptions().getStorageType() != StorageType.RAM) {
        List<Integer> segmentNumbers;
        segmentNumbers = FileUtil.numericFilesInDirAsSortedIntegerList(nsDir);
        if (segmentNumbers.size() > 0) {
            FileSegmentRecoverer fsr;
            int headSegmentNumber;
            int headSegmentNumberIndex;
            fsr = new FileSegmentRecoverer(nsDir);
            headSegmentNumberIndex = segmentNumbers.size() - 1;
            headSegmentNumber = segmentNumbers.get(headSegmentNumberIndex);
            segmentNumbers.remove(headSegmentNumberIndex);
            numSegmentsToPreread = (int) ((long) nsPrereadGB * (1024L * 1024L * 1024L) / (long) (nsProperties.getOptions().getSegmentSize()));
            numSegmentsToSkipPreread = segmentNumbers.size() - numSegmentsToPreread;
            segmentsPrereadSkipped = 0;
            Log.warningf("segmentsToPreread: %d", numSegmentsToPreread);
            for (int i : segmentNumbers) {
                FileSegment segment;
                SegmentPrereadMode segmentPrereadMode;
                segmentPrereadMode = segmentsPrereadSkipped < numSegmentsToSkipPreread ? SegmentPrereadMode.NoPreread : SegmentPrereadMode.Preread;
                segment = null;
                try {
                    segment = fsr.recoverFullSegment(i, nsStore, segmentIndexLocation, segmentPrereadMode);
                } catch (Exception e) {
                    Log.logErrorWarning(e, "Error recovering full segment " + i);
                    Log.warningf("Attempting partial segment recovery of segment: %d %s", i, segmentPrereadMode);
                    segment = fsr.readPartialSegment(i, false);
                    Log.warning("Successfully read segment as partial segment: " + i);
                    Log.warning("Persisting segment: " + i);
                    try {
                        segment.persist();
                    } catch (IOException ioe) {
                        throw new RuntimeException("Segment persists failed for recovered segment" + i, ioe);
                    }
                    Log.warning("Persisted segment: " + i);
                    Log.warning("Resuming full segment recovery: " + i);
                    segment = fsr.recoverFullSegment(i, nsStore, segmentIndexLocation, segmentPrereadMode);
                }
                if (segmentPrereadMode == SegmentPrereadMode.Preread && segment != null) {
                    nsStore.addRecentFileSegment(i, segment);
                }
                segmentsPrereadSkipped++;
            }
            // Check for partial recovery on last
            // FUTURE - Check for corruption
            // FUTURE - If full, then do full recovery?
            nsStore.setHeadSegment(fsr.recoverPartialSegment(headSegmentNumber, nsStore));
        } else {
            nsStore.createInitialHeadSegment();
        }
    } else {
        nsStore.initRAMSegments();
    }
    return nsStore;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyAndInteger(com.ms.silverking.cloud.dht.common.KeyAndInteger) SegmentPrereadMode(com.ms.silverking.cloud.dht.daemon.storage.FileSegment.SegmentPrereadMode) NamespaceProperties(com.ms.silverking.cloud.dht.common.NamespaceProperties) SSNamespaceStore(com.ms.silverking.cloud.dht.serverside.SSNamespaceStore) IOException(java.io.IOException) 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)

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 KeyAndInteger (com.ms.silverking.cloud.dht.common.KeyAndInteger)1 NamespaceProperties (com.ms.silverking.cloud.dht.common.NamespaceProperties)1 SegmentPrereadMode (com.ms.silverking.cloud.dht.daemon.storage.FileSegment.SegmentPrereadMode)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 SSNamespaceStore (com.ms.silverking.cloud.dht.serverside.SSNamespaceStore)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1