@@ -392,7 +392,6 @@ bool InfluxDBClient::writeRecord(String &record) {
392392 _batchPointer = 0 ;
393393 }
394394 }
395- INFLUXDB_CLIENT_DEBUG (" [D] writeRecord: bufferPointer: %d, batchPointer: %d\n " , _bufferPointer, _batchPointer);
396395 if (_writeBuffer[_bufferPointer]->append (record)) { // we reached batch size
397396 _bufferPointer++;
398397 if (_bufferPointer == _writeBufferSize) { // writeBuffer is full
@@ -404,7 +403,7 @@ bool InfluxDBClient::writeRecord(String &record) {
404403 _bufferCeiling++;
405404 }
406405 }
407-
406+ INFLUXDB_CLIENT_DEBUG ( " [D] writeRecord: bufferPointer: %d, batchPointer: %d, _bufferCeiling: %d \n " , _bufferPointer, _batchPointer, _bufferCeiling);
408407 return checkBuffer ();
409408}
410409
@@ -421,20 +420,6 @@ bool InfluxDBClient::checkBuffer() {
421420 return true ;
422421}
423422
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-
438423bool InfluxDBClient::flushBuffer () {
439424 return flushBufferInternal (false );
440425}
@@ -464,8 +449,8 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
464449 // send all batches, It could happen there was long network outage and buffer is full
465450 while (_writeBuffer[_batchPointer] && (!flashOnlyFull || _writeBuffer[_batchPointer]->isFull ())) {
466451 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
469454 if (++_bufferPointer == _writeBufferSize) {
470455 _bufferPointer = 0 ;
471456 }
@@ -483,19 +468,21 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
483468 _lastFlushed = millis ()/1000 ;
484469 dropCurrentBatch ();
485470 } 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+ }
499486 }
500487 }
501488 }
@@ -507,18 +494,31 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
507494 yield ();
508495 }
509496 // 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 " );
517503 }
518504 return success;
519505}
520506
521507
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+
522522bool InfluxDBClient::validateConnection () {
523523 if (!_wifiClient && !init ()) {
524524 _lastStatusCode = 0 ;
0 commit comments