Search in sources :

Example 31 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project pinot by linkedin.

the class PinotSegmentRebalancer method rebalanceTable.

/**
   * Rebalances a table
   * @param tableName
   * @throws Exception
   */
public void rebalanceTable(String tableName) throws Exception {
    String tableConfigPath = "/CONFIGS/TABLE/" + tableName;
    Stat stat = new Stat();
    ZNRecord znRecord = propertyStore.get(tableConfigPath, stat, 0);
    AbstractTableConfig tableConfig = AbstractTableConfig.fromZnRecord(znRecord);
    String tenantName = tableConfig.getTenantConfig().getServer().replaceAll(TableType.OFFLINE.toString(), "").replace(TableType.OFFLINE.toString(), "");
    rebalanceTable(tableName, tenantName);
}
Also used : Stat(org.apache.zookeeper.data.Stat) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) ZNRecord(org.apache.helix.ZNRecord)

Example 32 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project pulsar by yahoo.

the class MockZooKeeper method setData.

@Override
public Stat setData(final String path, byte[] data, int version) throws KeeperException, InterruptedException {
    final Set<Watcher> toNotify = Sets.newHashSet();
    int newVersion;
    synchronized (this) {
        checkProgrammedFail();
        if (stopped) {
            throw new KeeperException.ConnectionLossException();
        }
        if (!tree.containsKey(path)) {
            throw new KeeperException.NoNodeException();
        }
        int currentVersion = tree.get(path).second;
        // Check version
        if (version != -1 && version != currentVersion) {
            throw new KeeperException.BadVersionException(path);
        }
        newVersion = currentVersion + 1;
        log.debug("[{}] Updating -- current version: {}", path, currentVersion);
        tree.put(path, Pair.create(new String(data), newVersion));
        toNotify.addAll(watchers.get(path));
        watchers.removeAll(path);
    }
    executor.execute(() -> {
        toNotify.forEach(watcher -> watcher.process(new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path)));
    });
    Stat stat = new Stat();
    stat.setVersion(newVersion);
    return stat;
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Example 33 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project pulsar by yahoo.

the class MockZooKeeper method exists.

@Override
public synchronized Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
    checkProgrammedFail();
    if (stopped)
        throw new KeeperException.ConnectionLossException();
    if (watcher != null) {
        watchers.put(path, watcher);
    }
    if (tree.containsKey(path)) {
        Stat stat = new Stat();
        stat.setVersion(tree.get(path).second);
        return stat;
    } else {
        return null;
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Example 34 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project pulsar by yahoo.

the class MockZooKeeper method exists.

@Override
public synchronized Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
    checkProgrammedFail();
    if (stopped)
        throw new KeeperException.ConnectionLossException();
    if (tree.containsKey(path)) {
        Stat stat = new Stat();
        stat.setVersion(tree.get(path).second);
        return stat;
    } else {
        return null;
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Example 35 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project pulsar by yahoo.

the class LocalZooKeeperConnectionService method createIfAbsent.

public static String createIfAbsent(ZooKeeper zk, String path, byte[] data, CreateMode createMode, boolean gc) throws KeeperException, InterruptedException {
    String pathCreated = null;
    try {
        pathCreated = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
    } catch (NodeExistsException e) {
        // OK
        LOG.debug("Create skipped for existing znode: path={}", path);
    }
    // reset if what exists is the ephemeral garbage.
    if (gc && (pathCreated == null) && CreateMode.EPHEMERAL.equals(createMode)) {
        Stat stat = zk.exists(path, false);
        if (stat != null && zk.getSessionId() != stat.getEphemeralOwner()) {
            deleteIfExists(zk, path, -1);
            pathCreated = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
        }
    }
    return pathCreated;
}
Also used : Stat(org.apache.zookeeper.data.Stat) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27