private static List<Get> makeTimelineGets(byte[]... rows) { List<Get> result = new ArrayList<>(rows.length); for (byte[] row : rows) { Get get = new Get(row); get.setConsistency(Consistency.TIMELINE); result.add(get); } return result; }
@Override protected Get createGet(long keyToRead) throws IOException { Get get = super.createGet(keyToRead); get.setConsistency(Consistency.TIMELINE); return get; }
@Override protected void readAndCheck(AsyncTable<?> table, int replicaId) throws Exception { Get get = new Get(ROW).setConsistency(Consistency.TIMELINE); if (replicaId >= 0) { get.setReplicaId(replicaId); } assertArrayEquals(VALUE, table.get(get).get().getValue(FAMILY, QUALIFIER)); } }
@Test public void testGetNoResultStaleRegionWithReplica() throws Exception { byte[] b1 = "testGetNoResultStaleRegionWithReplica".getBytes(); openRegion(hriSecondary); SlowMeCopro.getPrimaryCdl().set(new CountDownLatch(1)); try { Get g = new Get(b1); g.setConsistency(Consistency.TIMELINE); Result r = table.get(g); Assert.assertTrue(r.isStale()); } finally { SlowMeCopro.getPrimaryCdl().get().countDown(); closeRegion(hriSecondary); } }
this.setConsistency(get.getConsistency());
get.setFilter(new FilterAllFilter()); get.setConsistency(consistency); if (LOG.isTraceEnabled()) LOG.trace(get.toString()); try {
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; }
get.setFilter(new FilterAllFilter()); get.setConsistency(consistency); if (LOG.isTraceEnabled()) LOG.trace(get.toString()); if (opts.multiGet > 0) {
@Test public void testCreateDeleteTable() throws IOException { // Create table then get the single region for our new table. HTableDescriptor hdt = HTU.createTableDescriptor("testCreateDeleteTable"); hdt.setRegionReplication(NB_SERVERS); hdt.addCoprocessor(SlowMeCopro.class.getName()); Table table = HTU.createTable(hdt, new byte[][]{f}, null); Put p = new Put(row); p.addColumn(f, row, row); table.put(p); Get g = new Get(row); Result r = table.get(g); Assert.assertFalse(r.isStale()); try { // But if we ask for stale we will get it SlowMeCopro.cdl.set(new CountDownLatch(1)); g = new Get(row); g.setConsistency(Consistency.TIMELINE); r = table.get(g); Assert.assertTrue(r.isStale()); SlowMeCopro.cdl.get().countDown(); } finally { SlowMeCopro.cdl.get().countDown(); SlowMeCopro.sleepTime.set(0); } HTU.getAdmin().disableTable(hdt.getTableName()); HTU.deleteTable(hdt.getTableName()); }
SlowMeCopro.getSecondaryCdl().set(new CountDownLatch(1)); g = new Get(b1); g.setConsistency(Consistency.TIMELINE); r = table.get(g); Assert.assertFalse(r.isStale()); g.setConsistency(Consistency.TIMELINE); r = table.get(g); Assert.assertTrue(r.isStale());
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, 1, result.getColumnCells(f, null).size()); Cell cell = result.getColumnLatestCell(f, null); assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
/** * Tests the case where a newly created table with region replicas and no data, the secondary * region replicas are available to read immediately. */ @Test public void testSecondaryRegionWithEmptyRegion() throws IOException { // Create a new table with region replication, don't put any data. Test that the secondary // region replica is available to read. try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration()); Table table = connection.getTable(htd.getTableName())) { Get get = new Get(row); get.setConsistency(Consistency.TIMELINE); get.setReplicaId(1); table.get(get); // this should not block } }
g.setConsistency(Consistency.TIMELINE); Result r = t.get(g); Assert.assertTrue(r.isStale());
@Test public void testReplicaGetWithPrimaryDown() throws IOException { // Create table then get the single region for our new table. HTableDescriptor hdt = HTU.createTableDescriptor("testCreateDeleteTable"); hdt.setRegionReplication(NB_SERVERS); hdt.addCoprocessor(RegionServerStoppedCopro.class.getName()); try { Table table = HTU.createTable(hdt, new byte[][] { f }, null); Put p = new Put(row); p.addColumn(f, row, row); table.put(p); // Flush so it can be picked by the replica refresher thread HTU.flush(table.getName()); // Sleep for some time until data is picked up by replicas try { Thread.sleep(2 * REFRESH_PERIOD); } catch (InterruptedException e1) { LOG.error(e1.toString(), e1); } // But if we ask for stale we will get it Get g = new Get(row); g.setConsistency(Consistency.TIMELINE); Result r = table.get(g); Assert.assertTrue(r.isStale()); } finally { HTU.getAdmin().disableTable(hdt.getTableName()); HTU.deleteTable(hdt.getTableName()); } }
@Test public void testGetOnTargetRegionReplica() throws Exception { try { //load some data to primary HTU.loadNumericRows(table, f, 0, 1000); // assert that we can read back from primary Assert.assertEquals(1000, HTU.countRows(table)); // flush so that region replica can read HRegion region = getRS().getRegionByEncodedName(hriPrimary.getEncodedName()); region.flush(true); openRegion(HTU, getRS(), hriSecondary); // try directly Get against region replica byte[] row = Bytes.toBytes(String.valueOf(42)); Get get = new Get(row); get.setConsistency(Consistency.TIMELINE); get.setReplicaId(1); Result result = table.get(get); Assert.assertArrayEquals(row, result.getValue(f, null)); } finally { HTU.deleteNumericRows(table, HConstants.CATALOG_FAMILY, 0, 1000); closeRegion(HTU, getRS(), hriSecondary); } }
get.setCheckExistenceOnly(checkExistenceOnly); if (get.getConsistency() == null){ get.setConsistency(DEFAULT_CONSISTENCY);
for (int j = 0; j < regionReplication; j++) { Get get = new Get(splits[i]); get.setConsistency(Consistency.TIMELINE); get.setReplicaId(j);
SlowMeCopro.cdl.set(new CountDownLatch(1)); g = new Get(row); g.setConsistency(Consistency.TIMELINE); r = table.get(g); Assert.assertTrue(r.isStale());
Get get = new Get(Bytes.toBytes(1)); get.setCacheBlocks(true) .setConsistency(Consistency.TIMELINE) .setFilter(new FilterList()) .setId("get")
get.setAuthorizations(new Authorizations("foo")); get.setACL("u", new Permission(Permission.Action.READ)); get.setConsistency(Consistency.TIMELINE); get.setReplicaId(2); get.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED);