private Sink.Status prepareAndSend(Context context, String msg) throws EventDeliveryException { Sink kafkaSink = new KafkaSink(); Configurables.configure(kafkaSink, context); Channel memoryChannel = new MemoryChannel(); Configurables.configure(memoryChannel, context); kafkaSink.setChannel(memoryChannel); kafkaSink.start(); Transaction tx = memoryChannel.getTransaction(); tx.begin(); Event event = EventBuilder.withBody(msg.getBytes()); memoryChannel.put(event); tx.commit(); tx.close(); return kafkaSink.process(); }
Channel channel = getChannel(); Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); sinkCounter.incrementBatchUnderflowCount(); else sinkCounter.incrementBatchCompleteCount(); sinkCounter.incrementBatchEmptyCount(); sinkCounter.addToEventDrainAttemptCount(batch.size()); transaction.commit(); sinkCounter.addToEventDrainSuccessCount(batch.size()); transaction.rollback(); throw new EventDeliveryException(e); transaction.close();
/** * Rollback the transaction. If there is a RuntimeException during rollback, * it will be logged but the transaction instance variable will still be * nullified. */ private void rollbackTransaction() { if (transaction != null) { try { // If the transaction wasn't committed before we got the exception, we // need to rollback. transaction.rollback(); } catch (RuntimeException ex) { LOG.error("Transaction rollback failed: " + ex.getLocalizedMessage()); LOG.debug("Exception follows.", ex); } finally { transaction.close(); this.transaction = null; } } }
/** * Commit and close the transaction. * * If this method throws an Exception the caller *must* ensure that the * transaction is rolled back. Callers can roll back the transaction by * calling {@link #rollbackTransaction()}. * * @return True if there was an open transaction and it was committed, false * otherwise. * @throws EventDeliveryException There was an error ending the batch with * the failure policy. */ @VisibleForTesting boolean commitTransaction() throws EventDeliveryException { if (transaction != null) { failurePolicy.sync(); transaction.commit(); transaction.close(); this.transaction = null; return true; } else { return false; } }
@Override public Status process() throws EventDeliveryException { Status result = Status.READY; Channel channel = getChannel(); Transaction transaction = channel.getTransaction(); Event event = null; try { transaction.begin(); event = channel.take(); if (event != null) { if (logger.isInfoEnabled()) { logger.info("Event: " + EventHelper.dumpEvent(event, maxBytesToLog)); } } else { // No event found, request back-off semantics from the sink runner result = Status.BACKOFF; } transaction.commit(); } catch (Exception ex) { transaction.rollback(); throw new EventDeliveryException("Failed to log event: " + event, ex); } finally { transaction.close(); } return result; } }
serializerType, serializerContext, outputStream); serializer.afterCreate(); sinkCounter.incrementConnectionCreatedCount(); throw new EventDeliveryException("Failed to open file " + pathController.getCurrentFile() + " while delivering event", e); Transaction transaction = channel.getTransaction(); Event event = null; Status result = Status.READY; transaction.begin(); int eventAttemptCounter = 0; for (int i = 0; i < batchSize; i++) { event = channel.take(); transaction.commit(); transaction.rollback(); throw new EventDeliveryException("Failed to process transaction", ex); } finally { transaction.close();
Transaction txn = ch.getTransaction(); txn.begin(); Event event = ch.take(); txn.rollback(); } else { txn.commit(); sinkCounter.incrementEventDrainSuccessCount(); txn.rollback(); status = Status.BACKOFF; txn.rollback(); status = Status.BACKOFF; sinkCounter.incrementEventWriteFail(); txn.commit(); status = Status.BACKOFF; txn.rollback(); status = Status.BACKOFF; txn.close();
Transaction transaction = channel.getTransaction(); transaction.begin(); boolean success = false; try { transaction.commit(); success = true; return Status.BACKOFF; } catch (Exception e) { sinkCounter.incrementEventWriteOrChannelFail(e); throw new EventDeliveryException(e); } finally { if (!success) { transaction.rollback(); transaction.close();
private void handleTransactionFailure(Transaction txn) throws EventDeliveryException { if (maxConsecutiveFails > 0 && consecutiveHBaseFailures >= maxConsecutiveFails) { if (client != null) { shutdownHBaseClient(); } consecutiveHBaseFailures = 0; } try { txn.rollback(); } catch (Throwable e) { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); if (e instanceof Error || e instanceof RuntimeException) { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); Throwables.propagate(e); } else { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); throw new EventDeliveryException("Failed to commit transaction." + "Transaction rolled back.", e); } } finally { txn.close(); } }
txn.commit(); sinkCounter.addToEventDrainSuccessCount(actions.size());
/** * Enter the transaction boundary. This will either begin a new transaction * if one didn't already exist. If we're already in a transaction boundary, * then this method does nothing. * * @param channel The Sink's channel * @throws EventDeliveryException There was an error starting a new batch * with the failure policy. */ private void enterTransaction(Channel channel) throws EventDeliveryException { // There's no synchronization around the transaction instance because the // Sink API states "the Sink#process() call is guaranteed to only // be accessed by a single thread". Technically other methods could be // called concurrently, but the implementation of SinkRunner waits // for the Thread running process() to end before calling stop() if (transaction == null) { this.transaction = channel.getTransaction(); transaction.begin(); failurePolicy = FAILURE_POLICY_FACTORY.newPolicy(context); } }
private void commitPutsToOverflow_core(Transaction overflowPutTx) throws InterruptedException { // reattempt only once if overflow is full first time around for (int i = 0; i < 2; ++i) { try { synchronized (queueLock) { overflowPutTx.commit(); drainOrder.putOverflow(putList.size()); channelCounter.setChannelSize(memQueue.size() + drainOrder.overflowCounter); break; } } catch (ChannelFullException e) { // drop lock & reattempt if (i == 0) { Thread.sleep(overflowTimeout * 1000); } else { throw e; } } } }
Transaction tx = reqChannel.getTransaction(); Preconditions.checkNotNull(tx, "Transaction object must not be null"); try { tx.begin(); reqChannel.put(event); tx.commit(); } catch (Throwable t) { tx.rollback(); if (t instanceof Error) { LOG.error("Error while writing to required channel: " + reqChannel, t); tx.close(); Transaction tx = null; try { tx = optChannel.getTransaction(); tx.begin(); tx.commit(); } catch (Throwable t) { tx.rollback(); LOG.error("Unable to put event on optional channel: " + optChannel, t); if (t instanceof Error) { tx.close();
serializerType, serializerContext, outputStream); serializer.afterCreate(); sinkCounter.incrementConnectionCreatedCount(); throw new EventDeliveryException("Failed to open file " + pathController.getCurrentFile() + " while delivering event", e); Transaction transaction = channel.getTransaction(); Event event = null; Status result = Status.READY; transaction.begin(); int eventAttemptCounter = 0; for (int i = 0; i < batchSize; i++) { event = channel.take(); transaction.commit(); transaction.rollback(); throw new EventDeliveryException("Failed to process transaction", ex); } finally { transaction.close();
Transaction txn = ch.getTransaction(); txn.begin(); Event event = ch.take(); txn.rollback(); } else { txn.commit(); sinkCounter.incrementEventDrainSuccessCount(); txn.rollback(); status = Status.BACKOFF; txn.rollback(); status = Status.BACKOFF; sinkCounter.incrementEventWriteFail(); txn.commit(); status = Status.BACKOFF; txn.rollback(); status = Status.BACKOFF; txn.close();
Transaction transaction = channel.getTransaction(); transaction.begin(); boolean success = false; try { transaction.commit(); success = true; return Status.BACKOFF; } catch (Exception e) { sinkCounter.incrementEventWriteOrChannelFail(e); throw new EventDeliveryException(e); } finally { if (!success) { transaction.rollback(); transaction.close();
private void handleTransactionFailure(Transaction txn) throws EventDeliveryException { if (maxConsecutiveFails > 0 && consecutiveHBaseFailures >= maxConsecutiveFails) { if (client != null) { shutdownHBaseClient(); } consecutiveHBaseFailures = 0; } try { txn.rollback(); } catch (Throwable e) { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); if (e instanceof Error || e instanceof RuntimeException) { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); Throwables.propagate(e); } else { logger.error("Failed to commit transaction." + "Transaction rolled back.", e); throw new EventDeliveryException("Failed to commit transaction." + "Transaction rolled back.", e); } } finally { txn.close(); } }
}); txn.commit(); sinkCounter.addToEventDrainSuccessCount(actions.size());
/** * Rollback the transaction. If there is a RuntimeException during rollback, * it will be logged but the transaction instance variable will still be * nullified. */ private void rollbackTransaction() { if (transaction != null) { try { // If the transaction wasn't committed before we got the exception, we // need to rollback. transaction.rollback(); } catch (RuntimeException ex) { LOG.error("Transaction rollback failed: " + ex.getLocalizedMessage()); LOG.debug("Exception follows.", ex); } finally { transaction.close(); this.transaction = null; } } }