Skip to content
Snippets Groups Projects
Commit 5a239cdd authored by Simon Désaulniers's avatar Simon Désaulniers Committed by Adrien Béraud
Browse files

pht: fix insert always to root bug

This makes the pht node recover all indexed data on a DHT node (maximum
MAX_NODE_ENTRY_COUNT per node) so that the pht node can be aware if it has to
split its data in the leaf.
parent c4928553
Branches
Tags
No related merge requests found
...@@ -131,7 +131,11 @@ struct IndexEntry : public dht::Value::Serializable<IndexEntry> { ...@@ -131,7 +131,11 @@ struct IndexEntry : public dht::Value::Serializable<IndexEntry> {
class Pht { class Pht {
static constexpr const char* INDEX_PREFIX = "index.pht."; static constexpr const char* INDEX_PREFIX = "index.pht.";
static constexpr const size_t MAX_NODE_ENTRY_COUNT {128};
/* This is the maximum number of entries per node. This parameter is
* critical and influences the traffic alot during a lookup operation.
*/
static constexpr const size_t MAX_NODE_ENTRY_COUNT {16};
public: public:
using Key = std::map<std::string, Prefix>; using Key = std::map<std::string, Prefix>;
...@@ -180,7 +184,7 @@ private: ...@@ -180,7 +184,7 @@ private:
void lookupStep(Prefix k, std::shared_ptr<int> lo, std::shared_ptr<int> hi, void lookupStep(Prefix k, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals, std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals,
LookupCallback cb, Dht::DoneCallbackSimple done_cb, LookupCallback cb, Dht::DoneCallbackSimple done_cb,
std::shared_ptr<unsigned> max_common_prefix_len); std::shared_ptr<unsigned> max_common_prefix_len, bool all_values = false);
/** /**
* Updates the canary token on the node responsible for the specified * Updates the canary token on the node responsible for the specified
......
...@@ -9,7 +9,7 @@ const ValueType IndexEntry::TYPE = ValueType::USER_DATA; ...@@ -9,7 +9,7 @@ const ValueType IndexEntry::TYPE = ValueType::USER_DATA;
void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals, std::shared_ptr<std::vector<std::shared_ptr<Value>>> vals,
LookupCallback cb, Dht::DoneCallbackSimple done_cb, LookupCallback cb, Dht::DoneCallbackSimple done_cb,
std::shared_ptr<unsigned> max_common_prefix_len) std::shared_ptr<unsigned> max_common_prefix_len, bool all_values)
{ {
struct node_lookup_result { struct node_lookup_result {
bool done {false}; bool done {false};
...@@ -27,20 +27,21 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, ...@@ -27,20 +27,21 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
} }
else if (is_leaf or *lo > *hi) { else if (is_leaf or *lo > *hi) {
// leaf node // leaf node
if (cb) if (cb) {
if (vals->size() == 0 and max_common_prefix_len and mid > 0) { if (vals->size() == 0 and max_common_prefix_len and mid > 0) {
auto p_ = (p.getPrefix(mid)).getSibling().getFullSize(); auto p_ = (p.getPrefix(mid)).getSibling().getFullSize();
*lo = mid; *lo = mid;
*hi = p_.size_; *hi = p_.size_;
lookupStep(p_, lo, hi, vals, cb, done_cb, max_common_prefix_len); lookupStep(p_, lo, hi, vals, cb, done_cb, max_common_prefix_len, all_values);
} }
cb(*vals, p.getPrefix(mid)); cb(*vals, p.getPrefix(mid));
}
if (done_cb) if (done_cb)
done_cb(true); done_cb(true);
} else if (first_res->is_pht) { } else if (first_res->is_pht) {
// internal node // internal node
*lo = mid+1; *lo = mid+1;
lookupStep(p, lo, hi, vals, cb, done_cb, max_common_prefix_len); lookupStep(p, lo, hi, vals, cb, done_cb, max_common_prefix_len, all_values);
} else { } else {
// first get failed before second. // first get failed before second.
if (done_cb) if (done_cb)
...@@ -77,7 +78,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, ...@@ -77,7 +78,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
} }
} }
} }
else if (entry.prefix == p.content_) else if (all_values or entry.prefix == p.content_)
add_value(false); add_value(false);
} }
return true; return true;
...@@ -95,7 +96,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, ...@@ -95,7 +96,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
if (not first_res->is_pht) { if (not first_res->is_pht) {
// Not a PHT node. // Not a PHT node.
*hi = mid-1; *hi = mid-1;
lookupStep(p, lo, hi, vals, cb, done_cb, max_common_prefix_len); lookupStep(p, lo, hi, vals, cb, done_cb, max_common_prefix_len, all_values);
} else { } else {
first_res->done = true; first_res->done = true;
if (second_res->done) if (second_res->done)
...@@ -172,7 +173,7 @@ void Pht::insert(Key k, Value v, Dht::DoneCallbackSimple done_cb) { ...@@ -172,7 +173,7 @@ void Pht::insert(Key k, Value v, Dht::DoneCallbackSimple done_cb) {
if (done_cb) if (done_cb)
done_cb(false); done_cb(false);
} else { } else {
if (vals->size() > MAX_NODE_ENTRY_COUNT) if (vals->size() >= MAX_NODE_ENTRY_COUNT)
*final_prefix = kp.getPrefix(final_prefix->size_+1); *final_prefix = kp.getPrefix(final_prefix->size_+1);
IndexEntry entry; IndexEntry entry;
...@@ -183,7 +184,7 @@ void Pht::insert(Key k, Value v, Dht::DoneCallbackSimple done_cb) { ...@@ -183,7 +184,7 @@ void Pht::insert(Key k, Value v, Dht::DoneCallbackSimple done_cb) {
updateCanary(*final_prefix); updateCanary(*final_prefix);
dht_->put(final_prefix->hash(), std::move(entry), done_cb); dht_->put(final_prefix->hash(), std::move(entry), done_cb);
} }
}, nullptr }, nullptr, true
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment