Search in sources :

Example 1 with SimpleNamespaceCreator

use of com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator in project SilverKing by Morgan-Stanley.

the class StorageModule method recoverExistingNamespace.

private void recoverExistingNamespace(File nsDir) throws IOException {
    try {
        long ns;
        NamespaceProperties nsProperties;
        NamespaceStore parent;
        NamespaceStore nsStore;
        Log.warning("\t\tRecovering: " + nsDir.getName());
        ns = NumConversion.parseHexStringAsUnsignedLong(nsDir.getName());
        nsProperties = NamespacePropertiesIO.read(nsDir);
        nsMetaStore.setNamespaceProperties(ns, nsProperties);
        if (nsProperties.getParent() != null) {
            long parentContext;
            parentContext = new SimpleNamespaceCreator().createNamespace(nsProperties.getParent()).contextAsLong();
            parent = namespaces.get(parentContext);
            if (parent == null) {
                throw new RuntimeException("Unexpected parent not found: " + parentContext);
            }
        } else {
            parent = null;
        }
        nsStore = NamespaceStore.recoverExisting(ns, nsDir, parent, null, mgBase, ringMaster, activeRetrievals, zk, nsLinkBasePath, this);
        namespaces.put(ns, nsStore);
        nsStore.startWatches(zk, nsLinkBasePath, this);
        Log.warning("\t\tDone recovering: " + nsDir.getName());
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        Log.warning("Recovery ignoring unexpected nsDir: ", nsDir);
    }
}
Also used : NamespaceProperties(com.ms.silverking.cloud.dht.common.NamespaceProperties) SimpleNamespaceCreator(com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator)

Example 2 with SimpleNamespaceCreator

use of com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator 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 3 with SimpleNamespaceCreator

use of com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator 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 4 with SimpleNamespaceCreator

use of com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator in project SilverKing by Morgan-Stanley.

the class NamespaceLinksZK method writeToZK.

public void writeToZK(String child, String parent) throws IOException, KeeperException {
    String basePath;
    long childContext;
    long parentContext;
    basePath = mc.getMetaPaths().getInstanceNSLinkPath();
    zk.createString(basePath + "/" + child, parent);
    childContext = new SimpleNamespaceCreator().createNamespace(child).contextAsLong();
    parentContext = new SimpleNamespaceCreator().createNamespace(parent).contextAsLong();
    zk.createString(basePath + "/" + Long.toHexString(childContext), Long.toHexString(parentContext));
}
Also used : SimpleNamespaceCreator(com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator)

Aggregations

SimpleNamespaceCreator (com.ms.silverking.cloud.dht.client.impl.SimpleNamespaceCreator)4 NamespaceProperties (com.ms.silverking.cloud.dht.common.NamespaceProperties)3 File (java.io.File)2