PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un… - #2594
PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un…#2594ishitadixit-dot wants to merge 5 commits into
Conversation
…derlying HBase table exists but is disabled
There was a problem hiding this comment.
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.
| */ | ||
| private void reenableOrphanedDisabledHBaseTable(byte[] schemaBytes, byte[] tableBytes, | ||
| boolean isNamespaceMapped, PTableType tableType) throws SQLException { | ||
| if (tableType != PTableType.TABLE) { |
There was a problem hiding this comment.
Should we return early for SYSTEM tables as well?
There was a problem hiding this comment.
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.
| ) { | ||
| // 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thank you @sanjeet006py. I've added it in ensureTableCreated. Making it usable for view-index tables would require us to strip IDX first and then run the checks. The current metadata lookup uses the physical name directly, which works for base tables but not for view-index physicals (they're shared across all view indexes on a parent and aren't row-keyed by their physical name in SYSTEM.CATALOG).
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