Search in sources :

Example 66 with ReadOnlyProps

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

the class MetaDataRegionObserver method postOpen.

@Override
public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) {
    final RegionCoprocessorEnvironment env = e.getEnvironment();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            HTableInterface metaTable = null;
            HTableInterface statsTable = null;
            try {
                ReadOnlyProps props = new ReadOnlyProps(env.getConfiguration().iterator());
                Thread.sleep(1000);
                metaTable = env.getTable(SchemaUtil.getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, props));
                statsTable = env.getTable(SchemaUtil.getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES, props));
                final HTableInterface mTable = metaTable;
                final HTableInterface sTable = statsTable;
                User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {

                    @Override
                    public Void run() throws Exception {
                        if (UpgradeUtil.truncateStats(mTable, sTable)) {
                            LOG.info("Stats are successfully truncated for upgrade 4.7!!");
                        }
                        return null;
                    }
                });
            } catch (Exception exception) {
                LOG.warn("Exception while truncate stats..," + " please check and delete stats manually inorder to get proper result with old client!!");
                LOG.warn(exception.getStackTrace());
            } finally {
                try {
                    if (metaTable != null) {
                        metaTable.close();
                    }
                    if (statsTable != null) {
                        statsTable.close();
                    }
                } catch (IOException e) {
                }
            }
        }
    };
    Thread t = new Thread(r);
    t.setDaemon(true);
    t.start();
    if (!enableRebuildIndex) {
        LOG.info("Failure Index Rebuild is skipped by configuration.");
        return;
    }
    // turn off verbose deprecation logging
    Logger deprecationLogger = Logger.getLogger("org.apache.hadoop.conf.Configuration.deprecation");
    if (deprecationLogger != null) {
        deprecationLogger.setLevel(Level.WARN);
    }
    // Ensure we only run one of the index rebuilder tasks
    if (ServerUtil.isKeyInRegion(SYSTEM_CATALOG_KEY, e.getEnvironment().getRegion())) {
        try {
            Class.forName(PhoenixDriver.class.getName());
            initRebuildIndexConnectionProps(e.getEnvironment().getConfiguration());
            // starts index rebuild schedule work
            BuildIndexScheduleTask task = new BuildIndexScheduleTask(e.getEnvironment());
            executor.scheduleWithFixedDelay(task, initialRebuildTaskDelay, rebuildIndexTimeInterval, TimeUnit.MILLISECONDS);
        } catch (ClassNotFoundException ex) {
            LOG.error("BuildIndexScheduleTask cannot start!", ex);
        }
    }
}
Also used : PhoenixDriver(org.apache.phoenix.jdbc.PhoenixDriver) IOException(java.io.IOException) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Logger(org.apache.log4j.Logger) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)

Example 67 with ReadOnlyProps

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

the class UngroupedAggregateRegionObserver method start.

@Override
public void start(CoprocessorEnvironment e) throws IOException {
    super.start(e);
    // Can't use ClientKeyValueBuilder on server-side because the memstore expects to
    // be able to get a single backing buffer for a KeyValue.
    this.kvBuilder = GenericKeyValueBuilder.INSTANCE;
    /*
         * We need to create a copy of region's configuration since we don't want any side effect of
         * setting the RpcControllerFactory.
         */
    upsertSelectConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
    /*
         * Till PHOENIX-3995 is fixed, we need to use the
         * InterRegionServerIndexRpcControllerFactory. Although this would cause remote RPCs to use
         * index handlers on the destination region servers, it is better than using the regular
         * priority handlers which could result in a deadlock.
         */
    upsertSelectConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY, InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
    compactionConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
    // lower the number of rpc retries, so we don't hang the compaction
    compactionConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, e.getConfiguration().getInt(QueryServices.METADATA_WRITE_RETRIES_NUMBER, QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRIES_NUMBER));
    compactionConfig.setInt(HConstants.HBASE_CLIENT_PAUSE, e.getConfiguration().getInt(QueryServices.METADATA_WRITE_RETRY_PAUSE, QueryServicesOptions.DEFAULT_METADATA_WRITE_RETRY_PAUSE));
    // For retries of index write failures, use the same # of retries as the rebuilder
    indexWriteConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
    indexWriteConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, e.getConfiguration().getInt(QueryServices.INDEX_REBUILD_RPC_RETRIES_COUNTER, QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_RETRIES_COUNTER));
    indexWriteProps = new ReadOnlyProps(indexWriteConfig.iterator());
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps)

Example 68 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, boolean checkLastStatsUpdateTime) throws SQLException {
    ReadOnlyProps props = connection.getQueryServices().getProps();
    final long msMinBetweenUpdates = props.getLong(QueryServices.MIN_STATS_UPDATE_FREQ_MS_ATTRIB, QueryServicesOptions.DEFAULT_MIN_STATS_UPDATE_FREQ_MS);
    Long scn = connection.getSCN();
    // Always invalidate the cache
    long clientTimeStamp = connection.getSCN() == null ? HConstants.LATEST_TIMESTAMP : scn;
    long msSinceLastUpdate = Long.MAX_VALUE;
    if (checkLastStatsUpdateTime) {
        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);
        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 69 with ReadOnlyProps

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

the class WALRecoveryRegionPostOpenIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(10);
    serverProps.put("hbase.coprocessor.region.classes", IndexTableFailingRegionObserver.class.getName());
    serverProps.put(Indexer.RecoveryFailurePolicyKeyForTesting, ReleaseLatchOnFailurePolicy.class.getName());
    serverProps.put(IndexWriterUtils.INDEX_WRITER_RPC_RETRIES_NUMBER, "2");
    serverProps.put(HConstants.HBASE_RPC_TIMEOUT_KEY, "10000");
    serverProps.put(IndexWriterUtils.INDEX_WRITER_RPC_PAUSE, "5000");
    serverProps.put("data.tx.snapshot.dir", "/tmp");
    serverProps.put("hbase.balancer.period", String.valueOf(Integer.MAX_VALUE));
    serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_ATTRIB, Boolean.FALSE.toString());
    Map<String, String> clientProps = Collections.singletonMap(QueryServices.TRANSACTIONS_ENABLED, Boolean.FALSE.toString());
    NUM_SLAVES_BASE = 2;
    setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
}
Also used : ReadOnlyProps(org.apache.phoenix.util.ReadOnlyProps) BeforeClass(org.junit.BeforeClass)

Example 70 with ReadOnlyProps

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

the class TableSnapshotReadsMapReduceIT method doSetup.

@BeforeClass
public static void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    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