{"record":{"id":"d9c395f990b20a78","repo":"prestodb/presto","slug":"hive-metastore-error-d9c395","errorCode":"HIVE_METASTORE_ERROR","errorMessage":"HIVE_METASTORE_ERROR: ${e}","messagePattern":"HIVE_METASTORE_ERROR: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java","lineNumber":253,"sourceCode":"            Optional<PrimaryKeysResponse> pkResponse = retry()\n                    .stopOnIllegalExceptions()\n                    .run(\"getPrimaryKey\", stats.getGetPrimaryKey().wrap(() ->\n                            getMetastoreClientThenCall(metastoreContext, client -> client.getPrimaryKey(dbName, tableName))));\n\n            if (!pkResponse.isPresent() || pkResponse.get().getPrimaryKeys().size() == 0) {\n                return Optional.empty();\n            }\n\n            List<SQLPrimaryKey> pkCols = pkResponse.get().getPrimaryKeys();\n            boolean isEnabled = pkCols.get(0).isEnable_cstr();\n            boolean isRely = pkCols.get(0).isRely_cstr();\n            boolean isEnforced = pkCols.get(0).isValidate_cstr();\n            String pkName = pkCols.get(0).getPk_name();\n            LinkedHashSet<String> keyCols = pkCols.stream().map(SQLPrimaryKey::getColumn_name).collect(toCollection(LinkedHashSet::new));\n            return Optional.of(new PrimaryKeyConstraint<>(Optional.of(pkName), keyCols, isEnabled, isRely, isEnforced));\n        }\n        catch (TException e) {\n            throw new PrestoException(HIVE_METASTORE_ERROR, e);\n        }\n        catch (Exception e) {\n            throw propagate(e);\n        }\n    }\n\n    @Override\n    public List<UniqueConstraint<String>> getUniqueConstraints(MetastoreContext metastoreContext, String dbName, String tableName)\n    {\n        try {\n            Optional<UniqueConstraintsResponse> uniqueConstraintsResponse = retry()\n                    .stopOnIllegalExceptions()\n                    .run(\"getUniqueConstraints\", stats.getGetUniqueConstraints().wrap(() ->\n                            getMetastoreClientThenCall(metastoreContext, client -> client.getUniqueConstraints(\"hive\", dbName, tableName))));\n\n            if (!uniqueConstraintsResponse.isPresent() || uniqueConstraintsResponse.get().getUniqueConstraints().size() == 0) {\n                return ImmutableList.of();\n            }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java#L235-L271","documentation":"ThriftHiveMetastore.getPrimaryKey wraps any TException raised by the underlying metastore client when fetching a table's primary-key metadata into a PrestoException with code HIVE_METASTORE_ERROR. It signals that the Thrift RPC itself failed (transport, protocol, or metastore-side error), not that the table lacks a primary key.","triggerScenarios":"Calling getPrimaryKey (e.g. via connector metadata listing of table constraints) while the metastore RPC throws TException — connection drop, thrift protocol mismatch, NoSuchObject-like server errors, or serialization problems.","commonSituations":"Metastore restarted mid-query; older Hive metastore version lacking the primary-key API (get_primary_keys); network interruption between coordinator and metastore; thrift timeout under load.","solutions":["Read the cause chained in the PrestoException — it names the real TException; fix transport (connectivity) or API-mismatch issues accordingly","Retry the operation; transient thrift failures are often resolved by Presto's built-in metastore retry on the next attempt","If the metastore version predates Hive 2.x transactional constraint APIs, upgrade the metastore or avoid reading PK metadata for those catalogs","Increase hive.metastore.thrift.client.read-timeout if the failure is a timeout on large metadata"],"exampleFix":"// before\n// client version too old, RPC method missing\ncatch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); }\n// after\n# upgrade Hive metastore to >= 2.2 which supports get_primary_keys\n# or pin catalog so constraint lookup is skipped for legacy metastores","handlingStrategy":"retry","validationCode":"// Check metastore reachability and version support before reading primary-key metadata\ntry (Socket s = new Socket()) {\n    s.connect(new InetSocketAddress(\"metastore-host\", 9083), 3000);\n}\n// Primary-key API requires Hive metastore >= 2.2\nboolean supportsPk = metastoreHiveVersionAtLeast(\"2.2\");\nif (!supportsPk) {\n    log.warn(\"Skipping primary-key lookup: metastore does not support constraint APIs\");\n}","typeGuard":"public static boolean isMetastoreRpcError(PrestoException e) {\n    return HIVE_METASTORE_ERROR.equals(e.getErrorCode())\n        && e.getCause() instanceof TException;\n}","tryCatchPattern":"try {\n    return thriftHiveMetastore.getPrimaryKey(tableHandle);\n} catch (PrestoException e) {\n    if (isMetastoreRpcError(e)) {\n        throw new RetriableException(\"Metastore RPC failed reading primary key; retrying\", e);\n    }\n    throw e;\n}","preventionTips":["Upgrade the Hive metastore to >= 2.2 so constraint RPCs exist","Monitor metastore health and restart-on-failure so RPCs don't hit dead services","Keep hive.metastore.thrift.client read timeouts generous for metadata-heavy workloads","Log and alert on the chained cause of HIVE_METASTORE_ERROR to distinguish transient vs permanent failures"],"tags":["hive-metastore","thrift","presto-exception","metadata"],"backgroundTag":"hive-metastore-rpc-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"}