use of com.ms.silverking.cloud.dht.common.NamespaceProperties in project SilverKing by Morgan-Stanley.
the class StorageModule method getNamespaceStore.
private NamespaceStore getNamespaceStore(long ns, NSCreationMode mode) {
NamespaceStore nsStore;
nsStore = namespaces.get(ns);
if (nsStore == null && mode == NSCreationMode.CreateIfAbsent) {
NamespaceStore old;
boolean created;
NamespaceProperties nsProperties;
nsProperties = nsMetaStore.getNamespaceProperties(ns, NamespaceOptionsRetrievalMode.FetchRemotely);
created = false;
// FUTURE - could make this lock finer grained
LWTThreadUtil.setBlocked();
nsCreationLock.lock();
try {
nsStore = namespaces.get(ns);
if (nsStore == null) {
NamespaceStore parent;
if (nsProperties.getParent() != null) {
long parentNS;
parentNS = new SimpleNamespaceCreator().createNamespace(nsProperties.getParent()).contextAsLong();
LWTThreadUtil.setNonBlocked();
nsCreationLock.unlock();
try {
parent = getNamespaceStore(parentNS, NSCreationMode.CreateIfAbsent);
} finally {
LWTThreadUtil.setBlocked();
nsCreationLock.lock();
}
if (parent == null) {
throw new RuntimeException("Unexpected parent not created: " + Long.toHexString(ns));
}
} else {
parent = null;
}
created = true;
nsStore = new NamespaceStore(ns, new File(baseDir, Long.toHexString(ns)), NamespaceStore.DirCreationMode.CreateNSDir, // spGroup.getRootPolicy(),
nsProperties, parent, mgBase, ringMaster, false, activeRetrievals);
} else {
created = false;
}
} finally {
nsCreationLock.unlock();
LWTThreadUtil.setNonBlocked();
}
if (created) {
old = namespaces.putIfAbsent(ns, nsStore);
if (old != null) {
nsStore = old;
} else {
Log.warning("Created new namespace store: " + Long.toHexString(ns));
nsStore.startWatches(zk, nsLinkBasePath, this);
}
}
}
return nsStore;
}
use of com.ms.silverking.cloud.dht.common.NamespaceProperties in project SilverKing by Morgan-Stanley.
the class StorageModule method addDirAndParents.
private void addDirAndParents(List<File> sorted, File childDir) throws IOException {
if (!sorted.contains(childDir)) {
NamespaceProperties nsProperties;
String parentName;
nsProperties = NamespacePropertiesIO.read(childDir);
parentName = nsProperties.getParent();
if (parentName != null) {
long parentContext;
File parentDir;
parentContext = new SimpleNamespaceCreator().createNamespace(parentName).contextAsLong();
parentDir = new File(baseDir, Long.toHexString(parentContext));
addDirAndParents(sorted, parentDir);
}
sorted.add(childDir);
}
}
use of com.ms.silverking.cloud.dht.common.NamespaceProperties 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.common.NamespaceProperties 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.common.NamespaceProperties in project SilverKing by Morgan-Stanley.
the class FileSegmentUtil method readNamespaceOptions.
private static NamespaceOptions readNamespaceOptions(File nsDir) {
try {
NamespaceProperties nsProperties;
nsProperties = NamespacePropertiesIO.read(nsDir);
return nsProperties.getOptions();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
Aggregations