func centerSendGetServerReq(conn net.Conn) { // send getserver var req3 PbCenter.GetServerReq req3.Type = proto.Int(4) req3.Aid = proto.Int(-1) req3.Sid = proto.Int(-1) sirius_net.SendMsg(conn, &req3, uint32(PbCenter.Command_CMD_GET_SERVER_REQ), 3) }
func (task *FlushTask) doFlush(values [][]byte, items []dbproto.FlushItem) error { var err error var set dbproto.Set if err = task.useDB(); err != nil { return err } startrecv := false itemmap := map[string]int{} done := make(chan error, 1) for i := 0; i < len(values); i++ { // no data, ignore if values[i] == nil { continue } dumpkey := items[i].GetMsgType() + "_" + items[i].GetKey() // dumplicated, ignore if _, ok := itemmap[dumpkey]; ok { continue } task.stat.flushCount++ itemmap[dumpkey] = 1 set.MsgType = items[i].MsgType set.Flags = proto.Uint32(uint32(dbproto.Flags_FLAG_DB_ONLY)) set.Value = values[i] set.Key = items[i].Key err = sirius_net.SendMsg(task.proxy_conn[0], &set, uint32(dbproto.Command_CMD_SET_REQ), task.nextseq) if err != nil { // network err return err } if !startrecv { go task.proxyLoop(done) startrecv = true } task.lock.Lock() task.reqmap[task.nextseq] = &items[i] task.lock.Unlock() // logger.Printf("send %v\n", set) task.nextseq++ task.reqchan <- 1 } close(task.reqchan) // wait recv done if startrecv { err = <-done } return err }
func centerSendRegister(conn net.Conn) { // send register var reg PbCenter.RegReq var addr PbCommon.Addr addr.Ip = proto.String("0.0.0.0") addr.Port = proto.Uint32(0) addr.Aid = proto.Int(-1) addr.Sid = proto.Int(-1) addr.Gid = proto.Int64(-1) reg.Type = proto.Int(8) reg.Addr = &addr // keep dbflushd only 1 reg.Resv = proto.Int(1) logger.Println(reg) sirius_net.SendMsg(conn, ®, uint32(PbCenter.Command_CMD_REG_REQ), 1) }
func sendUseDB(conn net.Conn) error { var usedb dbproto.UseDB usedb.Dbname = proto.String(dbName) err := sirius_net.SendMsg(conn, &usedb, uint32(dbproto.Command_CMD_USEDB_REQ), 1) if err != nil { return err } var header sirius_net.Header var body [64]byte _, err = sirius_net.Recv(conn, &header, body[0:]) if err != nil { return err } if header.Err != 0 { log.Fatal("use db err %v\n", err) } return nil }
func (task *FlushTask) useDB() error { var usedb dbproto.UseDB usedb.Dbname = proto.String(task.dbname) err := sirius_net.SendMsg(task.proxy_conn[0], &usedb, uint32(dbproto.Command_CMD_USEDB_REQ), 1) if err != nil { return err } var header sirius_net.Header var b [64]byte _, err = sirius_net.Recv(task.proxy_conn[0], &header, b[0:]) if err != nil { return err } if header.Err != 0 { logger.Print("use db err:", err) return ErrorUseDB } return nil }
func centerSendNotifyReg(conn net.Conn) { // send notifyreg var req2 PbCenter.RegNotifyReq req2.Type = proto.Int(4) sirius_net.SendMsg(conn, &req2, uint32(PbCenter.Command_CMD_REG_NOTIFY_REQ), 2) }