@Override public int hashCode() { // TODO: This is wrong. Can't have two gets the same just because on same row. But it // matches how equals works currently and gets rid of the findbugs warning. return Bytes.hashCode(this.getRow()); }
@Override public int compareTo(Row other) { // TODO: This is wrong. Can't have two gets the same just because on same row. return Bytes.compareTo(this.getRow(), other.getRow()); }
public ReplicaRegionServerCallable(int id, HRegionLocation location) { super(RpcRetryingCallerWithReadReplicas.this.cConnection, RpcRetryingCallerWithReadReplicas.this.tableName, get.getRow(), rpcControllerFactory.newController(), rpcTimeout, new RetryingTimeTracker(), PRIORITY_UNSET); this.id = id; this.location = location; }
protected Result getRow(Get get, long rowKeyBase, byte[] cf) { Result result = null; try { result = table.get(get); } catch (IOException ie) { LOG.warn( "Failed to get the row for key = [" + Bytes.toString(get.getRow()) + "], column family = [" + Bytes.toString(cf) + "]", ie); } return result; }
@Test public void testGetRowConstructor() { byte[] row1 = Bytes.toBytes("testRow"); byte[] row2 = Bytes.toBytes("testtestRow"); ByteBuffer rowBuffer = ByteBuffer.allocate(16); rowBuffer = ByteBuffer.wrap(row1); Get get1 = new Get(rowBuffer); Get get2 = new Get(row2, 4, 7); Assert.assertArrayEquals(get1.getRow(), get2.getRow()); } }
@Override public Result[] get(List<Get> gets) throws IOException { byte[][] rows = new byte[gets.size()][]; int maxVersions = 1; int count = 0; for(Get g:gets) { if ( count == 0 ) { maxVersions = g.getMaxVersions(); } else if (g.getMaxVersions() != maxVersions) { LOG.warn("MaxVersions on Gets do not match, using the first in the list ("+maxVersions+")"); } if (g.getFilter() != null) { LOG.warn("filters not supported on gets"); } rows[count] = g.getRow(); count ++; } String spec = buildMultiRowSpec(rows, maxVersions); return getResults(spec); }
public static <K> Map<K, QuotaState> fetchGlobalQuotas(final String type, final Connection connection, final List<Get> gets, final KeyFromRow<K> kfr) throws IOException { long nowTs = EnvironmentEdgeManager.currentTime(); Result[] results = doGet(connection, gets); Map<K, QuotaState> globalQuotas = new HashMap<>(results.length); for (int i = 0; i < results.length; ++i) { byte[] row = gets.get(i).getRow(); K key = kfr.getKeyFromRow(row); QuotaState quotaInfo = new QuotaState(nowTs); globalQuotas.put(key, quotaInfo); if (results[i].isEmpty()) continue; assert Bytes.equals(row, results[i].getRow()); byte[] data = results[i].getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); if (data == null) continue; try { Quotas quotas = quotasFromData(data); quotaInfo.setQuotas(quotas); } catch (IOException e) { LOG.error("Unable to parse " + type + " '" + key + "' quotas", e); globalQuotas.remove(key); } } return globalQuotas; }
@Override public CompletableFuture<Result> get(Get get) { return timelineConsistentRead(conn.getLocator(), tableName, get, get.getRow(), RegionLocateType.CURRENT, replicaId -> get(get, replicaId), readRpcTimeoutNs, conn.connConf.getPrimaryCallTimeoutNs(), retryTimer); }
@Override public Object run() throws Exception { Result res = null; Table localTable = null; try { int mod = ((int) rowKeyBase % userNames.length); if (userVsTable.get(userNames[mod]) == null) { localTable = connection.getTable(tableName); userVsTable.put(userNames[mod], localTable); res = localTable.get(get); } else { localTable = userVsTable.get(userNames[mod]); res = localTable.get(get); } } catch (IOException ie) { LOG.warn("Failed to get the row for key = [" + Bytes.toString(get.getRow()) + "], column family = [" + Bytes.toString(cf) + "]", ie); } return res; } };
@Override public Result get(Get get) throws IOException { TimeRange range = get.getTimeRange(); String spec = buildRowSpec(get.getRow(), get.getFamilyMap(), range.getMin(), range.getMax(), get.getMaxVersions()); if (get.getFilter() != null) { LOG.warn("filters not supported on gets"); } Result[] results = getResults(spec); if (results.length > 0) { if (results.length > 1) { LOG.warn("too many results for get (" + results.length + ")"); } return results[0]; } else { return new Result(); } }
void prepareGet(final Get get) throws IOException { checkRow(get.getRow(), "Get"); // Verify families are all valid if (get.hasFamilies()) { for (byte[] family : get.familySet()) { checkFamily(family); } } else { // Adding all families to scanner for (byte[] family : this.htableDescriptor.getColumnFamilyNames()) { get.addFamily(family); } } }
/** * Two responsibilities * - if the call is already completed (by another replica) stops the retries. * - set the location to the right region, depending on the replica. */ @Override // TODO: Very like the super class implemenation. Can we shrink this down? public void prepare(final boolean reload) throws IOException { if (getRpcController().isCanceled()) return; if (Thread.interrupted()) { throw new InterruptedIOException(); } if (reload || location == null) { RegionLocations rl = getRegionLocations(false, id, cConnection, tableName, get.getRow()); location = id < rl.size() ? rl.getRegionLocation(id) : null; } if (location == null || location.getServerName() == null) { // With this exception, there will be a retry. The location can be null for a replica // when the table is created or after a split. throw new HBaseIOException("There is no location for replica id #" + id); } setStubByServiceName(this.location.getServerName()); }
/** * Do a small get/scan against one store. This is required because store * has no actual methods of querying itself, and relies on StoreScanner. */ public static List<Cell> getFromStoreFile(HStore store, Get get) throws IOException { Scan scan = new Scan(get); InternalScanner scanner = (InternalScanner) store.getScanner(scan, scan.getFamilyMap().get(store.getColumnFamilyDescriptor().getName()), // originally MultiVersionConcurrencyControl.resetThreadReadPoint() was called to set // readpoint 0. 0); List<Cell> result = new ArrayList<>(); scanner.next(result); if (!result.isEmpty()) { // verify that we are on the row we want: Cell kv = result.get(0); if (!CellUtil.matchingRows(kv, get.getRow())) { result.clear(); } } scanner.close(); return result; }
@Test public void testGet() throws Exception{ byte[] row = "row".getBytes(); byte[] fam = "fam".getBytes(); byte[] qf1 = "qf1".getBytes(); long ts = System.currentTimeMillis(); int maxVersions = 2; Get get = new Get(row); get.addColumn(fam, qf1); get.setTimeRange(ts, ts+1); get.setMaxVersions(maxVersions); ClientProtos.Get getProto = ProtobufUtil.toGet(get); Get desGet = ProtobufUtil.toGet(getProto); assertTrue(Bytes.equals(get.getRow(), desGet.getRow())); Set<byte[]> set = null; Set<byte[]> desSet = null; for(Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()){ assertTrue(desGet.getFamilyMap().containsKey(entry.getKey())); set = entry.getValue(); desSet = desGet.getFamilyMap().get(entry.getKey()); for(byte [] qualifier : set){ assertTrue(desSet.contains(qualifier)); } } assertEquals(get.getMaxVersions(), desGet.getMaxVersions()); TimeRange tr = get.getTimeRange(); TimeRange desTr = desGet.getTimeRange(); assertEquals(tr.getMax(), desTr.getMax()); assertEquals(tr.getMin(), desTr.getMin()); }
final Get configuredGet = get; ClientServiceCallable<Result> callable = new ClientServiceCallable<Result>(this.connection, getName(), get.getRow(), this.rpcControllerFactory.newController(), get.getPriority()) { @Override protected Result rpcCall() throws Exception {
get.getRow(), qualifiers); assertEquals(1, result.size());
/** * Getting data from memstore and files * @throws IOException */ @Test public void testGet_FromMemStoreAndFiles() throws IOException { init(this.name.getMethodName()); //Put data in memstore this.store.add(new KeyValue(row, family, qf1, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf2, 1, (byte[])null), null); //flush flush(1); //Add more data this.store.add(new KeyValue(row, family, qf3, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf4, 1, (byte[])null), null); //flush flush(2); //Add more data this.store.add(new KeyValue(row, family, qf5, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf6, 1, (byte[])null), null); //Get result = HBaseTestingUtility.getFromStoreFile(store, get.getRow(), qualifiers); //Need to sort the result since multiple files Collections.sort(result, CellComparatorImpl.COMPARATOR); //Compare assertCheck(); }
get.getRow(), qualifiers);
/** * Getting data from memstore only * @throws IOException */ @Test public void testGet_FromMemStoreOnly() throws IOException { init(this.name.getMethodName()); //Put data in memstore this.store.add(new KeyValue(row, family, qf1, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf2, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf3, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf4, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf5, 1, (byte[])null), null); this.store.add(new KeyValue(row, family, qf6, 1, (byte[])null), null); //Get result = HBaseTestingUtility.getFromStoreFile(store, get.getRow(), qualifiers); //Compare assertCheck(); }