Search in sources :

Example 1 with StatisticsCollectionRunTracker

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;
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) EncodedColumnQualiferCellsList(org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList) ArrayList(java.util.ArrayList) List(java.util.List) StatisticsCollectionRunTracker(org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker)

Example 2 with StatisticsCollectionRunTracker

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));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Configuration(org.apache.hadoop.conf.Configuration) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PreparedStatement(java.sql.PreparedStatement) StatisticsCollectionRunTracker(org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker) Test(org.junit.Test)

Example 3 with StatisticsCollectionRunTracker

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));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Configuration(org.apache.hadoop.conf.Configuration) StatisticsCollectionRunTracker(org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker) Test(org.junit.Test)

Example 4 with StatisticsCollectionRunTracker

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);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) StatisticsCollectionRunTracker(org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker)

Example 5 with StatisticsCollectionRunTracker

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));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Configuration(org.apache.hadoop.conf.Configuration) StatisticsCollectionRunTracker(org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker) Test(org.junit.Test)

Aggregations

StatisticsCollectionRunTracker (org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker)6 Configuration (org.apache.hadoop.conf.Configuration)5 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 Test (org.junit.Test)3 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 EncodedColumnQualiferCellsList (org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList)1