Search in sources :

Example 6 with RpcController

use of org.apache.hbase.thirdparty.com.google.protobuf.RpcController in project hbase by apache.

the class AggregationClient method min.

/**
 * It gives the minimum value of a column for a given column family for the
 * given range. In case qualifier is null, a min of all values for the given
 * family is returned.
 * @param table table to scan.
 * @param ci the user's ColumnInterpreter implementation
 * @param scan the HBase scan object to use to read data from HBase
 * @return min val <R>
 * @throws Throwable The caller is supposed to handle the exception as they are thrown
 *           & propagated to it.
 */
public <R, S, P extends Message, Q extends Message, T extends Message> R min(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false);
    class MinCallBack implements Batch.Callback<R> {

        private R min = null;

        public R getMinimum() {
            return min;
        }

        @Override
        public synchronized void update(byte[] region, byte[] row, R result) {
            min = (min == null || (result != null && ci.compare(result, min) < 0)) ? result : min;
        }
    }
    MinCallBack minCallBack = new MinCallBack();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(), new Batch.Call<AggregateService, R>() {

        @Override
        public R call(AggregateService instance) throws IOException {
            RpcController controller = new AggregationClientRpcController();
            CoprocessorRpcUtils.BlockingRpcCallback<AggregateResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
            instance.getMin(controller, requestArg, rpcCallback);
            AggregateResponse response = rpcCallback.get();
            if (controller.failed()) {
                throw new IOException(controller.errorText());
            }
            if (response.getFirstPartCount() > 0) {
                ByteString b = response.getFirstPart(0);
                Q q = getParsedGenericInstance(ci.getClass(), 3, b);
                return ci.getCellValueFromProto(q);
            }
            return null;
        }
    }, minCallBack);
    log.debug("Min fom all regions is: " + minCallBack.getMinimum());
    return minCallBack.getMinimum();
}
Also used : AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) IOException(java.io.IOException) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)

Example 7 with RpcController

use of org.apache.hbase.thirdparty.com.google.protobuf.RpcController in project hbase by apache.

the class AggregationClient method getAvgArgs.

/**
 * It computes average while fetching sum and row count from all the
 * corresponding regions. Approach is to compute a global sum of region level
 * sum and rowcount and then compute the average.
 * @param table table to scan.
 * @param scan the HBase scan object to use to read data from HBase
 * @throws Throwable The caller is supposed to handle the exception as they are thrown
 *           &amp; propagated to it.
 */
private <R, S, P extends Message, Q extends Message, T extends Message> Pair<S, Long> getAvgArgs(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false);
    class AvgCallBack implements Batch.Callback<Pair<S, Long>> {

        S sum = null;

        Long rowCount = 0L;

        public synchronized Pair<S, Long> getAvgArgs() {
            return new Pair<>(sum, rowCount);
        }

        @Override
        public synchronized void update(byte[] region, byte[] row, Pair<S, Long> result) {
            sum = ci.add(sum, result.getFirst());
            rowCount += result.getSecond();
        }
    }
    AvgCallBack avgCallBack = new AvgCallBack();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(), new Batch.Call<AggregateService, Pair<S, Long>>() {

        @Override
        public Pair<S, Long> call(AggregateService instance) throws IOException {
            RpcController controller = new AggregationClientRpcController();
            CoprocessorRpcUtils.BlockingRpcCallback<AggregateResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
            instance.getAvg(controller, requestArg, rpcCallback);
            AggregateResponse response = rpcCallback.get();
            if (controller.failed()) {
                throw new IOException(controller.errorText());
            }
            Pair<S, Long> pair = new Pair<>(null, 0L);
            if (response.getFirstPartCount() == 0) {
                return pair;
            }
            ByteString b = response.getFirstPart(0);
            T t = getParsedGenericInstance(ci.getClass(), 4, b);
            S s = ci.getPromotedValueFromProto(t);
            pair.setFirst(s);
            ByteBuffer bb = ByteBuffer.allocate(8).put(getBytesFromResponse(response.getSecondPart()));
            bb.rewind();
            pair.setSecond(bb.getLong());
            return pair;
        }
    }, avgCallBack);
    return avgCallBack.getAvgArgs();
}
Also used : AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) Pair(org.apache.hadoop.hbase.util.Pair) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)

Example 8 with RpcController

use of org.apache.hbase.thirdparty.com.google.protobuf.RpcController in project hbase by apache.

the class AggregationClient method getStdArgs.

/**
 * It computes a global standard deviation for a given column and its value.
 * Standard deviation is square root of (average of squares -
 * average*average). From individual regions, it obtains sum, square sum and
 * number of rows. With these, the above values are computed to get the global
 * std.
 * @param table table to scan.
 * @param scan the HBase scan object to use to read data from HBase
 * @return standard deviations
 * @throws Throwable The caller is supposed to handle the exception as they are thrown
 *           &amp; propagated to it.
 */
