{"record":{"id":"07418e6e47adf25b","repo":"apache/beam","slug":"at-least-session-countpendingerrors-error-s-occurred-writing","errorCode":null,"errorMessage":"At least \" + session.countPendingErrors() + \" error(s) occurred writing to Kudu","messagePattern":"At least \" \\+ session\\.countPendingErrors\\(\\) \\+ \" error\\(s\\) occurred writing to Kudu","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sdks/java/io/kudu/src/main/java/org/apache/beam/sdk/io/kudu/KuduServiceImpl.java","lineNumber":116,"sourceCode":"    }\n\n    @Override\n    public void write(T entity) throws KuduException {\n      checkState(session != null, \"must call openSession() before writing\");\n      session.apply(formatFunction.apply(new TableAndRecord(table, entity)));\n    }\n\n    @Override\n    public void closeSession() throws Exception {\n      try {\n        session.close();\n        if (session.countPendingErrors() > 0) {\n          LOG.error(\"At least {} errors occurred writing to Kudu\", session.countPendingErrors());\n          RowError[] errors = session.getPendingErrors().getRowErrors();\n          for (int i = 0; errors != null && i < 3 && i < errors.length; i++) {\n            LOG.error(\"Sample error: {}\", errors[i]);\n          }\n          throw new Exception(\n              \"At least \" + session.countPendingErrors() + \" error(s) occurred writing to Kudu\");\n        }\n      } finally {\n        session = null;\n      }\n    }\n\n    @Override\n    public void close() throws Exception {\n      client.close();\n      client = null;\n    }\n  }\n\n  /** Bounded reader of an Apache Kudu table. */\n  class ReaderImpl extends BoundedSource.BoundedReader<T> {\n    private final KuduIO.KuduSource<T> source;\n    private KuduClient client;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/kudu/src/main/java/org/apache/beam/sdk/io/kudu/KuduServiceImpl.java#L98-L134","documentation":"KuduServiceImpl.closeSession checks the Kudu session for pending errors after applying writes; if the KuduScanner/KuduSession accumulated row errors, the writer fails the whole operation with this Exception after logging a sample of the errors.","triggerScenarios":"Writing rows to Kudu where the KuduSession reports countPendingErrors() > 0 at flush/close time — e.g., schema mismatches, constraint violations, non-existent tablets/table, or duplicate primary keys in the batch.","commonSituations":"Bulk inserts/updates into Kudu during Beam pipeline runs; bad data rows or a table whose schema changed while the pipeline runs; misconfigured masters causing write failures.","solutions":["Inspect the KuduTablet server / session pending errors logged ('Sample error: ...') to identify the failing rows","Fix the offending rows (validate schema, primary keys, nullability) before writing","Verify the target table exists and its schema matches the Rows being written","Catch this exception in the DoFn and route failed batches to a dead-letter sink"],"exampleFix":"// before\nsession.apply(insertWithWrongSchema);\n// throws at closeSession: \"At least 3 error(s) occurred writing to Kudu\"\n// after\nif (!table.getSchema().equals(expectedSchema)) {\n  throw new IllegalArgumentException(\"Kudu schema mismatch, refusing write\");\n}\nsession.apply(insertMatchingSchema);","handlingStrategy":"try-catch","validationCode":"// before writing, verify table schema matches rows\nif (!table.getSchema().equals(expectedSchema)) {\n  throw new IllegalStateException(\"Kudu table schema drift detected\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  kuduWriter.close(); // may throw Kudu write errors\n} catch (Exception e) {\n  if (e.getMessage().contains(\"error(s) occurred writing to Kudu\")) {\n    // inspect logged 'Sample error:' lines; route batch to dead-letter and retry\n  }\n}","preventionTips":["Validate rows against the Kudu schema (types, nullability, primary keys) before apply","Monitor Kudu tablet/table schema changes during long-running pipelines","Log full pending errors, not just the first three, in staging to catch data issues early"],"tags":["java","apache-beam","kudu","database-write","batch-write"],"backgroundTag":"database-write-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}