Java Code Examples for org.apache.hadoop.hbase.client.coprocessor.Batch#Call
The following examples show how to use
org.apache.hadoop.hbase.client.coprocessor.Batch#Call .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockHTable.java From hgraphdb with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public <T extends Service, R> void coprocessorService(final Class<T> service, byte[] startKey, byte[] endKey, final Batch.Call<T, R> callable, final Batch.Callback<R> callback) throws ServiceException { throw new RuntimeException(this.getClass() + " does NOT implement this method."); }
Example 2
Source File: MockHTable.java From hgraphdb with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public <T extends Service, R> Map<byte[], R> coprocessorService(final Class<T> service, byte[] startKey, byte[] endKey, final Batch.Call<T, R> callable) throws ServiceException { throw new RuntimeException(this.getClass() + " does NOT implement this method."); }
Example 3
Source File: VisibilityClient.java From hbase with Apache License 2.0 | 5 votes |
/** * @param connection the Connection instance to use. * @param user * @return labels, the given user is globally authorized for. * @throws Throwable */ public static GetAuthsResponse getAuths(Connection connection, final String user) throws Throwable { try (Table table = connection.getTable(LABELS_TABLE_NAME)) { Batch.Call<VisibilityLabelsService, GetAuthsResponse> callable = new Batch.Call<VisibilityLabelsService, GetAuthsResponse>() { ServerRpcController controller = new ServerRpcController(); CoprocessorRpcUtils.BlockingRpcCallback<GetAuthsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>(); @Override public GetAuthsResponse call(VisibilityLabelsService service) throws IOException { GetAuthsRequest.Builder getAuthReqBuilder = GetAuthsRequest.newBuilder(); getAuthReqBuilder.setUser(UnsafeByteOperations.unsafeWrap(Bytes.toBytes(user))); service.getAuths(controller, getAuthReqBuilder.build(), rpcCallback); GetAuthsResponse response = rpcCallback.get(); if (controller.failedOnException()) { throw controller.getFailedOn(); } return response; } }; Map<byte[], GetAuthsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } }
Example 4
Source File: VisibilityClient.java From hbase with Apache License 2.0 | 5 votes |
private static VisibilityLabelsResponse setOrClearAuths(Connection connection, final String[] auths, final String user, final boolean setOrClear) throws IOException, ServiceException, Throwable { try (Table table = connection.getTable(LABELS_TABLE_NAME)) { Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse>() { ServerRpcController controller = new ServerRpcController(); CoprocessorRpcUtils.BlockingRpcCallback<VisibilityLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>(); @Override public VisibilityLabelsResponse call(VisibilityLabelsService service) throws IOException { SetAuthsRequest.Builder setAuthReqBuilder = SetAuthsRequest.newBuilder(); setAuthReqBuilder.setUser(UnsafeByteOperations.unsafeWrap(Bytes.toBytes(user))); for (String auth : auths) { if (auth.length() > 0) { setAuthReqBuilder.addAuth((ByteString.copyFromUtf8(auth))); } } if (setOrClear) { service.setAuths(controller, setAuthReqBuilder.build(), rpcCallback); } else { service.clearAuths(controller, setAuthReqBuilder.build(), rpcCallback); } VisibilityLabelsResponse response = rpcCallback.get(); if (controller.failedOnException()) { throw controller.getFailedOn(); } return response; } }; Map<byte[], VisibilityLabelsResponse> result = table.coprocessorService( VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } }
Example 5
Source File: VisibilityClient.java From hbase with Apache License 2.0 | 5 votes |
/** * Retrieve the list of visibility labels defined in the system. * @param connection The Connection instance to use. * @param regex The regular expression to filter which labels are returned. * @return labels The list of visibility labels defined in the system. * @throws Throwable */ public static ListLabelsResponse listLabels(Connection connection, final String regex) throws Throwable { try (Table table = connection.getTable(LABELS_TABLE_NAME)) { Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() { ServerRpcController controller = new ServerRpcController(); CoprocessorRpcUtils.BlockingRpcCallback<ListLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>(); @Override public ListLabelsResponse call(VisibilityLabelsService service) throws IOException { ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder(); if (regex != null) { // Compile the regex here to catch any regex exception earlier. Pattern pattern = Pattern.compile(regex); listAuthLabelsReqBuilder.setRegex(pattern.toString()); } service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback); ListLabelsResponse response = rpcCallback.get(); if (controller.failedOnException()) { throw controller.getFailedOn(); } return response; } }; Map<byte[], ListLabelsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } }
Example 6
Source File: ConnectionQueryServicesImpl.java From phoenix with Apache License 2.0 | 5 votes |
/** * Invoke meta data coprocessor with one retry if the key was found to not be in the regions * (due to a table split) */ private MetaDataMutationResult metaDataCoprocessorExec(byte[] tableKey, Batch.Call<MetaDataService, MetaDataResponse> callable) throws SQLException { try { boolean retried = false; while (true) { if (retried) { connection.relocateRegion( TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES), tableKey); } HTableInterface ht = this.getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); try { final Map<byte[], MetaDataResponse> results = ht.coprocessorService(MetaDataService.class, tableKey, tableKey, callable); assert(results.size() == 1); MetaDataResponse result = results.values().iterator().next(); if (result.getReturnCode() == MetaDataProtos.MutationCode.TABLE_NOT_IN_REGION) { if (retried) return MetaDataMutationResult.constructFromProto(result); retried = true; continue; } return MetaDataMutationResult.constructFromProto(result); } finally { Closeables.closeQuietly(ht); } } } catch (IOException e) { throw ServerUtil.parseServerException(e); } catch (Throwable t) { throw new SQLException(t); } }
Example 7
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { return hTable.coprocessorService(service, startKey, endKey, callable); }
Example 8
Source File: MockHTable.java From metron with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> aClass, byte[] bytes, byte[] bytes1, Batch.Call<T, R> call) throws ServiceException, Throwable { throw new UnsupportedOperationException(); }
Example 9
Source File: MockHTable.java From metron with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> aClass, byte[] bytes, byte[] bytes1, Batch.Call<T, R> call, Batch.Callback<R> callback) throws ServiceException, Throwable { throw new UnsupportedOperationException(); }
Example 10
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { return hTable.coprocessorService(service, startKey, endKey, callable); }
Example 11
Source File: RemoteHTable.java From hbase with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws ServiceException, Throwable { throw new UnsupportedOperationException("coprocessorService not implemented"); }
Example 12
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { return hTable.coprocessorService(service, startKey, endKey, callable); }
Example 13
Source File: MockHTable.java From simplified-lambda with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> var1, byte[] var2, byte[] var3, Batch.Call<T, R> var4, Batch.Callback<R> var5) throws ServiceException, Throwable { throw new RuntimeException(this.getClass() + " does NOT implement this method."); }
Example 14
Source File: RemoteHTable.java From hbase with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { throw new UnsupportedOperationException("coprocessorService not implemented"); }
Example 15
Source File: MetaTableAccessor.java From hbase with Apache License 2.0 | 4 votes |
/** * Performs an atomic multi-mutate operation against the given table. Used by the likes of merge * and split as these want to make atomic mutations across multiple rows. * @throws IOException even if we encounter a RuntimeException, we'll still wrap it in an IOE. */ @VisibleForTesting static void multiMutate(final Table table, byte[] row, final List<Mutation> mutations) throws IOException { debugLogMutations(mutations); Batch.Call<MultiRowMutationService, MutateRowsResponse> callable = instance -> { MutateRowsRequest.Builder builder = MutateRowsRequest.newBuilder(); for (Mutation mutation : mutations) { if (mutation instanceof Put) { builder.addMutationRequest( ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.PUT, mutation)); } else if (mutation instanceof Delete) { builder.addMutationRequest( ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.DELETE, mutation)); } else { throw new DoNotRetryIOException( "multi in MetaEditor doesn't support " + mutation.getClass().getName()); } } ServerRpcController controller = new ServerRpcController(); CoprocessorRpcUtils.BlockingRpcCallback<MutateRowsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>(); instance.mutateRows(controller, builder.build(), rpcCallback); MutateRowsResponse resp = rpcCallback.get(); if (controller.failedOnException()) { throw controller.getFailedOn(); } return resp; }; try { table.coprocessorService(MultiRowMutationService.class, row, row, callable); } catch (Throwable e) { // Throw if an IOE else wrap in an IOE EVEN IF IT IS a RuntimeException (e.g. // a RejectedExecutionException because the hosting exception is shutting down. // This is old behavior worth reexamining. Procedures doing merge or split // currently don't handle RuntimeExceptions coming up out of meta table edits. // Would have to work on this at least. See HBASE-23904. Throwables.throwIfInstanceOf(e, IOException.class); throw new IOException(e); } }
Example 16
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { return hTable.coprocessorService(service, startKey, endKey, callable); }
Example 17
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws ServiceException, Throwable { hTable.coprocessorService(service, startKey, endKey, callable, callback); }
Example 18
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws ServiceException, Throwable { hTable.coprocessorService(service, startKey, endKey, callable, callback); }
Example 19
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> Map<byte[], R> coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws ServiceException, Throwable { return hTable.coprocessorService(service, startKey, endKey, callable); }
Example 20
Source File: MockHTable.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public <T extends Service, R> void coprocessorService(Class<T> service, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws ServiceException, Throwable { throw new NotImplementedException(); }