• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang proto.PkgMultiOp类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/stevejiang/gotable/api/go/table/proto.PkgMultiOp的典型用法代码示例。如果您正苦于以下问题:Golang PkgMultiOp类的具体用法?Golang PkgMultiOp怎么用?Golang PkgMultiOp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PkgMultiOp类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Sync

func (tbl *Table) Sync(req *PkgArgs) ([]byte, bool) {
	var in proto.PkgMultiOp
	_, err := in.Decode(req.Pkg)
	if err == nil {
		// Sync full DB, including DB 0
		var wb = tbl.db.NewWriteBatch()
		for i := 0; i < len(in.Kvs); i++ {
			tbl.setSyncKV(wb, in.DbId, &in.Kvs[i])
		}
		tbl.rwMtx.RLock()
		err = tbl.db.Commit(wb)
		tbl.rwMtx.RUnlock()
		wb.Destroy()

		if err == nil {
			return nil, true
		} else {
			in.SetErrCode(table.EcWriteFail)
			log.Printf("setRawKV failed: %s\n", err)
		}
	} else {
		in.SetErrCode(table.EcDecodeFail)
	}

	return replyHandle(&in), table.EcOk == in.ErrCode
}
开发者ID:tradia,项目名称:gotable,代码行数:26,代码来源:table.go


示例2: myMIncr

func myMIncr(in proto.PkgMultiOp, au Authorize, wa *WriteAccess, expected bool,
	t *testing.T) proto.PkgMultiOp {
	var pkg = make([]byte, in.Length())
	_, err := in.Encode(pkg)
	if err != nil {
		t.Fatalf("Encode failed: ", err)
	}

	pkg, ok := testTbl.MIncr(&PkgArgs{in.Cmd, in.DbId, in.Seq, pkg}, au, wa)
	if ok != expected {
		if expected {
			t.Fatalf("MIncr failed")
		} else {
			t.Fatalf("MIncr should fail")
		}
	}

	var out proto.PkgMultiOp
	_, err = out.Decode(pkg)
	if err != nil {
		t.Fatalf("Decode failed: ", err)
	}

	if expected {
		if out.ErrCode != 0 {
			t.Fatalf("Failed with ErrCode %d", out.ErrCode)
		}
	}
	if out.DbId != in.DbId || out.Seq != in.Seq {
		t.Fatalf("DbId/Seq mismatch")
	}

	return out
}
开发者ID:tradia,项目名称:gotable,代码行数:34,代码来源:table_test.go


示例3: myMGet

func myMGet(in proto.PkgMultiOp, au Authorize, wa *WriteAccess,
	t *testing.T) proto.PkgMultiOp {
	var pkg = make([]byte, in.Length())
	_, err := in.Encode(pkg)
	if err != nil {
		t.Fatalf("Encode failed: ", err)
	}

	pkg = testTbl.MGet(&PkgArgs{in.Cmd, in.DbId, in.Seq, pkg}, au, wa)

	var out proto.PkgMultiOp
	_, err = out.Decode(pkg)
	if err != nil {
		t.Fatalf("Decode failed: ", err)
	}

	if out.ErrCode != 0 {
		t.Fatalf("Failed with ErrCode %d", out.ErrCode)
	}
	if out.DbId != in.DbId || out.Seq != in.Seq {
		t.Fatalf("DbId/Seq mismatch")
	}

	return out
}
开发者ID:tradia,项目名称:gotable,代码行数:25,代码来源:table_test.go


示例4: replyMultiOp

func (srv *Server) replyMultiOp(req *Request, errCode int8) {
	var out proto.PkgMultiOp
	out.Cmd = req.Cmd
	out.DbId = req.DbId
	out.Seq = req.Seq
	out.ErrCode = errCode

	var pkg = make([]byte, out.Length())
	_, err := out.Encode(pkg)
	if err != nil {
		log.Fatalf("Encode failed: %s\n", err)
	}

	srv.sendResp(false, req, pkg)
}
开发者ID:tradia,项目名称:gotable,代码行数:15,代码来源:server.go


