protected Table createTable() throws IOException { return connection.getTable(tableName); }
protected Table createTable() throws IOException { return connection.getTable(tableName); }
protected Table createTable() throws IOException { return connection.getTable(tableName); }
@Override public Object run() throws Exception { try { if (table == null) { table = connection.getTable(tableName); } table.put(put); } catch (IOException e) { recordFailure(table, put, keyBase, start, e); } return null; } }
/** * Create a 'smarter' Connection, one that is capable of by-passing RPC if the request is to the * local server; i.e. a short-circuit Connection. Safe to use going to local or remote server. */ private ClusterConnection createClusterConnection() throws IOException { Configuration conf = this.conf; if (conf.get(HConstants.CLIENT_ZOOKEEPER_QUORUM) != null) { // Use server ZK cluster for server-issued connections, so we clone // the conf and unset the client ZK related properties conf = new Configuration(this.conf); conf.unset(HConstants.CLIENT_ZOOKEEPER_QUORUM); } // Create a cluster connection that when appropriate, can short-circuit and go directly to the // local server if the request is to the local server bypassing RPC. Can be used for both local // and remote invocations. ClusterConnection conn = ConnectionUtils.createShortCircuitConnection(conf, null, userProvider.getCurrent(), serverName, rpcServices, rpcServices); // This is used to initialize the batch thread pool inside the connection implementation. // When deploy a fresh cluster, we may first use the cluster connection in InitMetaProcedure, // which will be executed inside the PEWorker, and then the batch thread pool will inherit the // thread group of PEWorker, which will be destroy when shutting down the ProcedureExecutor. It // will cause lots of procedure related UTs to fail, so here let's initialize it first, no harm. conn.getTable(TableName.META_TABLE_NAME).close(); return conn; }
@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; } };
/** * Setup a clean table with a certain region_replica count * * It will set tbl which needs to be closed after test * * @throws Exception */ void setupTableWithRegionReplica(TableName tablename, int replicaCount) throws Exception { HTableDescriptor desc = new HTableDescriptor(tablename); desc.setRegionReplication(replicaCount); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM)); desc.addFamily(hcd); // If a table has no CF's it doesn't get checked createTable(TEST_UTIL, desc, SPLITS); tbl = connection.getTable(tablename, tableExecutorService); List<Put> puts = new ArrayList<>(ROWKEYS.length); for (byte[] row : ROWKEYS) { Put p = new Put(row); p.addColumn(FAM, Bytes.toBytes("val"), row); puts.add(p); } tbl.put(puts); }
meta = connection.getTable(TableName.META_TABLE_NAME); status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.MASTER, Option.BACKUP_MASTERS,
/** * Setup a clean table with a mob-enabled column. * * @param tablename The name of a table to be created. * @throws Exception */ void setupMobTable(TableName tablename) throws Exception { HTableDescriptor desc = new HTableDescriptor(tablename); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM)); hcd.setMobEnabled(true); hcd.setMobThreshold(0); desc.addFamily(hcd); // If a table has no CF's it doesn't get checked createTable(TEST_UTIL, desc, SPLITS); tbl = connection.getTable(tablename, tableExecutorService); List<Put> puts = new ArrayList<>(ROWKEYS.length); for (byte[] row : ROWKEYS) { Put p = new Put(row); p.addColumn(FAM, Bytes.toBytes("val"), row); puts.add(p); } tbl.put(puts); }
@Override public Object run() throws Exception { Table localTable = null; try { Result result = null; int specialPermCellInsertionFactor = Integer.parseInt(dataGenerator.getArgs()[2]); int mod = ((int) keyToRead % userNames.length); if (userVsTable.get(userNames[mod]) == null) { localTable = connection.getTable(tableName); userVsTable.put(userNames[mod], localTable); result = localTable.get(get); } else { localTable = userVsTable.get(userNames[mod]); result = localTable.get(get); } boolean isNullExpected = ((((int) keyToRead % specialPermCellInsertionFactor)) == 0); long end = System.nanoTime(); verifyResultsAndUpdateMetrics(verify, get, end - start, result, localTable, isNullExpected); } catch (IOException e) { recordFailure(keyToRead); } return null; } };
ClusterConnection conn = new MyConnectionImpl(copyConf); MyAsyncProcess ap = new MyAsyncProcess(conn, copyConf); try (HTable ht = (HTable) conn.getTable(DUMMY_TABLE)) { ht.multiAp = ap; List<Get> gets = new LinkedList<>();
@Override public Object run() throws Exception { try { if (table == null) { table = connection.getTable(tableName); } if (m instanceof Increment) { table.increment((Increment) m); } else if (m instanceof Append) { table.append((Append) m); } else if (m instanceof Put) { table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m); } else if (m instanceof Delete) { table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m); } else { throw new IllegalArgumentException("unsupported mutation " + m.getClass().getSimpleName()); } totalOpTimeMs.addAndGet(System.currentTimeMillis() - start); } catch (IOException e) { recordFailure(m, keyBase, start, e); } return null; } }
@Override protected Void rpcCall() throws Exception { LOG.debug("Going to connect to server " + getLocation() + " for row " + Bytes.toStringBinary(getRow())); try (Table table = conn.getTable(getTableName())) { boolean loaded = new SecureBulkLoadEndpointClient(table).bulkLoadHFiles(famPaths, null, bulkToken, getLocation().getRegionInfo().getStartKey()); } return null; } };
@Test public void testBatch() throws IOException, InterruptedException { ClusterConnection conn = new MyConnectionImpl(CONF); HTable ht = (HTable) conn.getTable(DUMMY_TABLE); ht.multiAp = new MyAsyncProcess(conn, CONF); List<Put> puts = new ArrayList<>(7); puts.add(createPut(1, true)); puts.add(createPut(1, true)); puts.add(createPut(1, true)); puts.add(createPut(1, true)); puts.add(createPut(1, false)); // <=== the bad apple, position 4 puts.add(createPut(1, true)); puts.add(createPut(1, false)); // <=== another bad apple, position 6 Object[] res = new Object[puts.size()]; try { ht.batch(puts, res); Assert.fail(); } catch (RetriesExhaustedException expected) { } Assert.assertEquals(success, res[0]); Assert.assertEquals(success, res[1]); Assert.assertEquals(success, res[2]); Assert.assertEquals(success, res[3]); Assert.assertEquals(failure, res[4]); Assert.assertEquals(success, res[5]); Assert.assertEquals(failure, res[6]); } @Test
Table table = conn.getTable(tableName); final String bulkToken = new SecureBulkLoadEndpointClient(table).prepareBulkLoad(tableName); RpcControllerFactory rpcControllerFactory = new RpcControllerFactory(UTIL.getConfiguration());
try (Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService)) { Delete delete = new Delete(deleteRow); meta.delete(delete);
@Override public Void rpcCall() throws Exception { LOG.debug("Going to connect to server " + getLocation() + " for row " + Bytes.toStringBinary(getRow())); SecureBulkLoadClient secureClient = null; byte[] regionName = getLocation().getRegionInfo().getRegionName(); try (Table table = conn.getTable(getTableName())) { secureClient = new SecureBulkLoadClient(UTIL.getConfiguration(), table); secureClient.secureBulkLoadHFiles(getStub(), famPaths, regionName, true, null, bulkToken); } return null; } };
@Test public void testMutateRowStats() throws IOException { Configuration conf = UTIL.getConfiguration(); ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(conf); Table table = conn.getTable(tableName); HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0); Region region = rs.getRegions(tableName).get(0); RowMutations mutations = new RowMutations(Bytes.toBytes("row")); Put p = new Put(Bytes.toBytes("row")); p.addColumn(family, qualifier, Bytes.toBytes("value2")); mutations.add(p); table.mutateRow(mutations); ServerStatisticTracker stats = conn.getStatisticsTracker(); assertNotNull( "No stats configured for the client!", stats); // get the names so we can query the stats ServerName server = rs.getServerName(); byte[] regionName = region.getRegionInfo().getRegionName(); // check to see we found some load on the memstore ServerStatistics serverStats = stats.getServerStatsForTesting(server); ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName); assertNotNull(regionStats); assertTrue(regionStats.getMemStoreLoadPercent() > 0); } }
HTable table = (HTable) conn.getTable(tn); try { ColumnFamilyDescriptorBuilder cfDescBuilder =
@Test @SuppressWarnings("deprecation") public void testShortCircuitConnection() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = UTIL.createTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf")); htd.addFamily(hcd); UTIL.createTable(htd, null); HRegionServer regionServer = UTIL.getRSForFirstRegionInTable(tableName); ClusterConnection connection = regionServer.getClusterConnection(); Table tableIf = connection.getTable(tableName); assertTrue(tableIf instanceof HTable); HTable table = (HTable) tableIf; assertTrue(table.getConnection() == connection); AdminService.BlockingInterface admin = connection.getAdmin(regionServer.getServerName()); ClientService.BlockingInterface client = connection.getClient(regionServer.getServerName()); assertTrue(admin instanceof RSRpcServices); assertTrue(client instanceof RSRpcServices); ServerName anotherSn = ServerName.valueOf(regionServer.getServerName().getHostAndPort(), EnvironmentEdgeManager.currentTime()); admin = connection.getAdmin(anotherSn); client = connection.getClient(anotherSn); assertFalse(admin instanceof RSRpcServices); assertFalse(client instanceof RSRpcServices); assertTrue(connection.getAdmin().getConnection() == connection); } }