private <R, S, P extends Message, Q extends Message, T extends Message> Pair<List<S>, Long> getStdArgs(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false);
    class StdCallback implements Batch.Callback<Pair<List<S>, Long>> {

        long rowCountVal = 0L;

        S sumVal = null, sumSqVal = null;

        public synchronized Pair<List<S>, Long> getStdParams() {
            List<S> l = new ArrayList<>(2);
            l.add(sumVal);
            l.add(sumSqVal);
            Pair<List<S>, Long> p = new Pair<>(l, rowCountVal);
            return p;
        }

        @Override
        public synchronized void update(byte[] region, byte[] row, Pair<List<S>, Long> result) {
            if (result.getFirst().size() > 0) {
                sumVal = ci.add(sumVal, result.getFirst().get(0));
                sumSqVal = ci.add(sumSqVal, result.getFirst().get(1));
                rowCountVal += result.getSecond();
            }
        }
    }
    StdCallback stdCallback = new StdCallback();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(), new Batch.Call<AggregateService, Pair<List<S>, Long>>() {

        @Override
        public Pair<List<S>, Long> call(AggregateService instance) throws IOException {
            RpcController controller = new AggregationClientRpcController();
            CoprocessorRpcUtils.BlockingRpcCallback<AggregateResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
            instance.getStd(controller, requestArg, rpcCallback);
            AggregateResponse response = rpcCallback.get();
            if (controller.failed()) {
                throw new IOException(controller.errorText());
            }
            Pair<List<S>, Long> pair = new Pair<>(new ArrayList<>(), 0L);
            if (response.getFirstPartCount() == 0) {
                return pair;
            }
            List<S> list = new ArrayList<>();
            for (int i = 0; i < response.getFirstPartCount(); i++) {
                ByteString b = response.getFirstPart(i);
                T t = getParsedGenericInstance(ci.getClass(), 4, b);
                S s = ci.getPromotedValueFromProto(t);
                list.add(s);
            }
            pair.setFirst(list);
            ByteBuffer bb = ByteBuffer.allocate(8).put(getBytesFromResponse(response.getSecondPart()));
            bb.rewind();
            pair.setSecond(bb.getLong());
            return pair;
        }
    }, stdCallback);
    return stdCallback.getStdParams();
}
Also used : AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.hadoop.hbase.util.Pair) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)

Example 9 with RpcController

use of org.apache.hbase.thirdparty.com.google.protobuf.RpcController in project hbase by apache.

the class AggregationClient method rowCount.

/**
 * It gives the row count, by summing up the individual results obtained from
 * regions. In case the qualifier is null, FirstKeyValueFilter is used to
 * optimised the operation. In case qualifier is provided, I can't use the
 * filter as it may set the flag to skip to next row, but the value read is
 * not of the given filter: in this case, this particular row will not be
 * counted ==&gt; an error.
 * @param table table to scan.
 * @param ci the user's ColumnInterpreter implementation
 * @param scan the HBase scan object to use to read data from HBase
 * @return &lt;R, S&gt;
 * @throws Throwable The caller is supposed to handle the exception as they are thrown
 *           &amp; propagated to it.
 */
public <R, S, P extends Message, Q extends Message, T extends Message> long rowCount(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, true);
    class RowNumCallback implements Batch.Callback<Long> {

        private final AtomicLong rowCountL = new AtomicLong(0);

        public long getRowNumCount() {
            return rowCountL.get();
        }

        @Override
        public void update(byte[] region, byte[] row, Long result) {
            rowCountL.addAndGet(result.longValue());
        }
    }
    RowNumCallback rowNum = new RowNumCallback();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(), new Batch.Call<AggregateService, Long>() {

        @Override
        public Long call(AggregateService instance) throws IOException {
            RpcController controller = new AggregationClientRpcController();
            CoprocessorRpcUtils.BlockingRpcCallback<AggregateResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
            instance.getRowNum(controller, requestArg, rpcCallback);
            AggregateResponse response = rpcCallback.get();
            if (controller.failed()) {
                throw new IOException(controller.errorText());
            }
            byte[] bytes = getBytesFromResponse(response.getFirstPart(0));
            ByteBuffer bb = ByteBuffer.allocate(8).put(bytes);
            bb.rewind();
            return bb.getLong();
        }
    }, rowNum);
    return rowNum.getRowNumCount();
}
Also used : AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) AtomicLong(java.util.concurrent.atomic.AtomicLong) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)

Example 10 with RpcController

use of org.apache.hbase.thirdparty.com.google.protobuf.RpcController in project hbase by apache.

the class HBaseRpcServicesBase method clearSlowLogsResponses.

