{"record":{"id":"6dec817186e66c44","repo":"apache/hadoop","slug":"cannot-fetch-records-for-clazz-6dec81","errorCode":null,"errorMessage":"Cannot fetch records for {clazz}","messagePattern":"Cannot fetch records for (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreMySQLImpl.java","lineNumber":157,"sourceCode":"    StateStoreMetrics metrics = getMetrics();\n    List<T> ret = new ArrayList<>();\n    try (Connection connection = connectionFactory.getConnection();\n        PreparedStatement statement = connection.prepareStatement(\n            String.format(\"SELECT * FROM %s\", tableName))) {\n      try (ResultSet result = statement.executeQuery()) {\n        while(result.next()) {\n          String recordValue = result.getString(\"recordValue\");\n          T record = newRecord(recordValue, clazz, false);\n          ret.add(record);\n        }\n      }\n    } catch (SQLException e) {\n      if (metrics != null) {\n        metrics.addFailure(Time.monotonicNow() - start);\n      }\n      String msg = \"Cannot fetch records for \" + clazz.getSimpleName();\n      LOG.error(msg, e);\n      throw new IOException(msg, e);\n    }\n\n    if (metrics != null) {\n      metrics.addRead(Time.monotonicNow() - start);\n    }\n    return new QueryResult<>(ret, getTime());\n  }\n\n  @Override\n  public <T extends BaseRecord> StateStoreOperationResult putAll(\n      List<T> records, boolean allowUpdate, boolean errorIfExists) throws IOException {\n    if (records.isEmpty()) {\n      return StateStoreOperationResult.getDefaultSuccessResult();\n    }\n\n    verifyDriverReady();\n    StateStoreMetrics metrics = getMetrics();\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreMySQLImpl.java#L139-L175","documentation":"StateStoreMySQLImpl executes a SELECT over the record table to fetch all records of a class; any SQLException — connection failure, missing table, schema drift, timeout, lock wait — is recorded as a state store metrics failure and wrapped as IOException('Cannot fetch records for <Class>') with the SQLException as cause. It signals the relational backend of the State Store failed to serve the query.","triggerScenarios":"MySQL down or network-partitioned; the record table for the named class was never created (schema not provisioned); wrong JDBC URL/credentials; connection pool exhausted; lock wait timeout or query timeout under heavy router load; charset/collation mismatch producing SQL errors.","commonSituations":"First deployment where the MySQL State Store DDL was not applied; DB restart or failover while routers query it; wrong database name in the JDBC URL; pool sized below router concurrency.","solutions":["Check the router log — LOG.error prints the SQLException with SQLState/error code identifying the exact failure.","Provision the missing schema tables for the record class named in the message.","Verify JDBC connectivity and credentials from the router host with the same URL.","Tune the connection pool / timeouts if the cause is exhaustion or lock waits, then restart the router."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: schema must contain the record tables before router start\ntry (Connection c = dataSource.getConnection(); ResultSet rs = c.getMetaData()\n        .getTables(null, null, \"MembershipState\", null)) {\n  if (!rs.next()) throw new IllegalStateException(\"State store schema missing\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  QueryResult<T> r = driver.fetchAll(clazz);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot fetch records\")\n      && e.getCause() instanceof SQLException) {\n    SQLException sql = (SQLException) e.getCause();\n    if (\"08*\".startsWith(String.valueOf(sql.getSQLState())) // connection class\n        || sql.getSQLState() == null) {\n      retryWithBackoff(); // transient DB issue\n    } else {\n      throw e; // missing table / SQL error: fix schema\n    }\n  } else { throw e; }\n}","preventionTips":["Run the MySQL state store DDL as a versioned migration before pointing routers at the database.","Use the same JDBC URL/user in pre-flight checks as the router configuration.","Size the connection pool above peak router concurrency to avoid exhausted-connection SQLStates."],"tags":["hdfs","router-based-federation","state-store","mysql","sql","jdbc"],"backgroundTag":"sql-query-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}