{"record":{"id":"e9af10bc229a24cc","repo":"dgraph-io/badger","slug":"errtxntoobig","errorCode":"ErrTxnTooBig","errorMessage":"Txn is too big to fit into one request","messagePattern":"Txn is too big to fit into one request","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":27,"sourceCode":"\tstderrors \"errors\"\n\t\"math\"\n)\n\nconst (\n\t// ValueThresholdLimit is the maximum permissible value of opt.ValueThreshold.\n\tValueThresholdLimit = math.MaxUint16 - 16 + 1\n)\n\nvar (\n\t// ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid\n\t// range.\n\tErrValueLogSize = stderrors.New(\"Invalid ValueLogFileSize, must be in range [1MB, 2GB)\")\n\n\t// ErrKeyNotFound is returned when key isn't found on a txn.Get.\n\tErrKeyNotFound = stderrors.New(\"Key not found\")\n\n\t// ErrTxnTooBig is returned if too many writes are fit into a single transaction.\n\tErrTxnTooBig = stderrors.New(\"Txn is too big to fit into one request\")\n\n\t// ErrConflict is returned when a transaction conflicts with another transaction. This can\n\t// happen if the read rows had been updated concurrently by another transaction.\n\tErrConflict = stderrors.New(\"Transaction Conflict. Please retry\")\n\n\t// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.\n\tErrReadOnlyTxn = stderrors.New(\"No sets or deletes are allowed in a read-only transaction\")\n\n\t// ErrDiscardedTxn is returned if a previously discarded transaction is reused.\n\tErrDiscardedTxn = stderrors.New(\"This transaction has been discarded. Create a new one\")\n\n\t// ErrEmptyKey is returned if an empty key is passed on an update function.\n\tErrEmptyKey = stderrors.New(\"Key cannot be empty\")\n\n\t// ErrInvalidKey is returned if the key has a special !badger! prefix,\n\t// reserved for internal usage.\n\tErrInvalidKey = stderrors.New(\"Key is using a reserved !badger! prefix\")\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L9-L45","documentation":"ErrTxnTooBig is returned when too many writes are fit into a single transaction, exceeding Badger's per-transaction entry-count/size budget (derived from opt.maxBatchCount/maxBatchSize). The pending transaction refuses further mutations so the caller can commit and start a new one.","triggerScenarios":"Txn.SetEntry or Txn.Delete after the pending batch exceeds its size budget; WriteBatch.handleEntry (batch.go:138) and WriteBatch.Delete (batch.go:178) when wb.txn.SetEntry/Delete returns ErrTxnTooBig; bulk imports inside one Update().","commonSituations":"Bulk-loading millions of rows in a single transaction, writing many large values, long-running loops that never commit, assuming transactions are unbounded.","solutions":["For WriteBatch, call wb.Flush() when you get ErrTxnTooBig, then continue adding entries","For plain txns, commit and create a new transaction periodically in write loops","Reduce entries-per-transaction or value sizes; chunk the workload","Use db.WriteBatch or the Stream framework for bulk loads (handles batching)"],"exampleFix":"// before\nerr := db.Update(func(txn *Txn) error {\n    for _, e := range millions {\n        if err := txn.SetEntry(e); err != nil { return err } // ErrTxnTooBig\n    }\n    return nil\n})\n// after\nwb := db.NewWriteBatch()\nfor _, e := range millions {\n    if err := wb.SetEntry(e); err != nil {\n        if err == badger.ErrTxnTooBig {\n            if err := wb.Flush(); err != nil { return err }\n            if err := wb.SetEntry(e); err != nil { return err }\n        } else { return err }\n    }\n}\nreturn wb.Flush()","handlingStrategy":"validation","validationCode":"// before each write, or on error, rotate the batch\nif err := txn.SetEntry(e); err == badger.ErrTxnTooBig {\n    _ = txn.Commit()\n    txn = db.NewTransaction(true)\n    err = txn.SetEntry(e)\n}","typeGuard":null,"tryCatchPattern":"if err := txn.SetEntry(e); err != nil {\n    if errors.Is(err, badger.ErrTxnTooBig) {\n        return rotateAndRetry(err)\n    }\n    return err\n}","preventionTips":["Cap entries/values per transaction well below the batch limits","Prefer db.NewWriteBatch or Stream for bulk loads","Commit periodically in long write loops"],"tags":["badger","transaction","batching","write-path"],"backgroundTag":"transaction-size-limit-exceeded","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}