Skip to content

Commit

Permalink
Merge pull request #75 from mgarolera/batch
Browse files Browse the repository at this point in the history
Remove excess batch methods
  • Loading branch information
mgarolera committed Oct 29, 2014
2 parents 180ec5b + fd12ca4 commit 1c40513
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Result get(Get get) throws IOException {

@Override
public Result[] get(List<Get> gets) throws IOException {
return batchExecutor.get(gets);
return (Result[]) batchExecutor.batch(gets);
}

@Override
Expand Down Expand Up @@ -271,7 +271,7 @@ public void put(Put put) throws IOException {

@Override
public void put(List<Put> puts) throws IOException {
batchExecutor.put(puts);
batchExecutor.batch(puts);
}

@Override
Expand Down Expand Up @@ -306,7 +306,7 @@ public void delete(Delete delete) throws IOException {

@Override
public void delete(List<Delete> deletes) throws IOException {
batchExecutor.delete(deletes);
batchExecutor.batch(deletes);
}

@Override
Expand Down
78 changes: 1 addition & 77 deletions src/main/java/com/google/cloud/anviltop/hbase/BatchExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,34 +522,12 @@ public <R> void batchCallback(List<? extends Row> actions,
}
}

/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#delete(List)}
*/
public List<AnviltopServices.MutateRowResponse> delete(List<Delete> deletes) throws IOException {
List<AnviltopServices.MutateRowResponse> responses;
try {
/* The following is from Table#delete(List): "If there are any failures even after retries,
* there will be a null in the results array for those Gets, AND an exception will be thrown."
* This sentence makes my head hurt. The best interpretation I can come up with is "execute
* all gets and then throw an exception". This is what allAsList will do. Wait for all to
* complete and throw an exception for failed futures.
*/
responses = Futures.allAsList(issueDeleteRequests(deletes)).get();
} catch (ExecutionException | InterruptedException e) {
// TODO: For Execution exception, add inspection of ExecutionException#getCause to get the
// real issue.
throw new IOException("Error in batch delete", e);
}

return responses;
}

/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#exists(List)}.
*/
public Boolean[] exists(List<Get> gets) throws IOException {
// get(gets) will throw if there are any errors:
Result[] getResults = get(gets);
Result[] getResults = (Result[]) batch(gets);

Boolean[] exists = new Boolean[getResults.length];
for (int index = 0; index < getResults.length; index++) {
Expand All @@ -558,58 +536,4 @@ public Boolean[] exists(List<Get> gets) throws IOException {
return exists;
}

/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#get(List)}
*/
public Result[] get(List<Get> gets) throws IOException {
List<AnviltopServices.GetRowResponse> responses;
try {
/* The following is from Table#get(List): "If there are any failures even after retries,
* there will be a null in the results array for those Gets, AND an exception will be thrown."
* This sentence makes my head hurt. The best interpretation I can come up with is "execute
* all gets and then throw an exception". This is what allAsList will do. Wait for all to
* complete and throw an exception for failed futures.
*/
responses = Futures.allAsList(issueGetRequests(gets)).get();
} catch (ExecutionException | InterruptedException e) {
// TODO: For Execution exception, add inspection of ExecutionException#getCause to get the
// real issue.
throw new IOException("Error in batch get", e);
}

List<Result> resultList =
Lists.transform(responses, new Function<AnviltopServices.GetRowResponse, Result>(){
@Override
public Result apply(@Nullable AnviltopServices.GetRowResponse getRowResponse) {
return getRowResponseAdapter.adaptResponse(getRowResponse);
}
});

int resultCount = resultList.size();
Result[] results = new Result[resultCount];
resultList.toArray(results);
return results;
}

/**
* Implementation of {@link org.apache.hadoop.hbase.client.HTable#put(List)}
*/
public List<AnviltopServices.MutateRowResponse> put(List<Put> puts) throws IOException {
List<AnviltopServices.MutateRowResponse> responses;
try {
/* The following is from Table#put(List): "If there are any failures even after retries,
* there will be a null in the results array for those Gets, AND an exception will be thrown."
* This sentence makes my head hurt. The best interpretation I can come up with is "execute
* all gets and then throw an exception". This is what allAsList will do. Wait for all to
* complete and throw an exception for failed futures.
*/
responses = Futures.allAsList(issuePutRequests(puts)).get();
} catch (ExecutionException | InterruptedException e) {
// TODO: For Execution exception, add inspection of ExecutionException#getCause to get the
// real issue.
throw new IOException("Error in batch put", e);
}

return responses;
}
}

0 comments on commit 1c40513

Please sign in to comment.