{"record":{"id":"ed9ca08357d4ef61","repo":"apache/druid","slug":"table-s-not-found-is-being-deleted-or-update-ve","errorCode":null,"errorMessage":"Table %s: not found, is being deleted or update version does not match DB version","messagePattern":"Table (.+?): not found, is being deleted or update version does not match DB version","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/storage/sql/SQLCatalogManager.java","lineNumber":315,"sourceCode":"          {\n            @Override\n            public TableMetadata withHandle(Handle handle) throws NotFoundException\n            {\n              final TableId id = table.id();\n              final TableSpec spec = table.spec();\n              final long updateTime = System.currentTimeMillis();\n              final int updateCount = handle\n                  .createStatement(statement(UPDATE_SPEC_STMT))\n                  .bind(SCHEMA_NAME_COL, id.schema())\n                  .bind(TABLE_NAME_COL, id.name())\n                  .bind(TABLE_TYPE_COL, spec.type())\n                  .bind(PROPERTIES_COL, JacksonUtils.toBytes(jsonMapper, spec.properties()))\n                  .bind(COLUMNS_COL, JacksonUtils.toBytes(jsonMapper, spec.columns()))\n                  .bind(UPDATE_TIME_COL, updateTime)\n                  .bind(OLD_VERSION_PARAM, oldVersion)\n                  .execute();\n              if (updateCount == 0) {\n                throw new NotFoundException(\n                    \"Table %s: not found, is being deleted or update version does not match DB version\",\n                    id.sqlName()\n                );\n              }\n              return table.asUpdate(updateTime);\n            }\n          }\n      );\n      sendUpdate(EventType.UPDATE, revised);\n      return revised.updateTime();\n    }\n    catch (CallbackFailedException e) {\n      if (e.getCause() instanceof NotFoundException) {\n        throw (NotFoundException) e.getCause();\n      }\n      throw e;\n    }\n  }","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/storage/sql/SQLCatalogManager.java#L297-L333","documentation":"alterTable performs a conditional UPDATE guarded by the expected old version (OLD_VERSION_PARAM). If the affected row count is 0, the table either does not exist, was deleted, or its stored version differs from the caller-supplied oldVersion (optimistic concurrency failure). It surfaces as NotFoundException.","triggerScenarios":"Calling alterTable(id, oldVersion, spec) where the row is absent, was removed concurrently, or the DB version no longer equals oldVersion — typically another writer already updated the table.","commonSituations":"Two editors altering the same table concurrently (lost-update protection kicking in); stale client cache holding an outdated version; the table deleted between read and alter; typo in table name.","solutions":["Re-read the table via readTable to get the current version, re-apply your change, and retry alterTable with the fresh version.","Catch NotFoundException and surface a conflict/retry to the user rather than treating it as a missing table blindly.","Verify the table name/Id is correct and the table wasn't dropped.","Serialize alterations through the manager's table lock to avoid concurrent version bumps."],"exampleFix":"// before\nmanager.alterTable(id, staleVersion, spec); // NotFoundException\n\n// after\nTableMetadata current = manager.readTable(id);\nif (current != null) {\n  manager.alterTable(id, current.version(), spec); // retry with fresh version\n}","handlingStrategy":"retry","validationCode":"TableMetadata meta = manager.readTable(id);\nif (meta == null) {\n  throw new IllegalStateException(\"Table does not exist: \" + id.sqlName());\n}\n// use meta.version() as oldVersion","typeGuard":null,"tryCatchPattern":"try {\n  manager.alterTable(id, oldVersion, spec);\n} catch (NotFoundException e) {\n  TableMetadata fresh = manager.readTable(id);\n  if (fresh != null) {\n    manager.alterTable(id, fresh.version(), rebase(spec, fresh));\n  }\n}","preventionTips":["Always fetch the current version immediately before alter.","Rebase your intended change onto the latest table spec before retrying.","Watch for concurrent editors and use the table lock for multi-step updates."],"tags":["sql","optimistic-locking","conflict"],"backgroundTag":"record-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}