{"record":{"id":"36adebdda7400062","repo":"apache/iceberg","slug":"interrupted-in-call-to-createdatabase-name-name","errorCode":null,"errorMessage":"Interrupted in call to createDatabase(name) ${namespace} in Hive Metastore","messagePattern":"Interrupted in call to createDatabase\\(name\\) (.+?) in Hive Metastore","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java","lineNumber":559,"sourceCode":"    try {\n      clients.run(\n          client -> {\n            client.createDatabase(convertToDatabase(namespace, meta));\n            return null;\n          });\n\n      LOG.info(\"Created namespace: {}\", namespace);\n\n    } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n      throw new AlreadyExistsException(e, \"Namespace already exists: %s\", namespace);\n\n    } catch (TException e) {\n      throw new RuntimeException(\n          \"Failed to create namespace \" + namespace + \" in Hive Metastore\", e);\n\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(\n          \"Interrupted in call to createDatabase(name) \" + namespace + \" in Hive Metastore\", e);\n    }\n  }\n\n  @Override\n  public List<Namespace> listNamespaces(Namespace namespace) {\n    if (!namespace.isEmpty() && (!isValidateNamespace(namespace) || !namespaceExists(namespace))) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", namespace);\n    }\n    if (!namespace.isEmpty()) {\n      return ImmutableList.of();\n    }\n    try {\n      List<Namespace> namespaces =\n          clients.run(IMetaStoreClient::getAllDatabases).stream()\n              .map(Namespace::of)\n              .collect(Collectors.toList());\n","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L541-L577","documentation":"createNamespace restores the interrupt flag and throws a RuntimeException when the thread is interrupted while executing the metastore createDatabase call via the retry client. It signals the operation was aborted due to thread interruption, not a metastore failure.","triggerScenarios":"Thread running catalog.createNamespace(...) is interrupted (e.g. task cancellation, executor shutdown, Spark job cancel) while the metastore call is in flight.","commonSituations":"Cancelling a Spark/Flink job mid-create; shutdown hooks interrupting worker threads; timeouts in orchestration frameworks that interrupt threads.","solutions":["Avoid interrupting the thread; let the createNamespace call finish or cancel before shutdown","Check your job/cancellation logic — handle the RuntimeException and re-check whether the database was actually created before retrying","If intentional cancellation, catch the exception and exit cleanly (the interrupt flag is already restored)"],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts in-flight createNamespace\n// after\nexecutor.shutdown();\nexecutor.awaitTermination(5, TimeUnit.MINUTES);","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) {\n  throw new InterruptedException(\"Skipping createNamespace: already interrupted\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  catalog.createNamespace(ns);\n} catch (RuntimeException e) {\n  if (Thread.currentThread().isInterrupted()) {\n    // intentional cancellation; exit cleanly\n    return;\n  }\n  throw e;\n}","preventionTips":["Use graceful shutdown instead of shutdownNow","Verify whether the namespace was created before retrying after interruption","Avoid watchdog timeouts that interrupt catalog threads"],"tags":["interruption","threading","hive-metastore"],"backgroundTag":"request-timeout","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}