示例5: replyMulti

func replyMulti(out *proto.PkgMultiOp) []byte {
	var pkgLen = out.Length()
	if pkgLen > proto.MaxPkgLen {
		out.Kvs = nil
		out.SetErrCode(table.EcInvPkgLen)
		pkgLen = out.Length()
	}

	var pkg = make([]byte, pkgLen)
	_, err := out.Encode(pkg)
	if err != nil {
		log.Fatalf("Encode failed: %s\n", err)
	}
	return pkg
}
开发者ID:tradia,项目名称:gotable,代码行数:15,代码来源:table.go


示例6: SeekAndCopySyncPkg

func SeekAndCopySyncPkg(it *Iterator, p *proto.PkgMultiOp,
	migration bool, migSlotId uint16) bool {
	p.PkgFlag &^= 0xFF
	p.ErrCode = 0
	p.Kvs = nil

	var size = 0
	for i := 0; i < 10 && size < 400 && it.Valid(); i++ {
		var kv proto.KeyValue
		dbId, slotId, ok := seekAndCopySyncKV(it, &kv)
		if !ok {
			return false
		}
		if migration && migSlotId != slotId {
			if migSlotId < slotId {
				return false
			} else if migSlotId > slotId {
				seekToSlot(it, migSlotId, 0, 0)
				if !it.Valid() {
					return false
				}
				dbId, slotId, ok = seekAndCopySyncKV(it, &kv)
				if !ok || migSlotId != slotId {
					return false
				}
			}
		}

		if len(p.Kvs) == 0 {
			p.DbId = dbId
		} else if p.DbId != dbId {
			return true
		}

		p.Kvs = append(p.Kvs, kv)
		size += 13 + len(kv.RowKey) + len(kv.ColKey) + len(kv.Value)
		it.Next()
	}

	return true
}
开发者ID:tradia,项目名称:gotable,代码行数:41,代码来源:table.go


示例7: TestTableMDel

func TestTableMDel(t *testing.T) {
	var in proto.PkgMultiOp
	in.Cmd = proto.CmdMSet
	in.DbId = 2
	in.Seq = 20
	in.Kvs = append(in.Kvs, getTestKV(2, []byte("row1"), []byte("col0"), nil, 0, 0))
	in.Kvs = append(in.Kvs, getTestKV(2, []byte("row1"), []byte("col1"), nil, 0, 0))
	in.Kvs = append(in.Kvs, getTestKV(2, []byte("row1"), []byte("col2"), nil, 0, 0))

	out := myMDel(in, testAuth, getTestWA(), true, t)

	if len(out.Kvs) != 3 {
		t.Fatalf("Invalid KV number: %d", len(out.Kvs))
	}

	for i := 0; i < len(out.Kvs); i++ {
		if out.Kvs[i].ErrCode != 0 {
			t.Fatalf("ErrCode is 0")
		}
		if out.Kvs[i].TableId != 2 {
			t.Fatalf("TableId mismatch")
		}
		if bytes.Compare(out.Kvs[i].RowKey, []byte("row1")) != 0 {
			t.Fatalf("RowKey mismatch")
		}
		if bytes.Compare(out.Kvs[i].ColKey, []byte(fmt.Sprintf("col%d", i))) != 0 {
			t.Fatalf("ColKey mismatch")
		}
	}
}
开发者ID:tradia,项目名称:gotable,代码行数:30,代码来源:table_test.go


示例8: goMultiOp

