From b5701553fcc13f30ebf35a6ee8402cfd43f24e18 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Fri, 26 Jun 2015 10:21:49 +0100 Subject: [PATCH] mon: MonOpRequest: allow setting the op type When we introduced the MonOpRequest in the monitor and moved pretty much every single function receiving messages in their arguments to take op requests, we basically lost the type safety that was guaranteed from Monitor::dispatch(). This patch adds an op_type field to the op request, as an easy fix for this now lacking safety. Signed-off-by: Joao Eduardo Luis --- src/mon/MonOpRequest.h | 52 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/mon/MonOpRequest.h b/src/mon/MonOpRequest.h index 329607c53c436..ebb44d1c8fe5d 100644 --- a/src/mon/MonOpRequest.h +++ b/src/mon/MonOpRequest.h @@ -64,19 +64,31 @@ struct MonOpRequest : public TrackedOp { mark_svc_event("paxos", event); } + + enum op_type_t { + OP_TYPE_NONE = 0, ///< no type defined (default) + OP_TYPE_SERVICE, ///< belongs to a Paxos Service or similar + OP_TYPE_MONITOR, ///< belongs to the Monitor class + OP_TYPE_ELECTION, ///< belongs to the Elector class + OP_TYPE_PAXOS, ///< refers to Paxos messages + OP_TYPE_COMMAND, ///< is a command + }; + private: Message *request; utime_t dequeued_time; MonSession *session; ConnectionRef con; bool forwarded_to_leader; + op_type_t op_type; MonOpRequest(Message *req, OpTracker *tracker) : TrackedOp(tracker, req->get_recv_stamp()), request(req->get()), session(NULL), con(NULL), - forwarded_to_leader(false) + forwarded_to_leader(false), + op_type(OP_TYPE_NONE) { tracker->mark_event(this, "header_read", request->get_recv_stamp()); tracker->mark_event(this, "throttled", request->get_throttle_stamp()); @@ -163,6 +175,44 @@ public: } } + void set_op_type(op_type_t t) { + op_type = t; + } + void set_type_service() { + set_op_type(OP_TYPE_SERVICE); + } + void set_type_monitor() { + set_op_type(OP_TYPE_MONITOR); + } + void set_type_paxos() { + set_op_type(OP_TYPE_PAXOS); + } + void set_type_election() { + set_op_type(OP_TYPE_ELECTION); + } + void set_type_command() { + set_op_type(OP_TYPE_COMMAND); + } + + op_type_t get_op_type() { + return op_type; + } + + bool is_type_service() { + return (get_op_type() == OP_TYPE_SERVICE); + } + bool is_type_monitor() { + return (get_op_type() == OP_TYPE_MONITOR); + } + bool is_type_paxos() { + return (get_op_type() == OP_TYPE_PAXOS); + } + bool is_type_election() { + return (get_op_type() == OP_TYPE_ELECTION); + } + bool is_type_command() { + return (get_op_type() == OP_TYPE_COMMAND); + } }; typedef MonOpRequest::Ref MonOpRequestRef; -- 2.39.5