Search in sources :

Example 1 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class DependencyWatcher method build.

private void build(Map<String, Long> curBuild) {
    try {
        boolean buildOK;
        long ringConfigVersion;
        Log.warning("New build triggered");
        buildOK = false;
        ringConfigVersion = -1;
        try {
            if (TopoRingConstants.verbose) {
                System.out.println("Building tree");
            }
            RingTreeRecipe recipe;
            Topology topology;
            WeightSpecifications weightSpecs;
            ExclusionSet exclusionSet;
            ExclusionSet instanceExclusionSet;
            StoragePolicyGroup storagePolicyGroup;
            long topologyVersion;
            long weightsVersion;
            long exclusionVersion;
            long instanceExclusionVersion;
            long storagePolicyGroupVersion;
            RingConfiguration ringConfig;
            ZooKeeperExtended zk;
            HostGroupTable hostGroupTable;
            long hostGroupTableVersion;
            ExclusionSet mergedExclusionSet;
            zk = mc.getZooKeeper();
            topologyVersion = curBuild.get(mp.getTopologyPath());
            weightsVersion = curBuild.get(mp.getWeightsPath());
            exclusionVersion = curBuild.get(mp.getExclusionsPath());
            instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
            storagePolicyGroupVersion = curBuild.get(mp.getStoragePolicyGroupPath());
            ringConfigVersion = curBuild.get(mp.getConfigPath());
            topology = new TopologyZK(cloudMC).readFromZK(topologyVersion, null);
            weightSpecs = new WeightsZK(mc).readFromZK(weightsVersion, null);
            exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
            if (options.ignoreInstanceExclusions) {
                instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
            } else {
                try {
                    instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readFromZK(instanceExclusionVersion, null));
                } catch (Exception e) {
                    Log.warning("No instance ExclusionSet found");
                    instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
                }
            }
            mergedExclusionSet = ExclusionSet.union(exclusionSet, instanceExclusionSet);
            storagePolicyGroup = new StoragePolicyGroupZK(mc).readFromZK(storagePolicyGroupVersion, null);
            ringConfig = new RingConfigurationZK(mc).readFromZK(ringConfigVersion, null);
            Log.warningf("ringConfiguration %s", ringConfig);
            hostGroupTableVersion = zk.getLatestVersion(cloudMC.getMetaPaths().getHostGroupPath());
            hostGroupTable = new HostGroupTableZK(cloudMC).readFromZK(hostGroupTableVersion, null);
            try {
                recipe = new RingTreeRecipe(topology, ringConfig.getRingParentName(), weightSpecs, mergedExclusionSet, storagePolicyGroup, ringConfig.getStoragePolicyName(), hostGroupTable, ringConfig.getHostGroups(), ringConfigVersion, DHTUtil.currentTimeMillis());
                Log.warning("Recipe.ringParent: " + recipe.ringParent);
            } catch (RuntimeException re) {
                re.printStackTrace(System.out);
                Log.warning("ringConfig: ", ringConfig + " " + re);
                Log.logErrorWarning(re);
                throw re;
            }
            RingTree ringTree;
            RingTree prevRingTree;
            long configInstanceVersion;
            String newInstancePath;
            configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
            if (configInstanceVersion >= 0 && !ignoreSource) {
                prevRingTree = SingleRingZK.readTree(mc, ringConfigVersion, configInstanceVersion);
            } else {
                prevRingTree = null;
            }
            if (prevRingTree == null || ignoreFeasibility || RingTreeBuilder.convergenceFeasible(prevRingTree, storagePolicyGroup, ringConfig.getStoragePolicyName(), ringConfig.getRingParentName(), exclusionSet)) {
                ringTree = RingTreeBuilder.create(recipe, prevRingTree);
                // ringTree = RingTreeBuilder.create(recipe, null); // for testing without movement reduction
                newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
                SingleRingZK.writeTree(mc, topologyVersion, newInstancePath, ringTree);
                if (TopoRingConstants.verbose) {
                    System.out.println(ringTree);
                    System.out.println(ringConfigVersion);
                    System.out.println(configInstanceVersion);
                    System.out.println(topologyVersion);
                    System.out.println(newInstancePath);
                    System.out.println("Building complete");
                }
                buildOK = true;
            } else {
                Log.warning("Convergence is infeasible. A region in prevTree does not have a viable server.");
            }
        } catch (IOException ioe) {
            Log.logErrorWarning(ioe);
        } catch (KeeperException ke) {
            Log.logErrorWarning(ke);
        }
        if (exitAfterBuild) {
            if (buildOK) {
                try {
                    if (ringConfigVersion < 0) {
                        throw new RuntimeException("ringConfigVersion < 0");
                    }
                    setRing(ringConfigVersion);
                } catch (KeeperException ke) {
                    Log.logErrorWarning(ke);
                    buildOK = false;
                }
            }
            System.exit(buildOK ? 0 : -1);
        }
    } catch (RuntimeException re) {
        re.printStackTrace();
    } finally {
        Log.warning("Leaving build");
    }
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) HostGroupTable(com.ms.silverking.cloud.config.HostGroupTable) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) Topology(com.ms.silverking.cloud.topology.Topology) IOException(java.io.IOException) StoragePolicyGroupZK(com.ms.silverking.cloud.toporing.meta.StoragePolicyGroupZK) StoragePolicyGroup(com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup) ServerSetExtensionZK(com.ms.silverking.cloud.meta.ServerSetExtensionZK) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException) WeightSpecifications(com.ms.silverking.cloud.toporing.meta.WeightSpecifications) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) WeightsZK(com.ms.silverking.cloud.toporing.meta.WeightsZK) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) HostGroupTableZK(com.ms.silverking.cloud.meta.HostGroupTableZK) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class DependencyWatcher method triggerBuild.

