Java Code Examples for org.apache.hadoop.hbase.HTableDescriptor#hasCoprocessor()

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#hasCoprocessor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployCoprocessorCLI.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public static void resetCoprocessor(String tableName, HBaseAdmin hbaseAdmin, Path hdfsCoprocessorJar) throws IOException {
    logger.info("Disable " + tableName);
    hbaseAdmin.disableTable(tableName);

    logger.info("Unset coprocessor on " + tableName);
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
    while (desc.hasCoprocessor(OBSERVER_CLS_NAME)) {
        desc.removeCoprocessor(OBSERVER_CLS_NAME);
    }
    while (desc.hasCoprocessor(ENDPOINT_CLS_NAMAE)) {
        desc.removeCoprocessor(ENDPOINT_CLS_NAMAE);
    }

    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);
    hbaseAdmin.modifyTable(tableName, desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(tableName);
}
 
Example 2
Source File: CoprocessorTool.java    From eagle with Apache License 2.0 5 votes vote down vote up
private void registerCoprocessor(String jarPath, String tableName, String localJarPath) throws IOException {
    Configuration configuration = getConf();
    try (FileSystem fs = FileSystem.get(configuration); HBaseAdmin admin = new HBaseAdmin(configuration)) {
        Path path = new Path(fs.getUri() + Path.SEPARATOR + jarPath);
        LOGGER.info("Checking path {} ... ", path.toString());
        if (!fs.exists(path)) {
            LOGGER.info("Path: {} not exist, uploading jar ...", path.toString());
            if (localJarPath == null) {
                throw new IOException("local jar path is not given, please manually upload coprocessor jar onto hdfs at " + jarPath
                        + " and retry, or provide local coprocessor jar path through CLI argument and upload automatically");
            }
            LOGGER.info("Copying from local {} to {}", localJarPath, jarPath);
            fs.copyFromLocalFile(new Path(localJarPath), path);
            LOGGER.info("Succeed to copied coprocessor jar to {}", path.toString());
        } else {
            LOGGER.info("Path {} already exists", path.toString());
        }
        LOGGER.info("Checking hbase table {}", tableName);
        TableName table = TableName.valueOf(tableName);
        HTableDescriptor tableDescriptor = admin.getTableDescriptor(table);
        LOGGER.info("Table {} found", tableName);
        if (tableDescriptor.hasCoprocessor(AggregateProtocolEndPoint.class.getName())) {
            LOGGER.warn("Table '" + tableName + "' already registered coprocessor: " + AggregateProtocolEndPoint.class.getName() + ", removing firstly");
            tableDescriptor.removeCoprocessor(AggregateProtocolEndPoint.class.getName());
            admin.modifyTable(table, tableDescriptor);
            tableDescriptor = admin.getTableDescriptor(table);
        }
        tableDescriptor.addCoprocessor(AggregateProtocolEndPoint.class.getName(),
                path, Coprocessor.PRIORITY_USER, new HashMap<>());
        admin.modifyTable(table, tableDescriptor);
        LOGGER.info("Succeed to enable coprocessor on table " + tableName);
    }
}
 
Example 3
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 4
Source File: ConnectionQueryServicesImpl.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void addCoprocessors(byte[] tableName, HTableDescriptor descriptor, PTableType tableType) throws SQLException {
    // The phoenix jar must be available on HBase classpath
    int priority = props.getInt(QueryServices.COPROCESSOR_PRIORITY_ATTRIB, QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY);
    try {
        if (!descriptor.hasCoprocessor(ScanRegionObserver.class.getName())) {
            descriptor.addCoprocessor(ScanRegionObserver.class.getName(), null, priority, null);
        }
        if (!descriptor.hasCoprocessor(UngroupedAggregateRegionObserver.class.getName())) {
            descriptor.addCoprocessor(UngroupedAggregateRegionObserver.class.getName(), null, priority, null);
        }
        if (!descriptor.hasCoprocessor(GroupedAggregateRegionObserver.class.getName())) {
            descriptor.addCoprocessor(GroupedAggregateRegionObserver.class.getName(), null, priority, null);
        }
        if (!descriptor.hasCoprocessor(ServerCachingEndpointImpl.class.getName())) {
            descriptor.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null);
        }
        // TODO: better encapsulation for this
        // Since indexes can't have indexes, don't install our indexing coprocessor for indexes.
        // Also don't install on the SYSTEM.CATALOG and SYSTEM.STATS table because we use
        // all-or-none mutate class which break when this coprocessor is installed (PHOENIX-1318).
        if ((tableType != PTableType.INDEX && tableType != PTableType.VIEW)
                && !SchemaUtil.isMetaTable(tableName)
                && !SchemaUtil.isStatsTable(tableName)
                && !descriptor.hasCoprocessor(Indexer.class.getName())) {
            Map<String, String> opts = Maps.newHashMapWithExpectedSize(1);
            opts.put(CoveredColumnsIndexBuilder.CODEC_CLASS_NAME_KEY, PhoenixIndexCodec.class.getName());
            Indexer.enableIndexing(descriptor, PhoenixIndexBuilder.class, opts, priority);
        }
        if (SchemaUtil.isStatsTable(tableName) && !descriptor.hasCoprocessor(MultiRowMutationEndpoint.class.getName())) {
            descriptor.addCoprocessor(MultiRowMutationEndpoint.class.getName(),
                    null, priority, null);
        }

        if (descriptor.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null
                && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(descriptor
                        .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
            if (!descriptor.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) {
                descriptor.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(),
                    null, priority, null);
            }
        } else {
            if (!descriptor.hasCoprocessor(LocalIndexSplitter.class.getName())
                    && !SchemaUtil.isMetaTable(tableName)
                    && !SchemaUtil.isSequenceTable(tableName)) {
                descriptor.addCoprocessor(LocalIndexSplitter.class.getName(), null, priority, null);
            }
        }

        // Setup split policy on Phoenix metadata table to ensure that the key values of a Phoenix table
        // stay on the same region.
        if (SchemaUtil.isMetaTable(tableName)) {
            if (!descriptor.hasCoprocessor(MetaDataEndpointImpl.class.getName())) {
                descriptor.addCoprocessor(MetaDataEndpointImpl.class.getName(), null, priority, null);
            }
            if (!descriptor.hasCoprocessor(MetaDataRegionObserver.class.getName())) {
                descriptor.addCoprocessor(MetaDataRegionObserver.class.getName(), null, priority + 1, null);
            }
        } else if (SchemaUtil.isSequenceTable(tableName)) {
            if (!descriptor.hasCoprocessor(SequenceRegionObserver.class.getName())) {
                descriptor.addCoprocessor(SequenceRegionObserver.class.getName(), null, priority, null);
            }
        }
    } catch (IOException e) {
        throw ServerUtil.parseServerException(e);
    }
}
 
