1
0
Fork 0

ids need to be sorted in the proper order. zero filling from left

This commit is contained in:
Kaveh Vahedipour 2016-03-31 12:23:07 +02:00
parent cdd76c1b89
commit a0edfe2b8d
4 changed files with 24 additions and 8 deletions

View File

@ -246,8 +246,8 @@ bool Agent::load () {
_spearhead.apply(_state.slices(_last_commit_index+1));
LOG_TOPIC(INFO, Logger::AGENCY) << "Starting spearhead worker.";
_spearhead.start();
_read_db.start();
_spearhead.start(this);
_read_db.start(this);
LOG_TOPIC(INFO, Logger::AGENCY) << "Starting constituent personality.";
_constituent.update(0,0);

View File

@ -27,6 +27,7 @@
#include <velocypack/velocypack-aliases.h>
#include <chrono>
#include <iomanip>
#include <sstream>
#include <thread>
@ -54,7 +55,9 @@ bool State::persist (index_t index, term_t term, id_t lid,
Builder body;
body.add(VPackValue(VPackValueType::Object));
body.add("_key", Value(std::to_string(index)));
std::ostringstream i_str;
i_str << std::setw( 20 ) << std::setfill( '0' ) << index;
body.add("_key", Value(i_str.str()));
body.add("term", Value(term));
body.add("leader", Value((uint32_t)lid));
body.add("request", entry[0]);

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Store.h"
#include "Agent.h"
#include <velocypack/Buffer.h>
#include <velocypack/Iterator.h>
@ -64,14 +65,14 @@ Node::Node (std::string const& name, Node* parent) :
Node::~Node() {}
Slice Node::slice() const {
VPackSlice Node::slice() const {
return (_value.size()==0) ?
Slice("\x00a",&Options::Defaults):Slice(_value.data());
VPackSlice("\x00a",&Options::Defaults):VPackSlice(_value.data());
}
std::string const& Node::name() const {return _node_name;}
Node& Node::operator= (Slice const& slice) { // Assign value (become leaf)
Node& Node::operator= (VPackSlice const& slice) { // Assign value (become leaf)
_children.clear();
_value.reset();
_value.append(reinterpret_cast<char const*>(slice.begin()), slice.byteSize());
@ -193,7 +194,7 @@ bool Node::applies (VPackSlice const& slice) {
if (slice.hasKey("op")) {
std::string oper = slice.get("op").copyString();
Slice const& self = this->slice();
VPackSlice const& self = this->slice();
if (oper == "delete") {
return _parent->removeChild(_node_name);
} else if (oper == "set") { //
@ -508,10 +509,11 @@ void Store::beginShutdown() {
void Store::clearTimeTable () {
for (auto it = _time_table.cbegin(); it != _time_table.cend() ;) {
// Remove expired from front
if (it->first < std::chrono::system_clock::now()) {
it->second->remove();
_time_table.erase(it++);
} else {
break;
}
@ -523,6 +525,11 @@ bool Store::start () {
return true;
}
bool Store::start (Agent* agent) {
_agent = agent;
return start();
}
void Store::run() {
CONDITION_LOCKER(guard, _cv);
while (!this->isStopping()) { // Check timetable and remove overage entries

View File

@ -168,6 +168,8 @@ protected:
};
class Agent;
/// @brief Key value tree
class Store : public Node, public arangodb::Thread {
@ -194,6 +196,8 @@ public:
/// @brief Start thread
bool start ();
bool start (Agent*);
/// @brief Set name
void name (std::string const& name);
@ -216,6 +220,8 @@ private:
/// @brief Read/Write mutex on database
mutable arangodb::Mutex _storeLock;
Agent* _agent;
};