]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: create_or_move_item()
authorSage Weil <sage@inktank.com>
Mon, 10 Sep 2012 21:25:11 +0000 (14:25 -0700)
committerSage Weil <sage@inktank.com>
Tue, 11 Sep 2012 17:48:01 +0000 (10:48 -0700)
Create an item if it doesn't exist, with the specified weight.  If it is
already in the tree, move it, but do not adjust the weight.

Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 8b3e895d793bb23f79a817eb7735e2482be1467d..c9f69bd78d451eaa7c00cbdfa9f3f7123815d3b9 100644 (file)
@@ -282,6 +282,27 @@ int CrushWrapper::move_bucket(CephContext *cct, int id, map<string,string>& loc)
   return insert_item(cct, id, bucket_weight / (float)0x10000, id_name, loc);
 }
 
+int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight, string name,
+                                     map<string,string>& loc)  // typename -> bucketname
+{
+  int ret = 0;
+  int old_iweight;
+  if (check_item_loc(cct, item, loc, &old_iweight)) {
+    ldout(cct, 5) << "create_or_move_item " << item << " already at " << loc << dendl;
+  } else {
+    if (item_exists(item)) {
+      weight = get_item_weightf(item);
+      ldout(cct, 10) << "create_or_move_item " << item << " exists with weight " << weight << dendl;
+      remove_item(cct, item);
+    }
+    ldout(cct, 5) << "create_or_move_item adding " << item << " weight " << weight
+                 << " at " << loc << dendl;
+    ret = insert_item(cct, item, weight, name.c_str(), loc);
+    if (ret == 0)
+      ret = 1;  // changed
+  }
+  return ret;
+}
 
 int CrushWrapper::update_item(CephContext *cct, int item, float weight, string name,
                              map<string,string>& loc)  // typename -> bucketname
index 5925b83aef19cbb0dfaf5683ecea37b9f40947e5..5bd9336270cca213b1ad200ddbc2a1927ff722ee 100644 (file)
@@ -312,6 +312,19 @@ public:
    */
   int update_item(CephContext *cct, int id, float weight, string name, map<string,string>& loc);
 
+  /**
+   * create or move an item, but do not adjust its weight if it already exists
+   *
+   * @param cct cct
+   * @param item item id
+   * @param weight initial item weight (if we need to create it)
+   * @param name item name
+   * @param loc location (map of type to bucket names)
+   * @return 0 for no change, 1 for successful change, negative on error
+   */
+  int create_or_move_item(CephContext *cct, int item, float weight, string name,
+                         map<string,string>& loc);
+
   /**
    * remove an item from the map
    *