Example 5
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 6
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 7
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 8
Source File: DeployCoprocessorCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static boolean resetCoprocessor(String tableName, Admin hbaseAdmin, Path hdfsCoprocessorJar)
        throws IOException {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    //when the table has migrated from dev env to test(prod) env, the dev server
    //should not reset the coprocessor of the table.
    String host = desc.getValue(IRealizationConstants.HTableTag);
    if (!host.equalsIgnoreCase(kylinConfig.getMetadataUrlPrefix())) {
        logger.warn("This server doesn't own this table: " + tableName);
        return false;
    }

    logger.info("reset coprocessor on " + tableName);

    logger.info("Disable " + tableName);
    if (hbaseAdmin.isTableEnabled(TableName.valueOf(tableName))) {
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
    }

    while (desc.hasCoprocessor(CubeObserverClassOld2)) {
        desc.removeCoprocessor(CubeObserverClassOld2);
    }
    while (desc.hasCoprocessor(CubeEndpointClass)) {
        desc.removeCoprocessor(CubeEndpointClass);
    }
    while (desc.hasCoprocessor(IIEndpointClass)) {
        desc.removeCoprocessor(IIEndpointClass);
    }
    // remove legacy coprocessor from v1.x
    while (desc.hasCoprocessor(CubeObserverClassOld)) {
        desc.removeCoprocessor(CubeObserverClassOld);
    }
    while (desc.hasCoprocessor(IIEndpointClassOld)) {
        desc.removeCoprocessor(IIEndpointClassOld);
    }
    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);

    // update commit tags
    String commitInfo = KylinVersion.getGitCommitInfo();
    if (!StringUtils.isEmpty(commitInfo)) {
        desc.setValue(IRealizationConstants.HTableGitTag, commitInfo);
    }

    hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(TableName.valueOf(tableName));

    return true;
}
 
Example 9
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 10
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 11
Source File: InvalidListPruneTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TestTransactionProcessor.class.getName());
}
 
Example 12
Source File: Constraints.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Enable constraints on a table.
 * <p>
 * Currently, if you attempt to add a constraint to the table, then
 * Constraints will automatically be turned on.
 * 
 * @param desc
 *          table description to add the processor
 * @throws IOException
 *           If the {@link ConstraintProcessor} CP couldn't be added to the
 *           table.
 */
public static void enable(HTableDescriptor desc) throws IOException {
  // if the CP has already been loaded, do nothing
  String clazz = ConstraintProcessor.class.getName();
  if (desc.hasCoprocessor(clazz)) {
    return;
  }

  // add the constrain processor CP to the table
  desc.addCoprocessor(clazz);
}
 
Example 13
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 14
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 15
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 16
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 17
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 18
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 19
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}
 
Example 20
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the table is a transactional table. By default, it is a table is identified as a transactional
 * table if it has a the coprocessor {@link TransactionProcessor} attached to it. Should be overriden if the users
 * attach a different coprocessor.
 *
 * @param tableDescriptor {@link HTableDescriptor} of the table
 * @return true if the table is transactional
 */
protected boolean isTransactionalTable(HTableDescriptor tableDescriptor) {
  return tableDescriptor.hasCoprocessor(TransactionProcessor.class.getName());
}