@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public ClearSlowLogResponses clearSlowLogsResponses(final RpcController controller, final ClearSlowLogResponseRequest request) throws ServiceException {
    try {
        requirePermission("clearSlowLogsResponses", Permission.Action.ADMIN);
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    final NamedQueueRecorder namedQueueRecorder = this.server.getNamedQueueRecorder();
    boolean slowLogsCleaned = Optional.ofNullable(namedQueueRecorder).map(queueRecorder -> queueRecorder.clearNamedQueue(NamedQueuePayload.NamedQueueEvent.SLOW_LOG)).orElse(false);
    ClearSlowLogResponses clearSlowLogResponses = ClearSlowLogResponses.newBuilder().setIsCleaned(slowLogsCleaned).build();
    return clearSlowLogResponses;
}
Also used : NamedQueueRecorder(org.apache.hadoop.hbase.namequeues.NamedQueueRecorder) GetMastersRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMastersRequest) SlowLogPayload(org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog.SlowLogPayload) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) LoggerFactory(org.slf4j.LoggerFactory) RpcSchedulerFactory(org.apache.hadoop.hbase.regionserver.RpcSchedulerFactory) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) NamedQueueGetResponse(org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse) NamedQueueRecorder(org.apache.hadoop.hbase.namequeues.NamedQueueRecorder) Configuration(org.apache.hadoop.conf.Configuration) PriorityFunction(org.apache.hadoop.hbase.ipc.PriorityFunction) Method(java.lang.reflect.Method) Address(org.apache.hadoop.hbase.net.Address) NoopAccessChecker(org.apache.hadoop.hbase.security.access.NoopAccessChecker) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) RpcLogDetails(org.apache.hadoop.hbase.namequeues.RpcLogDetails) ZKPermissionWatcher(org.apache.hadoop.hbase.security.access.ZKPermissionWatcher) GetBootstrapNodesRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetBootstrapNodesRequest) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) SlowLogResponseRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.SlowLogResponseRequest) GetMetaRegionLocationsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMetaRegionLocationsRequest) InetSocketAddress(java.net.InetSocketAddress) GetMetaRegionLocationsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMetaRegionLocationsResponse) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) ConfigurationObserver(org.apache.hadoop.hbase.conf.ConfigurationObserver) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) UpdateConfigurationResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.UpdateConfigurationResponse) Optional(java.util.Optional) ClearSlowLogResponseRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ClearSlowLogResponseRequest) GetActiveMasterResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetActiveMasterResponse) HBaseRPCErrorHandler(org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler) Permission(org.apache.hadoop.hbase.security.access.Permission) DNS(org.apache.hadoop.hbase.util.DNS) ByteBuffAllocator(org.apache.hadoop.hbase.io.ByteBuffAllocator) ReservoirSample(org.apache.hadoop.hbase.util.ReservoirSample) NamedQueueGetRequest(org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest) ConnectionUtils(org.apache.hadoop.hbase.client.ConnectionUtils) RpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController) GetMastersResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMastersResponse) BindException(java.net.BindException) User(org.apache.hadoop.hbase.security.User) ClearSlowLogResponses(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ClearSlowLogResponses) UpdateConfigurationRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.UpdateConfigurationRequest) GetBootstrapNodesResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetBootstrapNodesResponse) GetClusterIdResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetClusterIdResponse) NamedQueuePayload(org.apache.hadoop.hbase.namequeues.NamedQueuePayload) GetMastersResponseEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMastersResponseEntry) RpcServer(org.apache.hadoop.hbase.ipc.RpcServer) SlowLogResponses(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.SlowLogResponses) Logger(org.slf4j.Logger) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) KeeperException(org.apache.zookeeper.KeeperException) GetClusterIdRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetClusterIdRequest) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) GetActiveMasterRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetActiveMasterRequest) IOException(java.io.IOException) ClientMetaService(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.ClientMetaService) RpcServerFactory(org.apache.hadoop.hbase.ipc.RpcServerFactory) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority) OOMEChecker(org.apache.hadoop.hbase.util.OOMEChecker) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) AccessChecker(org.apache.hadoop.hbase.security.access.AccessChecker) RpcScheduler(org.apache.hadoop.hbase.ipc.RpcScheduler) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) Collections(java.util.Collections) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) IOException(java.io.IOException) ClearSlowLogResponses(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ClearSlowLogResponses) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Aggregations

RpcController (org.apache.hbase.thirdparty.com.google.protobuf.RpcController)16 IOException (java.io.IOException)15 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)14 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)12 List (java.util.List)8 Pair (org.apache.hadoop.hbase.util.Pair)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Method (java.lang.reflect.Method)6 Collections (java.util.Collections)6 Configuration (org.apache.hadoop.conf.Configuration)6 InetAddress (java.net.InetAddress)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Entry (java.util.Map.Entry)5 Set (java.util.Set)5 AggregateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest)5 AggregateResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse)5 AggregateService (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)5