mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 05:04:56 +09:00
Compute number of replicas needed to commit a log record
This commit is contained in:
1 parent
1df842f43c
commit
10f014db10
4 files changed
+21
-78
No files matched your search
@@ -91,15 +91,6 @@ public:
|
||||
*/
|
||||
void replicate_log(ReplicaRequest * rr);
|
||||
|
||||
/**
|
||||
* Allocate a replica request fot the given index.
|
||||
* @param rindex of the record for the request
|
||||
*/
|
||||
void replicate_allocate(int rindex)
|
||||
{
|
||||
requests.allocate(rindex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizes the Raft Consensus Manager
|
||||
*/
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
std::map<int, ReplicaRequest *>::iterator it = requests.find(rindex);
|
||||
|
||||
if ( it != requests.end() && it->second != 0 )
|
||||
if ( it != requests.end() )
|
||||
{
|
||||
it->second->add_replica();
|
||||
|
||||
@@ -152,25 +152,6 @@ public:
|
||||
return to_commit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocated an empty replica request. It marks a writer thread will wait
|
||||
* on this request.
|
||||
* @param rindex of the request
|
||||
*/
|
||||
void allocate(int rindex)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
std::map<int, ReplicaRequest *>::iterator it = requests.find(rindex);
|
||||
|
||||
if ( it == requests.end() )
|
||||
{
|
||||
requests.insert(std::make_pair(rindex, (ReplicaRequest*) 0));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the replication request associated to this index. If there is no
|
||||
* previous request associated to the index it is created.
|
||||
@@ -187,28 +168,6 @@ public:
|
||||
{
|
||||
requests.insert(std::make_pair(rindex, rr));
|
||||
}
|
||||
else if ( it->second == 0 )
|
||||
{
|
||||
it->second = rr;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a replication request associated to this index
|
||||
* @param rindex of the request
|
||||
*/
|
||||
void remove(int rindex)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
std::map<int, ReplicaRequest *>::iterator it = requests.find(rindex);
|
||||
|
||||
if ( it != requests.end() )
|
||||
{
|
||||
requests.erase(it);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
@@ -248,28 +207,18 @@ public:
|
||||
*/
|
||||
bool need_replica(int db_index, int rindex)
|
||||
{
|
||||
if ( db_index <= rindex )
|
||||
bool rc = false;
|
||||
|
||||
if ( db_index > rindex )
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
std::map<int,ReplicaRequest *>::iterator it = requests.find(rindex + 1);
|
||||
|
||||
bool rc = true;
|
||||
|
||||
if ( it != requests.end() && it->second == 0 )
|
||||
{
|
||||
rc = false;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
/**
|
||||
|
||||
+15
-6
@@ -581,13 +581,24 @@ void RaftManager::replicate_log(ReplicaRequest * request)
|
||||
{
|
||||
request->notify();
|
||||
|
||||
requests.remove(request->index());
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( num_servers <= 1 )
|
||||
//Count servers that need to replicate this record
|
||||
int to_commit = num_servers / 2;
|
||||
|
||||
std::map<int, unsigned int>::iterator it;
|
||||
|
||||
for (it = next.begin(); it != next.end() && to_commit > 0; ++it)
|
||||
{
|
||||
if ( request->index() < (int) it->second )
|
||||
{
|
||||
to_commit--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( to_commit <= 0 )
|
||||
{
|
||||
request->notify();
|
||||
|
||||
@@ -595,12 +606,10 @@ void RaftManager::replicate_log(ReplicaRequest * request)
|
||||
request->timeout = false;
|
||||
|
||||
commit = request->index();
|
||||
|
||||
requests.remove(request->index());
|
||||
}
|
||||
else
|
||||
{
|
||||
request->to_commit(num_servers / 2 );
|
||||
request->to_commit(to_commit);
|
||||
|
||||
requests.set(request->index(), request);
|
||||
}
|
||||
|
||||
@@ -407,12 +407,6 @@ int LogDB::insert_log_record(unsigned int term, std::ostringstream& sql,
|
||||
return -1;
|
||||
}
|
||||
|
||||
//allocate a replication request if log record is going to be replicated
|
||||
if ( timestamp == 0 )
|
||||
{
|
||||
Nebula::instance().get_raftm()->replicate_allocate(next_index);
|
||||
}
|
||||
|
||||
last_index = next_index;
|
||||
|
||||
last_term = term;
|
||||
|
||||
Reference in new issue
Block a user