private int getNumOpen() throws Exception { return env.getSharedResources().getCurator().getChildren() .forPath(ZookeeperPath.TRANSACTOR_NODES).size(); }
public TransactorID(Environment env) { this(env.getSharedResources().getCurator()); }
GcTimestampTracker() throws Exception { this.curator = env.getSharedResources().getCurator(); }
public TransactorID(Environment env) { this(env.getSharedResources().getCurator()); }
GcTimestampTracker() throws Exception { this.curator = env.getSharedResources().getCurator(); }
private boolean zkNodeExists(TimestampTracker tracker) throws Exception { return env.getSharedResources().getCurator().checkExists() .forPath(tracker.getNodePath()) != null; }
private boolean checkExists(TransactorNode t) throws Exception { return env.getSharedResources().getCurator().checkExists().forPath(t.getNodePath()) != null; }
private long getOldestTs() throws Exception { CuratorFramework curator = env.getSharedResources().getCurator(); List<String> children; try { children = curator.getChildren().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS); } catch (NoNodeException nne) { children = Collections.emptyList(); } long oldestTs = Long.MAX_VALUE; for (String child : children) { Long ts = LongUtil.fromByteArray( curator.getData().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS + "/" + child)); if (ts < oldestTs) { oldestTs = ts; } } return oldestTs == Long.MAX_VALUE ? 0 : oldestTs; }
private long zkNodeValue(TimestampTracker tracker) throws Exception { if (zkNodeExists(tracker) == false) { throw new IllegalStateException("node does not exist"); } return LongUtil.fromByteArray( env.getSharedResources().getCurator().getData().forPath(tracker.getNodePath())); } }
CuratorFramework curator = env.getSharedResources().getCurator();
public TransactorCache(Environment env) { final FluoConfiguration conf = env.getConfiguration(); timeoutCache = CacheBuilder.newBuilder().maximumSize(FluoConfigurationImpl.getTransactorMaxCacheSize(conf)) .expireAfterAccess( FluoConfigurationImpl.getTransactorCacheTimeout(conf, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .concurrencyLevel(10).build(); this.env = env; cache = new PathChildrenCache(env.getSharedResources().getCurator(), ZookeeperPath.TRANSACTOR_NODES, true); try { cache.start(StartMode.BUILD_INITIAL_CACHE); status = TcStatus.OPEN; } catch (Exception e) { throw new RuntimeException(e); } }
public TransactorCache(Environment env) { final FluoConfiguration conf = env.getConfiguration(); timeoutCache = CacheBuilder.newBuilder().maximumSize(FluoConfigurationImpl.getTransactorMaxCacheSize(conf)) .expireAfterAccess( FluoConfigurationImpl.getTransactorCacheTimeout(conf, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .concurrencyLevel(10).build(); this.env = env; cache = new PathChildrenCache(env.getSharedResources().getCurator(), ZookeeperPath.TRANSACTOR_NODES, true); try { cache.start(StartMode.BUILD_INITIAL_CACHE); status = TcStatus.OPEN; } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void testGetOldestTimestamp() throws Exception { // we are expecting an error in this test final Level curLevel = Logger.getLogger(ZookeeperUtil.class).getLevel(); Logger.getLogger(ZookeeperUtil.class).setLevel(Level.FATAL); // verify that oracle initial current ts Assert.assertEquals(0, ZookeeperUtil.getGcTimestamp(config.getAppZookeepers())); // delete the oracle current timestamp path env.getSharedResources().getCurator().delete().forPath(ZookeeperPath.ORACLE_GC_TIMESTAMP); // verify that oldest possible is returned Assert.assertEquals(ZookeeperUtil.OLDEST_POSSIBLE, ZookeeperUtil.getGcTimestamp(config.getAppZookeepers())); // set level back Logger.getLogger(ZookeeperUtil.class).setLevel(curLevel); }
private void createZkNode(long ts) { Preconditions.checkState(node == null, "expected node to be null"); node = new PersistentEphemeralNode(env.getSharedResources().getCurator(), Mode.EPHEMERAL, getNodePath(), LongUtil.toByteArray(ts)); CuratorUtil.startAndWait(node, 10); zkTimestamp = ts; }
private void createZkNode(long ts) { Preconditions.checkState(node == null, "expected node to be null"); node = new PersistentNode(env.getSharedResources().getCurator(), CreateMode.EPHEMERAL, false, getNodePath(), LongUtil.toByteArray(ts)); CuratorUtil.startAndWait(node, 10); zkTimestamp = ts; }
/** * Creates a transactor node using given transactor id * * @param env Environment * @param tid Transactor ID used to create node */ public TransactorNode(Environment env, TransactorID tid) { this.env = env; this.tid = tid; node = new PersistentNode(env.getSharedResources().getCurator(), CreateMode.EPHEMERAL, false, getNodePath(), tid.toString().getBytes()); CuratorUtil.startAndWait(node, 10); status = TrStatus.OPEN; }
/** * Creates a transactor node using given transactor id * * @param env Environment * @param tid Transactor ID used to create node */ public TransactorNode(Environment env, TransactorID tid) { this.env = env; this.tid = tid; node = new PersistentEphemeralNode(env.getSharedResources().getCurator(), Mode.EPHEMERAL, getNodePath(), tid.toString().getBytes()); CuratorUtil.startAndWait(node, 10); status = TrStatus.OPEN; }
PartitionManager(Environment env, long minSleepTime, long maxSleepTime) { try { this.curator = env.getSharedResources().getCurator(); this.env = env; this.minSleepTime = minSleepTime; this.maxSleepTime = maxSleepTime; this.retrySleepTime = minSleepTime; groupSize = env.getConfiguration().getInt(FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE, FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE_DEFAULT); myESNode = new PersistentNode(curator, CreateMode.EPHEMERAL_SEQUENTIAL, false, ZookeeperPath.FINDERS + "/" + ZK_FINDER_PREFIX, ("" + groupSize).getBytes(UTF_8)); myESNode.start(); myESNode.waitForInitialCreate(1, TimeUnit.MINUTES); childrenCache = new PathChildrenCache(curator, ZookeeperPath.FINDERS, true); childrenCache.getListenable().addListener(new FindersListener()); childrenCache.start(StartMode.BUILD_INITIAL_CACHE); schedExecutor = Executors.newScheduledThreadPool(1, new FluoThreadFactory("Fluo worker partition manager")); schedExecutor.scheduleWithFixedDelay(new CheckTabletsTask(), 0, maxSleepTime, TimeUnit.MILLISECONDS); scheduleUpdate(); } catch (Exception e) { throw new RuntimeException(e); } }
PartitionManager(Environment env, long minSleepTime, long maxSleepTime) { try { this.curator = env.getSharedResources().getCurator(); this.env = env; this.minSleepTime = minSleepTime; this.maxSleepTime = maxSleepTime; this.retrySleepTime = minSleepTime; groupSize = env.getConfiguration().getInt(FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE, FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE_DEFAULT); myESNode = new PersistentEphemeralNode(curator, Mode.EPHEMERAL_SEQUENTIAL, ZookeeperPath.FINDERS + "/" + ZK_FINDER_PREFIX, ("" + groupSize).getBytes(UTF_8)); myESNode.start(); myESNode.waitForInitialCreate(1, TimeUnit.MINUTES); childrenCache = new PathChildrenCache(curator, ZookeeperPath.FINDERS, true); childrenCache.getListenable().addListener(new FindersListener()); childrenCache.start(StartMode.BUILD_INITIAL_CACHE); schedExecutor = Executors.newScheduledThreadPool(1, new FluoThreadFactory("Fluo worker partition manager")); schedExecutor.scheduleWithFixedDelay(new CheckTabletsTask(), 0, maxSleepTime, TimeUnit.MILLISECONDS); scheduleUpdate(); } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void testFailures() throws Exception { TransactorNode t1 = new TransactorNode(env); assertNumOpen(1); Assert.assertEquals(id1, t1.getTransactorID().getLongID()); Assert.assertTrue(checkExists(t1)); // Test that node will be recreated if removed env.getSharedResources().getCurator().delete().forPath(t1.getNodePath()); Assert.assertEquals(id1, t1.getTransactorID().getLongID()); assertNumOpen(1); Assert.assertTrue(checkExists(t1)); t1.close(); assertNumOpen(0); Assert.assertFalse(checkExists(t1)); // Test for exception to be called exception.expect(IllegalStateException.class); t1.getTransactorID().getLongID(); }