Search in sources :

Example 11 with NamespaceProperties

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

Example 12 with NamespaceProperties

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

Example 13 with NamespaceProperties

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

Example 14 with NamespaceProperties

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();
    }
}
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 15 with NamespaceProperties

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

Aggregations

NamespaceProperties (com.ms.silverking.cloud.dht.common.NamespaceProperties)16 NamespaceOptions (com.ms.silverking.cloud.dht.NamespaceOptions)8 IOException (java.io.IOException)6 File (java.io.File)4 SimpleNamespaceCreator (com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator)3 ByteBuffer (java.nio.ByteBuffer)2 NamespaceServerSideCode (com.ms.silverking.cloud.dht.NamespaceServerSideCode)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 DHTKeyIntEntry (com.ms.silverking.cloud.dht.collection.DHTKeyIntEntry)1 TableFullException (com.ms.silverking.cloud.dht.collection.TableFullException)1 Context (com.ms.silverking.cloud.dht.common.Context)1 CorruptValueException (com.ms.silverking.cloud.dht.common.CorruptValueException)1 KeyAndInteger (com.ms.silverking.cloud.dht.common.KeyAndInteger)1 DataSegmentWalkEntry (com.ms.silverking.cloud.dht.daemon.storage.DataSegmentWalkEntry)1 DataSegmentWalker (com.ms.silverking.cloud.dht.daemon.storage.DataSegmentWalker)1 SegmentPrereadMode (com.ms.silverking.cloud.dht.daemon.storage.FileSegment.SegmentPrereadMode)1 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 SSNamespaceStore (com.ms.silverking.cloud.dht.serverside.SSNamespaceStore)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1