final byte[] region_name = rpc.getRegion().name(); final boolean new_region = !Bytes.equals(prev.getRegion().name(), region_name); final byte[] family = rpc.family(); final boolean new_key = (new_region || prev.code() != rpc.code() || !Bytes.equals(prev.key, rpc.key) || family == DeleteRequest.WHOLE_ROW); final boolean new_family = new_key || !Bytes.equals(prev.family(), family); if (rpc.code() == PutRequest.CODE) { size += 4; // int: Total number of bytes for all those KeyValues. size += rpc.payloadSize(); prev = rpc;
/** * Creates callbacks to handle a single-put and adds them to the request. * @param edit The edit for which we must handle the response. */ private void addSingleEditCallbacks(final BatchableRpc edit) { // There's no callback to add on a single put request, because // the remote method returns `void', so we only need an errback. final class SingleEditErrback implements Callback<Object, Exception> { public Object call(final Exception e) { if (!(e instanceof RecoverableException)) { return e; // Can't recover from this error, let it propagate. } return retryEdit(edit, (RecoverableException) e); } public String toString() { return "single-edit errback"; } }; edit.getDeferred().addErrback(new SingleEditErrback()); }
@Override /** * Compares two RPCs. */ public int compare(final BatchableRpc a, final BatchableRpc b) { int d; if ((d = Bytes.memcmp(a.getRegion().name(), b.getRegion().name())) != 0) { return d; } else if ((d = a.code() - b.code()) != 0) { // Sort by code before key. // Note that DeleteRequest.code() < PutRequest.code() and this matters // as the RegionServer processes deletes before puts, and we want to // send RPCs in the same order as they will be processed. return d; } else if ((d = Bytes.memcmp(a.key, b.key)) != 0) { return d; } return Bytes.memcmp(a.family(), b.family()); }
BatchableRpc prev = PutRequest.EMPTY_PUT; for (final BatchableRpc rpc : batch) { final byte[] region_name = rpc.getRegion().name(); final boolean new_region = !Bytes.equals(prev.getRegion().name(), region_name); final byte[] family = rpc.family(); final boolean new_key = (new_region || prev.code() != rpc.code() || !Bytes.equals(prev.key, rpc.key) || family == DeleteRequest.WHOLE_ROW); final boolean new_family = new_key || !Bytes.equals(prev.family(), family); buf.writeByte(rpc.code()); // Code this object. buf.writeByte(rpc.version(server_version)); // Undocumented versioning. if (prev.code() == PutRequest.CODE) { buf.setInt(nkeys_per_family_index + 4, nbytes_per_family); if (rpc.code() == PutRequest.CODE) { nkeys_per_family += rpc.numKeyValues(); nrpcs_per_key++; nbytes_per_family += rpc.payloadSize(); rpc.serializePayload(buf); prev = rpc;
int i = 0; for (final BatchableRpc rpc : batch) { final RegionInfo region = rpc.getRegion(); final boolean new_region = !Bytes.equals(prev_region, region.name()); if (new_region) { actions.setRegion(rpc.getRegion().toProtobuf()); prev_region = region.name(); action.setGet(((GetRequest)rpc).getPB()); } else { action.setMutation(rpc.toMutationProto());
/** * Retries an edit that failed with a recoverable error. * @param rpc The RPC that failed. * @param e The recoverable error that caused the edit to fail, if known. * Can be {@code null}. * @param The deferred result of the new attempt to send this edit. */ private Deferred<Object> retryEdit(final BatchableRpc rpc, final RecoverableException e) { if (hbase_client.cannotRetryRequest(rpc)) { return HBaseClient.tooManyAttempts(rpc, e); } // This RPC has already been delayed because of a failure, // so make sure we don't buffer it again. rpc.setBufferable(false); return hbase_client.sendRpcToRegion(rpc); }
if (edit.canBuffer() && hbase_client.getFlushInterval() > 0) { bufferEdit(edit); return;
final byte[] region_name = HBaseRpc.readByteArray(buf); assert Bytes.equals(region_name, batch.get(n).getRegion().name()) : ("WTF? " + Bytes.pretty(region_name) + " != " + batch.get(n).getRegion().name()); final int failed = buf.readInt(); // Index of the first failed edit. while (edits_per_region < nrpcs && Bytes.equals(region_name, batch.get(edits_per_region).getRegion().name())) { edits_per_region++;
final byte[] region_name = batch.get(n).getRegion().name(); while (last_edit < nrpcs && Bytes.equals(region_name, batch.get(last_edit).getRegion().name())) { last_edit++; final byte[] region_name = batch.get(n).getRegion().name(); while (last_edit < nrpcs && Bytes.equals(region_name, batch.get(last_edit).getRegion().name())) { last_edit++;
/** * Transforms the given single-edit multi-put into a regular single-put. * @param multiput The single-edit multi-put to transform. */ private BatchableRpc multiActionToSingleAction(final MultiAction batch) { final BatchableRpc rpc = batch.batch().get(0); addSingleEditCallbacks(rpc); // Once the single-edit is done, we still need to make sure we're // going to run the callback chain of the MultiAction. final class Multi2SingleCB implements Callback<Object, Object> { public Object call(final Object arg) { // If there was a problem, let the MultiAction know. // Otherwise, give the HBaseRpc in argument to the MultiAction // callback. This is kind of a kludge: the MultiAction callback // will understand that this means that this single-RPC was already // successfully executed on its own. batch.callback(arg instanceof Exception ? arg : rpc); return arg; } } rpc.getDeferred().addBoth(new Multi2SingleCB()); return rpc; }