Search in sources :

Example 1 with RequestInProgressException

use of org.zalando.nakadi.exceptions.runtime.RequestInProgressException in project nakadi by zalando.

the class AbstractZkSubscriptionClient method resetCursors.

@Override
public final void resetCursors(final List<SubscriptionCursorWithoutToken> cursors, final long timeout) throws OperationTimeoutException, ZookeeperException, OperationInterruptedException, RequestInProgressException {
    ZkSubscription<List<String>> sessionsListener = null;
    boolean resetWasAlreadyInitiated = false;
    try {
        // close subscription connections
        getCurator().create().withMode(CreateMode.EPHEMERAL).forPath(resetCursorPath);
        final AtomicBoolean sessionsChanged = new AtomicBoolean(true);
        sessionsListener = subscribeForSessionListChanges(() -> {
            sessionsChanged.set(true);
            synchronized (sessionsChanged) {
                sessionsChanged.notifyAll();
            }
        });
        final long finishAt = System.currentTimeMillis() + timeout;
        while (finishAt > System.currentTimeMillis()) {
            if (sessionsChanged.compareAndSet(true, false)) {
                if (sessionsListener.getData().isEmpty()) {
                    forceCommitOffsets(cursors);
                    return;
                }
            }
            synchronized (sessionsChanged) {
                sessionsChanged.wait(100);
            }
        }
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new OperationInterruptedException("Resetting cursors is interrupted", e);
    } catch (final KeeperException.NodeExistsException e) {
        resetWasAlreadyInitiated = true;
        throw new RequestInProgressException("Cursors reset is already in progress for provided subscription", e);
    } catch (final KeeperException.NoNodeException e) {
        throw new UnableProcessException("Impossible to reset cursors for subscription", e);
    } catch (final Exception e) {
        getLog().error(e.getMessage(), e);
        throw new ZookeeperException("Unexpected problem occurred when resetting cursors", e);
    } finally {
        if (sessionsListener != null) {
            sessionsListener.close();
        }
        try {
            if (!resetWasAlreadyInitiated) {
                getCurator().delete().guaranteed().forPath(resetCursorPath);
            }
        } catch (final Exception e) {
            getLog().error(e.getMessage(), e);
        }
    }
    throw new OperationTimeoutException("Timeout resetting cursors");
}
Also used : RequestInProgressException(org.zalando.nakadi.exceptions.runtime.RequestInProgressException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) RequestInProgressException(org.zalando.nakadi.exceptions.runtime.RequestInProgressException) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationInterruptedException(org.zalando.nakadi.exceptions.runtime.OperationInterruptedException) List(java.util.List) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

IOException (java.io.IOException)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 KeeperException (org.apache.zookeeper.KeeperException)1 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)1 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)1 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)1 OperationInterruptedException (org.zalando.nakadi.exceptions.runtime.OperationInterruptedException)1 OperationTimeoutException (org.zalando.nakadi.exceptions.runtime.OperationTimeoutException)1 RequestInProgressException (org.zalando.nakadi.exceptions.runtime.RequestInProgressException)1 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)1 ZookeeperException (org.zalando.nakadi.exceptions.runtime.ZookeeperException)1