mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 05:04:56 +09:00
Revert "Better sync for DB writters and replication threads"
This reverts commit 66c900e974.
This commit is contained in:
1 parent
66c900e974
commit
5fc8112d7e
4 files changed
+35
-38
No files matched your search
@@ -92,12 +92,12 @@ public:
|
||||
void replicate_log(ReplicaRequest * rr);
|
||||
|
||||
/**
|
||||
* @return true if there is a replication request set (i.e. thread waiting
|
||||
* for the replication)
|
||||
* Allocate a replica request fot the given index.
|
||||
* @param rindex of the record for the request
|
||||
*/
|
||||
bool is_replica_request_set(int rindex)
|
||||
void replicate_allocate(int rindex)
|
||||
{
|
||||
return requests.is_set(rindex);
|
||||
requests.allocate(rindex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+25
-21
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
std::map<int, ReplicaRequest *>::iterator it = requests.find(rindex);
|
||||
|
||||
if ( it != requests.end() )
|
||||
if ( it != requests.end() && it->second != 0 )
|
||||
{
|
||||
it->second->add_replica();
|
||||
|
||||
@@ -152,6 +152,25 @@ 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.
|
||||
@@ -168,6 +187,10 @@ public:
|
||||
{
|
||||
requests.insert(std::make_pair(rindex, rr));
|
||||
}
|
||||
else if ( it->second == 0 )
|
||||
{
|
||||
it->second = rr;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
@@ -218,7 +241,7 @@ public:
|
||||
|
||||
bool rc = true;
|
||||
|
||||
if ( it != requests.end() )
|
||||
if ( it != requests.end() && it->second == 0 )
|
||||
{
|
||||
rc = false;
|
||||
}
|
||||
@@ -228,25 +251,6 @@ public:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a thread is ready and waiting for this request index
|
||||
* (rindex)
|
||||
*/
|
||||
bool is_set(int rindex)
|
||||
{
|
||||
bool ready = false;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
std::map<int, ReplicaRequest *>::iterator it = requests.find(rindex);
|
||||
|
||||
ready = it != requests.end();
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return ready;
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
|
||||
@@ -186,12 +186,6 @@ int RaftReplicaThread::replicate()
|
||||
|
||||
int next_index = raftm->get_next_index(follower_id);
|
||||
|
||||
//Do not trigger the log replication if the DB writer thread is not ready
|
||||
if ( !raftm->is_replica_request_set(next_index) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( logdb->get_log_record(next_index, lr) != 0 )
|
||||
{
|
||||
ostringstream ess;
|
||||
@@ -206,13 +200,6 @@ int RaftReplicaThread::replicate()
|
||||
if ( raftm->xmlrpc_replicate_log(follower_id, &lr, success, follower_term,
|
||||
error) != 0 )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << "Faild to replicate log record at index: " << next_index
|
||||
<< " on follower: " << follower_id << ", error: " << error;
|
||||
|
||||
NebulaLog::log("RCM", Log::DEBUG, oss);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -407,6 +407,12 @@ 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