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

[release-4.10] Bug 2104454: improve performance of service sync #1173

Merged
merged 4 commits into from
Aug 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions go-controller/pkg/libovsdbops/model_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ func (m *ModelClient) WithClient(client client.Client) *ModelClient {
If BulkOp is set, update or mutate can happen accross multiple models found.
*/
func (m *ModelClient) CreateOrUpdate(opModels ...OperationModel) ([]ovsdb.OperationResult, error) {
created, ops, err := m.CreateOrUpdateOps(opModels...)
created, ops, err := m.createOrUpdateOps(nil, opModels...)
if err != nil {
return nil, err
}
return TransactAndCheckAndSetUUIDs(m.client, created, ops)
}

func (m *ModelClient) CreateOrUpdateOps(opModels ...OperationModel) (interface{}, []ovsdb.Operation, error) {
func (m *ModelClient) CreateOrUpdateOps(ops []ovsdb.Operation, opModels ...OperationModel) ([]ovsdb.Operation, error) {
_, ops, err := m.createOrUpdateOps(ops, opModels...)
return ops, err
}

func (m *ModelClient) createOrUpdateOps(ops []ovsdb.Operation, opModels ...OperationModel) (interface{}, []ovsdb.Operation, error) {
doWhenFound := func(model interface{}, opModel *OperationModel) ([]ovsdb.Operation, error) {
if opModel.OnModelUpdates != nil {
return m.update(model, opModel)
Expand All @@ -169,7 +174,7 @@ func (m *ModelClient) CreateOrUpdateOps(opModels ...OperationModel) (interface{}
doWhenNotFound := func(model interface{}, opModel *OperationModel) ([]ovsdb.Operation, error) {
return m.create(opModel)
}
return m.buildOps(doWhenFound, doWhenNotFound, opModels...)
return m.buildOps(ops, doWhenFound, doWhenNotFound, opModels...)
}

/*
Expand All @@ -188,30 +193,32 @@ func (m *ModelClient) CreateOrUpdateOps(opModels ...OperationModel) (interface{}
If BulkOp is set, delete or mutate can happen accross multiple models found.
*/
func (m *ModelClient) Delete(opModels ...OperationModel) error {
ops, err := m.DeleteOps(opModels...)
ops, err := m.DeleteOps(nil, opModels...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! :) this is exactly what I need for my cherry-pick :)

if err != nil {
return err
}
_, err = TransactAndCheck(m.client, ops)
return err
}

func (m *ModelClient) DeleteOps(opModels ...OperationModel) ([]ovsdb.Operation, error) {
func (m *ModelClient) DeleteOps(ops []ovsdb.Operation, opModels ...OperationModel) ([]ovsdb.Operation, error) {
doWhenFound := func(model interface{}, opModel *OperationModel) (o []ovsdb.Operation, err error) {
if opModel.OnModelMutations != nil {
return m.mutate(model, opModel, ovsdb.MutateOperationDelete)
} else {
return m.delete(model, opModel)
}
}
_, ops, err := m.buildOps(doWhenFound, nil, opModels...)
_, ops, err := m.buildOps(ops, doWhenFound, nil, opModels...)
return ops, err
}

type opModelToOpMapper func(model interface{}, opModel *OperationModel) (o []ovsdb.Operation, err error)

func (m *ModelClient) buildOps(doWhenFound opModelToOpMapper, doWhenNotFound opModelToOpMapper, opModels ...OperationModel) (interface{}, []ovsdb.Operation, error) {
ops := []ovsdb.Operation{}
func (m *ModelClient) buildOps(ops []ovsdb.Operation, doWhenFound opModelToOpMapper, doWhenNotFound opModelToOpMapper, opModels ...OperationModel) (interface{}, []ovsdb.Operation, error) {
if ops == nil {
ops = []ovsdb.Operation{}
}
notfound := []interface{}{}
for _, opModel := range opModels {
if opModel.ExistingResult == nil && opModel.Model != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit1: LGTM, same as 4.11 no conflicts from cf3a846

Expand Down