private void triggerBuild() {
    try {
        ZooKeeperExtended zk;
        zk = mc.getZooKeeper();
        buildQueue.put(createBuildMap(zk));
    } catch (Exception e) {
        Log.logErrorWarning(e);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 3 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class MasterModeDependencyWatcher method handleExclusionChange.

private void handleExclusionChange() {
    synchronized (this) {
        try {
            Map<String, Long> curBuild;
            ExclusionSet exclusionSet;
            ExclusionSet instanceExclusionSet;
            long exclusionVersion;
            long instanceExclusionVersion;
            ZooKeeperExtended zk;
            ExclusionSet mergedExclusionSet;
            RingTree existingRingTree;
            RingTree newRingTree;
            String newInstancePath;
            ResolvedReplicaMap newReplicaMap;
            zk = mc.getZooKeeper();
            curBuild = createBuildMap(zk);
            exclusionVersion = curBuild.get(mp.getExclusionsPath());
            instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
            exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
            try {
                instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readFromZK(instanceExclusionVersion, null));
            } catch (Exception e) {
                Log.warning("No instance ExclusionSet found");
                instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
            }
            mergedExclusionSet = ExclusionSet.union(exclusionSet, instanceExclusionSet);
            newRingTree = RingTreeBuilder.removeExcludedNodes(masterRingTree, mergedExclusionSet);
            newReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingConfiguration().getRingParentName(), new ReplicaNaiveIPPrioritizer());
            if (!existingReplicaMap.equals(newReplicaMap)) {
                newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
                SingleRingZK.writeTree(mc, topology, newInstancePath, newRingTree);
                Log.warningf("RingTree written to ZK: %s", newInstancePath);
                existingReplicaMap = newReplicaMap;
            } else {
                Log.warning("RingTree unchanged. No ZK update.");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.logErrorWarning(e, "handleExclusionChange() failed");
        }
    }
}
Also used : ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) ReplicaNaiveIPPrioritizer(com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer) ServerSetExtensionZK(com.ms.silverking.cloud.meta.ServerSetExtensionZK) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 4 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class MasterModeDependencyWatcher method readLatestRingTree.

