private ClusterConnection getMockedConnection(final Configuration conf) throws IOException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { ClusterConnection c = Mockito.mock(ClusterConnection.class); Mockito.when(c.getConfiguration()).thenReturn(conf); Mockito.doNothing().when(c).close(); // Make it so we return a particular location when asked. final HRegionLocation loc = new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, ServerName.valueOf("example.org", 1234, 0)); Mockito.when( c.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean())) .thenReturn(loc); Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).thenReturn(loc); ClientProtos.ClientService.BlockingInterface hri = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito .when( hri.bulkLoadHFile((RpcController) Mockito.any(), (BulkLoadHFileRequest) Mockito.any())) .thenThrow(new ServiceException(new IOException("injecting bulk load error"))); Mockito.when(c.getClient(Mockito.any())).thenReturn(hri); return c; }
HRegionLocation hloc = connection.getRegionLocation(tableName, get.getRow(), false); String rowKey = Bytes.toString(get.getRow());
protected String getRegionDebugInfoSafe(Table table, byte[] rowKey) { HRegionLocation cached = null, real = null; try { cached = connection.getRegionLocation(tableName, rowKey, false); real = connection.getRegionLocation(tableName, rowKey, true); } catch (Throwable t) { // Cannot obtain region information for another catch block - too bad! } String result = "no information can be obtained"; if (cached != null) { result = "cached: " + cached.toString(); } if (real != null && real.getServerName() != null) { if (cached != null && cached.getServerName() != null && real.equals(cached)) { result += "; cache is up to date"; } else { result = (cached != null) ? (result + "; ") : ""; result += "real: " + real.toString(); } } return result; }
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row, boolean reload) throws IOException { return connection.getRegionLocation(tableName, row, reload); }
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row) throws IOException { return connection.getRegionLocation(tableName, row, false); }
/** * The put request will be buffered by its corresponding buffer queue. And the put request will be * retried before dropping the request. * Return false if the queue is already full. * @return true if the request can be accepted by its corresponding buffer queue. */ public boolean put(final TableName tableName, final Put put, int maxAttempts) { if (maxAttempts <= 0) { return false; } try { HTable.validatePut(put, maxKeyValueSize); // Allow mocking to get at the connection, but don't expose the connection to users. ClusterConnection conn = (ClusterConnection) getConnection(); // AsyncProcess in the FlushWorker should take care of refreshing the location cache // as necessary. We shouldn't have to do that here. HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), false); if (loc != null) { // Add the put pair into its corresponding queue. LinkedBlockingQueue<PutStatus> queue = getQueue(loc); // Generate a MultiPutStatus object and offer it into the queue PutStatus s = new PutStatus(loc.getRegion(), put, maxAttempts); return queue.offer(s); } } catch (IOException e) { LOG.debug("Cannot process the put " + put, e); } return false; }
byte[] currentKey = HConstants.EMPTY_START_ROW; do { HRegionLocation regionLocation = ((ClusterConnection)connection).getRegionLocation( TableName.valueOf(tableName), currentKey, reload); locations.add(regionLocation);
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row) throws IOException { return connection.getRegionLocation(tableName, row, false); }
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row, boolean reload) throws IOException { return connection.getRegionLocation(tableName, row, reload); }
@Override public HRegionLocation getRegionLocation(byte[] tableName, byte[] row, boolean reload) throws IOException { return wrappedConnection.getRegionLocation(tableName, row, reload); }
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row) throws IOException { return connection.getRegionLocation(tableName, row, false); }
@Override public HRegionLocation getRegionLocation(TableName tableName, byte[] row, boolean reload) throws IOException { return wrappedConnection.getRegionLocation(tableName, row, reload); }
/** * {@inheritDoc} */ @Override public HRegionLocation getRegionLocation(final byte [] row, boolean reload) throws IOException { return connection.getRegionLocation(tableName, row, reload); }
/** * The put request will be buffered by its corresponding buffer queue. And the put request will be * retried before dropping the request. * Return false if the queue is already full. * @return true if the request can be accepted by its corresponding buffer queue. */ public boolean put(final TableName tableName, final Put put, int maxAttempts) { if (maxAttempts <= 0) { return false; } try { HTable.validatePut(put, maxKeyValueSize); // Allow mocking to get at the connection, but don't expose the connection to users. ClusterConnection conn = (ClusterConnection) getConnection(); // AsyncProcess in the FlushWorker should take care of refreshing the location cache // as necessary. We shouldn't have to do that here. HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), false); if (loc != null) { // Add the put pair into its corresponding queue. LinkedBlockingQueue<PutStatus> queue = getQueue(loc); // Generate a MultiPutStatus object and offer it into the queue PutStatus s = new PutStatus(loc.getRegion(), put, maxAttempts); return queue.offer(s); } } catch (IOException e) { LOG.debug("Cannot process the put " + put, e); } return false; }
private ClusterConnection getMockedConnection(final Configuration conf) throws IOException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { ClusterConnection c = Mockito.mock(ClusterConnection.class); Mockito.when(c.getConfiguration()).thenReturn(conf); Mockito.doNothing().when(c).close(); // Make it so we return a particular location when asked. final HRegionLocation loc = new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, ServerName.valueOf("example.org", 1234, 0)); Mockito.when( c.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean())) .thenReturn(loc); Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).thenReturn(loc); ClientProtos.ClientService.BlockingInterface hri = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito .when( hri.bulkLoadHFile((RpcController) Mockito.any(), (BulkLoadHFileRequest) Mockito.any())) .thenThrow(new ServiceException(new IOException("injecting bulk load error"))); Mockito.when(c.getClient(Mockito.any())).thenReturn(hri); return c; }
byte[] currentKey = HConstants.EMPTY_START_ROW; do { HRegionLocation regionLocation = ((ClusterConnection)connection).getRegionLocation( TableName.valueOf(tableName), currentKey, reload); locations.add(regionLocation);
byte[] currentKey = HConstants.EMPTY_START_ROW; do { HRegionLocation regionLocation = ((ClusterConnection)connection).getRegionLocation( TableName.valueOf(tableName), currentKey, reload); locations.add(regionLocation);
HRegionLocation hloc = connection.getRegionLocation(tableName, get.getRow(), false); String rowKey = Bytes.toString(get.getRow());
protected String getRegionDebugInfoSafe(Table table, byte[] rowKey) { HRegionLocation cached = null, real = null; try { cached = connection.getRegionLocation(tableName, rowKey, false); real = connection.getRegionLocation(tableName, rowKey, true); } catch (Throwable t) { // Cannot obtain region information for another catch block - too bad! } String result = "no information can be obtained"; if (cached != null) { result = "cached: " + cached.toString(); } if (real != null && real.getServerName() != null) { if (cached != null && cached.getServerName() != null && real.equals(cached)) { result += "; cache is up to date"; } else { result = (cached != null) ? (result + "; ") : ""; result += "real: " + real.toString(); } } return result; }
/** * Internal "put" which exposes a boolean flag to control whether or not the region location * cache should be reloaded when trying to queue the {@link Put}. * @param tableName Destination table for the Put * @param put The Put to send * @param retry Number of attempts to retry the {@code put} * @param reloadCache Should the region location cache be reloaded * @return true if the request was accepted in the queue, otherwise false */ boolean _put(final TableName tableName, final Put put, int retry, boolean reloadCache) { if (retry <= 0) { return false; } try { HTable.validatePut(put, maxKeyValueSize); // Allow mocking to get at the connection, but don't expose the connection to users. ClusterConnection conn = (ClusterConnection) getConnection(); HRegionLocation loc = conn.getRegionLocation(tableName, put.getRow(), reloadCache); if (loc != null) { // Add the put pair into its corresponding queue. LinkedBlockingQueue<PutStatus> queue = getQueue(loc); // Generate a MultiPutStatus object and offer it into the queue PutStatus s = new PutStatus(loc.getRegionInfo(), put, retry); return queue.offer(s); } } catch (IOException e) { LOG.debug("Cannot process the put " + put, e); } return false; }