Skip to content

PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un… - #2594

Open
ishitadixit-dot wants to merge 4 commits into
apache:masterfrom
ishitadixit-dot:PHOENIX-7788-reenable-disabled-hbase-table
Open

PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un…#2594
ishitadixit-dot wants to merge 4 commits into
apache:masterfrom
ishitadixit-dot:PHOENIX-7788-reenable-disabled-hbase-table

Conversation

@ishitadixit-dot

Copy link
Copy Markdown
Contributor

When an HBase table exists and is disabled but has no corresponding Phoenix metadata in SYSTEM.CATALOG, executing CREATE TABLE IF NOT EXISTS fails with TableNotEnabledException.

JIRA: https://issues.apache.org/jira/browse/PHOENIX-7788

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Re-enables orphaned disabled HBase tables during Phoenix table creation.

Changes:

  • Detects disabled non-system HBase tables during creation.
  • Adds race-safe table enabling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sanjeet006py
sanjeet006py self-requested a review August 25, 2026 12:40
@virajjasani
virajjasani self-requested a review August 25, 2026 15:03
*/
private void reenableOrphanedDisabledHBaseTable(byte[] schemaBytes, byte[] tableBytes,
boolean isNamespaceMapped, PTableType tableType) throws SQLException {
if (tableType != PTableType.TABLE) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return early for SYSTEM tables as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current guard also handles SYSTEM tables. tableType != PTableType.TABLE returns early for everything that isn't TABLE, which is: SYSTEM, VIEW, INDEX, SUBQUERY, PROJECTED, CDC.

HConstants.LATEST_TIMESTAMP, HConstants.LATEST_TIMESTAMP);
if (result.getMutationCode() != MutationCode.TABLE_NOT_FOUND) {
LOGGER.info(
"Physical HBase table {} is disabled but SYSTEM.CATALOG has metadata for it "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Instead of hardcoding SYSTEM.CATALOG how about using PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME? This will keep code DRY.

) {
// PHOENIX-7788: recover from an orphaned disabled physical table before ensureTableCreated
// runs modifyTable on it. See the helper for the metadata-preserving contract.
reenableOrphanedDisabledHBaseTable(schemaBytes, tableBytes, isNamespaceMapped, tableType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about shifting this to ensureTableCreated? That way the responsibility of ensuring table is created and usable lies with ensureTableCreated only. Further, you will notice that in subsequent lines ensureViewIndexTableCreated is called which eventually calls ensureTableCreated for physical HBase table used by view indexes. And, same situation of physical HBase table for view index being disabled can happen here also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants