{"record":{"id":"208adb47536bbb36","repo":"prestodb/presto","slug":"failed-to-acquire-lock-s","errorCode":null,"errorMessage":"Failed to acquire lock: %s","messagePattern":"Failed to acquire lock: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java","lineNumber":1814,"sourceCode":"                                    // only retry on waiting for lock exception\n                                    return e;\n                                }\n                                else {\n                                    return new IllegalStateException(e.getMessage(), e);\n                                }\n                            })\n                            .run(\"lock\", stats.getLock().wrap(() ->\n                                getMetastoreClientThenCall(metastoreContext, client -> {\n                                    LockResponse response = client.checkLock(new CheckLockRequest(lockId));\n                                    LockState newState = response.getState();\n                                    if (newState.equals(WAITING)) {\n                                        throw new WaitingForLockException(\"Waiting for lock.\");\n                                    }\n                                    else if (newState.equals(ACQUIRED)) {\n                                        acquired.set(true);\n                                    }\n                                    else {\n                                        throw new RuntimeException(String.format(\"Failed to acquire lock: %s\", newState.name()));\n                                    }\n                                    return null;\n                                })));\n                }\n            }\n            finally {\n                if (!acquired.get()) {\n                    unlock(metastoreContext, lockId);\n                }\n            }\n\n            if (!acquired.get()) {\n                throw new RuntimeException(\"Failed to acquire lock\");\n            }\n\n            return lockId;\n        }\n        catch (TException e) {","sourceCodeStart":1796,"sourceCodeEnd":1832,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java#L1796-L1832","documentation":"During lock acquisition ThriftHiveMetastore polls the metastore lock state; if the lock enters a terminal non-ACQUIRED state (ABORTED, EXPIRED, etc.) it throws RuntimeException(\"Failed to acquire lock: <state>\"). The Hive metastore's locking service refused or cancelled the lock needed for the operation (e.g. dropPartition).","triggerScenarios":"Acquiring a metastore lock (lockTable/heartbeat/checkLock flow) where checkLock reports a state other than ACQUIRED or WAITING — typically ABORTED or EXPIRED — before the retry loop succeeds.","commonSituations":"Lock contention with another long-running transaction that caused lock expiry, metastore lock manager (in-memory or DB-backed) timing out because the operation took longer than hive.lock.numretries/timeout, another session explicitly aborted the lock, misconfigured hive.lock.check.interval.","solutions":["Retry the operation — locks are often transient; ensure no other job holds a conflicting lock on the table.","Increase hive.lock.numretries / lock timeout settings and metastore lock manager capacity.","Check the metastore lock table for stale locks from dead sessions and clear them.","Shorten the operation holding the lock, or schedule conflicting work (e.g. big partition drops) to avoid overlap.","If using DB-backed lock manager, verify its connectivity and transaction health."],"exampleFix":"// before\nhive.lock.numretries=100\n\n// after: more retries and longer wait for heavy DDL\nhive.lock.numretries=1000\nhive.lock.sleep.between.retries=60s","handlingStrategy":"retry","validationCode":"// check for existing conflicting locks on the table before the operation\n// query metastore lock manager (show locks / lock table API) and wait until free\nwhile (tableIsLocked(db, table)) { Thread.sleep(1000); }","typeGuard":null,"tryCatchPattern":"try {\n    metastore.dropPartition(context, db, table, parts, false);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to acquire lock:\")) {\n        // wait/backoff and retry the whole operation\n    } else throw e;\n}","preventionTips":["Raise lock retry counts and sleep intervals for long DDL.","Avoid overlapping heavy DDL/DML on the same Hive table.","Monitor and clean stale metastore locks from dead sessions.","Heartbeat long-running transactions holding locks."],"tags":["hive","metastore","locking","concurrency"],"backgroundTag":"lock-acquisition-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}