PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un… - #2594
PHOENIX-7788 CREATE TABLE fails with TableNotEnabledException when un…#2594ishitadixit-dot wants to merge 4 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.
| 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 " |
There was a problem hiding this comment.
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); |
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.
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