summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage.weil@dreamhost.com>2012-05-03 20:28:21 -0700
committerSage Weil <sage.weil@dreamhost.com>2012-05-03 20:28:21 -0700
commit1cd6f764206bddac840935a3c7bb657e18359c62 (patch)
tree9811ed41c929c48ae54f5ee87367bba1c4a34414
parent684558ace9e29303cde02b5542f2df1962cab661 (diff)
downloadceph-1cd6f764206bddac840935a3c7bb657e18359c62.tar.gz
crush: compare fixed-point weights in update_item
This is less ugly than converting the quantized value back to a float and comparing that. Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
-rw-r--r--src/crush/CrushWrapper.cc18
-rw-r--r--src/crush/CrushWrapper.h10
2 files changed, 18 insertions, 10 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc
index fc30f2de179..a6141d4ebe4 100644
--- a/src/crush/CrushWrapper.cc
+++ b/src/crush/CrushWrapper.cc
@@ -66,7 +66,7 @@ int CrushWrapper::remove_item(CephContext *cct, int item)
}
bool CrushWrapper::check_item_loc(CephContext *cct, int item, map<string,string>& loc,
- float *weight)
+ int *weight)
{
ldout(cct, 5) << "check_item_loc item " << item << " loc " << loc << dendl;
@@ -101,7 +101,7 @@ bool CrushWrapper::check_item_loc(CephContext *cct, int item, map<string,string>
if (b->items[j] == cur) {
ldout(cct, 2) << "check_item_loc " << cur << " exists in bucket " << b->id << dendl;
if (weight)
- *weight = (float)crush_get_bucket_item_weight(b, j) / (float)0x10000;
+ *weight = crush_get_bucket_item_weight(b, j);
return true;
}
}
@@ -185,15 +185,15 @@ int CrushWrapper::update_item(CephContext *cct, int item, float weight, string n
<< " name " << name << " loc " << loc << dendl;
int ret = 0;
- weight = quantize_weight(weight);
-
- float old_weight;
- if (check_item_loc(cct, item, loc, &old_weight)) {
+ // compare quantized (fixed-point integer) weights!
+ int iweight = (int)(weight * (float)0x10000);
+ int old_iweight;
+ if (check_item_loc(cct, item, loc, &old_iweight)) {
ldout(cct, 5) << "update_item " << item << " already at " << loc << dendl;
- if (old_weight != weight) {
+ if (old_iweight != iweight) {
ldout(cct, 5) << "update_item " << item << " adjusting weight "
- << old_weight << " -> " << weight << dendl;
- adjust_item_weightf(cct, item, weight);
+ << ((float)old_iweight/(float)0x10000) << " -> " << weight << dendl;
+ adjust_item_weight(cct, item, iweight);
ret = 1;
}
if (get_item_name(item) != name) {
diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h
index d12cd835fa4..e9aa96f9db9 100644
--- a/src/crush/CrushWrapper.h
+++ b/src/crush/CrushWrapper.h
@@ -172,8 +172,16 @@ public:
* @param item item id
* @param loc location to check (map of type to bucket names)
* @param weight optional pointer to weight of item at that location
+ * @return true if item is at specified location
*/
- bool check_item_loc(CephContext *cct, int item, map<string,string>& loc, float *weight);
+ bool check_item_loc(CephContext *cct, int item, map<string,string>& loc, int *iweight);
+ bool check_item_loc(CephContext *cct, int item, map<string,string>& loc, float *weight) {
+ int iweight;
+ bool ret = check_item_loc(cct, item, loc, &iweight);
+ if (weight)
+ *weight = (float)iweight / (float)0x10000;
+ return ret;
+ }
/**
* insert an item into the map at a specific position