use of com.ms.silverking.cloud.skfs.dir.DirectoryInPlace in project SilverKing by Morgan-Stanley.
the class DirectoryInMemorySS method recover.
private void recover() {
List<Long> versions;
Log.warningf("Recovering directory from %s", sDir);
versions = FileUtil.numericFilesInDirAsSortedLongList(sDir);
for (long version : versions) {
try {
Pair<SSStorageParameters, byte[]> sd;
SerializedDirectory _sd;
DirectoryInPlace recoveredDir;
sd = readFromDisk(version);
_sd = new SerializedDirectory(sd);
serializedVersions.put(version, _sd);
latestUpdateSP = _sd.getStorageParameters();
recoveredDir = new DirectoryInPlace(sd.getV2(), 0, sd.getV2().length);
// recoveredDir.display();
super.update(recoveredDir);
// Log.warningf("Recovered version %d", version);
} catch (IOException ioe) {
Log.logErrorWarning(ioe, "Failed to recover " + sDir + " " + version);
}
}
}
use of com.ms.silverking.cloud.skfs.dir.DirectoryInPlace in project SilverKing by Morgan-Stanley.
the class DataMigrationTool method migrateEntry.
private void migrateEntry(DataSegmentWalkEntry entry, File ssDir) throws IOException {
ByteBuffer valueBuf;
byte[] value;
File dirDir;
StorageParameters newSP;
StorageParameters o;
// System.out.printf("\n ------------- \n%s\n", StringUtil.byteBufferToHexString(entry.getStoredFormat()));
valueBuf = entry.getValue();
value = BufferUtil.arrayCopy(valueBuf);
// System.out.printf("\n......... \n%s\n", StringUtil.byteArrayToHexString(value));
File destFile;
dirDir = new File(ssDir, KeyUtil.keyToString(entry.getKey()));
if (!dirDir.exists()) {
if (!dirDir.mkdir()) {
throw new RuntimeException("Unable to create: " + dirDir);
}
}
o = entry.getStorageParameters();
newSP = new StorageParameters(o.getVersion(), value.length, value.length, CCSSUtil.createCCSS(Compression.NONE, o.getChecksumType(), o.getStorageState()), o.getChecksum(), o.getValueCreator(), o.getCreationTime());
destFile = new File(dirDir, Long.toString(entry.getVersion()));
FileUtil.writeToFile(destFile, StorageParameterSerializer.serialize(newSP), value);
if (displayDirs) {
DirectoryInMemorySS dim;
Pair<SSStorageParameters, byte[]> p;
DirectoryInPlace dip;
dim = new DirectoryInMemorySS(entry.getKey(), null, entry.getStorageParameters(), new File(ssDir, KeyUtil.keyToString(entry.getKey())), null, false);
p = dim.readFromDisk(entry.getStorageParameters().getVersion());
System.out.println(p.getV1());
// System.out.println(StringUtil.byteArrayToHexString(p.getV2()));
dip = new DirectoryInPlace(p.getV2(), 0, p.getV2().length);
dip.display();
}
}
use of com.ms.silverking.cloud.skfs.dir.DirectoryInPlace in project SilverKing by Morgan-Stanley.
the class DirectoryServer method put.
@Override
public OpResult put(SSNamespaceStore nsStore, DHTKey key, ByteBuffer value, SSStorageParameters storageParams, byte[] userData, NamespaceVersionMode nsVersionMode) {
byte[] buf;
int bufOffset;
int bufLimit;
DirectoryInMemorySS existingDir;
DirectoryInPlace updateDir;
// Log.warningf("DirectoryServer.put() %s %s %s %s %s", KeyUtil.keyToString(key), stringToKeyString("/"), stringToKeyString("/skfs"), value.hasArray(), storageParams.getCompression());
buf = value.array();
bufOffset = value.arrayOffset();
bufLimit = bufOffset + value.limit();
if (storageParams.getCompression() == Compression.NONE) {
// System.out.printf("No compression\n");
} else {
try {
int dataOffset;
// System.out.printf("Compression\n");
dataOffset = value.position();
buf = CompressionUtil.decompress(storageParams.getCompression(), value.array(), dataOffset, storageParams.getCompressedSize(), storageParams.getUncompressedSize());
bufOffset = 0;
bufLimit = buf.length;
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
return OpResult.ERROR;
}
}
updateDir = new DirectoryInPlace(buf, bufOffset, bufLimit);
existingDir = directories.get(key);
if (existingDir == null) {
DirectoryInMemorySS newDir;
newDir = new DirectoryInMemorySS(key, updateDir, storageParams, new File(logDir, KeyUtil.keyToString(key)), nsStore.getNamespaceOptions());
directories.put(key, newDir);
} else {
existingDir.update(updateDir, storageParams);
}
return OpResult.SUCCEEDED;
}
Aggregations