public TransactionImpl(Environment env) { this(env, null, allocateTimestamp(env).getTxTimestamp()); }
@Override CompletableFuture<Boolean> getMainOp(CommitData cd) { return getStampOp().thenApply(commitStamp -> { if (startTs < commitStamp.getGcTimestamp()) { return false; } else { getStats().setCommitTs(commitStamp.getTxTimestamp()); return true; } }); }
private synchronized void close(boolean checkForStaleScan) { if (status != TxStatus.CLOSED) { status = TxStatus.CLOSED; if (checkForStaleScan && !commitAttempted) { Stamp stamp = env.getSharedResources().getOracleClient().getStamp(); if (startTs < stamp.getGcTimestamp()) { throw new StaleScanException(); } } env.getSharedResources().getTimestampTracker().removeTimestamp(startTs); } }
Stamp stampRes = new Stamp(txStampsStart + i, gcStamp); tr.stampRef.set(stampRes); if (tr.cf == null) {
private synchronized void close(boolean checkForStaleScan) { if (status != TxStatus.CLOSED) { status = TxStatus.CLOSED; if (checkForStaleScan && !commitAttempted) { Stamp stamp = env.getSharedResources().getOracleClient().getStamp(); if (startTs < stamp.getGcTimestamp()) { throw new StaleScanException(); } } env.getSharedResources().getTimestampTracker().removeTimestamp(startTs); } }
Stamp stampRes = new Stamp(txStampsStart + i, gcStamp); tr.stampRef.set(stampRes); if (tr.cf == null) {
public TransactionImpl(Environment env) { this(env, null, allocateTimestamp(env).getTxTimestamp()); }
@Override CompletableFuture<Boolean> getMainOp(CommitData cd) { return getStampOp().thenApply(commitStamp -> { if (startTs < commitStamp.getGcTimestamp()) { return false; } else { getStats().setCommitTs(commitStamp.getTxTimestamp()); return true; } }); }
public TransactionImpl(Environment env, Notification trigger) { this(env, trigger, allocateTimestamp(env).getTxTimestamp()); }
public TransactionImpl(Environment env, Notification trigger) { this(env, trigger, allocateTimestamp(env).getTxTimestamp()); }
@Override public void run() { OracleClient oclient = env.getSharedResources().getOracleClient(); for (int i = 0; i < numToGet; i++) { try { output.add(oclient.getStamp().getTxTimestamp()); } catch (Exception e) { e.printStackTrace(); } } cdl.countDown(); } }
/** * Allocate a timestamp */ public Stamp allocateTimestamp() { synchronized (this) { Preconditions.checkState(!closed, "tracker closed "); if (node == null) { Preconditions.checkState(allocationsInProgress == 0, "expected allocationsInProgress == 0 when node == null"); Preconditions.checkState(!updatingZk, "unexpected concurrent ZK update"); createZkNode(getTimestamp().getTxTimestamp()); } allocationsInProgress++; } try { Stamp ts = getTimestamp(); synchronized (this) { timestamps.add(ts.getTxTimestamp()); } return ts; } catch (RuntimeException re) { synchronized (this) { allocationsInProgress--; } throw re; } }
/** * Allocate a timestamp */ public Stamp allocateTimestamp() { synchronized (this) { Preconditions.checkState(!closed, "tracker closed "); if (node == null) { Preconditions.checkState(allocationsInProgress == 0, "expected allocationsInProgress == 0 when node == null"); Preconditions.checkState(!updatingZk, "unexpected concurrent ZK update"); createZkNode(getTimestamp().getTxTimestamp()); } allocationsInProgress++; } try { Stamp ts = getTimestamp(); synchronized (this) { timestamps.add(ts.getTxTimestamp()); } return ts; } catch (RuntimeException re) { synchronized (this) { allocationsInProgress--; } throw re; } }
/** * Test that bogus input into the oracle server doesn't cause an OOM exception. This essentially * tests for THRIFT-602 */ @Test public void bogusDataTest() throws Exception { Socket socket = new Socket(); socket.connect(new InetSocketAddress(HostUtil.getHostName(), oserver.getPort())); OutputStream outstream = socket.getOutputStream(); try (PrintWriter out = new PrintWriter(outstream)) { out.print("abcd"); out.flush(); } socket.close(); OracleClient client = env.getSharedResources().getOracleClient(); assertEquals(2, client.getStamp().getTxTimestamp()); }
@VisibleForTesting public boolean finishCommit(CommitData cd, Stamp commitStamp) { cd.commitObserver = new SyncCommitObserver(); getStats().setCommitTs(commitStamp.getTxTimestamp()); CommitStep firstStep = new DeleteLocksStep(); firstStep.andThen(new FinishCommitStep()); firstStep.compose(cd).exceptionally(throwable -> { System.err.println("Unexpected exception in finish commit test method : "); throwable.printStackTrace(); return null; }); return true; }
@Test public void testRestart() throws Exception { OracleClient client = env.getSharedResources().getOracleClient(); long ts1 = client.getStamp().getTxTimestamp(); long ts2 = client.getStamp().getTxTimestamp(); oserver.stop(); oserver.start(); long ts3 = client.getStamp().getTxTimestamp(); long ts4 = client.getStamp().getTxTimestamp(); assertTrue(ts1 + " " + ts2, ts1 < ts2); assertTrue(ts2 + " " + ts3, ts2 < ts3); assertTrue(ts3 + " " + ts4, ts3 < ts4); }
@VisibleForTesting public boolean finishCommit(CommitData cd, Stamp commitStamp) { cd.commitObserver = new SyncCommitObserver(); getStats().setCommitTs(commitStamp.getTxTimestamp()); CommitStep firstStep = new DeleteLocksStep(); firstStep.andThen(new FinishCommitStep()); firstStep.compose(cd).exceptionally(throwable -> { System.err.println("Unexpected exception in finish commit test method : "); throwable.printStackTrace(); return null; }); return true; }
public void waitUntilFinished(FluoConfiguration config) { try (Environment env = new Environment(config)) { log.info("The wait command will exit when all notifications are processed"); while (true) { long ts1 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); long ntfyCount = countNotifications(env); long ts2 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); if (ntfyCount == 0 && ts1 == (ts2 - 1)) { log.info("All processing has finished!"); break; } try { long sleepSec = calculateSleep(ntfyCount, org.apache.fluo.cluster.util.FluoYarnConfig.getWorkerInstances(config)); log.info("{} notifications are still outstanding. Will try again in {} seconds...", ntfyCount, sleepSec); Thread.sleep(1000 * sleepSec); } catch (InterruptedException e) { log.error("Sleep was interrupted! Exiting..."); System.exit(-1); } } } catch (FluoException e) { log.error(e.getMessage()); System.exit(-1); } catch (Exception e) { log.error("An exception was thrown -", e); System.exit(-1); } }
public void waitUntilFinished(FluoConfiguration config) { try (Environment env = new Environment(config)) { log.info("The wait command will exit when all notifications are processed"); while (true) { long ts1 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); long ntfyCount = countNotifications(env); long ts2 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); if (ntfyCount == 0 && ts1 == (ts2 - 1)) { log.info("All processing has finished!"); break; } try { long sleepSec = calculateSleep(ntfyCount, org.apache.fluo.cluster.util.FluoYarnConfig.getWorkerInstances(config)); log.info("{} notifications are still outstanding. Will try again in {} seconds...", ntfyCount, sleepSec); Thread.sleep(1000 * sleepSec); } catch (InterruptedException e) { log.error("Sleep was interrupted! Exiting..."); System.exit(-1); } } } catch (FluoException e) { log.error(e.getMessage()); System.exit(-1); } catch (Exception e) { log.error("An exception was thrown -", e); System.exit(-1); } }
@Override public void waitForObservers() { try { Scanner scanner = env.getConnector().createScanner(env.getTable(), env.getAuthorizations()); Notification.configureScanner(scanner); while (true) { long ts1 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); long ntfyCount = Iterables.size(scanner); long ts2 = env.getSharedResources().getOracleClient().getStamp().getTxTimestamp(); if (ntfyCount == 0 && ts1 == (ts2 - 1)) { break; } long sleepTime = ntfyCount / 2; sleepTime = Math.min(Math.max(10, sleepTime), 10000); Uninterruptibles.sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS); } } catch (Exception e) { throw new RuntimeException(e); } }