HBASE-26479 Print too slow/big scan's operation_id in region server log (#3870)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
liangxs 2021-11-24 23:35:00 +08:00 committed by Duo Zhang
parent 0a51d2b5be
commit b437a96272
4 changed files with 40 additions and 0 deletions

View File

@ -77,6 +77,7 @@ import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment; import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Mutation; 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.Put;
import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionReplicaUtil; import org.apache.hadoop.hbase.client.RegionReplicaUtil;
@ -1366,6 +1367,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("table: ").append(scanner.getRegionInfo().getTable().getNameAsString()); builder.append("table: ").append(scanner.getRegionInfo().getTable().getNameAsString());
builder.append(" region: ").append(scanner.getRegionInfo().getRegionNameAsString()); builder.append(" region: ").append(scanner.getRegionInfo().getRegionNameAsString());
builder.append(" operation_id: ").append(scanner.getOperationId());
return builder.toString(); return builder.toString();
} }
@ -1378,6 +1380,12 @@ public class RSRpcServices implements HBaseRPCErrorHandler, AdminService.Blockin
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("table: ").append(region.getRegionInfo().getTable().getNameAsString()); builder.append("table: ").append(region.getRegionInfo().getTable().getNameAsString());
builder.append(" region: ").append(region.getRegionInfo().getRegionNameAsString()); 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(); return builder.toString();
} catch (IOException ignored) { } catch (IOException ignored) {
return null; return null;

View File

@ -73,6 +73,14 @@ public interface RegionScanner extends InternalScanner {
*/ */
int getBatch(); 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 * 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 * coprocessor hooks to avoid expensive setup. Caller must set the thread's readpoint, start and

View File

@ -89,6 +89,7 @@ class RegionScannerImpl implements RegionScanner, Shipper, RpcCallback {
private final long maxResultSize; private final long maxResultSize;
private final ScannerContext defaultScannerContext; private final ScannerContext defaultScannerContext;
private final FilterWrapper filter; private final FilterWrapper filter;
private final String operationId;
private RegionServerServices rsServices; private RegionServerServices rsServices;
@ -121,6 +122,7 @@ class RegionScannerImpl implements RegionScanner, Shipper, RpcCallback {
defaultScannerContext = ScannerContext.newBuilder().setBatchLimit(scan.getBatch()).build(); defaultScannerContext = ScannerContext.newBuilder().setBatchLimit(scan.getBatch()).build();
this.stopRow = scan.getStopRow(); this.stopRow = scan.getStopRow();
this.includeStopRow = scan.includeStopRow(); this.includeStopRow = scan.includeStopRow();
this.operationId = scan.getId();
// synchronize on scannerReadPoints so that nobody calculates // synchronize on scannerReadPoints so that nobody calculates
// getSmallestReadPoint, before scannerReadPoints is updated. // getSmallestReadPoint, before scannerReadPoints is updated.
@ -215,6 +217,11 @@ class RegionScannerImpl implements RegionScanner, Shipper, RpcCallback {
return this.defaultScannerContext.getBatchLimit(); return this.defaultScannerContext.getBatchLimit();
} }
@Override
public String getOperationId() {
return operationId;
}
/** /**
* Reset both the filter and the old filter. * Reset both the filter and the old filter.
* @throws IOException in case a filter raises an I/O exception. * @throws IOException in case a filter raises an I/O exception.

View File

@ -4439,6 +4439,23 @@ public class TestHRegion {
} }
} }
@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 * Write an HFile block full with Cells whose qualifier that are identical between
* 0 and Short.MAX_VALUE. See HBASE-13329. * 0 and Short.MAX_VALUE. See HBASE-13329.