Changing Index Status
The alterGlobalIndicesActive API, alterGlobalIndicesInactive API, and alterGlobalIndicesUnusable API are used to change the index status.
alterGlobalIndicesActive API
- alterGlobalIndicesActive API
void alterGlobalIndicesActive(TableName tableName, List<String> indexNames)
- Function description
Clients call this API to change the index table status to Active.
- API description
- Package name: package com.huawei.boostkit.hindex
- Class name: GlobalIndexAdmin
- Method name: alterGlobalIndicesActive
- Parameter description:
Parameter
Value
Description
tableName
TableName
User data table.
List<String> indexNames
List<String>
Index table whose status is to be changed.
- Example
// Create a user table myuser and add data. Admin admin = connection.getAdmin(); TableName myuser = TableName.valueOf("myuser"); HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser); HColumnDescriptor f1 = new HColumnDescriptor("f1"); hTableDescriptor.addFamily(f1); admin.createTable(hTableDescriptor); try (Table table = conn.getTable(myuser)) { Put put0 = new Put(Bytes.toBytes("001")); put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test")); table.put(ImmutableList.of(put0)); } // Create an index table myindex. TableIndices myindex = new TableIndices(); HIndexSpecification spec = new HIndexSpecification("myindex"); // Create an index for q1 in the f1 column family of the data table. The data type is STRING. spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING); myindex.addIndex(spec); GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin); globalIndexAdmin.addIndicesWithData(myuser, myindex); // Change the status of the myindex index table. globalIndexAdmin.alterGlobalIndicesUnusable(myuser, Collections.singletonList("myindex")); globalIndexAdmin.alterGlobalIndicesActive(myuser, Collections.singletonList("myindex")); - Result
The status of the myindex table is changed from Active to Unusable and then back to Active.
alterGlobalIndicesInactive API
- API
void alterGlobalIndicesInactive(TableName tableName, List<String> indexNames)
- Function description
Clients call this API to change the index table status to Inactive.
- API description
- Package name: package com.huawei.boostkit.hindex
- Class name: GlobalIndexAdmin
- Method name: alterGlobalIndicesInactive
- Parameter description:
Parameter
Value
Description
tableName
TableName
User data table.
List<String> indexNames
List<String>
Index table whose status is to be changed.
- Example
// Create a user table myuser and add data. Admin admin = connection.getAdmin(); TableName myuser = TableName.valueOf("myuser"); HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser); HColumnDescriptor f1 = new HColumnDescriptor("f1"); hTableDescriptor.addFamily(f1); admin.createTable(hTableDescriptor); try (Table table = conn.getTable(myuser)) { Put put0 = new Put(Bytes.toBytes("001")); put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test")); table.put(ImmutableList.of(put0)); } // Create an index table myindex. TableIndices myindex = new TableIndices(); HIndexSpecification spec = new HIndexSpecification("myindex"); // Create an index for q1 in the f1 column family of the data table. The data type is STRING. spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING); myindex.addIndex(spec); GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin); globalIndexAdmin.addIndicesWithData(myuser, myindex); // Change the status of the myindex index table. globalIndexAdmin.alterGlobalIndicesInactive(myuser, Collections.singletonList("myindex")); - Result
The status of the myindex table is changed from Active to Inactive.
alterGlobalIndicesUnusable API
- API
void alterGlobalIndicesUnusable(TableName tableName, List<String> indexNames)
- Function description
Clients call this API to change the index table status to Unusable.
- API description
- Package name: package com.huawei.boostkit.hindex
- Class name: GlobalIndexAdmin
- Method name: alterGlobalIndicesUnusable
- Parameter description:
Parameter
Value
Description
tableName
TableName
User data table.
List<String> indexNames
List<String>
Index table whose status is to be changed.
- Example
// Create a user table myuser and add data. Admin admin = connection.getAdmin(); TableName myuser = TableName.valueOf("myuser"); HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser); HColumnDescriptor f1 = new HColumnDescriptor("f1"); hTableDescriptor.addFamily(f1); admin.createTable(hTableDescriptor); try (Table table = conn.getTable(myuser)) { Put put0 = new Put(Bytes.toBytes("001")); put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test")); table.put(ImmutableList.of(put0)); } // Create an index table myindex. TableIndices myindex = new TableIndices(); HIndexSpecification spec = new HIndexSpecification("myindex"); // Create an index for q1 in the f1 column family of the data table. The data type is STRING. spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING); myindex.addIndex(spec); GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin); globalIndexAdmin.addIndicesWithData(myuser, myindex); // Change the status of the myindex index table. globalIndexAdmin.alterGlobalIndicesUnusable(myuser, Collections.singletonList("myindex")); - Result
The status of the myindex table is changed from Active to Unusable.