Пример #1
0
func (task *FlushTask) proxyLoop(done chan error) {
	var header sirius_net.Header
	var err error
	var item *dbproto.FlushItem
	var ok bool
	var b [64 * 1024]byte

	for {
		err = nil
		_, more := <-task.reqchan
		if !more {
			break
		}

		_, err = sirius_net.Recv(task.proxy_conn[0], &header, b[0:])
		if err != nil {
			break
		}

		task.lock.Lock()
		item, ok = task.reqmap[header.Seq]
		task.lock.Unlock()
		if !ok {
			logger.Print("unknown seq:", header.Seq)
			task.stat.invalidCount++
			continue
		}

		if header.Err != 0 {
			task.err_items = append(task.err_items, item)
			task.stat.errorCount++
			logger.Printf("proxy flush %s return err %d", item.GetKey(), header.Err)
		}
	}

	logger.Printf("proxyLoop exit")
	task.stat.end = time.Now()

	// output stat
	logger.Printf("Stat of last task:")
	logger.Printf("%#v", task.stat)
	done <- err
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
func centerLoop(dest string, ch chan proto.Message) {
	var err error
	var conn net.Conn

	// connect
	for {
		conn, err = net.Dial("tcp", dest)
		if err != nil {
			logger.Printf("dial center err %v, sleep and reconnect\n", err)
			time.Sleep(5 * time.Second)
			continue
		}

		centerSendRegister(conn)
		centerSendNotifyReg(conn)

		var header sirius_net.Header
		var b [64 * 1024]byte
		var n int
		for {
			n, err = sirius_net.Recv(conn, &header, b[0:])
			if err != nil {
				logger.Printf("ERROR: sirius_net recv err %v\n", err)
				break
			}
			err = procCenterResp(conn, &header, b[0:n], ch)
			if err != nil {
				logger.Printf("ERROR: sirius_net resp err %v\n", err)
				break
			}
		}

		conn.Close()
		time.Sleep(time.Minute)
	}

	// wait loop
	return
}