@@ -392,7 +392,6 @@ bool InfluxDBClient::writeRecord(String &record) {
392
392
_batchPointer = 0 ;
393
393
}
394
394
}
395
- INFLUXDB_CLIENT_DEBUG (" [D] writeRecord: bufferPointer: %d, batchPointer: %d\n " , _bufferPointer, _batchPointer);
396
395
if (_writeBuffer[_bufferPointer]->append (record)) { // we reached batch size
397
396
_bufferPointer++;
398
397
if (_bufferPointer == _writeBufferSize) { // writeBuffer is full
@@ -404,7 +403,7 @@ bool InfluxDBClient::writeRecord(String &record) {
404
403
_bufferCeiling++;
405
404
}
406
405
}
407
-
406
+ INFLUXDB_CLIENT_DEBUG ( " [D] writeRecord: bufferPointer: %d, batchPointer: %d, _bufferCeiling: %d \n " , _bufferPointer, _batchPointer, _bufferCeiling);
408
407
return checkBuffer ();
409
408
}
410
409
@@ -421,20 +420,6 @@ bool InfluxDBClient::checkBuffer() {
421
420
return true ;
422
421
}
423
422
424
- void InfluxDBClient::dropCurrentBatch () {
425
- delete _writeBuffer[_batchPointer];
426
- _writeBuffer[_batchPointer] = nullptr ;
427
- _batchPointer++;
428
- // did we got over top?
429
- if (_batchPointer == _writeBufferSize) {
430
- // restart _batchPointer in ring buffer from start
431
- _batchPointer = 0 ;
432
- // we reached buffer size, that means buffer was full and now lower ceiling
433
- _bufferCeiling = _bufferPointer;
434
- }
435
- INFLUXDB_CLIENT_DEBUG (" [D] Droped batch, batchpointer: %d\n " , _batchPointer);
436
- }
437
-
438
423
bool InfluxDBClient::flushBuffer () {
439
424
return flushBufferInternal (false );
440
425
}
@@ -464,8 +449,8 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
464
449
// send all batches, It could happen there was long network outage and buffer is full
465
450
while (_writeBuffer[_batchPointer] && (!flashOnlyFull || _writeBuffer[_batchPointer]->isFull ())) {
466
451
data = _writeBuffer[_batchPointer]->createData ();
467
- if (!_writeBuffer[_batchPointer]->isFull ()) {
468
- // increase _bufferPointer as it happen when buffer is flushed when is full
452
+ if (!_writeBuffer[_batchPointer]->isFull () && _writeBuffer[_batchPointer]-> retryCount == 0 ) { // do not increase pointer in case of retrying
453
+ // points will be written so increase _bufferPointer as it happen when buffer is flushed when is full
469
454
if (++_bufferPointer == _writeBufferSize) {
470
455
_bufferPointer = 0 ;
471
456
}
@@ -483,19 +468,21 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
483
468
_lastFlushed = millis ()/1000 ;
484
469
dropCurrentBatch ();
485
470
} else if (retry) {
486
- _writeBuffer[_batchPointer]->retryCount ++;
487
- if (_writeBuffer[_batchPointer]->retryCount > _writeOptions._maxRetryAttempts ) {
488
- INFLUXDB_CLIENT_DEBUG (" [D] Reached max retry count, dropping batch\n " );
489
- dropCurrentBatch ();
490
- }
491
- if (!_lastRetryAfter && statusCode > 0 ) {
492
- _lastRetryAfter = _writeOptions._retryInterval ;
493
- if (_writeBuffer[_batchPointer]) {
494
- for (int i=1 ;i<_writeBuffer[_batchPointer]->retryCount ;i++) {
495
- _lastRetryAfter *= _writeOptions._retryInterval ;
496
- }
497
- if (_lastRetryAfter > _writeOptions._maxRetryInterval ) {
498
- _lastRetryAfter = _writeOptions._maxRetryInterval ;
471
+ if (statusCode > 0 ) { // apply retry strategy only in case of HTTP errors
472
+ _writeBuffer[_batchPointer]->retryCount ++;
473
+ if (_writeBuffer[_batchPointer]->retryCount > _writeOptions._maxRetryAttempts ) {
474
+ INFLUXDB_CLIENT_DEBUG (" [D] Reached max retry count, dropping batch\n " );
475
+ dropCurrentBatch ();
476
+ }
477
+ if (!_lastRetryAfter) {
478
+ _lastRetryAfter = _writeOptions._retryInterval ;
479
+ if (_writeBuffer[_batchPointer]) {
480
+ for (int i=1 ;i<_writeBuffer[_batchPointer]->retryCount ;i++) {
481
+ _lastRetryAfter *= _writeOptions._retryInterval ;
482
+ }
483
+ if (_lastRetryAfter > _writeOptions._maxRetryInterval ) {
484
+ _lastRetryAfter = _writeOptions._maxRetryInterval ;
485
+ }
499
486
}
500
487
}
501
488
}
@@ -507,18 +494,31 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
507
494
yield ();
508
495
}
509
496
// Have we emptied the buffer?
510
- if (success) {
511
- if (_batchPointer == _bufferPointer && !_writeBuffer[_bufferPointer]) {
512
- _bufferPointer = 0 ;
513
- _batchPointer = 0 ;
514
- _bufferCeiling = 0 ;
515
- INFLUXDB_CLIENT_DEBUG (" [D] Buffer empty\n " );
516
- }
497
+ INFLUXDB_CLIENT_DEBUG (" [D] Success: %d, _bufferPointer: %d, _batchPointer: %d, _writeBuffer[_bufferPointer]_%x\n " ,success,_bufferPointer,_batchPointer, _writeBuffer[_bufferPointer]);
498
+ if (_batchPointer == _bufferPointer && !_writeBuffer[_bufferPointer]) {
499
+ _bufferPointer = 0 ;
500
+ _batchPointer = 0 ;
501
+ _bufferCeiling = 0 ;
502
+ INFLUXDB_CLIENT_DEBUG (" [D] Buffer empty\n " );
517
503
}
518
504
return success;
519
505
}
520
506
521
507
508
+ void InfluxDBClient::dropCurrentBatch () {
509
+ delete _writeBuffer[_batchPointer];
510
+ _writeBuffer[_batchPointer] = nullptr ;
511
+ _batchPointer++;
512
+ // did we got over top?
513
+ if (_batchPointer == _writeBufferSize) {
514
+ // restart _batchPointer in ring buffer from start
515
+ _batchPointer = 0 ;
516
+ // we reached buffer size, that means buffer was full and now lower ceiling
517
+ _bufferCeiling = _bufferPointer;
518
+ }
519
+ INFLUXDB_CLIENT_DEBUG (" [D] Droped batch, batchpointer: %d\n " , _batchPointer);
520
+ }
521
+
522
522
bool InfluxDBClient::validateConnection () {
523
523
if (!_wifiClient && !init ()) {
524
524
_lastStatusCode = 0 ;
0 commit comments