Skip to content

Commit 66bea1f

Browse files
author
nooneliu
committed
--other=sync code
1 parent 81c9f44 commit 66bea1f

File tree

440 files changed

+18918
-7416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

440 files changed

+18918
-7416
lines changed

pb/README.md

Lines changed: 553 additions & 231 deletions
Large diffs are not rendered by default.

pb/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ func (c *client) Dial(appId uint64, zoneList []uint32, dirUrl string, signature
140140
c.netServer.stopNetWork <- true
141141
c.ctrl.Wait()
142142
//dir err
143-
if err := c.netServer.dirServer.GetError(); err != nil{
143+
if err := c.netServer.dirServer.GetError(); err != nil {
144144
logger.ERR("dir err %s", err.Error())
145145
return err
146146
}
147147

148148
//proxy err
149-
if err := c.netServer.router.GetError(); err != nil{
149+
if err := c.netServer.router.GetError(); err != nil {
150150
logger.ERR("router err %s", err.Error())
151151
return err
152152
}

pb/client_pb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ func (c *PBClient) initTableMeta(zoneTables map[uint32][]string) error {
5757
defer wg.Done()
5858
req, err := c.NewRequest(zone, table, cmd.TcaplusApiMetadataGetReq)
5959
if err != nil {
60-
logger.ERR("NewRequest error:%s", err.Error())
60+
logger.ERR("zone %d table %s NewRequest error:%s", zone, table, err.Error())
6161
atomic.StoreInt32(&initResult, 1)
6262
return
6363
}
64-
resp, err := c.Do(req, c.defTimeout*time.Second)
64+
resp, err := c.Do(req, c.defTimeout)
6565
if err != nil {
6666
logger.ERR("Do request error:%s", err)
6767
atomic.StoreInt32(&initResult, 1)

pb/client_pb_func.go

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tcaplus
22

33
import (
4+
"bytes"
45
"github.com/tencentyun/tcaplusdb-go-sdk/pb/common"
56
"github.com/tencentyun/tcaplusdb-go-sdk/pb/logger"
67
"github.com/tencentyun/tcaplusdb-go-sdk/pb/protocol/cmd"
@@ -33,6 +34,12 @@ func (c *PBClient) DoListSimple(msg proto.Message, index int32, apiCmd int, opt
3334
return index, &terror.ErrorCode{Code: ret, Message: "SetCondition maybe not support or len too long"}
3435
}
3536
}
37+
if opt != nil && len(opt.Operation) > 0 {
38+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
39+
logger.ERR("SetOperation error:%d", ret)
40+
return index, &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
41+
}
42+
}
3643

3744
_, err = rec.SetPBData(msg)
3845
if err != nil {
@@ -64,7 +71,7 @@ func (c *PBClient) DoListSimple(msg proto.Message, index int32, apiCmd int, opt
6471

6572
ret := res.GetResult()
6673
if ret != 0 {
67-
return index, &terror.ErrorCode{Code: ret}
74+
err = &terror.ErrorCode{Code: ret}
6875
}
6976

7077
if res.GetRecordCount() > 0 {
@@ -89,7 +96,7 @@ func (c *PBClient) DoListSimple(msg proto.Message, index int32, apiCmd int, opt
8996
return index, err
9097
}
9198
}
92-
return index, nil
99+
return index, err
93100
}
94101

95102
func (c *PBClient) doSimple(msg proto.Message, apiCmd int, opt *option.PBOpt, zoneId uint32) error {
@@ -123,6 +130,12 @@ func (c *PBClient) doSimple(msg proto.Message, apiCmd int, opt *option.PBOpt, zo
123130
return &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
124131
}
125132
}
133+
if opt != nil && len(opt.Operation) > 0 {
134+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
135+
logger.ERR("SetOperation error:%d", ret)
136+
return &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
137+
}
138+
}
126139

127140
_, err = rec.SetPBData(msg)
128141
if err != nil {
@@ -143,7 +156,7 @@ func (c *PBClient) doSimple(msg proto.Message, apiCmd int, opt *option.PBOpt, zo
143156

144157
ret := res.GetResult()
145158
if ret != 0 {
146-
return &terror.ErrorCode{Code: ret}
159+
err = &terror.ErrorCode{Code: ret}
147160
}
148161

149162
if res.GetRecordCount() > 0 {
@@ -167,7 +180,7 @@ func (c *PBClient) doSimple(msg proto.Message, apiCmd int, opt *option.PBOpt, zo
167180
return err
168181
}
169182
}
170-
return nil
183+
return err
171184
}
172185

173186
//调用前保证opt中field不为空
@@ -201,6 +214,12 @@ func (c *PBClient) doField(msg proto.Message, apiCmd int, opt *option.PBOpt, zon
201214
return &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
202215
}
203216
}
217+
if len(opt.Operation) > 0 {
218+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
219+
logger.ERR("SetOperation error:%d", ret)
220+
return &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
221+
}
222+
}
204223

205224
_, err = rec.SetPBFieldValues(msg, opt.FieldNames)
206225
if err != nil {
@@ -385,6 +404,12 @@ func (c *PBClient) doListBatch(msg proto.Message, indexs []int32,
385404
return nil, &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
386405
}
387406
}
407+
if opt != nil && len(opt.Operation) > 0 {
408+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
409+
logger.ERR("SetOperation error:%d", ret)
410+
return nil, &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
411+
}
412+
}
388413

389414
_, err = rec.SetPBData(msg)
390415
if err != nil {
@@ -409,7 +434,7 @@ func (c *PBClient) doListBatch(msg proto.Message, indexs []int32,
409434

410435
tmpIdxMap := map[int32]struct{}{}
411436
for _, index := range indexs {
412-
if _, exist := tmpIdxMap[index]; exist{
437+
if _, exist := tmpIdxMap[index]; exist {
413438
logger.ERR("batch record exist duplicate index")
414439
return nil, &terror.ErrorCode{Code: terror.ParameterInvalid, Message: "batch record exist duplicate index"}
415440
}
@@ -499,6 +524,7 @@ func (c *PBClient) doListBatchRecord(msgs []proto.Message, indexs []int32,
499524
}
500525
}
501526

527+
var keyBuf []byte
502528
for i, data := range msgs {
503529
rec, err := req.AddRecord(indexs[i])
504530
if err != nil {
@@ -512,12 +538,25 @@ func (c *PBClient) doListBatchRecord(msgs []proto.Message, indexs []int32,
512538
return &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
513539
}
514540
}
541+
if opt != nil && len(opt.Operation) > 0 {
542+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
543+
logger.ERR("SetOperation error:%d", ret)
544+
return &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
545+
}
546+
}
515547

516-
_, err = rec.SetPBData(data)
548+
pbKey, err := rec.SetPBData(data)
517549
if err != nil {
518550
logger.ERR("SetData error:%s", err)
519551
return err
520552
}
553+
if keyBuf == nil {
554+
keyBuf = pbKey
555+
} else if !bytes.Equal(keyBuf, pbKey) {
556+
logger.ERR("ListBatch only support same key")
557+
return &terror.ErrorCode{Code: terror.ParameterInvalid, Message: "ListBatch only support same key"}
558+
}
559+
521560
if opt != nil && opt.Version > 0 {
522561
rec.SetVersion(opt.Version)
523562
}
@@ -650,6 +689,12 @@ func (c *PBClient) doBatch(msgs []proto.Message, apiCmd int, opt *option.PBOpt,
650689
return &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
651690
}
652691
}
692+
if opt != nil && len(opt.Operation) > 0 {
693+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
694+
logger.ERR("SetOperation error:%d", ret)
695+
return &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
696+
}
697+
}
653698

654699
if opt != nil && (opt.BatchVersion)[i] > 0 {
655700
rec.SetVersion((opt.BatchVersion)[i])
@@ -687,6 +732,7 @@ func (c *PBClient) doBatch(msgs []proto.Message, apiCmd int, opt *option.PBOpt,
687732
if recErr != nil {
688733
globalErr = recErr
689734
logger.DEBUG("FetchRecord error:%s", recErr)
735+
continue
690736
}
691737

692738
if record == nil {
@@ -749,7 +795,7 @@ func (c *PBClient) doBatch(msgs []proto.Message, apiCmd int, opt *option.PBOpt,
749795
return globalErr
750796
}
751797

752-
func (c *PBClient) doPartKeyGet(msg proto.Message, keys []string, apiCmd int, opt *option.PBOpt,
798+
func (c *PBClient) doPartKey(msg proto.Message, keys []string, apiCmd int, opt *option.PBOpt,
753799
zoneId uint32) ([]proto.Message, error) {
754800
table := msg.ProtoReflect().Descriptor().Name()
755801
req, err := c.NewRequest(zoneId, string(table), apiCmd)
@@ -778,6 +824,12 @@ func (c *PBClient) doPartKeyGet(msg proto.Message, keys []string, apiCmd int, op
778824
return nil, &terror.ErrorCode{Code: ret, Message: "SetCondition failed, maybe not support or len too long"}
779825
}
780826
}
827+
if opt != nil && len(opt.Operation) > 0 {
828+
if ret := rec.SetOperation(opt.Operation, 0); ret != 0 {
829+
logger.ERR("SetOperation error:%d", ret)
830+
return nil, &terror.ErrorCode{Code: ret, Message: "SetOperation failed, maybe not support or len too long"}
831+
}
832+
}
781833
_, err = rec.SetPBPartKeys(msg, keys)
782834
if err != nil {
783835
logger.ERR("SetPBPartKeys error:%s", err)
@@ -827,7 +879,7 @@ func (c *PBClient) doPartKeyGet(msg proto.Message, keys []string, apiCmd int, op
827879
}
828880
}
829881

830-
if len(msgs) == 0 && globalErr == nil {
882+
if len(msgs) == 0 && globalErr == nil && apiCmd == cmd.TcaplusApiGetByPartkeyReq {
831883
return nil, &terror.ErrorCode{Code: terror.TXHDB_ERR_RECORD_NOT_EXIST}
832884
}
833885

@@ -999,9 +1051,29 @@ func (c *PBClient) DoGetByPartKey(msgs proto.Message, indexKeys []string, opt *o
9991051
return nil, &terror.ErrorCode{Code: terror.ParameterInvalid, Message: "partKeys is empty"}
10001052
}
10011053
if len(zoneId) == 1 {
1002-
return c.doPartKeyGet(msgs, indexKeys, cmd.TcaplusApiGetByPartkeyReq, opt, zoneId[0])
1054+
return c.doPartKey(msgs, indexKeys, cmd.TcaplusApiGetByPartkeyReq, opt, zoneId[0])
1055+
}
1056+
return c.doPartKey(msgs, indexKeys, cmd.TcaplusApiGetByPartkeyReq, opt, uint32(c.defZone))
1057+
}
1058+
1059+
/**
1060+
@brief 根据表的部分key字段删除
1061+
@param [IN] msgs proto.Message 由proto文件生成的记录结构体
1062+
@param [IN] indexKeys 使用的索引部分key字段名称
1063+
@param [IN/OUT] opt 可选参数
1064+
@param [IN] zoneId 可选参数,不设置则取默认zone,默认zone可通过client.SetDefaultZoneId设置
1065+
@retval error 错误码
1066+
**/
1067+
func (c *PBClient) DoDeleteByPartKey(msgs proto.Message, indexKeys []string, opt *option.PBOpt,
1068+
zoneId ...uint32) ([]proto.Message,
1069+
error) {
1070+
if len(indexKeys) == 0 {
1071+
return nil, &terror.ErrorCode{Code: terror.ParameterInvalid, Message: "partKeys is empty"}
1072+
}
1073+
if len(zoneId) == 1 {
1074+
return c.doPartKey(msgs, indexKeys, cmd.TcaplusApiDeleteByPartkeyReq, opt, zoneId[0])
10031075
}
1004-
return c.doPartKeyGet(msgs, indexKeys, cmd.TcaplusApiGetByPartkeyReq, opt, uint32(c.defZone))
1076+
return c.doPartKey(msgs, indexKeys, cmd.TcaplusApiDeleteByPartkeyReq, opt, uint32(c.defZone))
10051077
}
10061078

10071079
/**

0 commit comments

Comments
 (0)