Search in sources :

Example 1 with DHTRingCurTargetZK

use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.

the class DependencyWatcher method setRing.

private void setRing(long ringConfigVersion) throws KeeperException {
    long configInstanceVersion;
    String newInstancePath;
    DHTRingCurTargetZK dhtRingCurTargetZK;
    String ringName;
    configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
    mc.getLatestConfigInstanceVersion(ringConfigVersion);
    dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtMC.getDHTConfiguration());
    ringName = dhtMC.getDHTConfiguration().getRingName();
    dhtRingCurTargetZK.setCurRingAndVersionPair(ringName, ringConfigVersion, configInstanceVersion);
    dhtRingCurTargetZK.setTargetRingAndVersionPair(ringName, ringConfigVersion, configInstanceVersion);
    Log.warningf("Ring %s config %d instance %d", ringName, ringConfigVersion, configInstanceVersion);
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)

Example 2 with DHTRingCurTargetZK

use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.

the class SKAdmin method getRing.

private static Pair<RingConfiguration, InstantiatedRingTree> getRing(DHTConfiguration dhtConfig, com.ms.silverking.cloud.dht.meta.MetaClient dhtMC) throws IOException, KeeperException {
    String ringName;
    Pair<Long, Long> ringVersion;
    DHTRingCurTargetZK dhtRingCurTargetZK;
    Triple<String, Long, Long> curRingNameAndVersion;
    RingConfiguration ringConfig;
    RingConfigurationZK ringConfigZK;
    InstantiatedRingTree ringTree;
    com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
    dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
    curRingNameAndVersion = dhtRingCurTargetZK.getCurRingAndVersionPair();
    if (curRingNameAndVersion == null) {
        return null;
    }
    ringName = curRingNameAndVersion.getHead();
    ringVersion = curRingNameAndVersion.getTail();
    ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion.getV1(), dhtMC.getZooKeeper().getZKConfig());
    ringConfigZK = new RingConfigurationZK(ringMC);
    ringConfig = ringConfigZK.readFromZK(ringVersion.getV1(), null);
    // ringTree = SingleRingZK.readTree(ringMC, ringVersion);
    // FUTURE - think about whether or not we should keep this, currently unused
    ringTree = null;
    return new Pair<>(ringConfig, ringTree);
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) Pair(com.ms.silverking.collection.Pair)

Example 3 with DHTRingCurTargetZK

use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.

the class EmbeddedSK method createEmbeddedSKInstance.

