]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: factorize shard_id_t/shard_t into a struct
authorLoic Dachary <loic@dachary.org>
Thu, 29 May 2014 21:11:48 +0000 (23:11 +0200)
committerLoic Dachary <loic@dachary.org>
Thu, 29 May 2014 21:11:48 +0000 (23:11 +0200)
The struct contains a single uint8_t and is preferred to control
conversions that would otherwise be implicit. There is no difference
between shard_id_t and shard_t. The definition is moved in
include/types.h so it is available to both hobject.h and osd_types.h

http://tracker.ceph.com/issues/8254 Fixes: #8254

Signed-off-by: Loic Dachary <loic@dachary.org>
src/common/Makefile.am
src/common/hobject.h
src/common/types.cc [new file with mode: 0644]
src/include/types.h
src/osd/osd_types.h
src/test/osd/types.cc

index 3a63dc604fd523e351cba1c9c1fde7019670ffff..bb5c43f5f1dfc6a66552f530b52dadf48fe933b9 100644 (file)
@@ -38,6 +38,7 @@ libcommon_la_SOURCES = \
        common/ceph_argparse.cc \
        common/ceph_context.cc \
        common/buffer.cc \
+       common/types.cc \
        common/code_environment.cc \
        common/dout.cc \
        common/histogram.cc \
index fc12c9f1c457cba54c8e5c8ddf0824db4d3227ef..f911e6e08f32a8b94471e49fc2225dee741f5628 100644 (file)
@@ -231,11 +231,7 @@ WRITE_CMP_OPERATORS_7(hobject_t,
                      snap)
 
 typedef version_t gen_t;
-typedef uint8_t shard_t;
 
-#ifndef UINT8_MAX
-#define UINT8_MAX (255)
-#endif
 #ifndef UINT64_MAX
 #define UINT64_MAX (18446744073709551615ULL)
 #endif
@@ -243,18 +239,16 @@ typedef uint8_t shard_t;
 struct ghobject_t {
   hobject_t hobj;
   gen_t generation;
-  shard_t shard_id;
+  shard_id_t shard_id;
 
 public:
-  static const shard_t NO_SHARD = UINT8_MAX;
-  static shard_t no_shard() { return NO_SHARD; }
   static const gen_t NO_GEN = UINT64_MAX;
 
-  ghobject_t() : generation(NO_GEN), shard_id(NO_SHARD) {}
+  ghobject_t() : generation(NO_GEN), shard_id(shard_id_t::NO_SHARD) {}
 
-  ghobject_t(const hobject_t &obj) : hobj(obj), generation(NO_GEN), shard_id(NO_SHARD) {}
+  ghobject_t(const hobject_t &obj) : hobj(obj), generation(NO_GEN), shard_id(shard_id_t::NO_SHARD) {}
 
-  ghobject_t(const hobject_t &obj, gen_t gen, shard_t shard) : hobj(obj), generation(gen), shard_id(shard) {}
+  ghobject_t(const hobject_t &obj, gen_t gen, shard_id_t shard) : hobj(obj), generation(gen), shard_id(shard) {}
 
   bool match(uint32_t bits, uint32_t match) const {
     return hobj.match_hash(hobj.hash, bits, match);
diff --git a/src/common/types.cc b/src/common/types.cc
new file mode 100644 (file)
index 0000000..1ad2ccc
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+#ifndef __CEPH_TYPES_H
+#define __CEPH_TYPES_H
+
+#include <include/types.h>
+
+#ifndef UINT8_MAX
+#define UINT8_MAX (255)
+#endif
+
+const shard_id_t shard_id_t::NO_SHARD(UINT8_MAX);
+
+ostream &operator<<(ostream &lhs, const shard_id_t &rhs)
+{
+  return lhs << (unsigned)rhs.id;
+}
+
+#endif
index 5f9f25dba328871320c57fa14495669803941e28..ea80a552bc1172ab42d21ab30f822dd9ba9ce96f 100644 (file)
@@ -446,4 +446,26 @@ inline ostream& operator<<(ostream &oss, health_status_t status) {
 }
 #endif
 
+struct shard_id_t {
+  uint8_t id;
+
+  shard_id_t() : id(0) {}
+  explicit shard_id_t(uint8_t _id) : id(_id) {}
+
+  operator uint8_t() const { return id; }
+
+  const static shard_id_t NO_SHARD;
+
+  void encode(bufferlist &bl) const {
+    ::encode(id, bl);
+  }
+  void decode(bufferlist::iterator &bl) {
+    ::decode(id, bl);
+  }
+};
+WRITE_CLASS_ENCODER(shard_id_t)
+WRITE_EQ_OPERATORS_1(shard_id_t, id)
+WRITE_CMP_OPERATORS_1(shard_id_t, id)
+ostream &operator<<(ostream &lhs, const shard_id_t &rhs);
+
 #endif
index 5852b5745869342c3c4d3d6529706f4a39d70ead..8a94ca60afb6ad2dc954bcde0814dfb7d639bbe9 100644 (file)
@@ -58,8 +58,6 @@
 
 typedef hobject_t collection_list_handle_t;
 
-typedef uint8_t shard_id_t;
-
 /// convert a single CPEH_OSD_FLAG_* to a string
 const char *ceph_osd_flag_name(unsigned flag);
 
index 14935d8c66efdd2712499a77e5631cba52019eb0..83d9c0fff479c8eea3d3310421a5324347417ef9 100644 (file)
@@ -1282,9 +1282,19 @@ TEST(pg_pool_t_test, get_random_pg_position) {
   }
 }
 
+TEST(shard_id_t, iostream) {
+    set<shard_id_t> shards;
+    shards.insert(shard_id_t(0));
+    shards.insert(shard_id_t(1));
+    shards.insert(shard_id_t(2));
+    ostringstream out;
+    out << shards;
+    ASSERT_EQ(out.str(), "0,1,2");
+}
+
 /*
  * Local Variables:
- * compile-command: "cd .. ;
+ * compile-command: "cd ../.. ;
  *   make unittest_osd_types ;
  *   ./unittest_osd_types # --gtest_filter=pg_missing_t.constructor
  * "