return 0; // not found
}
+void CrushWrapper::get_subtree_of_type(int type, vector<int> *subtrees)
+{
+ set<int> roots;
+ find_roots(&roots);
+ for (auto r: roots) {
+ crush_bucket *b = get_bucket(r);
+ if (IS_ERR(b))
+ continue;
+ get_children_of_type(b->id, type, subtrees);
+ }
+}
+
+
int CrushWrapper::rename_class(const string& srcname, const string& dstname)
{
auto i = class_rname.find(srcname);
int type,
vector<int> *children,
bool exclude_shadow = true) const;
+ /**
+ * enumerate all subtrees by type
+ */
+ void get_subtree_of_type(int type, vector<int> *subtrees);
/**
* get failure-domain type of a specific crush rule
if (prev >= 0 && prev != next)
want.insert(prev);
+ // make sure we have at least **min_down** osds coming from different
+ // subtree level (e.g., hosts) for fast failure detection.
+ auto min_down = cct->_conf.get_val<uint64_t>("mon_osd_min_down_reporters");
+ auto subtree = cct->_conf.get_val<string>("mon_osd_reporter_subtree_level");
+ osdmap->get_random_up_osds_by_subtree(
+ whoami, subtree, min_down, want, &want);
+
for (set<int>::iterator p = want.begin(); p != want.end(); ++p) {
dout(10) << " adding neighbor peer osd." << *p << dendl;
extras.insert(*p);
}
return 0;
}
+
+void OSDMap::get_random_up_osds_by_subtree(int n, // whoami
+ string &subtree,
+ int limit, // how many
+ set<int> skip,
+ set<int> *want) const {
+ if (limit <= 0)
+ return;
+ int subtree_type = crush->get_type_id(subtree);
+ if (subtree_type < 1)
+ return;
+ vector<int> subtrees;
+ crush->get_subtree_of_type(subtree_type, &subtrees);
+ std::random_shuffle(subtrees.begin(), subtrees.end());
+ for (auto s : subtrees) {
+ if (limit <= 0)
+ break;
+ if (crush->subtree_contains(s, n))
+ continue;
+ vector<int> osds;
+ crush->get_children_of_type(s, 0, &osds);
+ if (osds.empty())
+ continue;
+ vector<int> up_osds;
+ for (auto o : osds) {
+ if (is_up(o) && !skip.count(o))
+ up_osds.push_back(o);
+ }
+ if (up_osds.empty())
+ continue;
+ auto it = up_osds.begin();
+ std::advance(it, (n % up_osds.size()));
+ want->insert(*it);
+ --limit;
+ }
+}
+
return -1;
}
+
+ void get_random_up_osds_by_subtree(int n, // whoami
+ string &subtree,
+ int limit, // how many
+ set<int> skip,
+ set<int> *want) const;
+
/**
* get feature bits required by the current structure
*