Revision 0a2f18a7 src/raft/ReplicaThread.cc

View differences:

src/raft/ReplicaThread.cc
216 216

  
217 217
    frm = nd.get_frm();
218 218
};
219

  
219 220
// -----------------------------------------------------------------------------
220 221
// -----------------------------------------------------------------------------
221 222

  
222

  
223 223
int FedReplicaThread::replicate()
224 224
{
225 225
    std::string error;
......
246 246
    return 0;
247 247
}
248 248

  
249
// -----------------------------------------------------------------------------
250
// -----------------------------------------------------------------------------
251

  
252
HeartBeatThread::HeartBeatThread(int fid):ReplicaThread(fid), last_error(0),
253
    num_errors(0)
254
{
255
    Nebula& nd = Nebula::instance();
256

  
257
    raftm = nd.get_raftm();
258
};
259

  
260
// -----------------------------------------------------------------------------
261
// -----------------------------------------------------------------------------
262

  
263
int HeartBeatThread::replicate()
264
{
265
    int rc;
266

  
267
	bool success;
268

  
269
	std::string error;
270

  
271
	unsigned int fterm;
272
    unsigned int term  = raftm->get_term();
273

  
274
	LogDBRecord lr;
275

  
276
	lr.index = 0;
277
	lr.prev_index = 0;
278

  
279
	lr.term = 0;
280
	lr.prev_term = 0;
281

  
282
	lr.sql = "";
283

  
284
	lr.timestamp = 0;
285

  
286
    rc = raftm->xmlrpc_replicate_log(follower_id, &lr, success, fterm, error);
287

  
288
    if ( rc == -1 )
289
    {
290
        num_errors++;
291

  
292
        if ( last_error == 0 )
293
        {
294
            last_error = time(0);
295
            num_errors = 1;
296
        }
297
        else if ( last_error + 60 < time(0) )
298
        {
299
            if ( num_errors > 10 )
300
            {
301
                std::ostringstream oss;
302

  
303
                oss << "Detetected error condition on follower "
304
                    << follower_id <<". Last error was: " << error;
305

  
306
                NebulaLog::log("RCM", Log::INFO, oss);
307
            }
308

  
309
            last_error = 0;
310
        }
311
    }
312
    else if ( success == false && fterm > term )
313
    {
314
        std::ostringstream oss;
315

  
316
        oss << "Follower " << follower_id << " term (" << fterm
317
            << ") is higher than current (" << term << ")";
318

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

  
321
        raftm->follower(fterm);
322
    }
323

  
324
    return 0;
325
}
326

  

Also available in: Unified diff