Search in sources :

Example 1 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class StatsCollectorIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    // enable name space mapping at global level on both client and server side
    Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(7);
    serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
    serverProps.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
    Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(2);
    clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, "true");
    clientProps.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
    setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) BeforeClass(org.junit.BeforeClass)

Example 2 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class MetaDataClient method updateStatisticsInternal.

private long updateStatisticsInternal(PName physicalName, PTable logicalTable, Map<String, Object> statsProps, List<byte[]> cfs) throws SQLException {
    ReadOnlyProps props = connection.getQueryServices().getProps();
    final long msMinBetweenUpdates = props.getLong(QueryServices.MIN_STATS_UPDATE_FREQ_MS_ATTRIB, props.getLong(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, QueryServicesOptions.DEFAULT_STATS_UPDATE_FREQ_MS) / 2);
    byte[] tenantIdBytes = ByteUtil.EMPTY_BYTE_ARRAY;
    Long scn = connection.getSCN();
    // Always invalidate the cache
    long clientTimeStamp = connection.getSCN() == null ? HConstants.LATEST_TIMESTAMP : scn;
    String query = "SELECT CURRENT_DATE()," + LAST_STATS_UPDATE_TIME + " FROM " + PhoenixDatabaseMetaData.SYSTEM_STATS_NAME + " WHERE " + PHYSICAL_NAME + "='" + physicalName.getString() + "' AND " + COLUMN_FAMILY + " IS NULL AND " + LAST_STATS_UPDATE_TIME + " IS NOT NULL";
    ResultSet rs = connection.createStatement().executeQuery(query);
    long msSinceLastUpdate = Long.MAX_VALUE;
    if (rs.next()) {
        msSinceLastUpdate = rs.getLong(1) - rs.getLong(2);
    }
    long rowCount = 0;
    if (msSinceLastUpdate >= msMinBetweenUpdates) {
        /*
             * Execute a COUNT(*) through PostDDLCompiler as we need to use the logicalTable passed through,
             * since it may not represent a "real" table in the case of the view indexes of a base table.
             */
        PostDDLCompiler compiler = new PostDDLCompiler(connection);
        //even if table is transactional, while calculating stats we scan the table non-transactionally to
        //view all the data belonging to the table
        PTable nonTxnLogicalTable = new DelegateTable(logicalTable) {

            @Override
            public boolean isTransactional() {
                return false;
            }
        };
        TableRef tableRef = new TableRef(null, nonTxnLogicalTable, clientTimeStamp, false);
        MutationPlan plan = compiler.compile(Collections.singletonList(tableRef), null, cfs, null, clientTimeStamp);
        Scan scan = plan.getContext().getScan();
        scan.setCacheBlocks(false);
        scan.setAttribute(ANALYZE_TABLE, TRUE_BYTES);
        boolean runUpdateStatsAsync = props.getBoolean(QueryServices.RUN_UPDATE_STATS_ASYNC, DEFAULT_RUN_UPDATE_STATS_ASYNC);
        scan.setAttribute(RUN_UPDATE_STATS_ASYNC_ATTRIB, runUpdateStatsAsync ? TRUE_BYTES : FALSE_BYTES);
        if (statsProps != null) {
            Object gp_width = statsProps.get(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB);
            if (gp_width != null) {
                scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_WIDTH_BYTES, PLong.INSTANCE.toBytes(gp_width));
            }
            Object gp_per_region = statsProps.get(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB);
            if (gp_per_region != null) {
                scan.setAttribute(BaseScannerRegionObserver.GUIDEPOST_PER_REGION, PInteger.INSTANCE.toBytes(gp_per_region));
            }
        }
        MutationState mutationState = plan.execute();
        rowCount = mutationState.getUpdateCount();
    }
    /*
         *  Update the stats table so that client will pull the new one with the updated stats.
         *  Even if we don't run the command due to the last update time, invalidate the cache.
         *  This supports scenarios in which a major compaction was manually initiated and the
         *  client wants the modified stats to be reflected immediately.
         */
    if (cfs == null) {
        List<PColumnFamily> families = logicalTable.getColumnFamilies();
        if (families.isEmpty()) {
            connection.getQueryServices().invalidateStats(new GuidePostsKey(physicalName.getBytes(), SchemaUtil.getEmptyColumnFamily(logicalTable)));
        } else {
            for (PColumnFamily family : families) {
                connection.getQueryServices().invalidateStats(new GuidePostsKey(physicalName.getBytes(), family.getName().getBytes()));
            }
        }
    } else {
        for (byte[] cf : cfs) {
            connection.getQueryServices().invalidateStats(new GuidePostsKey(physicalName.getBytes(), cf));
        }
    }
    return rowCount;
}
Also used : GuidePostsKey(org.apache.phoenix.schema.stats.GuidePostsKey) PostDDLCompiler(org.apache.phoenix.compile.PostDDLCompiler) MutationPlan(org.apache.phoenix.compile.MutationPlan) ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) MutationState(org.apache.phoenix.execute.MutationState) PUnsignedLong(org.apache.phoenix.schema.types.PUnsignedLong) PLong(org.apache.phoenix.schema.types.PLong) ResultSet(java.sql.ResultSet) Scan(org.apache.hadoop.hbase.client.Scan)

