Transaction interface

The Transaction interface is the basis of reliability for Flume. All themajor components (ie. Sources, Sinks and Channels) must use aFlume Transaction.

Transaction sequence diagram

A Transaction is implemented within a Channel implementation. EachSource and Sink that is connected to a Channel must obtain aTransaction object. The Sources use a ChannelProcessorto manage the Transactions, the Sinks manage them explicitly viatheir configured Channel. The operation to stage anEvent (put it into a Channel) or extract an Event (take it out of aChannel) is done inside an active Transaction. For example:

  1. Channel ch = new MemoryChannel();
  2. Transaction txn = ch.getTransaction();
  3. txn.begin();
  4. try {
  5. // This try clause includes whatever Channel operations you want to do
  6.  
  7. Event eventToStage = EventBuilder.withBody("Hello Flume!",
  8. Charset.forName("UTF-8"));
  9. ch.put(eventToStage);
  10. // Event takenEvent = ch.take();
  11. // ...
  12. txn.commit();
  13. } catch (Throwable t) {
  14. txn.rollback();
  15.  
  16. // Log exception, handle individual exceptions as needed
  17.  
  18. // re-throw all Errors
  19. if (t instanceof Error) {
  20. throw (Error)t;
  21. }
  22. } finally {
  23. txn.close();
  24. }

Here we get hold of a Transaction from a Channel. After begin()returns, the Transaction is now active/open and the Event is then putinto the Channel. If the put is successful, then the Transaction iscommitted and closed.