// MGet, MSet, MDel, MIncr, ZMGet, ZMSet, ZMDel, ZMIncr
func (c *Context) goMultiOp(zop bool, args multiArgs, cmd uint8,
	done chan *Call) (*Call, error) {
	call := c.cli.newCall(cmd, done)
	if call.err != nil {
		return call, call.err
	}

	var p proto.PkgMultiOp
	p.Seq = call.seq
	p.DbId = c.dbId
	p.Cmd = call.cmd

	// ZMGet, ZMSet, ZMDel, ZMIncr
	if zop {
		p.PkgFlag |= proto.FlagZop
	}

	p.Kvs = make([]proto.KeyValue, args.length())
	args.toKV(p.Kvs)

	var pkgLen = p.Length()
	if pkgLen > proto.MaxPkgLen {
		c.cli.errCall(call, ErrInvPkgLen)
		return call, call.err
	}

	call.pkg = make([]byte, pkgLen)
	_, err := p.Encode(call.pkg)
	if err != nil {
		c.cli.errCall(call, err)
		return call, err
	}

	c.cli.sending <- call

	return call, nil
}
开发者ID:tradia,项目名称:gotable,代码行数:38,代码来源:context.go


示例9: checkMultiOp

func checkMultiOp(in *proto.PkgMultiOp, req *PkgArgs, au Authorize) bool {
	n, err := in.Decode(req.Pkg)
	if err != nil || n != len(req.Pkg) {
		in.ErrCode = table.EcDecodeFail
	}
	if in.ErrCode == 0 && in.DbId == proto.AdminDbId {
		in.ErrCode = table.EcInvDbId
	}
	if in.ErrCode == 0 && !au.IsAuth(in.DbId) {
		in.ErrCode = table.EcNoPrivilege
	}

	if in.ErrCode != 0 {
		in.Kvs = nil
	}

	return in.ErrCode == 0
}
开发者ID:tradia,项目名称:gotable,代码行数:18,代码来源:table.go


示例10: fullSync

func (ms *master) fullSync(tbl *store.Table) (uint64, error) {
	var lastSeq uint64
	if ms.lastSeq > 0 {
		lastSeq = ms.lastSeq
		if ms.migration {
			log.Printf("Migration lastSeq is not 0, close now!\n")
			return lastSeq, errors.New("migration lastSeq is not 0")
		} else {
			log.Printf("Already full synced to %s\n", ms.slaveAddr)
			return lastSeq, nil
		}
	}

	// Stop write globally
	rwMtx := tbl.GetRWMutex()
	rwMtx.Lock()
	var chanLen int
	for lastSeq, chanLen = ms.bin.GetLogSeqChanLen(); chanLen != 0; {
		log.Println("Stop write globally for 1ms")
		time.Sleep(time.Millisecond)
		lastSeq, chanLen = ms.bin.GetLogSeqChanLen()
	}
	var it = tbl.NewIterator(false)
	rwMtx.Unlock()

	defer it.Destroy()

	// Open BinLog reader to keep log files from deleting
	var err = ms.openReader(lastSeq)
	if err != nil {
		return lastSeq, err
	}

	// Full sync
	var p proto.PkgMultiOp
	p.Cmd = proto.CmdSync
	for it.SeekToFirst(); it.Valid(); {
		ok := store.SeekAndCopySyncPkg(it, &p, ms.migration, ms.slotId)

		if ms.cli.IsClosed() {
			return lastSeq, nil
		}

		if len(p.Kvs) > 0 {
			p.Seq = 0
			var pkg = make([]byte, p.Length())
			p.Encode(pkg)
			ms.cli.AddResp(pkg)
		}

		if !ok {
			break
		}
	}

	// Tell slave full sync finished
	if ms.migration {
		ms.syncStatus(store.KeyFullSyncEnd, 0)
		log.Printf("Full migration to %s slotId %d finished\n",
			ms.slaveAddr, ms.slotId)
	} else {
		ms.syncStatus(store.KeyFullSyncEnd, lastSeq)
		log.Printf("Full sync to %s finished\n", ms.slaveAddr)
	}

	return lastSeq, nil
}
开发者ID:tradia,项目名称:gotable,代码行数:67,代码来源:replication.go


示例11: TestTableZScan

