setTable(table); final GetRequest get = new GetRequest( lastTableBytes, key.getBytes(), columnFamilyBytes); if (fields != null) { get.qualifiers(getQualifierList(fields));
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(); .setRow(Bytes.wrap(rpc.key())); if (rpc.family() != null) { final ClientPB.Column.Builder column = ClientPB.Column.newBuilder(); column.setFamily(Bytes.wrap(rpc.family())); if (rpc.qualifiers() != null) { for (final byte[] qualifier : rpc.qualifiers()) { column.addQualifier(Bytes.wrap(qualifier)); if (rpc.getFilter() != null) { getpb.setFilter(FilterPB.Filter.newBuilder() .setNameBytes(Bytes.wrap(rpc.getFilter().name())) .setSerializedFilter(Bytes.wrap(rpc.getFilter().serialize())) .build()); final long min_ts = rpc.getMinTimestamp(); final long max_ts = rpc.getMaxTimestamp(); if (min_ts != 0 || max_ts != Long.MAX_VALUE) { final HBasePB.TimeRange.Builder time = HBasePB.TimeRange.newBuilder(); final int versions = rpc.maxVersions(); // Shadows this.versions if (versions != 1) {
/** * Returns the cell of the specified row key, using family:kind. */ private byte[] hbaseGet(final byte[] key, final byte[] family) throws HBaseException { final GetRequest get = new GetRequest(table, key); get.family(family).qualifier(kind); try { final ArrayList<KeyValue> row = client.get(get).joinUninterruptibly(); if (row == null || row.isEmpty()) { return null; } return row.get(0).value(); } catch (HBaseException e) { throw e; } catch (Exception e) { throw new RuntimeException("Should never be here", e); } }
/** * Package-private factory method to build an "exists" RPC. * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @param family The column family to get in the table. * @return An {@link HBaseRpc} that will return a {@link Boolean} * indicating whether or not the given table / key exists. */ static HBaseRpc exists(final byte[] table, final byte[] key, final byte[] family) { final GetRequest rpc = new GetRequest(0F, table, key); rpc.family(family); rpc.setProbe(true); return rpc; }
/** * Constructor. * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @param family The column family. * @param qualifier The column qualifier. * @since 1.5 */ public GetRequest(final String table, final String key, final String family, final String qualifier) { this(table, key); this.family(family); this.qualifier(qualifier); this.bufferable = false; //don't buffer get request }
/** * Gets a given row in HBase and prints it on standard output. * * @param client The HBase client to use. * @param table The name of the HBase table to use. * @param key The row key to attempt to get from HBase. * @param family The family in which we're interested. * @return 0 if at least one cell was found and printed, 1 otherwise. */ private static int findAndPrintRow(final HBaseClient client, final byte[] table, final byte[] key, final byte[] family, boolean formard) { final GetRequest get = new GetRequest(table, key); get.family(family); ArrayList<KeyValue> row; try { row = client.get(get).joinUninterruptibly(); } catch (HBaseException e) { LOG.error("Get failed: " + get, e); return 1; } catch (Exception e) { LOG.error("WTF? Unexpected exception type, get=" + get, e); return 42; } return printResult(row, family, formard) ? 0 : 1; }
/** * Package-private factory method to build an "exists" RPC. * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @return An {@link HBaseRpc} that will return a {@link Boolean} * indicating whether or not the given table / key exists. */ static HBaseRpc exists(final byte[] table, final byte[] key) { final GetRequest rpc = new GetRequest(0F, table, key); rpc.setProbe(true); return rpc; }
/** * Constructor. * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @param family The column family. * @since 1.5 */ public GetRequest(final String table, final String key, final String family) { this(table, key); this.family(family); this.bufferable = false; //don't buffer get request }
@Override Object deserialize(final ChannelBuffer buf, final int cell_size) { final ClientPB.GetResponse resp = readProtobuf(buf, ClientPB.GetResponse.PARSER); if (isGetRequest()) { return extractResponse(resp, buf, cell_size); } else { final ClientPB.Result result = resp.getResult(); return result != null ? result.getExists() : false; // is `null' possible here? } }
/** * Gets the entire given row from the data table. */ final Deferred<ArrayList<KeyValue>> get(final byte[] key) { return client.get(new GetRequest(table, key)); }
/** * Transforms a protobuf get response into a list of {@link KeyValue}. * @param resp The protobuf response from which to extract the KVs. * @param buf The buffer from which the protobuf was read. * @param cell_size The number of bytes of the cell block that follows, * in the buffer. */ static ArrayList<KeyValue> extractResponse(final ClientPB.GetResponse resp, final ChannelBuffer buf, final int cell_size) { final ClientPB.Result res = resp.getResult(); if (res == null) { return new ArrayList<KeyValue>(0); } return convertResult(res, buf, cell_size); }
/** Specifies a particular column qualifier to get. */ public GetRequest qualifier(final String qualifier) { return qualifier(qualifier.getBytes()); }
request.setRegion(region); MultiAction batch = batch_by_region.get(client); if (batch == null) { result_deferreds.add(request.getDeferred().addBoth(MUL_GOT_ONE));
/** * Ensures that a given table/family pair really exists. * <p> * It's recommended to call this method in the startup code of your * application if you know ahead of time which tables / families you're * going to need, because it'll allow you to "fail fast" if they're missing. * <p> * @param table The name of the table you intend to use. * @param family The column family you intend to use in that table. * @return A deferred object that indicates the completion of the request. * The {@link Object} has not special meaning and can be {@code null} * (think of it as {@code Deferred<Void>}). But you probably want to attach * at least an errback to this {@code Deferred} to handle failures. * @throws TableNotFoundException (deferred) if the table doesn't exist. * @throws NoSuchColumnFamilyException (deferred) if the family doesn't exist. */ public Deferred<Object> ensureTableFamilyExists(final byte[] table, final byte[] family) { // Just "fault in" the first region of the table. Not the most optimal or // useful thing to do but gets the job done for now. TODO(tsuna): Improve. final HBaseRpc dummy; if (family == EMPTY_ARRAY) { dummy = GetRequest.exists(table, probeKey(ZERO_ARRAY)); } else { dummy = GetRequest.exists(table, probeKey(ZERO_ARRAY), family); } @SuppressWarnings("unchecked") final Deferred<Object> d = (Deferred) sendRpcToRegion(dummy); return d; }
ArrayList<KeyValue> kvs = GetRequest.convertResultWithAssociatedCells( roe.getResult(), buf, cell_size); if (append_request.returnResult()) { result = GetRequest.convertResultWithAssociatedCells( roe.getResult(), buf, cell_size); } else {
/** * Constructor. * <strong>These byte arrays will NOT be copied.</strong> * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @param family The column family. * @param qualifier The column qualifier. * @since 1.5 */ public GetRequest(final byte[] table, final byte[] key, final byte[] family, final byte[] qualifier) { super(table, key); this.family(family); this.qualifier(qualifier); this.bufferable = false; //don't buffer get request }
/** * Constructor. * <strong>These byte arrays will NOT be copied.</strong> * @param table The non-empty name of the table to use. * @param key The row key to get in that table. * @param family The column family. * @since 1.5 */ public GetRequest(final byte[] table, final byte[] key, final byte[] family) { super(table, key); this.family(family); this.bufferable = false; //don't buffer get request }
@Override Object deserialize(final ChannelBuffer buf, int cell_size) { final MutateResponse resp = readProtobuf(buf, MutateResponse.PARSER); // An increment must always produce a result, so we shouldn't need to // check whether the `result' field is set here. final ArrayList<KeyValue> kvs = GetRequest.convertResult(resp.getResult(), buf, cell_size); if (kvs.size() != 1) { throw new InvalidResponseException("Atomic increment returned " + kvs.size() + " KeyValue(s), but we expected exactly one. kvs=" + kvs, resp); } return Bytes.getLong(kvs.get(0).value()); }
exists_rpc = GetRequest.exists(rpc.table, probeKey(rpc.key)); newlist.add(exists_rpc); if (can_retry_rpc) { got_nsre.putIfAbsent(region_name, nsred_rpcs); if (added == null) { // We've just put `nsred_rpcs'. exists_rpc = GetRequest.exists(rpc.table, probeKey(rpc.key)); + " an empty list of NSRE'd RPCs (" + added + ") for " + Bytes.pretty(region_name)); exists_rpc = GetRequest.exists(rpc.table, probeKey(rpc.key)); added.add(exists_rpc); } else {
/** Specifies a particular column family to get. */ public GetRequest family(final String family) { return family(family.getBytes()); }