public static ClientDHTConfiguration createEmbeddedSKInstance(String dhtName, String gridConfigName, String ringName, int replication) {
    try {
        int zkPort;
        Path tempDir;
        File zkDir;
        File skDir;
        ZooKeeperConfig zkConfig;
        // 0) Create LWT work pools
        LWTPoolProvider.createDefaultWorkPools();
        // 1) Start an embedded ZooKeeper
        Log.warning("Creating embedded ZooKeeper");
        try {
            tempDir = Files.createTempDirectory(null);
            zkDir = new File(tempDir.toFile(), "zookeeper");
            zkDir.mkdirs();
            skDir = new File(tempDir.toFile(), "silverking");
            skDir.mkdirs();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
        zkPort = LocalZKImpl.startLocalZK(zkDir.getAbsolutePath());
        zkConfig = new ZooKeeperConfig(InetAddress.getLoopbackAddress().getHostAddress() + ":" + zkPort);
        Log.warning("Embedded ZooKeeper running at: " + zkConfig);
        DHTNodeConfiguration.setDataBasePath(skDir.getAbsolutePath() + "/data");
        // 2) Create ring in ZK
        Log.warning("Creating ring");
        StaticRingCreator.createStaticRing(ringName, zkConfig, ImmutableSet.of(IPAddrUtil.localIPString()), replication);
        Log.warning("Created: " + ringName);
        // 3) Create DHT Config in ZK
        DHTConfiguration dhtConfig;
        MetaClient dhtMC;
        DHTConfigurationZK dhtConfigZK;
        ClientDHTConfiguration clientDHTConfig;
        int dhtPort;
        Log.warning("Creating DHT configuration in ZK");
        if (skPort <= 0) {
            // FIXME
            dhtPort = ThreadLocalRandom.current().nextInt(10000, 20000);
        } else {
            dhtPort = skPort;
        }
        clientDHTConfig = new ClientDHTConfiguration(dhtName, dhtPort, zkConfig);
        dhtMC = new MetaClient(clientDHTConfig);
        dhtConfigZK = new DHTConfigurationZK(dhtMC);
        dhtConfig = DHTConfiguration.emptyTemplate.ringName(ringName).port(dhtPort).passiveNodeHostGroups("").hostGroupToClassVarsMap(new HashMap<String, String>());
        dhtConfigZK.writeToZK(dhtConfig, null);
        Log.warning("Created DHT configuration in ZK");
        // 4) Set cur and target rings
        DHTRingCurTargetZK curTargetZK;
        Log.warning("Setting ring targets");
        curTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
        curTargetZK.setCurRingAndVersionPair(ringName, 0, 0);
        curTargetZK.setTargetRingAndVersionPair(ringName, 0, 0);
        Log.warning("Ring targets set");
        // 4) Start DHTNode
        Log.warning("Starting DHTNode");
        new DHTNode(dhtName, zkConfig, 0, false, false);
        Log.warning("DHTNode started");
        // 5) Return the configuration to the caller
        return clientDHTConfig;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) DHTConfiguration(com.ms.silverking.cloud.dht.meta.DHTConfiguration) IOException(java.io.IOException) DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) DHTConfigurationZK(com.ms.silverking.cloud.dht.meta.DHTConfigurationZK) DHTNode(com.ms.silverking.cloud.dht.daemon.DHTNode) File(java.io.File)

Example 4 with DHTRingCurTargetZK

use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.

the class MasterModeDependencyWatcher method readMasterRingTree.

private Pair<RingTree, Triple<String, Long, Long>> readMasterRingTree(com.ms.silverking.cloud.dht.meta.MetaClient dhtMC, DHTConfiguration dhtConfig) throws KeeperException, IOException {
    DHTRingCurTargetZK dhtRingCurTargetZK;
    Triple<String, Long, Long> masterRingAndVersionPair;
    RingTree ringTree;
    dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
    masterRingAndVersionPair = dhtRingCurTargetZK.getMasterRingAndVersionPair();
    if (masterRingAndVersionPair == null) {
        throw new RuntimeException("Can't find master ring");
    } else {
        ringTree = SingleRingZK.readTree(mc, masterRingAndVersionPair.getV2(), masterRingAndVersionPair.getV3());
        return new Pair<>(ringTree, masterRingAndVersionPair);
    }
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) Pair(com.ms.silverking.collection.Pair)

Example 5 with DHTRingCurTargetZK

use of com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK in project SilverKing by Morgan-Stanley.

the class SKAdmin method verifyServerEligibility.

private void verifyServerEligibility(Set<String> servers, SKAdminCommand[] commands) throws KeeperException {
    if (Arrays.contains(commands, SKAdminCommand.StartNodes)) {
        Set<String> candidateServers;
        Set<String> ineligibleServers;
        DHTRingCurTargetZK dhtRingCurTargetZK;
        InstanceExclusionZK instanceExclusionZK;
        dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtMC.getDHTConfiguration());
        instanceExclusionZK = new InstanceExclusionZK(dhtMC);
        Log.warning("Verifying server eligibility for start");
        candidateServers = new HashSet<>(servers);
        ineligibleServers = HealthMonitor.removeIneligibleServers(candidateServers, dhtRingCurTargetZK, instanceExclusionZK);
        if (ineligibleServers.size() > 0) {
            for (String ineligibleServer : ineligibleServers) {
                Log.warning("Ineligible server: ", ineligibleServer);
            }
            if (!options.forceInclusionOfUnsafeExcludedServers) {
                throw new IneligibleServerException("Attempted to start ineligible servers: " + CollectionUtil.toString(ineligibleServers, ','));
            } else {
                Log.countdownWarning("*** Including unsafe excluded servers. This may result in data loss ***", unsafeWarningCountdown);
            }
        } else {
            Log.warning("Server eligibility verified");
        }
    }
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) IneligibleServerException(com.ms.silverking.cloud.dht.meta.IneligibleServerException) InstanceExclusionZK(com.ms.silverking.cloud.dht.meta.InstanceExclusionZK)

Aggregations

DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)8 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)2 NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)2 Pair (com.ms.silverking.collection.Pair)2 DHTNode (com.ms.silverking.cloud.dht.daemon.DHTNode)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 DHTConfiguration (com.ms.silverking.cloud.dht.meta.DHTConfiguration)1 DHTConfigurationZK (com.ms.silverking.cloud.dht.meta.DHTConfigurationZK)1 IneligibleServerException (com.ms.silverking.cloud.dht.meta.IneligibleServerException)1 InstanceExclusionZK (com.ms.silverking.cloud.dht.meta.InstanceExclusionZK)1 MetaClient (com.ms.silverking.cloud.dht.meta.MetaClient)1 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)1 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)1 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 KeeperException (org.apache.zookeeper.KeeperException)1