Skip to content

Commit 5930abd

Browse files
author
简游
committed
sort CURD oplog for effective bulk insert
1 parent c81e3ab commit 5930abd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

executor/executor.go

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package executor
33
import (
44
"fmt"
55
"go.mongodb.org/mongo-driver/bson"
6+
"sort"
67
"strings"
78
"sync"
89
"sync/atomic"
@@ -234,6 +235,14 @@ func (exec *Executor) doSync(logs []*OplogRecord) error {
234235

235236
transLogs := transformLogs(logs, exec.batchExecutor.NsTrans, conf.Options.IncrSyncDBRef)
236237

238+
// eventual consistency
239+
// only sort CURD now for effective bulk insert
240+
if len(logs) > 0 && logs[0].original.partialLog.Operation != "c" {
241+
sort.SliceStable(transLogs, func(i, j int) bool {
242+
return transLogs[i].original.partialLog.Namespace < transLogs[j].original.partialLog.Namespace
243+
})
244+
}
245+
237246
// split batched oplogRecords into (ns, op) groups. individual group
238247
// can be accomplished in single MongoDB request. groups
239248
// in this executor will be sequential

0 commit comments

Comments
 (0)