public static void main(String[] args) throws Exception { ToolRunner.run(new AsyncClientExample(), args); } }
public static void main(String[] args) throws Exception { ToolRunner.run(new BufferedMutatorExample(), args); } }
public static void main(String[] args) throws Exception { ToolRunner.run(new MultiThreadedClientExample(), args); } }
public static void main(String[] args) throws InterruptedException, ExecutionException { int port = Integer.parseInt(args[0]); HttpProxyExample proxy = new HttpProxyExample(HBaseConfiguration.create(), port); proxy.start(); proxy.join(); } }
final Connection writeConnection = ConnectionFactory.createConnection(getConf(), service); final Connection readConnection = ConnectionFactory.createConnection(getConf(), service); warmUpConnectionCache(readConnection, tableName); warmUpConnectionCache(writeConnection, tableName); f = internalPool.submit(new WriteExampleCallable(writeConnection, tableName)); } else if (r < .50) { f = internalPool.submit(new SingleWriteExampleCallable(writeConnection, tableName)); } else { f = internalPool.submit(new ReadExampleCallable(writeConnection, tableName));
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(1); UTIL.createTable(TABLE_NAME, Bytes.toBytes(FAMILY)); PROXY = new HttpProxyExample(UTIL.getConfiguration(), 0); PROXY.start(); PORT = PROXY.port(); }
private void callRefreshRegionHFilesEndPoint() throws IOException { try { RefreshHFilesClient refreshHFilesClient = new RefreshHFilesClient(CONF); refreshHFilesClient.refreshHFiles(TABLE_NAME); } catch (RetriesExhaustedException rex) { if (rex.getCause() instanceof IOException) throw new IOException(); } catch (Throwable ex) { LOG.error(ex.toString(), ex); fail("Couldn't call the RefreshRegionHFilesEndpoint"); } }
private void put(ChannelHandlerContext ctx, FullHttpRequest req) { Params params = parse(req); byte[] value = new byte[req.content().readableBytes()]; req.content().readBytes(value); conn.getTable(TableName.valueOf(params.table)).put(new Put(Bytes.toBytes(params.row)) .addColumn(Bytes.toBytes(params.family), Bytes.toBytes(params.qualifier), value)) .whenComplete((r, e) -> { if (e != null) { exceptionCaught(ctx, e); } else { write(ctx, HttpResponseStatus.OK, Optional.empty()); } }); }
@Test public void test() throws Exception { AsyncClientExample tool = new AsyncClientExample(); tool.setConf(UTIL.getConfiguration()); assertEquals(0, ToolRunner.run(tool, new String[] { TABLE_NAME.getNameAsString() })); } }
public void refreshHFiles(final TableName tableName) throws Throwable { try (Table table = connection.getTable(tableName)) { refreshHFiles(table); } }
@Test public void testRefreshHFilesClient() throws Exception { addHFilesToRegions(); assertEquals(2, HTU.getNumHFiles(TABLE_NAME, FAMILY)); RefreshHFilesClient tool = new RefreshHFilesClient(HTU.getConfiguration()); assertEquals(0, ToolRunner.run(tool, new String[] { TABLE_NAME.getNameAsString() })); assertEquals(4, HTU.getNumHFiles(TABLE_NAME, FAMILY)); } }
public static void main(String[] args) throws Exception { ToolRunner.run(new RefreshHFilesClient(HBaseConfiguration.create()), args); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (cause instanceof IllegalArgumentException) { write(ctx, HttpResponseStatus.BAD_REQUEST, Optional.of(cause.getMessage())); } else { write(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR, Optional.of(Throwables.getStackTraceAsString(cause))); } } }
private CompletableFuture<AsyncConnection> getConn() { CompletableFuture<AsyncConnection> f = future.get(); if (f != null) { return f; } for (;;) { if (future.compareAndSet(null, new CompletableFuture<>())) { CompletableFuture<AsyncConnection> toComplete = future.get(); ConnectionFactory.createAsyncConnection(getConf()).whenComplete((conn, error) -> { if (error != null) { toComplete.completeExceptionally(error); // we need to reset the future holder so we will get a chance to recreate an async // connection at next try. future.set(null); return; } toComplete.complete(conn); }); return toComplete; } else { f = future.get(); if (f != null) { return f; } } } }
@AfterClass public static void tearDown() throws Exception { if (PROXY != null) { PROXY.stop(); } UTIL.shutdownMiniCluster(); }
@Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addFirst(new HttpServerCodec(), new HttpObjectAggregator(4 * 1024 * 1024), new RequestHandler(conn, channelGroup)); } }).bind(port).syncUninterruptibly().channel();
private Params parse(FullHttpRequest req) { String[] components = new QueryStringDecoder(req.uri()).path().split("/"); Preconditions.checkArgument(components.length == 4, "Unrecognized uri: %s", req.uri()); // path is start with '/' so split will give an empty component String[] cfAndCq = components[3].split(":"); Preconditions.checkArgument(cfAndCq.length == 2, "Unrecognized uri: %s", req.uri()); return new Params(components[1], components[2], cfAndCq[0], cfAndCq[1]); }
@BeforeClass public static void setUp() { setUp(HRegion.class.getName()); }
@Override public int run(String[] args) throws Exception { if (args.length != 1) { String message = "When there are multiple HBase clusters are sharing a common root dir, " + "especially for read replica cluster (see detail in HBASE-18477), please consider to " + "use this tool manually sync the flushed HFiles from the source cluster."; message += "\nUsage: " + this.getClass().getName() + " tableName"; System.out.println(message); return -1; } final TableName tableName = TableName.valueOf(args[0]); try { refreshHFiles(tableName); } catch (Throwable t) { LOG.error("Refresh HFiles from table " + tableName.getNameAsString() + " failed: ", t); return -1; } return 0; }