]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: MonOpRequest: allow setting the op type
authorJoao Eduardo Luis <joao@suse.de>
Fri, 26 Jun 2015 09:21:49 +0000 (10:21 +0100)
committerJoao Eduardo Luis <joao@suse.de>
Thu, 16 Jul 2015 17:31:23 +0000 (18:31 +0100)
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 <joao@suse.de>
src/mon/MonOpRequest.h

index 329607c53c436105ed1e92bdcbef7d5106aa02c9..ebb44d1c8fe5d99536d4940ab9a3997e131effd9 100644 (file)
@@ -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;