@Inject public TransactionManager(Configuration conf, @Nonnull TransactionStateStorage persistor, MetricsCollector txMetricsCollector) { this.persistor = persistor; cleanupInterval = conf.getInt(TxConstants.Manager.CFG_TX_CLEANUP_INTERVAL, TxConstants.Manager.DEFAULT_TX_CLEANUP_INTERVAL); defaultTimeout = conf.getInt(TxConstants.Manager.CFG_TX_TIMEOUT, TxConstants.Manager.DEFAULT_TX_TIMEOUT); defaultLongTimeout = conf.getInt(TxConstants.Manager.CFG_TX_LONG_TIMEOUT, TxConstants.Manager.DEFAULT_TX_LONG_TIMEOUT); snapshotFrequencyInSeconds = conf.getLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_INTERVAL); // must always keep at least 1 snapshot snapshotRetainCount = Math.max(conf.getInt(TxConstants.Manager.CFG_TX_SNAPSHOT_RETAIN, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_RETAIN), 1); // intentionally not using a constant, as this config should not be exposed // TODO: REMOVE WITH txnBackwardsCompatCheck() longTimeoutTolerance = conf.getLong("data.tx.long.timeout.tolerance", 10000); // this.txMetricsCollector = txMetricsCollector; this.txMetricsCollector.configure(conf); clear(); }
@Override protected void onShutdown() { // perform a final metrics emit txMetricsCollector.gauge("committing.size", committingChangeSets.size()); txMetricsCollector.gauge("committed.size", committedChangeSets.size()); txMetricsCollector.gauge("inprogress.size", inProgress.size()); txMetricsCollector.gauge("invalid.size", invalidArray.length); }
private void appendToLog(List<TransactionEdit> edits) { try { Stopwatch timer = new Stopwatch().start(); currentLog.append(edits); txMetricsCollector.rate("wal.append.count", edits.size()); txMetricsCollector.histogram("wal.append.latency", (int) timer.elapsedMillis()); } catch (IOException ioe) { abortService("Error appending to transaction log", ioe); } }
@Override public synchronized void doStart() { LOG.info("Starting transaction manager."); txMetricsCollector.start(); // start up the persistor persistor.startAndWait(); try { persistor.setupStorage(); } catch (IOException e) { Throwables.propagate(e); } // establish defaults in case there is no persistence clear(); // attempt to recover state from last run recoverState(); // start the periodic cleanup thread startCleanupThread(); startSnapshotThread(); startMetricsThread(); // initialize the WAL if we did not force a snapshot in recoverState() initLog(); // initialize next write pointer if needed if (lastWritePointer == 0) { lastWritePointer = getNextWritePointer(); readPointer = lastWritePointer; } notifyStarted(); }
private void sync() throws IOException { // writes out pending entries to the HLog TransactionLogWriter tmpWriter = null; long latestSeq = 0; int entryCount = 0; synchronized (this) { if (closed) { return; } // prevent writer being dereferenced tmpWriter = writer; List<Entry> currentPending = getPendingWrites(); if (!currentPending.isEmpty()) { tmpWriter.commitMarker(currentPending.size()); } // write out all accumulated entries to log. for (Entry e : currentPending) { tmpWriter.append(e); entryCount++; latestSeq = Math.max(latestSeq, e.getKey().get()); } } long lastSynced = syncedUpTo.get(); // someone else might have already synced our edits, avoid double syncing if (lastSynced < latestSeq) { tmpWriter.sync(); metricsCollector.histogram("wal.sync.size", entryCount); syncedUpTo.compareAndSet(lastSynced, latestSeq); } }
txMetricsCollector.stop(); timer.stop(); LOG.info("Took " + timer + " to stop");
@Override public synchronized void doStart() { LOG.info("Starting transaction manager."); txMetricsCollector.start(); // start up the persistor persistor.startAndWait(); try { persistor.setupStorage(); } catch (IOException e) { Throwables.propagate(e); } // establish defaults in case there is no persistence clear(); // attempt to recover state from last run recoverState(); // start the periodic cleanup thread startCleanupThread(); startSnapshotThread(); startMetricsThread(); // initialize the WAL if we did not force a snapshot in recoverState() initLog(); // initialize next write pointer if needed if (lastWritePointer == 0) { lastWritePointer = getNextWritePointer(); readPointer = lastWritePointer; } notifyStarted(); }
private void sync() throws IOException { // writes out pending entries to the HLog TransactionLogWriter tmpWriter = null; long latestSeq = 0; int entryCount = 0; synchronized (this) { if (closed) { return; } // prevent writer being dereferenced tmpWriter = writer; List<Entry> currentPending = getPendingWrites(); if (!currentPending.isEmpty()) { tmpWriter.commitMarker(currentPending.size()); } // write out all accumulated entries to log. for (Entry e : currentPending) { tmpWriter.append(e); entryCount++; latestSeq = Math.max(latestSeq, e.getKey().get()); } } long lastSynced = syncedUpTo.get(); // someone else might have already synced our edits, avoid double syncing if (lastSynced < latestSeq) { tmpWriter.sync(); metricsCollector.histogram("wal.sync.size", entryCount); syncedUpTo.compareAndSet(lastSynced, latestSeq); } }
txMetricsCollector.stop(); timer.stop(); LOG.info("Took " + timer + " to stop");
private void appendToLog(List<TransactionEdit> edits) { try { Stopwatch timer = new Stopwatch().start(); currentLog.append(edits); txMetricsCollector.rate("wal.append.count", edits.size()); txMetricsCollector.histogram("wal.append.latency", (int) timer.elapsedMillis()); } catch (IOException ioe) { abortService("Error appending to transaction log", ioe); } }
@Override public void doRun() { txMetricsCollector.gauge("committing.size", committingChangeSets.size()); txMetricsCollector.gauge("committed.size", committedChangeSets.size()); txMetricsCollector.gauge("inprogress.size", inProgress.size()); txMetricsCollector.gauge("invalid.size", invalidArray.length); }
@Inject public TransactionManager(Configuration conf, @Nonnull TransactionStateStorage persistor, MetricsCollector txMetricsCollector) { this.persistor = persistor; cleanupInterval = conf.getInt(TxConstants.Manager.CFG_TX_CLEANUP_INTERVAL, TxConstants.Manager.DEFAULT_TX_CLEANUP_INTERVAL); defaultTimeout = conf.getInt(TxConstants.Manager.CFG_TX_TIMEOUT, TxConstants.Manager.DEFAULT_TX_TIMEOUT); defaultLongTimeout = conf.getInt(TxConstants.Manager.CFG_TX_LONG_TIMEOUT, TxConstants.Manager.DEFAULT_TX_LONG_TIMEOUT); snapshotFrequencyInSeconds = conf.getLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_INTERVAL); // must always keep at least 1 snapshot snapshotRetainCount = Math.max(conf.getInt(TxConstants.Manager.CFG_TX_SNAPSHOT_RETAIN, TxConstants.Manager.DEFAULT_TX_SNAPSHOT_RETAIN), 1); // intentionally not using a constant, as this config should not be exposed // TODO: REMOVE WITH txnBackwardsCompatCheck() longTimeoutTolerance = conf.getLong("data.tx.long.timeout.tolerance", 10000); // this.txMetricsCollector = txMetricsCollector; this.txMetricsCollector.configure(conf); clear(); }
/** * Start a short transaction with a given timeout. * @param timeoutInSeconds the time out period in seconds. */ public Transaction startShort(int timeoutInSeconds) { Preconditions.checkArgument(timeoutInSeconds > 0, "timeout must be positive but is %s", timeoutInSeconds); txMetricsCollector.rate("start.short"); Stopwatch timer = new Stopwatch().start(); long expiration = getTxExpiration(timeoutInSeconds); Transaction tx = startTx(expiration, TransactionType.SHORT); txMetricsCollector.histogram("start.short.latency", (int) timer.elapsedMillis()); return tx; }
@Override public void doRun() { txMetricsCollector.gauge("committing.size", committingChangeSets.size()); txMetricsCollector.gauge("committed.size", committedChangeSets.size()); txMetricsCollector.gauge("inprogress.size", inProgress.size()); txMetricsCollector.gauge("invalid.size", invalidArray.length); }
private void appendToLog(TransactionEdit edit) { try { Stopwatch timer = new Stopwatch().start(); currentLog.append(edit); txMetricsCollector.rate("wal.append.count"); txMetricsCollector.histogram("wal.append.latency", (int) timer.elapsedMillis()); } catch (IOException ioe) { abortService("Error appending to transaction log", ioe); } }
@Override protected void onShutdown() { // perform a final metrics emit txMetricsCollector.gauge("committing.size", committingChangeSets.size()); txMetricsCollector.gauge("committed.size", committedChangeSets.size()); txMetricsCollector.gauge("inprogress.size", inProgress.size()); txMetricsCollector.gauge("invalid.size", invalidArray.length); }
/** * Start a short transaction with a given timeout. * @param timeoutInSeconds the time out period in seconds. */ public Transaction startShort(int timeoutInSeconds) { Preconditions.checkArgument(timeoutInSeconds > 0, "timeout must be positive but is %s", timeoutInSeconds); txMetricsCollector.rate("start.short"); Stopwatch timer = new Stopwatch().start(); long expiration = getTxExpiration(timeoutInSeconds); Transaction tx = startTx(expiration, TransactionType.SHORT); txMetricsCollector.histogram("start.short.latency", (int) timer.elapsedMillis()); return tx; }
/** * Start a long transaction. Long transactions and do not participate in conflict detection. Also, aborting a long * transaction moves it to the invalid list because we assume that its writes cannot be rolled back. */ public Transaction startLong() { txMetricsCollector.rate("start.long"); Stopwatch timer = new Stopwatch().start(); long expiration = getTxExpiration(defaultLongTimeout); Transaction tx = startTx(expiration, TransactionType.LONG); txMetricsCollector.histogram("start.long.latency", (int) timer.elapsedMillis()); return tx; }
private void appendToLog(TransactionEdit edit) { try { Stopwatch timer = new Stopwatch().start(); currentLog.append(edit); txMetricsCollector.rate("wal.append.count"); txMetricsCollector.histogram("wal.append.latency", (int) timer.elapsedMillis()); } catch (IOException ioe) { abortService("Error appending to transaction log", ioe); } }
/** * Start a long transaction. Long transactions and do not participate in conflict detection. Also, aborting a long * transaction moves it to the invalid list because we assume that its writes cannot be rolled back. */ public Transaction startLong() { txMetricsCollector.rate("start.long"); Stopwatch timer = new Stopwatch().start(); long expiration = getTxExpiration(defaultLongTimeout); Transaction tx = startTx(expiration, TransactionType.LONG); txMetricsCollector.histogram("start.long.latency", (int) timer.elapsedMillis()); return tx; }