Skip to content

Commit

Permalink
crush: compare fixed-point weights in update_item
Browse files Browse the repository at this point in the history
This is less ugly than converting the quantized value back to a float and
comparing that.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed May 4, 2012
1 parent 684558a commit 1cd6f76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/crush/CrushWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion src/crush/CrushWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ class CrushWrapper {
* @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
Expand Down

0 comments on commit 1cd6f76

Please sign in to comment.