func (self *ProtobufRequestHandler) handleReplay(request *protocol.Request, conn net.Conn) {
	sendRequest := func(loggedRequestData *[]byte) error {
		var response *protocol.Response
		if loggedRequestData != nil {
			loggedRequest, err := protocol.DecodeRequest(bytes.NewBuffer(*loggedRequestData))
			if err != nil {
				return err
			}
			response = &protocol.Response{Type: &responseReplicationReplay, Request: loggedRequest, RequestId: request.Id}
		} else {
			response = &protocol.Response{Type: &replayReplicationEnd, RequestId: request.Id}
		}
		return self.WriteResponse(conn, response)
	}
	replicationFactor8 := uint8(*request.ReplicationFactor)
	err := self.db.ReplayRequestsFromSequenceNumber(
		request.ClusterVersion,
		request.OriginatingServerId,
		request.OwnerServerId,
		&replicationFactor8,
		request.LastKnownSequenceNumber,
		sendRequest)
	if err != nil {
		log.Error("REPLAY ERROR: %s", err)
	}
}
func (self *ProtobufServer) handleRequest(conn net.Conn, messageSize int64, buff *bytes.Buffer) error {
	reader := io.LimitReader(conn, messageSize)
	_, err := io.Copy(buff, reader)
	if err != nil {
		return err
	}
	request, err := protocol.DecodeRequest(buff)
	if err != nil {
		return err
	}

	return self.requestHandler.HandleRequest(request, conn)
}
Esempio n. 3
0
func (self *ProtobufServer) handleRequest(conn net.Conn, messageSize int64, buff *bytes.Buffer) error {
	reader := io.LimitReader(conn, messageSize)
	_, err := io.Copy(buff, reader)
	if err != nil {
		return err
	}
	request, err := protocol.DecodeRequest(buff)
	if err != nil {
		return err
	}

	log.Debug("Received %s request: %d", request.GetType(), request.GetRequestNumber())

	return self.requestHandler.HandleRequest(request, conn)
}
Esempio n. 4
0
func (prs *PingResponseServer) handleConnection(conn net.Conn) {
	message := make([]byte, 0, MAX_REQUEST_SIZE)
	buff := bytes.NewBuffer(message)
	var messageSizeU uint32

	for {
		buff.Reset()
		err := binary.Read(conn, binary.LittleEndian, &messageSizeU)
		if err != nil {
			log.Error("Error reading from connection (%s): %s", conn.RemoteAddr().String(), err)
			return
		}

		_, err = io.CopyN(buff, conn, int64(messageSizeU))

		if err != nil {
			break
		}

		request, err := protocol.DecodeRequest(buff)
		if err != nil {
			break
		}

		switch *request.Type {
		case protocol.Request_HEARTBEAT:
			response := &protocol.Response{RequestId: request.Id, Type: &heartbeatResponse}

			data, err := response.Encode()
			if err != nil {
				panic(err)
			}
			binary.Write(conn, binary.LittleEndian, uint32(len(data)))
			_, err = conn.Write(data)
		default:
			panic("Not a heartbeat request")

		}
	}
	conn.Close()
}