tianxiaoliang commented on a change in pull request #228: URL: https://github.com/apache/servicecomb-kie/pull/228#discussion_r757185948
########## File path: server/datasource/etcd/kv/kv_dao_trans.go ########## @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kv + +import ( + "context" + "encoding/json" + + "github.com/go-chassis/cari/sync" + "github.com/go-chassis/openlog" + "github.com/little-cui/etcdadpt" + + "github.com/apache/servicecomb-kie/pkg/model" + "github.com/apache/servicecomb-kie/server/datasource" + "github.com/apache/servicecomb-kie/server/datasource/etcd/key" +) + +func (s *Dao) createWithTask(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error) { + kvBytes, err := json.Marshal(kv) + if err != nil { + openlog.Error("marshal kv ") + return nil, err + } + task, err := datasource.NewTask(datasource.CreateAction, datasource.ConfigResource) + if err != nil { + openlog.Error("fail to create task" + err.Error()) + return nil, err + } + task.Data = kv + taskBytes, err := json.Marshal(task) + if err != nil { + openlog.Error("fail to marshal task ") + return nil, err + } + kvOpPut := etcdadpt.OpPut(etcdadpt.WithStrKey(key.KV(kv.Domain, kv.Project, kv.ID)), etcdadpt.WithValue(kvBytes)) + taskOpPut := etcdadpt.OpPut(etcdadpt.WithStrKey(key.TaskKey(kv.Domain, kv.Project, task.TaskID, task.Timestamp)), etcdadpt.WithValue(taskBytes)) + err = etcdadpt.Txn(ctx, []etcdadpt.OpOptions{kvOpPut, taskOpPut}) + if err != nil { + openlog.Error("create error", openlog.WithTags(openlog.Tags{ + "err": err.Error(), + "kv": kv, + "task": task, + })) + return nil, err + } + return kv, nil +} + +func (s *Dao) updateWithTask(ctx context.Context, kv *model.KVDoc) error { Review comment: update应该发生在任务处理的过程中,而且只能更新状态字段。 北向接口接受的所有写操作,都是不断地在创建新task,而不是针对通过一个业务实体,根据创建和更新操作对同一个task做更新 这是比较严重的业务逻辑错误 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
