Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcd_worker: batch etcd patch #3277

Merged
merged 25 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9423c4d
etcd_worker: batch etcd patch
asddongmen Nov 3, 2021
95b3f01
Merge branch 'master' into batch_patch_to_etcd
asddongmen Nov 4, 2021
4469137
etcd_worker: batch etcd patch
asddongmen Nov 4, 2021
e1c605c
etcd_worker: batch etcd watch response
asddongmen Nov 5, 2021
c60e88a
etcd_worker: batch etcd watch response
asddongmen Nov 5, 2021
4a0b41b
Merge remote-tracking branch 'origin/batch_patch_to_etcd' into batch_…
asddongmen Nov 6, 2021
27c232c
batch: extract batch logic into func
asddongmen Nov 6, 2021
78153a8
batch_test:fix check error
asddongmen Nov 7, 2021
b0c066b
batch_test:fix make check error
asddongmen Nov 7, 2021
f7a5681
batch_test: fix error
asddongmen Nov 8, 2021
2df2d75
etcd_worker: clean useless code
asddongmen Nov 8, 2021
bdea0aa
Merge branch 'master' into batch_patch_to_etcd
asddongmen Nov 8, 2021
e439671
Merge remote-tracking branch 'origin/batch_patch_to_etcd' into batch_…
asddongmen Nov 8, 2021
ff9aa38
etcd_worker: add metrics
asddongmen Nov 8, 2021
5d0f3ef
etcd_worker: add metrics
asddongmen Nov 8, 2021
7ab6d6d
Merge remote-tracking branch 'origin/batch_patch_to_etcd' into batch_…
asddongmen Nov 8, 2021
043b6b5
etcd_worker: add getBatchChangedState to get batch changedSate of mul…
asddongmen Nov 9, 2021
9a7a5a0
batch: fix some typos and resolves comments
asddongmen Nov 9, 2021
c84fd55
Merge branch 'master' into batch_patch_to_etcd
liuzix Nov 10, 2021
b4cc17b
batch: resolves comments
asddongmen Nov 10, 2021
a253cb0
Merge branch 'master' into batch_patch_to_etcd
ti-chi-bot Nov 10, 2021
a7d6c69
Merge branch 'master' into batch_patch_to_etcd
ti-chi-bot Nov 10, 2021
a2ed317
Merge branch 'master' into batch_patch_to_etcd
asddongmen Nov 10, 2021
3d0f583
Merge branch 'master' into batch_patch_to_etcd
ti-chi-bot Nov 10, 2021
0573167
Merge branch 'master' into batch_patch_to_etcd
ti-chi-bot Nov 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/orchestrator/etcd_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,33 @@ func (worker *EtcdWorker) cloneRawState() map[util.EtcdKey][]byte {
return ret
}

var maxBatchPatchSize = 96

func (worker *EtcdWorker) applyPatchGroups(ctx context.Context, patchGroups [][]DataPatch) ([][]DataPatch, error) {
getBatchPatches := func(patchGroups [][]DataPatch) ([]DataPatch, int) {
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
batchPatches := patchGroups[0]
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
patchesNum := 1
for _, patches := range patchGroups {
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
if patchesNum == 1 {
continue
}
if (len(batchPatches) + len(patches)) > maxBatchPatchSize {
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
break
}
batchPatches = append(batchPatches, patches...)
patchesNum++
}

return batchPatches, patchesNum
}

asddongmen marked this conversation as resolved.
Show resolved Hide resolved
for len(patchGroups) > 0 {
patches := patchGroups[0]
patches, n := getBatchPatches(patchGroups)
err := worker.applyPatches(ctx, patches)
if err != nil {
return patchGroups, err
}
patchGroups = patchGroups[1:]
patchGroups = patchGroups[n:]
}
return patchGroups, nil
}
Expand All @@ -310,10 +329,12 @@ func (worker *EtcdWorker) applyPatches(ctx context.Context, patches []DataPatch)
cmps := make([]clientv3.Cmp, 0, len(changedSet))
ops := make([]clientv3.Op, 0, len(changedSet))
hasDelete := false
entrys := make(map[string]int64)
for key := range changedSet {
// make sure someone else has not updated the key after the last snapshot
var cmp clientv3.Cmp
if entry, ok := worker.rawState[key]; ok {
entrys[key.String()] = entry.modRevision
cmp = clientv3.Compare(clientv3.ModRevision(key.String()), "=", entry.modRevision)
} else {
// if ok is false, it means that the key of this patch is not exist in a committed state
Expand Down
6 changes: 3 additions & 3 deletions pkg/orchestrator/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func (s *SingleDataPatch) Patch(valueMap map[util.EtcdKey][]byte, changedSet map
return nil
}

// MultiDatePatch represents an update to many keys
type MultiDatePatch func(valueMap map[util.EtcdKey][]byte, changedSet map[util.EtcdKey]struct{}) error
// MultiDataPatch represents an update to many keys
type MultiDataPatch func(valueMap map[util.EtcdKey][]byte, changedSet map[util.EtcdKey]struct{}) error

// Patch implements the DataPatch interface
func (m MultiDatePatch) Patch(valueMap map[util.EtcdKey][]byte, changedSet map[util.EtcdKey]struct{}) error {
func (m MultiDataPatch) Patch(valueMap map[util.EtcdKey][]byte, changedSet map[util.EtcdKey]struct{}) error {
return m(valueMap, changedSet)
}
1 change: 1 addition & 0 deletions pkg/orchestrator/reactor_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (s *GlobalReactorState) Update(key util.EtcdKey, value []byte, _ bool) erro
}

// GetPatches implements the ReactorState interface
// Every []DataPatch slice in [][]DataPatch slice is the patches of a ChangefeedReactorState
func (s *GlobalReactorState) GetPatches() [][]DataPatch {
pendingPatches := s.pendingPatches
for _, changefeedState := range s.Changefeeds {
Expand Down