commit executes the batch with given write options.
(sync bool)
| 75 | return w.db.ipfsDB.Delete(w.db.ctx, metaKey) |
| 76 | }) |
| 77 | |
| 78 | w.db.cache.Del(key) |
| 79 | } |
| 80 | |
| 81 | // commit executes the batch with given write options. |
| 82 | func (w *WriteBatch) commit(sync bool) error { |
| 83 | if w.err != nil { |
| 84 | return w.err |
| 85 | } |
| 86 | |
| 87 | // 1. Execute all IPFS operations first. |
| 88 | for _, op := range w.ipfsOps { |
| 89 | if err := op(); err != nil { |
| 90 | // If any IPFS operation fails, abort the entire batch. |
| 91 | // The local wbatch will be discarded. |
| 92 | return fmt.Errorf("ipfs operation failed during batch commit, aborting: %w", err) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // 2. If all IPFS operations succeed, commit the local leveldb batch. |
| 97 | var wo *opt.WriteOptions |
| 98 | if sync { |
| 99 | wo = w.db.syncOpts |
| 100 | } |
no outgoing calls
no test coverage detected