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;
}
Aggregations