forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
24 lines (21 loc) · 776 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package atomic
import (
"github.com/dim4egster/qmallgo/database"
)
// WriteAll writes all of the batches to the underlying database of baseBatch.
// Assumes all batches have the same underlying database.
func WriteAll(baseBatch database.Batch, batches ...database.Batch) error {
baseBatch = baseBatch.Inner()
// Replay the inner batches onto [baseBatch] so that it includes all DB
// operations as they would be applied to the base database.
for _, batch := range batches {
batch = batch.Inner()
if err := batch.Replay(baseBatch); err != nil {
return err
}
}
// Write all of the combined operations in one atomic batch.
return baseBatch.Write()
}