use of org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker in project phoenix by apache.
the class UngroupedAggregateRegionObserver method collectStats.
private RegionScanner collectStats(final RegionScanner innerScanner, StatisticsCollector stats, final Region region, final Scan scan, Configuration config) throws IOException {
StatsCollectionCallable callable = new StatsCollectionCallable(stats, region, innerScanner, config, scan);
byte[] asyncBytes = scan.getAttribute(BaseScannerRegionObserver.RUN_UPDATE_STATS_ASYNC_ATTRIB);
boolean async = false;
if (asyncBytes != null) {
async = Bytes.toBoolean(asyncBytes);
}
// in case of async, we report 0 as number of rows updated
long rowCount = 0;
StatisticsCollectionRunTracker statsRunTracker = StatisticsCollectionRunTracker.getInstance(config);
boolean runUpdateStats = statsRunTracker.addUpdateStatsCommandRegion(region.getRegionInfo());
if (runUpdateStats) {
if (!async) {
rowCount = callable.call();
} else {
statsRunTracker.runTask(callable);
}
} else {
rowCount = CONCURRENT_UPDATE_STATS_ROW_COUNT;
logger.info("UPDATE STATISTICS didn't run because another UPDATE STATISTICS command was already running on the region " + region.getRegionInfo().getRegionNameAsString());
}
byte[] rowCountBytes = PLong.INSTANCE.toBytes(Long.valueOf(rowCount));
final KeyValue aggKeyValue = KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, rowCountBytes, 0, rowCountBytes.length);
RegionScanner scanner = new BaseRegionScanner(innerScanner) {
@Override
public HRegionInfo getRegionInfo() {
return region.getRegionInfo();
}
@Override
public boolean isFilterDone() {
return true;
}
@Override
public void close() throws IOException {
// no-op because we want to manage closing of the inner scanner ourselves.
}
@Override
public boolean next(List<Cell> results) throws IOException {
results.add(aggKeyValue);
return false;
}
@Override
public long getMaxResultSize() {
return scan.getMaxResultSize();
}
};
return scanner;
}
use of org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker in project phoenix by apache.
the class StatisticsCollectionRunTrackerIT method testStateBeforeAndAfterMajorCompaction.
@Test
public void testStateBeforeAndAfterMajorCompaction() throws Exception {
String tableName = fullTableName;
HRegionInfo regionInfo = createTableAndGetRegion(tableName);
StatisticsCollectionRunTracker tracker = StatisticsCollectionRunTracker.getInstance(new Configuration());
// Upsert values in the table.
String keyPrefix = "aaaaaaaaaaaaaaaaaaaa";
String upsert = "UPSERT INTO " + tableName + " VALUES (?, ?)";
try (Connection conn = DriverManager.getConnection(getUrl())) {
PreparedStatement stmt = conn.prepareStatement(upsert);
for (int i = 0; i < 1000; i++) {
stmt.setString(1, keyPrefix + i);
stmt.setString(2, "KV" + i);
stmt.executeUpdate();
}
conn.commit();
}
// assert that the region wasn't added to the tracker
assertTrue(tracker.addCompactingRegion(regionInfo));
// assert that removing the region from the tracker works
assertTrue(tracker.removeCompactingRegion(regionInfo));
runMajorCompaction(tableName);
// assert that after major compaction is complete, tracker isn't tracking the region any more
assertFalse(tracker.removeCompactingRegion(regionInfo));
}
use of org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker in project phoenix by apache.
the class StatisticsCollectionRunTrackerIT method testStateBeforeAndAfterUpdateStatsCommand.
@Test
public void testStateBeforeAndAfterUpdateStatsCommand() throws Exception {
String tableName = fullTableName;
HRegionInfo regionInfo = createTableAndGetRegion(tableName);
StatisticsCollectionRunTracker tracker = StatisticsCollectionRunTracker.getInstance(new Configuration());
// assert that the region wasn't added to the tracker
assertTrue(tracker.addUpdateStatsCommandRegion(regionInfo));
// assert that removing the region from the tracker works
assertTrue(tracker.removeUpdateStatsCommandRegion(regionInfo));
runUpdateStats(tableName);
// assert that after update stats is complete, tracker isn't tracking the region any more
assertFalse(tracker.removeUpdateStatsCommandRegion(regionInfo));
}
use of org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker in project phoenix by apache.
the class StatisticsCollectionRunTrackerIT method markRegionAsCompacting.
private void markRegionAsCompacting(HRegionInfo regionInfo) {
StatisticsCollectionRunTracker tracker = StatisticsCollectionRunTracker.getInstance(new Configuration());
tracker.addCompactingRegion(regionInfo);
}
use of org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker in project phoenix by apache.
the class StatisticsCollectionRunTrackerIT method testMajorCompactionPreventsUpdateStatsFromRunning.
@Test
public void testMajorCompactionPreventsUpdateStatsFromRunning() throws Exception {
String tableName = fullTableName;
HRegionInfo regionInfo = createTableAndGetRegion(tableName);
// simulate stats collection via major compaction by marking the region as compacting in the tracker
markRegionAsCompacting(regionInfo);
Assert.assertEquals("Row count didn't match", COMPACTION_UPDATE_STATS_ROW_COUNT, runUpdateStats(tableName));
StatisticsCollectionRunTracker tracker = StatisticsCollectionRunTracker.getInstance(new Configuration());
// assert that the tracker state was cleared.
assertFalse(tracker.removeUpdateStatsCommandRegion(regionInfo));
}
Aggregations