Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #96 from yahoo/improve-exceptions
Browse files Browse the repository at this point in the history
Use IOException in TransactionException and ZKUtils.initZKClient()
  • Loading branch information
ikatkov committed Apr 25, 2016
2 parents 3072f32 + 83c252b commit 768a307
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
17 changes: 12 additions & 5 deletions common/src/main/java/org/apache/omid/zk/ZKUtils.java
Expand Up @@ -32,7 +32,7 @@ public class ZKUtils {
private static final Logger LOG = LoggerFactory.getLogger(ZKUtils.class);

public static CuratorFramework initZKClient(String zkCluster, String namespace, int zkConnectionTimeoutInSec)
throws IOException, InterruptedException {
throws IOException {

LOG.info("Creating Zookeeper Client connecting to {}", zkCluster);

Expand All @@ -44,10 +44,17 @@ public static CuratorFramework initZKClient(String zkCluster, String namespace,
.build();

zkClient.start();
if (zkClient.blockUntilConnected(zkConnectionTimeoutInSec, TimeUnit.SECONDS)) {
LOG.info("Connected to ZK cluster '{}', client in state: [{}]", zkCluster, zkClient.getState());
} else {
throw new IOException(String.format("Can't contact ZK cluster '%s' after 10 seconds", zkCluster));

try {
if (zkClient.blockUntilConnected(zkConnectionTimeoutInSec, TimeUnit.SECONDS)) {
LOG.info("Connected to ZK cluster '{}', client in state: [{}]", zkCluster, zkClient.getState());
} else {
String errorMsg = String.format("Can't contact ZK cluster '%s' after %d seconds",
zkCluster, zkConnectionTimeoutInSec);
throw new IOException(errorMsg);
}
} catch (InterruptedException ex) {
throw new IOException(String.format("Interrupted whilst connecting to ZK cluster '%s'", zkCluster));
}

return zkClient;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.apache.omid.transaction.RollbackException;
import org.apache.omid.transaction.TTable;
import org.apache.omid.transaction.Transaction;
import org.apache.omid.transaction.TransactionException;
import org.apache.omid.transaction.TransactionManager;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.client.Put;
Expand Down Expand Up @@ -91,7 +90,7 @@ public static void main(String[] args) throws Exception {
}

private void doWork(String userTableName, byte[] family, HBaseOmidClientConfiguration configuration)
throws IOException, TransactionException, RollbackException, InterruptedException {
throws IOException, RollbackException, InterruptedException {

byte[] exampleRow1 = Bytes.toBytes("EXAMPLE_ROW1");
byte[] exampleRow2 = Bytes.toBytes("EXAMPLE_ROW2");
Expand Down
Expand Up @@ -369,7 +369,7 @@ public void testScenario2() throws Exception {
}

private void checkRowValues(TTable txTable, byte[] expectedDataR1Q1, byte[] expectedDataR2Q2)
throws TransactionException, IOException, RollbackException {
throws IOException, RollbackException {
Transaction readTx = tm.begin();
LOG.info("Starting Read Tx {} for checking cell values", readTx.getTransactionId());
Get getRow1 = new Get(row1).setMaxVersions(1);
Expand Down
Expand Up @@ -204,7 +204,7 @@ public void testClientReceivesNotificationOfANewTSOCanInvalidateTransaction() th

}

private void executeTxAndCheckRollback() throws IOException, TransactionException, InterruptedException, java.util.concurrent.ExecutionException {
private void executeTxAndCheckRollback() throws IOException, InterruptedException, java.util.concurrent.ExecutionException {
try (TTable txTable = new TTable(hbaseConf, TEST_TABLE)) {
HBaseTransaction tx1 = (HBaseTransaction) tm.begin();
assertEquals(tx1.getStartTimestamp(), TX1_ST);
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void configure() {

@Provides
@Singleton
CuratorFramework provideInitializedZookeeperClient() throws IOException, InterruptedException {
CuratorFramework provideInitializedZookeeperClient() throws IOException {
return ZKUtils.initZKClient(zkCluster, namespace, 10);
}

Expand Down
Expand Up @@ -17,7 +17,9 @@
*/
package org.apache.omid.transaction;

public class TransactionException extends Exception {
import java.io.IOException;

public class TransactionException extends IOException {

private static final long serialVersionUID = 7273525983622126275L;

Expand All @@ -28,4 +30,5 @@ public TransactionException(String reason) {
public TransactionException(String reason, Throwable e) {
super(reason, e);
}

}
Expand Up @@ -96,13 +96,12 @@ public class TSOClient implements TSOProtocol, NodeCacheListener {
// Construction
// ----------------------------------------------------------------------------------------------------------------

public static TSOClient newInstance(OmidClientConfiguration tsoClientConf)
throws IOException, InterruptedException {
public static TSOClient newInstance(OmidClientConfiguration tsoClientConf) throws IOException {
return new TSOClient(tsoClientConf);
}

// Avoid instantiation
private TSOClient(OmidClientConfiguration omidConf) throws IOException, InterruptedException {
private TSOClient(OmidClientConfiguration omidConf) throws IOException {

// Start client with Nb of active threads = 3 as maximum.
int tsoExecutorThreads = omidConf.getExecutorThreads();
Expand Down

0 comments on commit 768a307

Please sign in to comment.