Skip to content

Commit

Permalink
HBASE-26479 Print too slow/big scan's operation_id in region server l…
Browse files Browse the repository at this point in the history
…og (apache#3870)

Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
liangxs authored Nov 24, 2021
1 parent e702aae commit c148d5b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.OperationWithAttributes;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
Expand Down Expand Up @@ -1278,6 +1279,7 @@ public String getScanDetailsWithId(long scannerId) {
StringBuilder builder = new StringBuilder();
builder.append("table: ").append(scanner.getRegionInfo().getTable().getNameAsString());
builder.append(" region: ").append(scanner.getRegionInfo().getRegionNameAsString());
builder.append(" operation_id: ").append(scanner.getOperationId());
return builder.toString();
}

Expand All @@ -1290,6 +1292,12 @@ public String getScanDetailsWithRequest(ScanRequest request) {
StringBuilder builder = new StringBuilder();
builder.append("table: ").append(region.getRegionInfo().getTable().getNameAsString());
builder.append(" region: ").append(region.getRegionInfo().getRegionNameAsString());
for (NameBytesPair pair : request.getScan().getAttributeList()) {
if (OperationWithAttributes.ID_ATRIBUTE.equals(pair.getName())) {
builder.append(" operation_id: ").append(Bytes.toString(pair.getValue().toByteArray()));
break;
}
}
return builder.toString();
} catch (IOException ignored) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public interface RegionScanner extends InternalScanner {
*/
int getBatch();

/**
* @return The Scanner's {@link org.apache.hadoop.hbase.client.Scan#ID_ATRIBUTE} value,
* or null if not set.
*/
default String getOperationId() {
return null;
}

/**
* Grab the next row's worth of values. This is a special internal method to be called from
* coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class RegionScannerImpl implements RegionScanner, Shipper, RpcCallback {
private final long maxResultSize;
private final ScannerContext defaultScannerContext;
private final FilterWrapper filter;
private final String operationId;

private RegionServerServices rsServices;

Expand Down Expand Up @@ -121,6 +122,7 @@ private static boolean hasNonce(HRegion region, long nonce) {
defaultScannerContext = ScannerContext.newBuilder().setBatchLimit(scan.getBatch()).build();
this.stopRow = scan.getStopRow();
this.includeStopRow = scan.includeStopRow();
this.operationId = scan.getId();

// synchronize on scannerReadPoints so that nobody calculates
// getSmallestReadPoint, before scannerReadPoints is updated.
Expand Down Expand Up @@ -215,6 +217,11 @@ public int getBatch() {
return this.defaultScannerContext.getBatchLimit();
}

@Override
public String getOperationId() {
return operationId;
}

/**
* Reset both the filter and the old filter.
* @throws IOException in case a filter raises an I/O exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,23 @@ public boolean isFamilyEssential(byte[] name) {
}
}

@Test
public void testScannerOperationId() throws IOException {
region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
Scan scan = new Scan();
RegionScanner scanner = region.getScanner(scan);
assertNull(scanner.getOperationId());
scanner.close();

String operationId = "test_operation_id_0101";
scan = new Scan().setId(operationId);
scanner = region.getScanner(scan);
assertEquals(operationId, scanner.getOperationId());
scanner.close();

HBaseTestingUtil.closeRegionAndWAL(this.region);
}

/**
* Write an HFile block full with Cells whose qualifier that are identical between
* 0 and Short.MAX_VALUE. See HBASE-13329.
Expand Down

0 comments on commit c148d5b

Please sign in to comment.