Search in sources :

Example 1 with PullerRetriesExhaustedException

use of com.linkedin.databus.core.PullerRetriesExhaustedException in project databus by linkedin.

the class RelayPullThread method doPickRelay.

protected void doPickRelay(ConnectionState curState) {
    int serversNum = _servers.size();
    if (0 == serversNum) {
        enqueueMessage(LifecycleMessage.createSuspendOnErroMessage(new DatabusException("No relays specified")));
        return;
    }
    Random rng = new Random();
    DatabusRelayConnection relayConn = null;
    ServerInfo serverInfo = null;
    int retriesLeft;
    BackoffTimer originalCounter = _status.getRetriesCounter();
    if (curState.isRelayFellOff())
        _status.setRetriesCounter(_retriesOnFallOff);
    while (null == relayConn && (retriesLeft = _status.getRetriesLeft()) >= 0 && !checkForShutdownRequest()) {
        _log.info("picking a relay; retries left:" + retriesLeft + ", Backoff Timer :" + _status.getRetriesCounter() + ", Are we retrying because of SCNNotFoundException : " + curState.isRelayFellOff());
        backoffOnPullError();
        _curServerIdx = (_curServerIdx < 0) ? rng.nextInt(serversNum) : (_curServerIdx + 1) % serversNum;
        Iterator<ServerInfo> setIter = _servers.iterator();
        for (int i = 0; i <= _curServerIdx; ++i) serverInfo = setIter.next();
        try {
            relayConn = _sourcesConn.getRelayConnFactory().createRelayConnection(serverInfo, this, _remoteExceptionHandler);
            _log.info("picked a relay:" + serverInfo.toSimpleString());
        } catch (Exception e) {
            _log.error("Unable to get connection to relay:" + serverInfo.toSimpleString(), e);
        }
    }
    _status.setRetriesCounter(originalCounter);
    if (!checkForShutdownRequest()) {
        _curServer = serverInfo;
        if (null == relayConn) {
            if (_currentState.isRelayFellOff()) {
                boolean enqueueMessage = false;
                try {
                    enqueueMessage = onRelayFellOff(curState, curState.getCheckpoint(), new ScnNotFoundException("Retries on SCNNotFoundException exhausted !!"));
                } catch (InterruptedException ie) {
                    _log.error("interrupted while processing onRelayFellOff", ie);
                    curState.switchToPickServer();
                    enqueueMessage(curState);
                } catch (InvalidEventException e) {
                    _log.error("error trying to notify dispatcher of bootstrapping :" + e.getMessage(), e);
                    curState.switchToPickServer();
                    enqueueMessage(curState);
                }
                if (enqueueMessage)
                    enqueueMessage(curState);
            } else {
                // There are no retries left. Invoke an onError callback
                try {
                    _log.info("Puller retries exhausted. Injecting an error event on dispatcher queue to invoke onError callback");
                    _remoteExceptionHandler.handleException(new PullerRetriesExhaustedException());
                } catch (InterruptedException ie) {
                    _log.error("Interrupted while processing retries exhausted", ie);
                } catch (InvalidEventException e) {
                    _log.error("Error trying to notify dispatcher of puller retries getting exhausted", e);
                }
                _log.error("Cannot find a relay");
            }
        } else {
            DatabusRelayConnection oldRelayConn = curState.getRelayConnection();
            if (null != oldRelayConn) {
                resetConnectionAndSetFlag();
            }
            sendHeartbeat(_sourcesConn.getUnifiedClientStats());
            _log.info("Relay Puller switching to request sources");
            curState.switchToRequestSources(serverInfo, serverInfo.getAddress(), relayConn);
            _lastOpenConnection = relayConn;
            enqueueMessage(curState);
        }
    }
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) Checkpoint(com.linkedin.databus.core.Checkpoint) InvalidEventException(com.linkedin.databus.core.InvalidEventException) ScnNotFoundException(com.linkedin.databus.core.ScnNotFoundException) PendingEventTooLargeException(com.linkedin.databus.core.PendingEventTooLargeException) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) DatabusException(com.linkedin.databus2.core.DatabusException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException) BackoffTimer(com.linkedin.databus2.core.BackoffTimer) DatabusException(com.linkedin.databus2.core.DatabusException) Random(java.util.Random) ScnNotFoundException(com.linkedin.databus.core.ScnNotFoundException) InvalidEventException(com.linkedin.databus.core.InvalidEventException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException)

Example 2 with PullerRetriesExhaustedException

use of com.linkedin.databus.core.PullerRetriesExhaustedException in project databus by linkedin.

the class RemoteExceptionHandler method suspendConnectionOnError.

