{"record":{"id":"5be4c379ac4dd1b5","repo":"apache/seatunnel","slug":"documentbulk-is-already-full","errorCode":null,"errorMessage":"DocumentBulk is already full","messagePattern":"DocumentBulk is already full","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/state/DocumentBulk.java","lineNumber":50,"sourceCode":" * size, typically 1,000 documents. But for the transactional mode, the maximum size should not be\n * respected because all that data must be written in one transaction.\n */\n@ToString\n@EqualsAndHashCode\npublic class DocumentBulk implements Serializable {\n\n    public static final int BUFFER_SIZE = 1024;\n    private static final long serialVersionUID = 7203410284346755522L;\n\n    private final List<BsonDocument> bufferedDocuments;\n\n    public DocumentBulk() {\n        bufferedDocuments = new ArrayList<>(BUFFER_SIZE);\n    }\n\n    public void add(BsonDocument document) {\n        if (bufferedDocuments.size() == BUFFER_SIZE) {\n            throw new IllegalStateException(\"DocumentBulk is already full\");\n        }\n        bufferedDocuments.add(document);\n    }\n\n    public int size() {\n        return bufferedDocuments.size();\n    }\n\n    public List<BsonDocument> getDocuments() {\n        return bufferedDocuments;\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/state/DocumentBulk.java#L32-L63","documentation":"DocumentBulk.add throws IllegalStateException when the bulk already holds BUFFER_SIZE documents. This is an internal invariant guard: callers must flush and start a new DocumentBulk before adding more documents. It signals a programming/ordering bug in the writer's buffering logic, not a user-data problem.","triggerScenarios":"Calling add(BsonDocument) on a DocumentBulk whose bufferedDocuments list already contains BUFFER_SIZE entries — i.e. the writer attempted to exceed the fixed internal buffer capacity without rolling over to a new bulk.","commonSituations":"Rare; indicates a bug in MongodbWriter's batch-rollover logic (isOverMaxBatchSizeLimit / flush ordering) or a misuse of the internal state class after a failed flush left the bulk full.","solutions":["Check writer code paths that add documents: ensure flushToBulk/rollover creates a new DocumentBulk once size == BUFFER_SIZE.","Check size() or a hasSpace check before calling add(); call the flush path when the bulk is full.","If reproducible, file a bug with the job config and stack trace; this should never be reachable from normal sink usage."],"exampleFix":"// before\nbulk.add(document);\n// after\nif (bulk.size() >= DocumentBulk.getBufferSize()) {\n    flushBulk();\n}\nbulk.add(document);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    bulk.add(doc);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"already full\")) {\n        flushAndRotateBulk(); // then re-add\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check bulk capacity before every add when using DocumentBulk directly.","Flush and rotate the bulk as soon as size == BUFFER_SIZE.","If hit through the sink, report as a connector bug with stack trace."],"tags":["mongodb","internal-error","buffer-overflow"],"backgroundTag":"internal-invariant-violation","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}