Example 3 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class PMetaDataImplTest method shouldNotEvictMoreEntriesThanNecessary.

@Test
public void shouldNotEvictMoreEntriesThanNecessary() throws Exception {
    TestTimeKeeper timeKeeper = new TestTimeKeeper();
    Map<String, String> props = Maps.newHashMapWithExpectedSize(2);
    props.put(QueryServices.MAX_CLIENT_METADATA_CACHE_SIZE_ATTRIB, "5");
    props.put(QueryServices.CLIENT_CACHE_ENCODING, "object");
    PMetaData metaData = new PMetaDataImpl(5, timeKeeper, new ReadOnlyProps(props));
    addToTable(metaData, "a", 1, timeKeeper);
    assertEquals(1, metaData.size());
    addToTable(metaData, "b", 1, timeKeeper);
    assertEquals(2, metaData.size());
    assertNames(metaData, "a", "b");
    addToTable(metaData, "c", 3, timeKeeper);
    assertEquals(3, metaData.size());
    assertNames(metaData, "a", "b", "c");
    getFromTable(metaData, "a", timeKeeper);
    getFromTable(metaData, "b", timeKeeper);
    addToTable(metaData, "d", 3, timeKeeper);
    assertEquals(3, metaData.size());
    assertNames(metaData, "a", "b", "d");
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) Test(org.junit.Test)

Example 4 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class PMetaDataImplTest method testAge.

@Test
public void testAge() throws Exception {
    TestTimeKeeper timeKeeper = new TestTimeKeeper();
    Map<String, String> props = Maps.newHashMapWithExpectedSize(2);
    props.put(QueryServices.MAX_CLIENT_METADATA_CACHE_SIZE_ATTRIB, "10");
    props.put(QueryServices.CLIENT_CACHE_ENCODING, "object");
    PMetaData metaData = new PMetaDataImpl(5, timeKeeper, new ReadOnlyProps(props));
    String tableName = "a";
    addToTable(metaData, tableName, 1, timeKeeper);
    PTableRef aTableRef = metaData.getTableRef(new PTableKey(null, tableName));
    assertNotNull(aTableRef);
    assertEquals(1, metaData.getAge(aTableRef));
    tableName = "b";
    addToTable(metaData, tableName, 1, timeKeeper);
    PTableRef bTableRef = metaData.getTableRef(new PTableKey(null, tableName));
    assertNotNull(bTableRef);
    assertEquals(1, metaData.getAge(bTableRef));
    assertEquals(2, metaData.getAge(aTableRef));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) Test(org.junit.Test)

Example 5 with ReadOnlyProps

use of org.apache.phoenix.util.ReadOnlyProps in project phoenix by apache.

the class QueryTimeoutIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(5);
    // Must update config before starting server
    props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(700));
    props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(10000));
    props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB, Boolean.TRUE.toString());
    props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) BeforeClass(org.junit.BeforeClass)

Aggregations

ReadOnlyProps (org.apache.phoenix.util.ReadOnlyProps)72 BeforeClass (org.junit.BeforeClass)43 Test (org.junit.Test)14 IOException (java.io.IOException)6 Properties (java.util.Properties)6 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)6 ResultSet (java.sql.ResultSet)5 Configuration (org.apache.hadoop.conf.Configuration)5 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)4 Connection (java.sql.Connection)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)3 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)3 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)3 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)3 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)3