protected void resetBackoff() { backoff.reset(); }
public HandlerBase(PulsarClientImpl client, String topic) { this.client = client; this.topic = topic; this.backoff = new Backoff(100, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS); STATE_UPDATER.set(this, State.Uninitialized); CLIENT_CNX_UPDATER.set(this, null); }
private synchronized CompletableFuture<Void> closeProducerAsync() { if (producer == null) { STATE_UPDATER.set(this, State.Stopped); return CompletableFuture.completedFuture(null); } CompletableFuture<Void> future = producer.closeAsync(); future.thenRun(() -> { STATE_UPDATER.set(this, State.Stopped); this.producer = null; // deactivate cursor after successfully close the producer this.cursor.setInactive(); }).exceptionally(ex -> { long waitTimeMs = backOff.next(); log.warn( "[{}][{} -> {}] Exception: '{}' occured while trying to close the producer. retrying again in {} s", topicName, localCluster, remoteCluster, ex.getMessage(), waitTimeMs / 1000.0); // BackOff before retrying brokerService.executor().schedule(this::closeProducerAsync, waitTimeMs, TimeUnit.MILLISECONDS); return null; }); return future; }
public synchronized void startProducer() { if (STATE_UPDATER.get(this) == State.Stopping) { long waitTimeMs = backOff.next(); if (log.isDebugEnabled()) { log.debug( backOff.reset(); long waitTimeMs = backOff.next(); log.warn("[{}][{} -> {}] Failed to create remote producer ({}), retrying in {} s", topicName, localCluster, remoteCluster, ex.getMessage(), waitTimeMs / 1000.0);
readFailureBackoff.reduceToHalf();
@Override public void readEntriesFailed(ManagedLedgerException exception, Object ctx) { if (STATE_UPDATER.get(this) != State.Started) { log.info("[{}][{} -> {}] Replicator was stopped while reading entries. Stop reading. Replicator state: {}", topic, localCluster, remoteCluster, STATE_UPDATER.get(this)); return; } // Reduce read batch size to avoid flooding bookies with retries readBatchSize = 1; long waitTimeMillis = readFailureBackoff.next(); if(exception instanceof CursorAlreadyClosedException) { log.error("[{}][{} -> {}] Error reading entries because replicator is already deleted and cursor is already closed {}, ({})", topic, localCluster, remoteCluster, ctx, exception.getMessage(), exception); // replicator is already deleted and cursor is already closed so, producer should also be stopped closeProducerAsync(); return; }else if (!(exception instanceof TooManyRequestsException)) { log.error("[{}][{} -> {}] Error reading entries at {}. Retrying to read in {}s. ({})", topic, localCluster, remoteCluster, ctx, waitTimeMillis / 1000.0, exception.getMessage(), exception); } else { if (log.isDebugEnabled()) { log.debug("[{}][{} -> {}] Throttled by bookies while reading at {}. Retrying to read in {}s. ({})", topic, localCluster, remoteCluster, ctx, waitTimeMillis / 1000.0, exception.getMessage(), exception); } } HAVE_PENDING_READ_UPDATER.set(this, FALSE); brokerService.executor().schedule(this::readMoreEntries, waitTimeMillis, TimeUnit.MILLISECONDS); }
readFailureBackoff.reduceToHalf();
protected void connectionClosed(ClientCnx cnx) { if (CLIENT_CNX_UPDATER.compareAndSet(this, cnx, null)) { if (!isValidStateForReconnection()) { log.info("[{}] [{}] Ignoring reconnection request (state: {})", topic, getHandlerName(), STATE_UPDATER.get(this)); return; } long delayMs = backoff.next(); STATE_UPDATER.set(this, State.Connecting); log.info("[{}] [{}] Closed connection {} -- Will try again in {} s", topic, getHandlerName(), cnx.channel(), delayMs / 1000.0); client.timer().newTimeout(timeout -> { log.warn("[{}] [{}] Reconnecting after timeout", topic, getHandlerName()); grabCnx(); }, delayMs, TimeUnit.MILLISECONDS); } }
readFailureBackoff.reduceToHalf();
protected void reconnectLater(Throwable exception) { CLIENT_CNX_UPDATER.set(this, null); if (!isValidStateForReconnection()) { log.info("[{}] [{}] Ignoring reconnection request (state: {})", topic, getHandlerName(), STATE_UPDATER.get(this)); return; } long delayMs = backoff.next(); log.warn("[{}] [{}] Could not get connection to broker: {} -- Will try again in {} s", topic, getHandlerName(), exception.getMessage(), delayMs / 1000.0); STATE_UPDATER.set(this, State.Connecting); client.timer().newTimeout(timeout -> { log.info("[{}] [{}] Reconnecting after connection was closed", topic, getHandlerName()); grabCnx(); }, delayMs, TimeUnit.MILLISECONDS); }
Consumer c = (Consumer) ctx; long waitTimeMillis = readFailureBackoff.next();
long waitTimeMillis = readFailureBackoff.next();