private void deleteAndWait(byte[] row, Table source, Table... targets) throws Exception { Delete del = new Delete(row); source.delete(del); Get get = new Get(row); for (int i = 0; i < NB_RETRIES; i++) { if (i==NB_RETRIES-1) { fail("Waited too much time for del replication"); } boolean removedFromAll = true; for (Table target : targets) { Result res = target.get(get); if (res.size() >= 1) { LOG.info("Row not deleted"); removedFromAll = false; break; } } if (removedFromAll) { break; } else { Thread.sleep(SLEEP_TIME); } } }
/** * Create a new protocol buffer GetRequest to get a row, all columns in a family. * If there is no such row, return the closest row before it. * * @param regionName the name of the region to get * @param row the row to get * @param family the column family to get * should return the immediate row before * @return a protocol buffer GetReuqest */ public static GetRequest buildGetRowOrBeforeRequest( final byte[] regionName, final byte[] row, final byte[] family) { GetRequest.Builder builder = GetRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.REGION_NAME, regionName); builder.setRegion(region); Column.Builder columnBuilder = Column.newBuilder(); columnBuilder.setFamily(ByteStringer.wrap(family)); ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder(); getBuilder.setRow(ByteStringer.wrap(row)); getBuilder.addColumn(columnBuilder.build()); getBuilder.setClosestRowBefore(true); builder.setGet(getBuilder.build()); return builder.build(); }
@Override public <T> List<T> get(TableName tableName, final List<Get> getList, final RowMapper<T> mapper) { assertAccessAvailable(); return execute(tableName, new TableCallback<List<T>>() { @Override public List<T> doInTable(Table table) throws Throwable { Result[] result = table.get(getList); List<T> list = new ArrayList<>(result.length); for (int i = 0; i < result.length; i++) { T t = mapper.mapRow(result[i], i); list.add(t); } return list; } }); }
public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int endRow, final boolean present) throws IOException { for (int i = startRow; i < endRow; i++) { String failMsg = "Failed verification of row :" + i; byte[] data = Bytes.toBytes(String.valueOf(i)); Result result = region.get(new Get(data)); boolean hasResult = result != null && !result.isEmpty(); assertEquals(failMsg + result, present, hasResult); if (!present) continue; assertTrue(failMsg, result.containsColumn(f, null)); assertEquals(failMsg, result.getColumnCells(f, null).size(), 1); Cell cell = result.getColumnLatestCell(f, null); assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
protected Get createGet(long keyToRead) throws IOException { Get get = new Get(dataGenerator.getDeterministicUniqueKey(keyToRead)); String cfsString = ""; byte[][] columnFamilies = dataGenerator.getColumnFamilies(); for (byte[] cf : columnFamilies) { get.addFamily(cf); if (verbose) { if (cfsString.length() > 0) { cfsString += ", "; } cfsString += "[" + Bytes.toStringBinary(cf) + "]"; } } get = dataGenerator.beforeGet(keyToRead, get); if (regionReplicaId > 0) { get.setReplicaId(regionReplicaId); get.setConsistency(Consistency.TIMELINE); } if (verbose) { LOG.info("[" + readerId + "] " + "Querying key " + keyToRead + ", cfs " + cfsString); } return get; }
@Override public Result next() throws IOException { if (rawTable == null) return null; if (localCache.isEmpty()) { // load cache by batch get int size = Math.min(rowkeyQueue.size(), LOCAL_CACHE_SIZE); List<Get> gets = new ArrayList<>(size); for (int i = 0; i < size; i++) { gets.add(new Get(rowkeyQueue.poll())); } Result[] results = rawTable.get(gets); for (Result res : results) { localCache.add(res); } } if (localCache.isEmpty()) { // still empty, no more result, set rawTable to null rawTable.close(); rawTable = null; return null; } return localCache.poll(); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region * @throws IOException */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; HRegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
@Test public void testIncrementTimestampsAreMonotonic() throws IOException { HRegion region = initHRegion(tableName, name.getMethodName(), CONF, fam1); ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); EnvironmentEdgeManager.injectEdge(edge); edge.setValue(10); Increment inc = new Increment(row); inc.setDurability(Durability.SKIP_WAL); inc.addColumn(fam1, qual1, 1L); region.increment(inc); Result result = region.get(new Get(row)); Cell c = result.getColumnLatestCell(fam1, qual1); assertNotNull(c); assertEquals(c.getTimestamp(), 10L); edge.setValue(1); // clock goes back region.increment(inc); result = region.get(new Get(row)); c = result.getColumnLatestCell(fam1, qual1); assertEquals(c.getTimestamp(), 10L); assertEquals(Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()), 2L); }
/** * Test the case where the secondary region replica is not in reads enabled state because it is * waiting for a flush or region open marker from primary region. Replaying CANNOT_FLUSH * flush marker entry should restore the reads enabled status in the region and allow the reads * to continue. */ @Test public void testReplayingFlushRequestRestoresReadsEnabledState() throws IOException { disableReads(secondaryRegion); // Test case 1: Test that replaying CANNOT_FLUSH request marker assuming this came from // triggered flush restores readsEnabled primaryRegion.flushcache(true, true); reader = createWALReaderForPrimary(); while (true) { WAL.Entry entry = reader.next(); if (entry == null) { break; } FlushDescriptor flush = WALEdit.getFlushDescriptor(entry.getEdit().getCells().get(0)); if (flush != null) { secondaryRegion.replayWALFlushMarker(flush, entry.getKey().getLogSeqNum()); } } // now reads should be enabled secondaryRegion.get(new Get(Bytes.toBytes(0))); }
private void wait(byte[] row, Table target, boolean isDeleted) throws Exception { Get get = new Get(row); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) { fail("Waited too much time for replication. Row:" + Bytes.toString(row) + ". IsDeleteReplication:" + isDeleted); } Result res = target.get(get); boolean sleep = isDeleted ? res.size() > 0 : res.size() == 0; if (sleep) { LOG.info("Waiting for more time for replication. Row:" + Bytes.toString(row) + ". IsDeleteReplication:" + isDeleted); Thread.sleep(SLEEP_TIME); } else { if (!isDeleted) { assertArrayEquals(res.value(), row); } LOG.info("Obtained row:" + Bytes.toString(row) + ". IsDeleteReplication:" + isDeleted); break; } } }
private void checkWithWait(byte[] row, int count, Table table) throws Exception { Get get = new Get(row); for (int i = 0; i < NB_RETRIES; i++) { if (i == NB_RETRIES - 1) { fail("Waited too much time while getting the row."); } boolean rowReplicated = false; Result res = table.get(get); if (res.size() >= 1) { LOG.info("Row is replicated"); rowReplicated = true; assertEquals("Table '" + table + "' did not have the expected number of results.", count, res.size()); break; } if (rowReplicated) { break; } else { Thread.sleep(SLEEP_TIME); } } }
@Test (timeout=180000) public void testNamespaceUserGrant() throws Exception { AccessTestAction getAction = new AccessTestAction() { @Override public Object run() throws Exception { try(Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(TEST_TABLE);) { return t.get(new Get(TEST_ROW)); } } }; String namespace = TEST_TABLE.getNamespaceAsString(); // Grant namespace READ to USER_NONE, this should supersede any table permissions grantOnNamespace(TEST_UTIL, USER_NONE.getShortName(), namespace, Permission.Action.READ); // Now USER_NONE should be able to read verifyAllowed(getAction, USER_NONE); // Revoke namespace READ to USER_NONE revokeFromNamespace(TEST_UTIL, USER_NONE.getShortName(), namespace, Permission.Action.READ); verifyDenied(getAction, USER_NONE); }
public void verifyNumericRows(Table table, final byte[] f, int startRow, int endRow, int replicaId) throws IOException { for (int i = startRow; i < endRow; i++) { String failMsg = "Failed verification of row :" + i; byte[] data = Bytes.toBytes(String.valueOf(i)); Get get = new Get(data); get.setReplicaId(replicaId); get.setConsistency(Consistency.TIMELINE); Result result = table.get(get); assertTrue(failMsg, result.containsColumn(f, null)); assertEquals(failMsg, result.getColumnCells(f, null).size(), 1); Cell cell = result.getColumnLatestCell(f, null); assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
public static void blockUntilRegionIsOpened(Configuration conf, long timeout, HRegionInfo hri) throws IOException, InterruptedException { log("blocking until region is opened for reading:" + hri.getRegionNameAsString()); long start = System.currentTimeMillis(); try (Connection conn = ConnectionFactory.createConnection(conf); Table table = conn.getTable(hri.getTable())) { byte[] row = hri.getStartKey(); // Check for null/empty row. If we find one, use a key that is likely to be in first region. if (row == null || row.length <= 0) row = new byte[] { '0' }; Get get = new Get(row); while (System.currentTimeMillis() - start < timeout) { try { table.get(get); break; } catch (IOException ex) { // wait some more } Threads.sleep(10); } } }
/** * Gets a Table for this table, does the get and closes the Table */ public Result doGet(final Get get) { Result result; final Table tableInterface = getTable(); try { result = doGet(tableInterface, get); } finally { closeTable(tableInterface); } return result; }
/** * Test merge tool. * @throws Exception */ public void testMergeTool() throws Exception { // First verify we can read the rows from the source regions and that they // contain the right data. for (int i = 0; i < regions.length; i++) { for (int j = 0; j < rows[i].length; j++) { Get get = new Get(rows[i][j]); get.addFamily(FAMILY); Result result = regions[i].get(get); byte [] bytes = CellUtil.cloneValue(result.rawCells()[0]); assertNotNull(bytes); assertTrue(Bytes.equals(bytes, rows[i][j])); } // Close the region and delete the log HRegion.closeHRegion(regions[i]); } WAL log = wals.getWAL(new byte[]{}); // Merge Region 0 and Region 1 HRegion merged = mergeAndVerify("merging regions 0 and 1 ", this.sourceRegions[0].getRegionNameAsString(), this.sourceRegions[1].getRegionNameAsString(), log, 2); // Merge the result of merging regions 0 and 1 with region 2 merged = mergeAndVerify("merging regions 0+1 and 2", merged.getRegionInfo().getRegionNameAsString(), this.sourceRegions[2].getRegionNameAsString(), log, 3); // Merge the result of merging regions 0, 1 and 2 with region 3 merged = mergeAndVerify("merging regions 0+1+2 and 3", merged.getRegionInfo().getRegionNameAsString(), this.sourceRegions[3].getRegionNameAsString(), log, 4); // Merge the result of merging regions 0, 1, 2 and 3 with region 4 merged = mergeAndVerify("merging regions 0+1+2+3 and 4", merged.getRegionInfo().getRegionNameAsString(), this.sourceRegions[4].getRegionNameAsString(), log, rows.length); }
/** * Usecase: * * - create a row with 1M cells, 10 bytes in each * - flush & run major compaction * - try to Get whole row. * * OOME happened in StoreScanner.next(..). * * @throws IOException */ @Test(expected = RowTooBigException.class) public void testScanAcrossManySmallColumns() throws IOException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); HTableDescriptor htd = TEST_HTD; HColumnDescriptor hcd = new HColumnDescriptor(fam1); if (htd.hasFamily(hcd.getName())) { htd.modifyFamily(hcd); } else { htd.addFamily(hcd); } final HRegionInfo hri = new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW, HConstants.EMPTY_END_ROW); Region region = HTU.createHRegion(hri, rootRegionDir, HTU.getConfiguration(), htd); try { // Add to memstore for (int i = 0; i < 10; i++) { Put put = new Put(row1); for (int j = 0; j < 10 * 10000; j++) { put.add(fam1, Bytes.toBytes("col_" + i + "_" + j), new byte[10]); } region.put(put); region.flush(true); } region.compact(true); Get get = new Get(row1); region.get(get); } finally { HBaseTestingUtility.closeRegion(region); } }
public void store(Record record) throws Exception { table = conn.getTable(TableName.valueOf(nameSpaceName + ":" + tableName)); Get get = new Get(Bytes.toBytes(record.getId().hashCode() + "" + record.getDate().hashCode())); if (table.get(get) == null) { Put put = new Put(Bytes.toBytes(record.getId().hashCode() + "" + record.getDate().hashCode())); // row // key /* * 7 结果公示类型——读取二级页面 */ if (noticeType == 7) { ExtendCandidate candidate = getRequest.getData(record.getId()); if (candidate != null) { put.addColumn(Bytes.toBytes(secondFamily), Bytes.toBytes("title"), Bytes.toBytes(candidate.getTitle())); put.addColumn(Bytes.toBytes(secondFamily), Bytes.toBytes("content"), Bytes.toBytes(candidate.getContent())); } } put.addColumn(Bytes.toBytes(firstFamily), Bytes.toBytes("name"), Bytes.toBytes(record.getName())); put.addColumn(Bytes.toBytes(firstFamily), Bytes.toBytes("type"), Bytes.toBytes(record.getTypeName())); put.addColumn(Bytes.toBytes(firstFamily), Bytes.toBytes("content"), Bytes.toBytes(record.getContent())); put.addColumn(Bytes.toBytes(firstFamily), Bytes.toBytes("date"), Bytes.toBytes(record.getDate())); put.addColumn(Bytes.toBytes(firstFamily), Bytes.toBytes("id"), Bytes.toBytes(record.getId())); table.put(put); } }
/** * 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, byte [] row, NavigableSet<byte[]> columns ) throws IOException { Get get = new Get(row); Map<byte[], NavigableSet<byte[]>> s = get.getFamilyMap(); s.put(store.getFamily().getName(), columns); return getFromStoreFile(store,get); }
static void assertGet(final HRegion r, final byte[] family, final byte[] k) throws IOException { // Now I have k, get values out and assert they are as expected. Get get = new Get(k).addFamily(family).setMaxVersions(); Cell[] results = r.get(get).rawCells(); for (int j = 0; j < results.length; j++) { byte[] tmp = CellUtil.cloneValue(results[j]); // Row should be equal to value every time. assertTrue(Bytes.equals(k, tmp)); } }
/** * Test basic Get conversions. * * @throws IOException */ @Test public void testGet() throws IOException { ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder(); getBuilder.setRow(ByteString.copyFromUtf8("row")); Column.Builder columnBuilder = Column.newBuilder(); columnBuilder.setFamily(ByteString.copyFromUtf8("f1")); columnBuilder.addQualifier(ByteString.copyFromUtf8("c1")); columnBuilder.addQualifier(ByteString.copyFromUtf8("c2")); getBuilder.addColumn(columnBuilder.build()); columnBuilder.clear(); columnBuilder.setFamily(ByteString.copyFromUtf8("f2")); getBuilder.addColumn(columnBuilder.build()); ClientProtos.Get proto = getBuilder.build(); // default fields assertEquals(1, proto.getMaxVersions()); assertEquals(true, proto.getCacheBlocks()); // set the default value for equal comparison getBuilder = ClientProtos.Get.newBuilder(proto); getBuilder.setMaxVersions(1); getBuilder.setCacheBlocks(true); Get get = ProtobufUtil.toGet(proto); assertEquals(getBuilder.build(), ProtobufUtil.toGet(get)); }
private static void assertGet(final HRegion region, byte [] row, byte [] familiy, byte[] qualifier, byte[] value) throws IOException { // run a get and see if the value matches Get get = new Get(row); get.addColumn(familiy, qualifier); Result result = region.get(get); assertEquals(1, result.size()); Cell kv = result.rawCells()[0]; byte[] r = CellUtil.cloneValue(kv); assertTrue(Bytes.compareTo(r, value) == 0); }
@Override public Result[] next(int nbRows) throws IOException { if (candidates == null || candidates.isEmpty()) return null; int size = Math.min(candidates.size(), nbRows); Result[] results = new Result[size]; for (int i = 0; i < size; i++) { results[i] = rawTable.get(new Get(candidates.poll().id)); } return results; }
@Override public void run() { for (int i = 0; i < numIncrements; i++) { try { Increment inc = new Increment(row); inc.addColumn(fam1, qual1, amount); inc.addColumn(fam1, qual2, amount*2); inc.addColumn(fam2, qual3, amount*3); inc.setDurability(Durability.ASYNC_WAL); region.increment(inc, HConstants.NO_NONCE, HConstants.NO_NONCE); // verify: Make sure we only see completed increments Get g = new Get(row); Result result = region.get(g); if (result != null) { assertTrue(result.getValue(fam1, qual1) != null); assertTrue(result.getValue(fam1, qual2) != null); assertEquals(Bytes.toLong(result.getValue(fam1, qual1))*2, Bytes.toLong(result.getValue(fam1, qual2))); assertTrue(result.getValue(fam2, qual3) != null); assertEquals(Bytes.toLong(result.getValue(fam1, qual1))*3, Bytes.toLong(result.getValue(fam2, qual3))); } } catch (IOException e) { e.printStackTrace(); } } }
/** * Create a protocol buffer GetRequest for a client Get * * @param regionName the name of the region to get * @param get the client Get * @return a protocol buffer GetRequest */ public static GetRequest buildGetRequest(final byte[] regionName, final Get get) throws IOException { GetRequest.Builder builder = GetRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.REGION_NAME, regionName); builder.setRegion(region); builder.setGet(ProtobufUtil.toGet(get)); return builder.build(); }
public RowResultGenerator(final String tableName, final RowSpec rowspec, final Filter filter, final boolean cacheBlocks) throws IllegalArgumentException, IOException { Table table = RESTServlet.getInstance().getTable(tableName); try { Get get = new Get(rowspec.getRow()); if (rowspec.hasColumns()) { for (byte[] col: rowspec.getColumns()) { byte[][] split = KeyValue.parseColumn(col); if (split.length == 1) { get.addFamily(split[0]); } else if (split.length == 2) { get.addColumn(split[0], split[1]); } else { throw new IllegalArgumentException("Invalid column specifier."); } } } get.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime()); get.setMaxVersions(rowspec.getMaxVersions()); if (filter != null) { get.setFilter(filter); } get.setCacheBlocks(cacheBlocks); Result result = table.get(get); if (result != null && !result.isEmpty()) { valuesI = result.listCells().iterator(); } } catch (DoNotRetryIOException | NeedUnmanagedConnectionException e) { // Warn here because Stargate will return 404 in the case if multiple // column families were specified but one did not exist -- currently // HBase will fail the whole Get. // Specifying multiple columns in a URI should be uncommon usage but // help to avoid confusion by leaving a record of what happened here in // the log. LOG.warn(StringUtils.stringifyException(e)); } finally { table.close(); } }
@Override public List<TRowResult> getRowsWithColumnsTs(ByteBuffer tableName, List<ByteBuffer> rows, List<ByteBuffer> columns, long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError { Table table= null; try { List<Get> gets = new ArrayList<Get>(rows.size()); table = getTable(tableName); if (metrics != null) { metrics.incNumRowKeysInBatchGet(rows.size()); } for (ByteBuffer row : rows) { Get get = new Get(getBytes(row)); addAttributes(get, attributes); if (columns != null) { for(ByteBuffer column : columns) { byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); if (famAndQf.length == 1) { get.addFamily(famAndQf[0]); } else { get.addColumn(famAndQf[0], famAndQf[1]); } } } get.setTimeRange(0, timestamp); gets.add(get); } Result[] result = table.get(gets); return ThriftUtilities.rowResultFromHBase(result); } catch (IOException e) { LOG.warn(e.getMessage(), e); throw new IOError(Throwables.getStackTraceAsString(e)); } finally{ closeTable(table); } }
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { if (!initialized) { throw new VisibilityControllerNotReadyException("VisibilityController not yet initialized"); } // Nothing useful to do if authorization is not enabled if (!authorizationEnabled) { return; } Region region = e.getEnvironment().getRegion(); Authorizations authorizations = null; try { authorizations = get.getAuthorizations(); } catch (DeserializationException de) { throw new IOException(de); } if (authorizations == null) { // No Authorizations present for this scan/Get! // In case of system tables other than "labels" just scan with out visibility check and // filtering. Checking visibility labels for META and NAMESPACE table is not needed. TableName table = region.getRegionInfo().getTable(); if (table.isSystemTable() && !table.equals(LABELS_TABLE_NAME)) { return; } } Filter visibilityLabelFilter = VisibilityUtils.createVisibilityLabelFilter(e.getEnvironment() .getRegion(), authorizations); if (visibilityLabelFilter != null) { Filter filter = get.getFilter(); if (filter != null) { get.setFilter(new FilterList(filter, visibilityLabelFilter)); } else { get.setFilter(visibilityLabelFilter); } } }
@Deprecated public Boolean[] exists(List<Get> gets) throws IOException { boolean[] results = existsAll(gets); Boolean[] objectResults = new Boolean[results.length]; for (int i = 0; i < results.length; ++i) { objectResults[i] = results[i]; } return objectResults; }
private void fetchNamespaceQuotaState() { fetch("namespace", QuotaCache.this.namespaceQuotaCache, new Fetcher<String, QuotaState>() { @Override public Get makeGet(final Map.Entry<String, QuotaState> entry) { return QuotaUtil.makeGetForNamespaceQuotas(entry.getKey()); } @Override public Map<String, QuotaState> fetchEntries(final List<Get> gets) throws IOException { return QuotaUtil.fetchNamespaceQuotas(rsServices.getConnection(), gets); } }); }
private void fetchTableQuotaState() { fetch("table", QuotaCache.this.tableQuotaCache, new Fetcher<TableName, QuotaState>() { @Override public Get makeGet(final Map.Entry<TableName, QuotaState> entry) { return QuotaUtil.makeGetForTableQuotas(entry.getKey()); } @Override public Map<TableName, QuotaState> fetchEntries(final List<Get> gets) throws IOException { return QuotaUtil.fetchTableQuotas(rsServices.getConnection(), gets); } }); }
@Test public void testMultiGet() throws Exception { ArrayList<Get> gets = new ArrayList<Get>(); gets.add(new Get(ROW_1)); gets.add(new Get(ROW_2)); Result[] results = remoteTable.get(gets); assertNotNull(results); assertEquals(2, results.length); assertEquals(1, results[0].size()); assertEquals(2, results[1].size()); //Test Versions gets = new ArrayList<Get>(); Get g = new Get(ROW_1); g.setMaxVersions(3); gets.add(g); gets.add(new Get(ROW_2)); results = remoteTable.get(gets); assertNotNull(results); assertEquals(2, results.length); assertEquals(1, results[0].size()); assertEquals(3, results[1].size()); //404 gets = new ArrayList<Get>(); gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE"))); results = remoteTable.get(gets); assertNotNull(results); assertEquals(0, results.length); gets = new ArrayList<Get>(); gets.add(new Get(Bytes.toBytes("RESALLYREALLYNOTTHERE"))); gets.add(new Get(ROW_1)); gets.add(new Get(ROW_2)); results = remoteTable.get(gets); assertNotNull(results); assertEquals(2, results.length); }
private void assertGetRpc(HRegionInfo info, int value, boolean expect) throws IOException, ServiceException { byte[] row = Bytes.toBytes(String.valueOf(value)); Get get = new Get(row); ClientProtos.GetRequest getReq = RequestConverter.buildGetRequest(info.getRegionName(), get); ClientProtos.GetResponse getResp = getRS().getRSRpcServices().get(null, getReq); Result result = ProtobufUtil.toResult(getResp.getResult()); if (expect) { Assert.assertArrayEquals(row, result.getValue(f, null)); } else { result.isEmpty(); } }
public static Get makeGetForUserQuotas(final String user, final Iterable<TableName> tables, final Iterable<String> namespaces) { Get get = new Get(getUserRowKey(user)); get.addColumn(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); for (final TableName table : tables) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserTable(table)); } for (final String ns : namespaces) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserNamespace(ns)); } return get; }
public static Map<String, QuotaState> fetchNamespaceQuotas(final Connection connection, final List<Get> gets) throws IOException { return fetchGlobalQuotas("namespace", connection, gets, new KeyFromRow<String>() { @Override public String getKeyFromRow(final byte[] row) { assert isNamespaceRowKey(row); return getNamespaceFromRowKey(row); } }); }
/** Use get to retrieve the HRegionInfo and validate it */ private void getRegionInfo() throws IOException { Get get = new Get(ROW_KEY); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); Result result = region.get(get); byte [] bytes = result.value(); validateRegionInfo(bytes); }
private void checkRowAndDelete(Table t, byte[] row, int count) throws IOException { Get g = new Get(row); Result r = t.get(g); assertEquals(count, r.size()); Delete d = new Delete(row); t.delete(d); }
@Override public void postGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> results) { RegionCoprocessorEnvironment e = c.getEnvironment(); assertNotNull(e); assertNotNull(e.getRegion()); assertNotNull(get); assertNotNull(results); if (e.getRegion().getTableDesc().getTableName().equals( TestRegionObserverInterface.TEST_TABLE)) { boolean foundA = false; boolean foundB = false; boolean foundC = false; for (Cell kv: results) { if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.A)) { foundA = true; } if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.B)) { foundB = true; } if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.C)) { foundC = true; } } assertTrue(foundA); assertTrue(foundB); assertTrue(foundC); } ctPostGet.incrementAndGet(); }
void updateDeleteLatestVersionTimeStamp(Cell cell, Get get, int count, byte[] byteNow) throws IOException { List<Cell> result = get(get, false); if (result.size() < count) { // Nothing to delete CellUtil.updateLatestStamp(cell, byteNow, 0); return; } if (result.size() > count) { throw new RuntimeException("Unexpected size: " + result.size()); } Cell getCell = result.get(count - 1); CellUtil.setTimestamp(cell, getCell.getTimestamp()); }
public void verifyInvocationResults(Integer[] selectQualifiers, Integer[] expectedQualifiers) throws Exception { Get get = new Get(ROW_BYTES); for (int i = 0; i < selectQualifiers.length; i++) { get.addColumn(FAMILY_NAME_BYTES, Bytes.toBytes(QUALIFIER_PREFIX + selectQualifiers[i])); } get.setFilter(new InvocationRecordFilter()); List<KeyValue> expectedValues = new ArrayList<KeyValue>(); for (int i = 0; i < expectedQualifiers.length; i++) { expectedValues.add(new KeyValue(ROW_BYTES, FAMILY_NAME_BYTES, Bytes .toBytes(QUALIFIER_PREFIX + expectedQualifiers[i]), expectedQualifiers[i], Bytes.toBytes(VALUE_PREFIX + expectedQualifiers[i]))); } Scan scan = new Scan(get); List<Cell> actualValues = new ArrayList<Cell>(); List<Cell> temp = new ArrayList<Cell>(); InternalScanner scanner = this.region.getScanner(scan); while (scanner.next(temp)) { actualValues.addAll(temp); temp.clear(); } actualValues.addAll(temp); Assert.assertTrue("Actual values " + actualValues + " differ from the expected values:" + expectedValues, expectedValues.equals(actualValues)); }