func TestTableZScan(t *testing.T) {
	// MZSET
	{
		var in proto.PkgMultiOp
		in.Cmd = proto.CmdMSet
		in.DbId = 2
		in.Seq = 20
		in.PkgFlag |= proto.FlagZop
		in.Kvs = append(in.Kvs, getTestKV(2, []byte("row2"), []byte("col0"), []byte("v0"), 40, 0))
		in.Kvs = append(in.Kvs, getTestKV(2, []byte("row2"), []byte("col1"), []byte("v1"), 30, 0))
		in.Kvs = append(in.Kvs, getTestKV(2, []byte("row2"), []byte("col2"), []byte("v2"), 20, 0))
		in.Kvs = append(in.Kvs, getTestKV(2, []byte("row2"), []byte("col3"), []byte("v3"), 10, 0))
		in.Kvs = append(in.Kvs, getTestKV(2, []byte("row2"), []byte("col4"), []byte("v4"), 0, 0))

		myMSet(in, testAuth, getTestWA(), true, t)
	}

	// ZSCAN ASC order by SCORE
	var in proto.PkgScanReq
	in.Cmd = proto.CmdScan
	in.DbId = 2
	in.Seq = 20
	in.Num = 10
	in.TableId = 2
	in.RowKey = []byte("row2")
	in.SetScore(-1)
	in.ColKey = []byte("")
	in.PkgFlag |= proto.FlagScanAsc
	in.SetColSpace(proto.ColSpaceScore1) // order by SCORE

	out := myScan(in, testAuth, t)
	if len(out.Kvs) != 5 {
		t.Fatalf("Invalid KV number: %d", len(out.Kvs))
	}
	if out.PkgFlag&proto.FlagScanEnd == 0 {
		t.Fatalf("Scan should end")
	}
	for i := 0; i < len(out.Kvs); i++ {
		idx := 4 - i
		if out.Kvs[i].ErrCode != 0 {
			t.Fatalf("ErrCode is 0")
		}
		if out.Kvs[i].TableId != 2 {
			t.Fatalf("TableId mismatch")
		}
		if bytes.Compare(out.Kvs[i].RowKey, []byte("row2")) != 0 {
			t.Fatalf("RowKey mismatch")
		}
		if bytes.Compare(out.Kvs[i].ColKey, []byte(fmt.Sprintf("col%d", idx))) != 0 {
			t.Fatalf("ColKey mismatch")
		}
		if out.Kvs[i].Score != int64(i*10) {
			t.Fatalf("Score mismatch")
		}
		if bytes.Compare(out.Kvs[i].Value, []byte(fmt.Sprintf("v%d", idx))) != 0 {
			t.Fatalf("Value mismatch")
		}
	}

	// ZSCAN DESC order by SCORE
	in.PkgFlag &^= 0xFF
	in.PkgFlag |= proto.FlagScanKeyStart

	out = myScan(in, testAuth, t)
	if len(out.Kvs) != 5 {
		t.Fatalf("Invalid KV number: %d", len(out.Kvs))
	}
	if out.PkgFlag&proto.FlagScanEnd == 0 {
		t.Fatalf("Scan should end")
	}
	for i := 0; i < len(out.Kvs); i++ {
		idx := 4 - i
		if out.Kvs[i].ErrCode != 0 {
			t.Fatalf("ErrCode is 0")
		}
		if out.Kvs[i].TableId != 2 {
			t.Fatalf("TableId mismatch")
		}
		if bytes.Compare(out.Kvs[i].RowKey, []byte("row2")) != 0 {
			t.Fatalf("RowKey mismatch")
		}
		if bytes.Compare(out.Kvs[i].ColKey, []byte(fmt.Sprintf("col%d", i))) != 0 {
			t.Fatalf("ColKey mismatch")
		}
		if out.Kvs[i].Score != int64(idx*10) {
			t.Fatalf("Score mismatch")
		}
		if bytes.Compare(out.Kvs[i].Value, []byte(fmt.Sprintf("v%d", i))) != 0 {
			t.Fatalf("Value mismatch")
		}
	}
}
开发者ID:tradia,项目名称:gotable,代码行数:92,代码来源:table_test.go


示例12: Reply

// Get call reply. The real reply types are:
// Auth/Ping/(Z)Set/(Z)Del: nil;
// (Z)Get: GetReply;
// (Z)Incr: IncrReply;
// (Z)MGet: []GetReply;
// (Z)MSet: []SetReply;
// (Z)MDel: []DelReply;
// (Z)MIncr: []IncrReply;
// (Z)Scan: ScanReply;
// Dump: DumpReply;
func (call *Call) Reply() (interface{}, error) {
	if call.err != nil {
		return nil, call.err
	}

	if !call.ready {
		return nil, ErrCallNotReady
	}

	if proto.CmdAuth == call.cmd ||
		proto.CmdPing == call.cmd ||
		proto.CmdIncr == call.cmd ||
		proto.CmdDel == call.cmd ||
		proto.CmdSet == call.cmd ||
		proto.CmdGet == call.cmd {
		var p proto.PkgOneOp
		_, err := p.Decode(call.pkg)
		if err != nil {
			call.err = err
			return nil, call.err
		}
		if p.ErrCode < 0 {
			return nil, getErr(p.ErrCode)
		}
		switch call.cmd {
		case proto.CmdAuth:
			return nil, nil
		case proto.CmdPing:
			return nil, nil
		case proto.CmdIncr:
			return IncrReply{p.ErrCode, p.TableId, copyBytes(p.RowKey),
				copyBytes(p.ColKey), copyBytes(p.Value), p.Score}, nil
		case proto.CmdDel:
			return nil, nil
		case proto.CmdSet:
			return nil, nil
		case proto.CmdGet:
			return GetReply{p.ErrCode, p.TableId, copyBytes(p.RowKey),
				copyBytes(p.ColKey), copyBytes(p.Value), p.Score, p.Cas}, nil
		}
	}

	if proto.CmdMIncr == call.cmd ||
		proto.CmdMDel == call.cmd ||
		proto.CmdMSet == call.cmd ||
		proto.CmdMGet == call.cmd {
		var p proto.PkgMultiOp
		_, err := p.Decode(call.pkg)
		if err != nil {
			call.err = err
			return nil, call.err
		}

		if p.ErrCode < 0 {
			return nil, getErr(p.ErrCode)
		}

		switch call.cmd {
		case proto.CmdMIncr:
			var r = make([]IncrReply, len(p.Kvs))
			for i := 0; i < len(r); i++ {
				r[i] = IncrReply{p.Kvs[i].ErrCode, p.Kvs[i].TableId,
					copyBytes(p.Kvs[i].RowKey), copyBytes(p.Kvs[i].ColKey),
					copyBytes(p.Kvs[i].Value), p.Kvs[i].Score}
			}
			return r, nil
		case proto.CmdMDel:
			var r = make([]DelReply, len(p.Kvs))
			for i := 0; i < len(r); i++ {
				r[i] = DelReply{p.Kvs[i].ErrCode, p.Kvs[i].TableId,
					copyBytes(p.Kvs[i].RowKey), copyBytes(p.Kvs[i].ColKey)}
			}
			return r, nil
		case proto.CmdMSet:
			var r = make([]SetReply, len(p.Kvs))
			for i := 0; i < len(r); i++ {
				r[i] = SetReply{p.Kvs[i].ErrCode, p.Kvs[i].TableId,
					copyBytes(p.Kvs[i].RowKey), copyBytes(p.Kvs[i].ColKey)}
			}
			return r, nil
		case proto.CmdMGet:
			var r = make([]GetReply, len(p.Kvs))
			for i := 0; i < len(r); i++ {
				r[i] = GetReply{p.Kvs[i].ErrCode, p.Kvs[i].TableId,
					copyBytes(p.Kvs[i].RowKey), copyBytes(p.Kvs[i].ColKey),
					copyBytes(p.Kvs[i].Value), p.Kvs[i].Score, p.Kvs[i].Cas}
			}
			return r, nil
		}
	}
//.........这里部分代码省略.........
开发者ID:tradia,项目名称:gotable,代码行数:101,代码来源:context.go



注:本文中的github.com/stevejiang/gotable/api/go/table/proto.PkgMultiOp类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang proto.PkgOneOp类代码示例发布时间:2022-05-28
下一篇:
Golang proto.KeyValue类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap