Revision 0c8299f1 src/logdb/LogDBManager.cc

View differences:

src/logdb/LogDBManager.cc
243 243

  
244 244
        while ( _pending_requests == false )
245 245
        {
246
            pthread_cond_wait(&cond,&mutex);
246
            pthread_cond_wait(&cond, &mutex);
247 247

  
248 248
            if ( _finalize )
249 249
            {
......
255 255

  
256 256
        pthread_mutex_unlock(&mutex);
257 257

  
258
        // ---------------------------------------------------------------------
259
        // Get parameters to call append entries on follower
260
        // ---------------------------------------------------------------------
258 261
        Zone * zone = zpool->get(zone_id, true);
259 262

  
260 263
        if ( zone == 0 )
......
303 306

  
304 307
        ostringstream oss;
305 308

  
309
        // ---------------------------------------------------------------------
310
        // Send log entry to follower
311
        // ---------------------------------------------------------------------
306 312
        oss << "Replicating log entry " << id << "-" << term << " on server: "
307 313
            << follower_id << " (" << follower_edp <<")";
308 314

  
......
338 344

  
339 345
                if ( success )
340 346
                {
347
                    // ---------------------------------------------------------
348
                    // Log entry replicated on follower
349
                    // - Increment next entry to send to follower
350
                    // - Update match entry on follower
351
                    // - Evaluate majority to apply changes to DB
352
                    // ---------------------------------------------------------
341 353
                    zone = zpool->get(zone_id, true);
342 354

  
343 355
                    if ( zone == 0 )
......
346 358
                    }
347 359

  
348 360
                    ZoneServer * follower = zone->get_server(follower_id);
361
                    ZoneServer * leader   = zone->get_server(leader_id);
349 362

  
350 363
                    if ( follower == 0 )
351 364
                    {
......
358 371

  
359 372
                    follower->set_match(id);
360 373

  
374
                    if ( leader->get_applied() > follower->get_next() )
375
                    {
376
                        _pending_requests = true;
377
                    }
378

  
361 379
                    zone->unlock();
362 380

  
363 381
                    LogDBRequest * lr = logdb->get_request(id);
364 382

  
365 383
                    if ( lr == 0 )
366 384
                    {
385
                        oss.str("");
386

  
367 387
                        lr->lock();
368 388

  
389
                        oss << "Log entry " << id << "-" << term << "replicated"
390
                            << " on server: " << follower_id << ". Total "
391
                            << "replicas: " << lr->replicas() << " Replicas to "
392
                            << "majority: " << lr->to_commit();
393

  
369 394
                        lr->replicated();
370 395

  
371 396
                        lr->unlock();
......
377 402

  
378 403
                    if ( follower_term > term )
379 404
                    {
380
                        //Convert to follower
381
                        // - Update term
382
                        // - Set state to follower
383
                        // - Stop replica threads
405
                        //------------------------------------------------------
406
                        // Convert to follower
407
                        //   - Update term
408
                        //   - Set state to follower
409
                        //   - Stop replica threads
410
                        //------------------------------------------------------
384 411
                        ostringstream ess;
385 412

  
386 413
                        ess << "Detected a higher term on follower: "
......
390 417
                    }
391 418
                    else
392 419
                    {
393
                        //Log inconsistency in follower
394
                        // - Decrease follower index
395
                        // - Retry
420
                        //------------------------------------------------------
421
                        // Log inconsistency in follower
422
                        //   - Decrease follower index
423
                        //   - Retry (do not wait for replica events)
424
                        //------------------------------------------------------
396 425
                        ostringstream ess;
397 426

  
398 427
                        ess << "Log inconsistency detected on follower: "

Also available in: Unified diff