Search in sources :

Example 1 with SSStorageParameters

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;
}
Also used : VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap)

Example 2 with SSStorageParameters

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);
}
Also used : StorageParameters(com.ms.silverking.cloud.dht.daemon.storage.StorageParameters) SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) Pair(com.ms.silverking.collection.Pair)

Example 3 with SSStorageParameters

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);
}
Also used : SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) Pair(com.ms.silverking.collection.Pair)

Example 4 with SSStorageParameters

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);
        }
    }
}
Also used : DirectoryInPlace(com.ms.silverking.cloud.skfs.dir.DirectoryInPlace) SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) IOException(java.io.IOException)

Example 5 with SSStorageParameters

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();
    }
}
Also used : StorageParameters(com.ms.silverking.cloud.dht.daemon.storage.StorageParameters) SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) DirectoryInPlace(com.ms.silverking.cloud.skfs.dir.DirectoryInPlace) SSStorageParameters(com.ms.silverking.cloud.dht.serverside.SSStorageParameters) ByteBuffer(java.nio.ByteBuffer) File(java.io.File)

Aggregations

SSStorageParameters (com.ms.silverking.cloud.dht.serverside.SSStorageParameters)7 StorageParameters (com.ms.silverking.cloud.dht.daemon.storage.StorageParameters)4 ByteBuffer (java.nio.ByteBuffer)3 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)2 DirectoryInPlace (com.ms.silverking.cloud.skfs.dir.DirectoryInPlace)2 Pair (com.ms.silverking.collection.Pair)2 IOException (java.io.IOException)2 File (java.io.File)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 TreeMap (java.util.TreeMap)1