/** * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. * Use {@link #setCoprocessor(String)} instead */ @Deprecated public TableDescriptorBuilder addCoprocessor(String className) throws IOException { return addCoprocessor(className, null, Coprocessor.PRIORITY_USER, null); }
/** * Enable indexing on the given table * @param desc {@link TableDescriptor} for the table on which indexing should be enabled * @param builder class to use when building the index for this table * @param properties map of custom configuration options to make available to your * {@link IndexBuilder} on the server-side * @param priority TODO * @throws IOException the Indexer coprocessor cannot be added */ public static void enableIndexing(TableDescriptorBuilder descBuilder, Class<? extends IndexBuilder> builder, Map<String, String> properties, int priority) throws IOException { if (properties == null) { properties = new HashMap<String, String>(); } properties.put(Indexer.INDEX_BUILDER_CONF_KEY, builder.getName()); descBuilder.addCoprocessor(Indexer.class.getName(), null, priority, properties); } }
TableDescriptor newDesc = builder.build(); if(!newDesc.hasCoprocessor(ScanRegionObserver.class.getName())) { builder.addCoprocessor(ScanRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(UngroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(GroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null); if (isTransactional) { if (!newDesc.hasCoprocessor(PhoenixTransactionalIndexer.class.getName())) { builder.addCoprocessor(PhoenixTransactionalIndexer.class.getName(), null, priority, null); builder.addCoprocessor(MultiRowMutationEndpoint.class.getName(), null, priority, null); if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) { if(!newDesc.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) { builder.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(), null, priority, null); break; builder.addCoprocessor(MetaDataEndpointImpl.class.getName(), null, priority, null); builder.addCoprocessor(MetaDataRegionObserver.class.getName(), null, priority + 1, null); builder.addCoprocessor(SequenceRegionObserver.class.getName(), null, priority, null);
public static void addCoprocessor(Connection conn, String tableName, Class coprocessorClass) throws Exception { int priority = QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY + 100; ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices(); TableDescriptor descriptor = services.getTableDescriptor(Bytes.toBytes(tableName)); TableDescriptorBuilder descriptorBuilder = null; if (!descriptor.getCoprocessors().contains(coprocessorClass.getName())) { descriptorBuilder=TableDescriptorBuilder.newBuilder(descriptor); descriptorBuilder.addCoprocessor(coprocessorClass.getName(), null, priority, null); }else{ return; } final int retries = 10; int numTries = 10; descriptor = descriptorBuilder.build(); try (Admin admin = services.getAdmin()) { admin.modifyTable(descriptor); while (!admin.getDescriptor(TableName.valueOf(tableName)).equals(descriptor) && numTries > 0) { numTries--; if (numTries == 0) { throw new Exception( "Failed to add " + coprocessorClass.getName() + " after " + retries + " retries."); } Thread.sleep(1000); } } }
private void testBuildingLocalIndexShouldHandleNoSuchColumnFamilyException(boolean coveredIndex) throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); String indexTableName = schemaName + "." + indexName; TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); createBaseTable(tableName, null, null, coveredIndex ? "cf" : null); Connection conn1 = DriverManager.getConnection(getUrl()); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')"); conn1.commit(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); TableDescriptor tableDescriptor = admin.getDescriptor(physicalTableName); tableDescriptor=TableDescriptorBuilder.newBuilder(tableDescriptor).addCoprocessor(DeleyOpenRegionObserver.class.getName(), null, QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY - 1, null).build(); admin.disableTable(physicalTableName); admin.modifyTable(tableDescriptor); admin.enableTable(physicalTableName); DeleyOpenRegionObserver.DELAY_OPEN = true; conn1.createStatement().execute( "CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(k3)" + (coveredIndex ? " include(cf.v1)" : "")); DeleyOpenRegionObserver.DELAY_OPEN = false; ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName); assertTrue(rs.next()); assertEquals(4, rs.getInt(1)); }
/** * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. * Use {@link #setCoprocessor(String)} instead */ @Deprecated public TableDescriptorBuilder addCoprocessor(String className) throws IOException { return addCoprocessor(className, null, Coprocessor.PRIORITY_USER, null); }
/** * Enable indexing on the given table * @param desc {@link TableDescriptor} for the table on which indexing should be enabled * @param builder class to use when building the index for this table * @param properties map of custom configuration options to make available to your * {@link IndexBuilder} on the server-side * @param priority TODO * @throws IOException the Indexer coprocessor cannot be added */ public static void enableIndexing(TableDescriptorBuilder descBuilder, Class<? extends IndexBuilder> builder, Map<String, String> properties, int priority) throws IOException { if (properties == null) { properties = new HashMap<String, String>(); } properties.put(Indexer.INDEX_BUILDER_CONF_KEY, builder.getName()); descBuilder.addCoprocessor(Indexer.class.getName(), null, priority, properties); } }
/** * Enable indexing on the given table * @param desc {@link TableDescriptor} for the table on which indexing should be enabled * @param builder class to use when building the index for this table * @param properties map of custom configuration options to make available to your * {@link IndexBuilder} on the server-side * @param priority TODO * @throws IOException the Indexer coprocessor cannot be added */ public static void enableIndexing(TableDescriptorBuilder descBuilder, Class<? extends IndexBuilder> builder, Map<String, String> properties, int priority) throws IOException { if (properties == null) { properties = new HashMap<String, String>(); } properties.put(Indexer.INDEX_BUILDER_CONF_KEY, builder.getName()); descBuilder.addCoprocessor(Indexer.class.getName(), null, priority, properties); } }
.addCoprocessor(IndexTableBlockingReplayObserver.class.getName()); TestIndexManagementUtil.createIndexTable(admin, indexTableBuilder);
TableDescriptor newDesc = builder.build(); if(!newDesc.hasCoprocessor(ScanRegionObserver.class.getName())) { builder.addCoprocessor(ScanRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(UngroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(GroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null); if (isTransactional) { if (!newDesc.hasCoprocessor(PhoenixTransactionalIndexer.class.getName())) { builder.addCoprocessor(PhoenixTransactionalIndexer.class.getName(), null, priority, null); builder.addCoprocessor(MultiRowMutationEndpoint.class.getName(), null, priority, null); if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) { if(!newDesc.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) { builder.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(), null, priority, null); break; builder.addCoprocessor(MetaDataEndpointImpl.class.getName(), null, priority, null); builder.addCoprocessor(MetaDataRegionObserver.class.getName(), null, priority + 1, null); builder.addCoprocessor(SequenceRegionObserver.class.getName(), null, priority, null);
TableDescriptor newDesc = builder.build(); if (!newDesc.hasCoprocessor(GetRegionObserver.class.getName())) { builder.addCoprocessor(GetRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(ScanRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(UngroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(GroupedAggregateRegionObserver.class.getName(), null, priority, null); builder.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null); if (isTransactional) { if (!newDesc.hasCoprocessor(PhoenixTransactionalIndexer.class.getName())) { builder.addCoprocessor(PhoenixTransactionalIndexer.class.getName(), null, priority, null); builder.addCoprocessor(MultiRowMutationEndpoint.class.getName(), null, priority, null); if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) { if(!newDesc.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) { builder.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(), null, priority, null); break; builder.addCoprocessor(MetaDataEndpointImpl.class.getName(), null, priority, null); builder.addCoprocessor(MetaDataRegionObserver.class.getName(), null, priority + 1, null);