[ISSUE] (TEPHRA-61) Add documentation on obtaining a TransactionSystemClient

4 views
Skip to first unread message

Gary Helmling (JIRA)

unread,
Jan 31, 2015, 3:42:45 PM1/31/15
to tephr...@googlegroups.com
Gary Helmling created an issue
 
Tephra / Task TEPHRA-61
Add documentation on obtaining a TransactionSystemClient
Issue Type: Task Task
Assignee: Gary Helmling
Created: 31/Jan/15 12:42 PM
Priority: Major Major
Reporter: Gary Helmling

We have some examples in the documentation on using TransactionContext and TransactionAwareHTable, but we don't explain how to get a TransactionSystemClient that's needed to interact with the Tephra server.

We need to add something along the lines of the following:

If you are using Google Guice, you can make use of the Guice modules that we provide for dependency injection, which will help you get a fully configured TransactionServiceClient instance:

Injector injector = Guice.createInjector(
    new ConfigModule(conf),
    new ZKModule(),
    new DiscoveryModules().getDistributedModules(),
    new TransactionModules().getDistributedModules(),
    new TransactionClientModule()
);

ZKClientService zkClient = injector.getInstance(ZKClientService.class);
zkClient.startAndWait();

TransactionServiceClient client = injector.getInstance(TransactionServiceClient.class);

You can do this during your application startup and reuse the same TransactionServiceClient instance across all application threads.

Then, within each application thread, you can use a TransactionContext instance, along with TransactionAwareHTable instances to interact with HBase:

Configuration conf = HBaseConfiguration.create();
HConnection conn = HConnectionManager.createConnection(conf);

TransactionAwareHTable txTable = new TransactionAwareHTable(conn.getTable("mytable"));
TransactionContext txContext = new TransactionContext(client, txTable);
try {
  txContext.start();
  txTable.put(...); // perform normal operations
  ...
  txContext.finish();
}  catch (TransactionFailureException tfe) {
  txContext.abort();
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.1.5#6160-sha1:a61a0fc)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages