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 }
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) }
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 }