]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_journal: new convenience functions for ObjectSetPosition
authorJason Dillaman <dillaman@redhat.com>
Wed, 1 Jul 2015 03:49:12 +0000 (23:49 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 6 Nov 2015 01:42:41 +0000 (20:42 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/cls/journal/cls_journal_types.cc
src/cls/journal/cls_journal_types.h

index 9ecb9516c4b5cc021565792de28c89da202c69da..65c0d98dc59e3f52e6a2de4aa7d60c158cafc0d0 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "cls/journal/cls_journal_types.h"
 #include "common/Formatter.h"
+#include <set>
 
 namespace cls {
 namespace journal {
@@ -31,6 +32,28 @@ void EntryPosition::generate_test_instances(std::list<EntryPosition *> &o) {
   o.push_back(new EntryPosition("id", 2));
 }
 
+bool ObjectSetPosition::operator<(const ObjectSetPosition& rhs) const {
+  if (entry_positions.size() < rhs.entry_positions.size()) {
+    return true;
+  } else if (entry_positions.size() > rhs.entry_positions.size()) {
+    return false;
+  }
+
+  std::map<std::string, uint64_t> rhs_tids;
+  for (EntryPositions::const_iterator it = rhs.entry_positions.begin();
+       it != rhs.entry_positions.end(); ++it) {
+    rhs_tids[it->tag] = it->tid;
+  }
+
+  for (size_t i=0; i<entry_positions.size(); ++i) {
+    const EntryPosition &entry_position = entry_positions[i];
+    if (entry_position.tid < rhs_tids[entry_position.tag]) {
+      return true;
+    }
+  }
+  return false;
+}
+
 void ObjectSetPosition::encode(bufferlist& bl) const {
   ENCODE_START(1, 1, bl);
   ::encode(object_number, bl);
@@ -100,5 +123,23 @@ void Client::generate_test_instances(std::list<Client *> &o) {
   o.push_back(new Client("id", "desc", ObjectSetPosition(1, entry_positions)));
 }
 
+std::ostream &operator<<(std::ostream &os,
+                         const EntryPosition &entry_position) {
+  os << "[tag=" << entry_position.tag << ", tid="
+     << entry_position.tid << "]";
+  return os;
+}
+
+std::ostream &operator<<(std::ostream &os,
+                         const ObjectSetPosition &object_set_position) {
+  os << "[object_number=" << object_set_position.object_number << ", "
+     << "positions=[";
+  for (size_t i=0; i<object_set_position.entry_positions.size(); ++i) {
+    os << object_set_position.entry_positions[i];
+  }
+  os << "]]";
+  return os;
+}
+
 } // namespace journal
 } // namespace cls
index 1a2777b24d52880193de00798b394b6178b0467c..a44a0f3969191c063d2504c71502c597e31bc7f0 100644 (file)
@@ -7,6 +7,7 @@
 #include "include/int_types.h"
 #include "include/buffer.h"
 #include "include/encoding.h"
+#include <iosfwd>
 #include <string>
 #include <vector>
 
@@ -47,6 +48,10 @@ struct ObjectSetPosition {
                     const EntryPositions &_entry_positions)
     : object_number(_object_number), entry_positions(_entry_positions) {}
 
+  bool operator<(const ObjectSetPosition& rhs) const;
+  inline bool operator<=(const ObjectSetPosition& rhs) const {
+    return (*this == rhs || *this < rhs);
+  }
   inline bool operator==(const ObjectSetPosition &rhs) const {
     return (object_number == rhs.object_number &&
             entry_positions == rhs.entry_positions);
@@ -88,6 +93,11 @@ WRITE_CLASS_ENCODER(EntryPosition);
 WRITE_CLASS_ENCODER(ObjectSetPosition);
 WRITE_CLASS_ENCODER(Client);
 
+std::ostream &operator<<(std::ostream &os,
+                         const EntryPosition &entry_position);
+std::ostream &operator<<(std::ostream &os,
+                         const ObjectSetPosition &object_set_position);
+
 } // namespace journal
 } // namespace cls