Revision 6d61d510 src/raft/RaftManager.cc

View differences:

src/raft/RaftManager.cc
291 291

  
292 292
void RaftManager::add_server(int follower_id, const std::string& endpoint)
293 293
{
294
    std::ostringstream oss;
295

  
294 296
	LogDB * logdb = Nebula::instance().get_logdb();
295 297

  
296 298
	unsigned int log_index, log_term;
......
299 301

  
300 302
	pthread_mutex_lock(&mutex);
301 303

  
304
    if ( state != LEADER )
305
    {
306
        pthread_mutex_unlock(&mutex);
307
        return;
308
    }
309

  
302 310
    num_servers++;
303 311
    servers.insert(std::make_pair(follower_id, endpoint));
304 312

  
......
306 314

  
307 315
	match.insert(std::make_pair(follower_id, 0));
308 316

  
317
    oss << "Starting replication and heartbeat threads for follower: "
318
        << follower_id;
319

  
320
    NebulaLog::log("RCM", Log::INFO, oss);
321

  
309 322
	replica_manager.add_replica_thread(follower_id);
310 323

  
311 324
	heartbeat_manager.add_replica_thread(follower_id);
......
317 330

  
318 331
void RaftManager::delete_server(int follower_id)
319 332
{
333
    std::ostringstream oss;
320 334
    std::map<int, std::string> _servers;
321 335

  
322 336
	pthread_mutex_lock(&mutex);
323 337

  
338
    if ( state != LEADER )
339
    {
340
        pthread_mutex_unlock(&mutex);
341
        return;
342
    }
343

  
324 344
    num_servers--;
325 345
    servers.erase(follower_id);
326 346

  
......
328 348

  
329 349
	match.erase(follower_id);
330 350

  
351
    oss << "Stopping replication and heartbeat threads for follower: "
352
        << follower_id;
353

  
354
    NebulaLog::log("RCM", Log::INFO, oss);
355

  
331 356
	replica_manager.delete_replica_thread(follower_id);
332 357

  
333 358
	heartbeat_manager.delete_replica_thread(follower_id);
......
367 392

  
368 393
    if ( state != CANDIDATE )
369 394
    {
370
        NebulaLog::log("RCM", Log::INFO, "Cannot become leader, no longer "
371
                "candidate");
372

  
373 395
        pthread_mutex_unlock(&mutex);
374

  
375 396
        return;
376 397
    }
377 398

  

Also available in: Unified diff