Search in sources :

Example 86 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException 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 87 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.

the class StaticRingCreator method createStaticRing.

public static RingCreationResults createStaticRing(String ringName, ZooKeeperConfig zkConfig, Set<String> servers, int replication, UUIDBase myID) {
    try {
        MetaClient mc;
        com.ms.silverking.cloud.meta.MetaClient cloudMC;
        NamedRingConfiguration namedRingConfig;
        RingConfiguration ringConfig;
        RingTreeRecipe recipe;
        Topology topology;
        WeightSpecifications weightSpecs;
        ExclusionSet exclusionSet;
        StoragePolicyGroup storagePolicyGroup;
        HostGroupTable hostGroupTable;
        long ringConfigVersion;
        CloudConfiguration cloudConfig;
        String exclusionSpecsName;
        String hostGroupTableName;
        topology = StaticTopologyCreator.createTopology("topology." + myID, servers);
        exclusionSpecsName = "exclusionSpecs." + myID;
        hostGroupTableName = "hostGroupTable." + myID;
        cloudConfig = new CloudConfiguration(topology.getName(), exclusionSpecsName, hostGroupTableName);
        cloudMC = new com.ms.silverking.cloud.meta.MetaClient(cloudConfig, zkConfig);
        new TopologyZK(cloudMC).writeToZK(topology, null);
        new ExclusionZK(cloudMC).writeToZK(ExclusionSet.emptyExclusionSet(0));
        mc = new MetaClient(NamedRingConfiguration.emptyTemplate.ringName(ringName), zkConfig);
        ringConfig = new RingConfiguration(cloudConfig, "weightSpecsName", StaticTopologyCreator.parentID, SimpleStoragePolicyCreator.storagePolicyGroupName, SimpleStoragePolicyCreator.storagePolicyName, null);
        new RingConfigurationZK(mc).writeToZK(ringConfig, null);
        namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
        mc = new MetaClient(namedRingConfig, zkConfig);
        EmbeddedSK.setEmbeddedNamedRingConfiguration(ringName, namedRingConfig);
        Log.warning(zkConfig);
        ringConfigVersion = 0;
        weightSpecs = new WeightSpecifications(0);
        exclusionSet = ExclusionSet.emptyExclusionSet(0);
        storagePolicyGroup = SimpleStoragePolicyCreator.createStoragePolicyGroup(replication);
        new StoragePolicyZK(mc).writeToZK(storagePolicyGroup, null);
        hostGroupTable = HostGroupTable.createHostGroupTable(servers, hostGroupName);
        new HostGroupTableZK(cloudMC).writeToZK(hostGroupTable, null);
        recipe = new RingTreeRecipe(topology, StaticTopologyCreator.parentID, weightSpecs, exclusionSet, storagePolicyGroup, SimpleStoragePolicyCreator.storagePolicyName, hostGroupTable, ImmutableSet.of(hostGroupName), ringConfigVersion, DHTUtil.currentTimeMillis());
        Log.warning("Recipe.ringParent: " + recipe.ringParent);
        RingTree ringTree;
        String newInstancePath;
        ringTree = RingTreeBuilder.create(recipe, null);
        newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
        SingleRingZK.writeTree(mc, topology, newInstancePath, ringTree);
        if (TopoRingConstants.verbose) {
            System.out.println(ringTree);
            System.out.println("Building complete");
        }
        return new RingCreationResults(exclusionSpecsName, hostGroupTableName, hostGroupTable, hostGroupName);
    } catch (IOException ioe) {
        Log.logErrorWarning(ioe);
        return null;
    } catch (KeeperException ke) {
        Log.logErrorWarning(ke);
        return null;
    }
}
Also used : MetaClient(com.ms.silverking.cloud.toporing.meta.MetaClient) HostGroupTable(com.ms.silverking.cloud.config.HostGroupTable) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) ExclusionZK(com.ms.silverking.cloud.meta.ExclusionZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) Topology(com.ms.silverking.cloud.topology.Topology) StoragePolicyZK(com.ms.silverking.cloud.storagepolicy.StoragePolicyZK) IOException(java.io.IOException) StoragePolicyGroup(com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup) WeightSpecifications(com.ms.silverking.cloud.toporing.meta.WeightSpecifications) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK) CloudConfiguration(com.ms.silverking.cloud.meta.CloudConfiguration) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) HostGroupTableZK(com.ms.silverking.cloud.meta.HostGroupTableZK) KeeperException(org.apache.zookeeper.KeeperException)

Example 88 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.

the class ValueWatcher method _doCheck.

