Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHOENIX-7449 Handling already disabled table gracefully during dropTables execution #2021

Open
wants to merge 2 commits into
base: 5.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import org.apache.hadoop.hbase.NamespaceNotFoundException;
import org.apache.hadoop.hbase.TableExistsException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.ClusterConnection;
Expand Down Expand Up @@ -1583,7 +1584,7 @@ private TableDescriptor ensureTableCreated(byte[] physicalTableName, PTableType
SQLExceptionCode.INCONSISTENT_NAMESPACE_MAPPING_PROPERTIES.getErrorCode()) {
try {
// In case we wrongly created SYSTEM.CATALOG or SYSTEM:CATALOG, we should drop it
admin.disableTable(TableName.valueOf(physicalTableName));
disableTable(admin, TableName.valueOf(physicalTableName));
admin.deleteTable(TableName.valueOf(physicalTableName));
} catch (org.apache.hadoop.hbase.TableNotFoundException ignored) {
// Ignore this since it just means that another client with a similar set of
Expand Down Expand Up @@ -1740,7 +1741,7 @@ private void modifyTable(byte[] tableName, TableDescriptor newDesc, boolean shou
TableName tn = TableName.valueOf(tableName);
try (Admin admin = getAdmin()) {
if (!allowOnlineTableSchemaUpdate()) {
admin.disableTable(tn);
disableTable(admin, tn);
admin.modifyTable(newDesc); // TODO: Update to TableDescriptor
admin.enableTable(tn);
} else {
Expand Down Expand Up @@ -1965,6 +1966,14 @@ private void ensureViewIndexTableCreated(byte[] physicalTableName, Map<String, O
}
}

private void disableTable(Admin admin, TableName tableName) throws IOException {
try {
admin.disableTable(tableName);
} catch (TableNotEnabledException e) {
LOGGER.info("Table already disabled, continuing with next steps", e);
}
}

private boolean ensureViewIndexTableDropped(byte[] physicalTableName, long timestamp) throws SQLException {
byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName);
boolean wasDeleted = false;
Expand All @@ -1976,7 +1985,7 @@ private boolean ensureViewIndexTableDropped(byte[] physicalTableName, long times
final ReadOnlyProps props = this.getProps();
final boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA);
if (dropMetadata) {
admin.disableTable(physicalIndexTableName);
disableTable(admin, physicalIndexTableName);
admin.deleteTable(physicalIndexTableName);
clearTableRegionCache(physicalIndexTableName);
wasDeleted = true;
Expand Down Expand Up @@ -2314,7 +2323,7 @@ private void dropTables(final List<byte[]> tableNamesToDelete) throws SQLExcepti
try {
TableName tn = TableName.valueOf(tableName);
TableDescriptor htableDesc = this.getTableDescriptor(tableName);
admin.disableTable(tn);
disableTable(admin, tn);
admin.deleteTable(tn);
tableStatsCache.invalidateAll(htableDesc);
clearTableRegionCache(TableName.valueOf(tableName));
Expand Down Expand Up @@ -3727,7 +3736,7 @@ protected PhoenixConnection upgradeSystemCatalogIfRequired(PhoenixConnection met
// co-location of data and index regions. If we just modify the
// table descriptor when online schema change enabled may reopen
// the region in same region server instead of following data region.
admin.disableTable(table.getTableName());
disableTable(admin,table.getTableName());
admin.modifyTable(table);
admin.enableTable(table.getTableName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.apache.phoenix.util.ReadOnlyProps;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down