{"record":{"id":"5fff0a8df16e3a37","repo":"apache/iceberg","slug":"failed-to-create-lock","errorCode":null,"errorMessage":"Failed to create lock {}","messagePattern":"Failed to create lock (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":309,"sourceCode":"    AtomicBoolean interrupted = new AtomicBoolean(false);\n    Tasks.foreach(lockRequest)\n        .retry(Integer.MAX_VALUE - 100)\n        .exponentialBackoff(\n            lockCreationMinWaitTime, lockCreationMaxWaitTime, lockCreationTimeout, 2.0)\n        .shouldRetryTest(\n            e ->\n                !interrupted.get()\n                    && e instanceof LockException\n                    && HiveVersion.min(HiveVersion.HIVE_2))\n        .throwFailureWhenFinished()\n        .run(\n            request -> {\n              try {\n                LockResponse lockResponse = metaClients.run(client -> client.lock(request));\n                lockInfo.lockId = lockResponse.getLockid();\n                lockInfo.lockState = lockResponse.getState();\n              } catch (TException te) {\n                LOG.warn(\"Failed to create lock {}\", request, te);\n                try {\n                  // If we can not check for lock, or we do not find it, then rethrow the exception\n                  // Otherwise we are happy as the findLock sets the lockId and the state correctly\n                  if (HiveVersion.min(HiveVersion.HIVE_2)) {\n                    LockInfo lockFound = findLock();\n                    if (lockFound != null) {\n                      lockInfo.lockId = lockFound.lockId;\n                      lockInfo.lockState = lockFound.lockState;\n                      LOG.info(\"Found lock {} by agentInfo {}\", lockInfo, agentInfo);\n                      return;\n                    }\n                  }\n\n                  throw new LockException(\n                      \"Failed to find lock for table %s.%s\", databaseName, tableName);\n                } catch (InterruptedException e) {\n                  Thread.currentThread().interrupt();\n                  interrupted.set(true);","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L291-L327","documentation":"MetastoreLock.createLock requests a lock from the Hive Metastore via client.lock(request). On TException (thrift transport/protocol error), it logs this warning with the LockRequest, then attempts to locate the lock via findLock(); if the lock cannot be found the exception is rethrown (on Hive >= 2).","triggerScenarios":"Acquiring a Hive lock for a commit when the metastore call fails — HMS unreachable, thrift session expired/invalid, metastore rejecting the lock request.","commonSituations":"HMS restarted between checkLock and lock acquisition; network blips to metastore; Hive 1.x where findLock behavior differs; concurrent lock contention triggering metastore errors.","solutions":["Check HMS connectivity and health (metastore logs, network, port)","Retry the operation — the code already retries via findLock; transient TExceptions often resolve","Verify Hive version compatibility of the metastore client vs server (HiveVersion.min(HIVE_2) path)","Increase metastore client timeouts / connection pool settings if under load"],"exampleFix":"// before\nops.commit(); // transient TException creating lock\n// after\nTasks.foreach(() -> ops.commit())\n    .retry(3)\n    .exponentialBackoff(100, 1000)\n    .throwFailureWhenFinished();","handlingStrategy":"retry","validationCode":"// Check HMS reachability before commit-heavy workflows\ntry (HiveMetaStoreClient c = new HiveMetaStoreClient(hiveConf)) { c.getAllDatabases(); }","typeGuard":null,"tryCatchPattern":"try { ops.commit(); } catch (org.apache.iceberg.exceptions.CommitFailedException e) { /* re-acquire lock / retry commit */ }","preventionTips":["Retry commits with exponential backoff (Tasks.foreach retry)","Keep HMS client timeouts generous for lock-heavy workloads","Align Hive client and server major versions","Monitor metastore availability"],"tags":["hive","lock","thrift","metastore"],"backgroundTag":"http-request-failed","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"}