use of com.ms.silverking.cloud.dht.NamespaceOptions in project SilverKing by Morgan-Stanley.
the class FileSegmentRecoverer method readPartialSegment.
/**
* Read a segment. Utility method only.
* @param segmentNumber
* @param displayEntries
* @param nsStore
* @return
*/
FileSegment readPartialSegment(int segmentNumber, boolean displayEntries) {
try {
DataSegmentWalker dsWalker;
FileSegment fileSegment;
DataSegmentWalkEntry lastEntry;
FileSegment.SyncMode syncMode;
NamespaceProperties nsProperties;
NamespaceOptions nsOptions;
// DataSegmentWalker dsWalker;
nsProperties = NamespacePropertiesIO.read(nsDir);
nsOptions = nsProperties.getOptions();
Log.warning("Reading partial segment: ", segmentNumber);
syncMode = nsOptions.getStorageType() == StorageType.FILE_SYNC ? FileSegment.SyncMode.Sync : FileSegment.SyncMode.NoSync;
fileSegment = FileSegment.openForRecovery(nsDir, segmentNumber, nsOptions.getSegmentSize(), syncMode, nsOptions);
fileSegment.addReference();
dsWalker = new DataSegmentWalker(fileSegment.dataBuf);
lastEntry = null;
for (DataSegmentWalkEntry entry : dsWalker) {
if (displayEntries || verbose) {
System.out.println(entry);
}
fileSegment._put(entry.getKey(), entry.getOffset(), entry.getVersion(), entry.getCreator().getBytes(), nsOptions);
// fileSegment.getPKC().put(entry.getKey(), entry.getOffset());
if (verbose) {
System.out.println("setting: " + entry.getOffset());
System.out.println("sanity check: " + fileSegment.getPKC().get(entry.getKey()));
}
lastEntry = entry;
}
if (lastEntry != null) {
if (displayEntries || verbose) {
System.out.println(lastEntry);
System.out.println("setting nextFree: " + lastEntry.nextEntryOffset());
}
fileSegment.setNextFree(lastEntry.nextEntryOffset());
} else {
fileSegment.setNextFree(SegmentFormat.headerSize);
}
Log.warning("Done reading partial segment: ", segmentNumber);
return fileSegment;
} catch (IOException ioe) {
Log.logErrorWarning(ioe, "Unable to read partial: " + segmentNumber);
Log.logErrorWarning(ioe);
return null;
}
}
use of com.ms.silverking.cloud.dht.NamespaceOptions in project SilverKing by Morgan-Stanley.
the class DataSegmentWalker method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
if (args.length != 2) {
System.out.println("args: <nsDir> <segmentNumber>");
return;
} else {
ByteBuffer dataBuf;
File nsDir;
int segmentNumber;
DataSegmentWalker dsWalker;
NamespaceProperties nsProperties;
NamespaceOptions nsOptions;
nsDir = new File(args[0]);
segmentNumber = Integer.parseInt(args[1]);
nsProperties = NamespacePropertiesIO.read(nsDir);
nsOptions = nsProperties.getOptions();
dataBuf = FileSegment.getDataSegment(nsDir, segmentNumber, nsOptions.getSegmentSize());
dsWalker = new DataSegmentWalker(dataBuf);
while (dsWalker.hasNext()) {
DataSegmentWalkEntry entry;
entry = dsWalker.next();
System.out.println(entry.getOffset() + " " + entry);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ms.silverking.cloud.dht.NamespaceOptions in project SilverKing by Morgan-Stanley.
the class FileSegmentCompactor method main.
public static void main(String[] args) {
try {
if (args.length != 3) {
System.out.println("args: <nsDir> <segmentNumber> <timeSpanSeconds>");
} else {
File nsDir;
int segmentNumber;
NamespaceOptions nsOptions;
ValueRetentionPolicy valueRetentionPolicy;
int timeSpanSeconds;
nsDir = new File(args[0]);
segmentNumber = Integer.parseInt(args[1]);
timeSpanSeconds = Integer.parseInt(args[2]);
valueRetentionPolicy = new TimeAndVersionRetentionPolicy(TimeAndVersionRetentionPolicy.Mode.wallClock, 1, timeSpanSeconds);
nsOptions = DHTConstants.defaultNamespaceOptions.valueRetentionPolicy(valueRetentionPolicy);
compact(nsDir, segmentNumber, nsOptions, new TestRetentionCheck(32768));
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ms.silverking.cloud.dht.NamespaceOptions in project SilverKing by Morgan-Stanley.
the class NamespaceOptionsClient method getNamespaceOptions.
public NamespaceOptions getNamespaceOptions(long namespace) throws RetrievalException {
if (namespace != NamespaceUtil.metaInfoNamespace.contextAsLong()) {
NamespaceOptions nsOptions;
nsOptions = systemNamespaceOptions.get(namespace);
if (nsOptions != null) {
return nsOptions;
} else {
String def;
def = null;
LWTThreadUtil.setBlocked();
try {
if (debug) {
System.out.printf("getNamespaceOptions(%x)\n", namespace);
}
def = syncNSP.get(getOptionsKey(namespace));
} finally {
LWTThreadUtil.setNonBlocked();
}
if (debug) {
System.out.printf("getNamespaceOptions def %s\n", def);
}
if (def != null) {
return NamespaceOptions.parse(def);
} else {
return null;
}
}
} else {
return NamespaceUtil.metaInfoNamespaceOptions;
}
}
Aggregations