private RingTree readLatestRingTree(MetaClient mc) throws KeeperException, IOException {
    RingTree ringTree;
    long ringConfigVersion;
    long configInstanceVersion;
    ZooKeeperExtended zk;
    zk = mc.getZooKeeper();
    ringConfigVersion = zk.getLatestVersion(mp.getConfigPath());
    configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
    if (configInstanceVersion < 0) {
        throw new RuntimeException("Can't find configInstanceVersion");
    } else {
        ringTree = SingleRingZK.readTree(mc, ringConfigVersion, configInstanceVersion);
    }
    return ringTree;
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 5 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class SingleRingZK method readTree.

public static InstantiatedRingTree readTree(MetaClient mc, long ringConfigVersion, long configInstanceVersion) throws KeeperException, IOException {
    ZooKeeperExtended zk;
    List<String> mapNames;
    // Map<Pair<String,String>,TopologyRing>    maps;
    Map<String, TopologyRing> maps;
    Topology topology;
    String ringInstancePath;
    // WeightSpecifications        weightSpecs;
    com.ms.silverking.cloud.meta.MetaClient cloudMC;
    long topologyVersion;
    long ringCreationTime;
    zk = mc.getZooKeeper();
    cloudMC = mc.createCloudMC();
    ringInstancePath = mc.getMetaPaths().getRingInstancePath(ringConfigVersion, configInstanceVersion);
    ringCreationTime = zk.getStat(ringInstancePath).getCtime();
    mapNames = zk.getChildren(ringInstancePath);
    // weightSpecs = new WeightsZK(mc).readFromZK(weightsVersion);
    while (mapNames.size() == 0) {
        Log.warning(String.format("No maps for: %s; waiting.", ringInstancePath));
        // FUTURE - move this retry loop out to common, primarily non-polling function
        ThreadUtil.sleepSeconds(mapNamesRetryIntervalSeconds);
        mapNames = zk.getChildren(ringInstancePath);
    }
    if (DHTConstants.isDaemon || Log.levelMet(Level.INFO)) {
        Log.warning(String.format("mapNames found: %d", mapNames.size()));
    }
    topologyVersion = VersionedDefinition.NO_VERSION;
    for (String mapName : mapNames) {
        String tp;
        long tv;
        tp = ringInstancePath + "/" + mapName + "/" + versionNode;
        tv = zk.getInt(tp);
        Log.warningf("topology %s %d", tp, tv);
        if (topologyVersion == VersionedDefinition.NO_VERSION) {
            topologyVersion = tv;
        } else {
            if (tv != topologyVersion) {
                throw new RuntimeException("inconsistent topologyVersions: " + ringInstancePath);
            }
        }
    }
    topology = new TopologyZK(cloudMC).readFromZK(topologyVersion, null);
    maps = new HashMap<>();
    for (String mapName : mapNames) {
        SingleRingZK singleRingZK;
        TopologyRing topologyRing;
        singleRingZK = new SingleRingZK(mc, null, /*parent.getNodeClass()*/
        topologyVersion, ringInstancePath, mapName);
        if (TopoRingConstants.verbose) {
            Log.warning("Waiting for valid ring: ", ringInstancePath + " " + mapName);
        }
        singleRingZK.waitUntilValid();
        if (TopoRingConstants.verbose) {
            Log.warning("Valid: ", ringInstancePath + " " + mapName);
        }
        // singleRingZK.setWeightSpecs(weightSpecs);
        // FIXME - version in single ring is unused
        // verify that we can remove version in SingleRing
        topologyRing = singleRingZK.readFromZK(0L, null);
        // maps.put(mapNameToTopologyNodeNameAndStoragePolicyName(mapName), topologyRing);
        maps.put(mapName, topologyRing);
    }
    return new InstantiatedRingTree(topology, maps, new Pair<>(ringConfigVersion, configInstanceVersion), ringCreationTime);
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) Topology(com.ms.silverking.cloud.topology.Topology) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK)

Aggregations

ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)33 KeeperException (org.apache.zookeeper.KeeperException)9 IOException (java.io.IOException)7 Stat (org.apache.zookeeper.data.Stat)4 NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)3 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)3 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)3 CmdLineException (org.kohsuke.args4j.CmdLineException)3 ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)2 ServerSetExtensionZK (com.ms.silverking.cloud.meta.ServerSetExtensionZK)2 Topology (com.ms.silverking.cloud.topology.Topology)2 TopologyZK (com.ms.silverking.cloud.topology.TopologyZK)2 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)2 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 OperationTimeoutException (org.apache.zookeeper.KeeperException.OperationTimeoutException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)1