Search in sources :

Example 21 with NamespaceOptions

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;
    }
}
Also used : NamespaceOptions(com.ms.silverking.cloud.dht.NamespaceOptions) NamespaceProperties(com.ms.silverking.cloud.dht.common.NamespaceProperties) IOException(java.io.IOException)

Example 22 with NamespaceOptions

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();
    }
}
Also used : NamespaceOptions(com.ms.silverking.cloud.dht.NamespaceOptions) NamespaceProperties(com.ms.silverking.cloud.dht.common.NamespaceProperties) ByteBuffer(java.nio.ByteBuffer) File(java.io.File)

Example 23 with NamespaceOptions

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();
    }
}
Also used : NamespaceOptions(com.ms.silverking.cloud.dht.NamespaceOptions) ValueRetentionPolicy(com.ms.silverking.cloud.dht.ValueRetentionPolicy) File(java.io.File) TimeAndVersionRetentionPolicy(com.ms.silverking.cloud.dht.TimeAndVersionRetentionPolicy) IOException(java.io.IOException)

Example 24 with NamespaceOptions

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;
    }
}
Also used : NamespaceOptions(com.ms.silverking.cloud.dht.NamespaceOptions)

Aggregations

NamespaceOptions (com.ms.silverking.cloud.dht.NamespaceOptions)24 NamespaceProperties (com.ms.silverking.cloud.dht.common.NamespaceProperties)8 IOException (java.io.IOException)7 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)4 File (java.io.File)4 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)3 ByteBuffer (java.nio.ByteBuffer)2 NamespaceServerSideCode (com.ms.silverking.cloud.dht.NamespaceServerSideCode)1 SecondaryTarget (com.ms.silverking.cloud.dht.SecondaryTarget)1 TimeAndVersionRetentionPolicy (com.ms.silverking.cloud.dht.TimeAndVersionRetentionPolicy)1 ValueRetentionPolicy (com.ms.silverking.cloud.dht.ValueRetentionPolicy)1 DHTKeyIntEntry (com.ms.silverking.cloud.dht.collection.DHTKeyIntEntry)1 Context (com.ms.silverking.cloud.dht.common.Context)1 DataSegmentWalkEntry (com.ms.silverking.cloud.dht.daemon.storage.DataSegmentWalkEntry)1 DataSegmentWalker (com.ms.silverking.cloud.dht.daemon.storage.DataSegmentWalker)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 FileNotFoundException (java.io.FileNotFoundException)1 Date (java.util.Date)1 Test (org.junit.Test)1