use of com.ms.silverking.cloud.dht.serverside.SSStorageParameters in project SilverKing by Morgan-Stanley.
the class DirectoryInMemorySS method retrieve.
public ByteBuffer retrieve(SSRetrievalOptions options) {
ByteBuffer rVal;
VersionConstraint vc;
SerializedDirectory sd;
Pair<SSStorageParameters, byte[]> sdp;
vc = options.getVersionConstraint();
if (vc.equals(VersionConstraint.greatest)) {
sd = serializedVersions.get(latestUpdateSP.getVersion());
} else {
Map.Entry<Long, SerializedDirectory> entry;
// For directories, versions must be ascending, max creation time not allowed in vc
if (vc.getMode().equals(VersionConstraint.Mode.GREATEST)) {
entry = serializedVersions.floorEntry(vc.getMax());
if (entry != null && entry.getKey() < vc.getMin()) {
entry = null;
}
} else {
entry = serializedVersions.ceilingEntry(vc.getMin());
if (entry != null && entry.getKey() > vc.getMax()) {
entry = null;
}
}
if (entry != null) {
sd = entry.getValue();
} else {
sd = null;
}
}
if (sd != null) {
try {
sdp = sd.readDir();
rVal = SSUtil.retrievalResultBufferFromValue(sdp.getV2(), StorageParameters.fromSSStorageParameters(sdp.getV1()));
return rVal;
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
}
}
return null;
}
use of com.ms.silverking.cloud.dht.serverside.SSStorageParameters in project SilverKing by Morgan-Stanley.
the class DirectoryInMemorySS method serializeDir.
/*
public DirectoryInMemorySS(byte[] buf, int offset, int limit, SSStorageParameters storageParams) {
super(buf, offset, limit);
this.storageParams = storageParams;
}
*/
public Pair<SSStorageParameters, byte[]> serializeDir() {
byte[] serializedDir;
StorageParameters sp;
byte[] checksum;
serializedDir = serialize();
checksum = new byte[0];
sp = new StorageParameters(latestUpdateSP.getVersion(), serializedDir.length, serializedDir.length, CCSSUtil.createCCSS(Compression.NONE, ChecksumType.NONE), checksum, latestUpdateSP.getValueCreator(), latestUpdateSP.getCreationTime());
return new Pair<>(sp, serializedDir);
}
use of com.ms.silverking.cloud.dht.serverside.SSStorageParameters in project SilverKing by Morgan-Stanley.
the class DirectoryInMemorySS method readFromDisk.
Pair<SSStorageParameters, byte[]> readFromDisk(long version) throws IOException {
byte[] b;
SSStorageParameters sp;
byte[] serializedDir;
int spLength;
b = FileUtil.readFileAsBytes(fileForVersion(version));
sp = StorageParameterSerializer.deserialize(b);
spLength = StorageParameterSerializer.getSerializedLength(sp);
serializedDir = new byte[b.length - spLength];
System.arraycopy(b, spLength, serializedDir, 0, b.length - spLength);
return new Pair<>(sp, serializedDir);
}
use of com.ms.silverking.cloud.dht.serverside.SSStorageParameters 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.dht.serverside.SSStorageParameters 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();
}
}
Aggregations