protected void _doCheck() throws KeeperException {
    try {
        ZooKeeperExtended _zk;
        byte[] value;
        Stat stat;
        if (verbose) {
            Log.warning("ValueCheck start: ", basePath);
        }
        _zk = metaClientCore.getZooKeeper();
        stat = new Stat();
        try {
            value = _zk.getData(basePath, this, stat);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        if (stat.getMzxid() > lastNotifiedZXID) {
            listener.newValue(basePath, value, stat);
            lastNotifiedZXID = stat.getMzxid();
        }
        if (verbose) {
            Log.warning("ValueCheck complete: ", basePath);
        }
    } catch (KeeperException ke) {
        System.out.println("*** ZooKeeper state: " + metaClientCore.getZooKeeper().getState());
        throw ke;
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException)

Example 89 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.

the class VersionWatcher method _doCheck.

protected void _doCheck() throws KeeperException {
    Log.fine("checkVersions");
    try {
        ZooKeeperExtended _zk;
        List<String> children;
        List<Long> currentVersions;
        long mostRecentVersion;
        if (verbose) {
            Log.warning("VersionCheck start: ", basePath);
        }
        _zk = metaClientCore.getZooKeeper();
        children = _zk.getChildren(basePath, this);
        currentVersions = new ArrayList<>(children.size());
        for (String child : children) {
            currentVersions.add(Long.parseLong(child));
        }
        Collections.sort(currentVersions);
        if (currentVersions.size() > 0) {
            mostRecentVersion = currentVersions.get(currentVersions.size() - 1);
        } else {
            mostRecentVersion = Long.MIN_VALUE;
        }
        if (active && mostRecentVersion > lastNotifiedVersion) {
            lastNotifiedVersion = mostRecentVersion;
            listener.newVersion(basePath, mostRecentVersion);
        }
        if (verbose) {
            Log.warning("VersionCheck complete: ", basePath);
        }
    } catch (KeeperException ke) {
        System.out.println("*** ZooKeeper state: " + metaClientCore.getZooKeeper().getState());
        throw ke;
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException)

Example 90 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.

the class DHTRingMaster method syncData.

public void syncData(Quadruple<UUIDBase, Quadruple<String, Long, Long, Long>, Quadruple<String, Long, Long, Long>, SyncTargets> idAndRings) {
    UUIDBase uuid;
    Quadruple<String, Long, Long, Long> sourceRing;
    Quadruple<String, Long, Long, Long> targetRing;
    uuid = idAndRings.getV1();
    sourceRing = idAndRings.getV2();
    targetRing = idAndRings.getV3();
    Log.warningAsyncf("DHTRingMaster.syncData %s %s %s", uuid, sourceRing.getV1(), targetRing.getV1());
    convergenceLock.lock();
    try {
        if (/*!isValidTarget(targetRing)*/
        false) {
            // FUTURE think about checking validity
            // FUTURE - could improve this sanity check to look at zk info
            Log.warningAsyncf("Ignoring invalid sync %s %s", sourceRing, targetRing);
        } else {
            if (enableLogging) {
                Log.warningAsync("New ring: ", targetRing);
            }
            try {
                ConvergencePoint _sourceCP;
                ConvergencePoint _targetCP;
                // Check for old convergence
                if (targetConvergenceController != null) {
                    if (enableLogging) {
                        Log.warningAsync("Can't sync due to ongoing convergence: ", targetRing);
                        return;
                    }
                }
                // Start new sync
                _sourceCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(sourceRing.getTripleAt1()), sourceRing.getV4());
                _targetCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(targetRing.getTripleAt1()), targetRing.getV4());
                try {
                    targetConvergenceController = new CentralConvergenceController(uuid, dhtMetaReader, _sourceCP, _targetCP, readExclusions(targetRing), mgBase, syncUnchangedOwners, CentralConvergenceController.RequestedSyncMode.SyncOnly);
                    convergenceControllers.put(targetConvergenceController.getUUID(), targetConvergenceController);
                } catch (IOException ioe) {
                    Log.logErrorWarning(ioe, "Unable to start sync");
                    return;
                }
                try {
                    convergenceLock.unlock();
                    try {
                        if (enableLogging) {
                            Log.warningAsync("Calling converge(): ", targetRing);
                        }
                        ((CentralConvergenceController) targetConvergenceController).converge(idAndRings.getV4());
                    } finally {
                        convergenceLock.lock();
                    }
                    targetConvergenceController = null;
                    if (enableLogging) {
                        Log.warningAsync("Convergence complete: ", targetRing);
                    }
                } catch (ConvergenceException ce) {
                    // Convergence failed
                    if (!ce.getAbandoned()) {
                        // Failed due to an exception
                        Log.logErrorWarning(ce, "Convergence failed due to exception");
                    } else {
                        // Failed due to a new target causing the old convergence to be abandoned
                        // In this case, the new convergence will take over the cur and target pointers
                        Log.warningAsync("Previous convergence abandoned");
                    }
                }
            } catch (KeeperException ke) {
                // Retries are internal to DHTringCurTargetZK. If we got here, those
                // retries failed.
                // FUTURE - relay to alerting
                Log.logErrorWarning(ke, "Unexpected exception during peerStateMet handling");
            }
        }
    } finally {
        convergenceLock.unlock();
    }
}
Also used : ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) UUIDBase(com.ms.silverking.id.UUIDBase) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)566 IOException (java.io.IOException)188 Stat (org.apache.zookeeper.data.Stat)127 ZooKeeper (org.apache.zookeeper.ZooKeeper)87 ArrayList (java.util.ArrayList)51 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 Test (org.junit.jupiter.api.Test)38 CountDownLatch (java.util.concurrent.CountDownLatch)30 SolrException (org.apache.solr.common.SolrException)30 HashMap (java.util.HashMap)29 List (java.util.List)28 ACL (org.apache.zookeeper.data.ACL)27 Test (org.junit.Test)27 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 ServerName (org.apache.hadoop.hbase.ServerName)24 Map (java.util.Map)23 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)23 InterruptedIOException (java.io.InterruptedIOException)20