private void suspendConnectionOnError(Throwable exception) throws InvalidEventException, InterruptedException {
    // suspend pull threads
    _sourcesConn.getConnectionStatus().suspendOnError(exception);
    // send an error event to dispatcher through dbusEventBuffer
    DbusEventInternalReadable errorEvent = null;
    if (exception instanceof BootstrapDatabaseTooOldException) {
        errorEvent = _eventFactory.createErrorEvent(new DbusErrorEvent(exception, DbusEventInternalWritable.BOOTSTRAPTOOOLD_ERROR_SRCID));
    } else if (exception instanceof PullerRetriesExhaustedException) {
        errorEvent = _eventFactory.createErrorEvent(new DbusErrorEvent(exception, DbusEventInternalWritable.PULLER_RETRIES_EXPIRED));
    } else {
        throw new InvalidEventException("Got an unrecognizable exception ");
    }
    byte[] errorEventBytes = new byte[errorEvent.getRawBytes().limit()];
    if (LOG.isDebugEnabled()) {
        LOG.debug("error event size: " + errorEventBytes.length);
        LOG.debug("error event:" + errorEvent.toString());
    }
    errorEvent.getRawBytes().get(errorEventBytes);
    ByteArrayInputStream errIs = new ByteArrayInputStream(errorEventBytes);
    ReadableByteChannel errRbc = Channels.newChannel(errIs);
    boolean success = false;
    int retryCounter = 0;
    while (!success && retryCounter < 10) {
        String errMsg = "Sending an internal system event to dispatcher. Retry count = " + retryCounter;
        DbusPrettyLogUtils.logExceptionAtInfo(errMsg, exception, LOG);
        success = _dbusEventBuffer.readEvents(errRbc) > 0 ? true : false;
        if (!success) {
            LOG.warn("Unable to send an internal system event to dispatcher. Will retry later " + retryCounter);
            retryCounter++;
            Thread.sleep(1000);
        }
    }
}
Also used : BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ReadableByteChannel(java.nio.channels.ReadableByteChannel) ChunkedBodyReadableByteChannel(com.linkedin.databus.client.ChunkedBodyReadableByteChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) DbusEventInternalReadable(com.linkedin.databus.core.DbusEventInternalReadable) DbusErrorEvent(com.linkedin.databus.core.DbusErrorEvent) InvalidEventException(com.linkedin.databus.core.InvalidEventException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException)

Example 3 with PullerRetriesExhaustedException

use of com.linkedin.databus.core.PullerRetriesExhaustedException in project databus by linkedin.

the class RemoteExceptionHandler method getException.

public Throwable getException(ChunkedBodyReadableByteChannel readChannel) {
    Throwable remoteException = null;
    String err = getExceptionName(readChannel);
    if (null != err) {
        // in theory, we shall be reading the actual exception from the read channel.
        if (err.equalsIgnoreCase(ScnNotFoundException.class.getName())) {
            remoteException = new ScnNotFoundException();
        } else if (err.equalsIgnoreCase(BootstrapDatabaseTooOldException.class.getName())) {
            remoteException = new BootstrapDatabaseTooOldException();
        } else if (err.equalsIgnoreCase(PullerRetriesExhaustedException.class.getName())) {
            remoteException = new PullerRetriesExhaustedException();
        } else if (err.equalsIgnoreCase(BootstrapDatabaseTooYoungException.class.getName())) {
            remoteException = new BootstrapDatabaseTooYoungException();
        } else if (err.equalsIgnoreCase(BootstrapDBException.class.getName())) {
            remoteException = new BootstrapDBException();
        } else if (err.equalsIgnoreCase(SQLException.class.getName())) {
            remoteException = new SQLException();
        } else {
            LOG.error("Unexpected remote error received: " + err);
        }
        LOG.info("Remote exception received: " + remoteException);
    }
    return remoteException;
}
Also used : BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) SQLException(java.sql.SQLException) ScnNotFoundException(com.linkedin.databus.core.ScnNotFoundException) BootstrapDBException(com.linkedin.databus2.core.container.request.BootstrapDBException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) PullerRetriesExhaustedException(com.linkedin.databus.core.PullerRetriesExhaustedException)

Aggregations

PullerRetriesExhaustedException (com.linkedin.databus.core.PullerRetriesExhaustedException)3 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)3 InvalidEventException (com.linkedin.databus.core.InvalidEventException)2 ScnNotFoundException (com.linkedin.databus.core.ScnNotFoundException)2 ChunkedBodyReadableByteChannel (com.linkedin.databus.client.ChunkedBodyReadableByteChannel)1 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)1 Checkpoint (com.linkedin.databus.core.Checkpoint)1 DbusErrorEvent (com.linkedin.databus.core.DbusErrorEvent)1 DbusEventInternalReadable (com.linkedin.databus.core.DbusEventInternalReadable)1 PendingEventTooLargeException (com.linkedin.databus.core.PendingEventTooLargeException)1 BackoffTimer (com.linkedin.databus2.core.BackoffTimer)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 BootstrapDBException (com.linkedin.databus2.core.container.request.BootstrapDBException)1 BootstrapDatabaseTooYoungException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 SQLException (java.sql.SQLException)1 Random (java.util.Random)1