Search in sources :

Example 1 with ReconfigurationErrorDetectedEvent

use of com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent in project couchbase-jvm-clients by couchbase.

the class Core method reconfigureDisconnectAll.

/**
 * This reconfiguration sequence takes all nodes and disconnects them.
 *
 * <p>This is usually called by the parent {@link #reconfigure()} when all buckets are closed which
 * points to a shutdown/all buckets closed disconnect phase.</p>
 */
private void reconfigureDisconnectAll() {
    long start = System.nanoTime();
    Flux.fromIterable(new ArrayList<>(nodes)).flatMap(Node::disconnect).doOnComplete(nodes::clear).subscribe(v -> {
    }, e -> {
        clearReconfigureInProgress();
        eventBus.publish(new ReconfigurationErrorDetectedEvent(context(), e));
    }, () -> {
        clearReconfigureInProgress();
        eventBus.publish(new ReconfigurationCompletedEvent(Duration.ofNanos(System.nanoTime() - start), coreContext));
    });
}
Also used : SeedNode(com.couchbase.client.core.env.SeedNode) Node(com.couchbase.client.core.node.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReconfigurationErrorDetectedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent) ReconfigurationCompletedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationCompletedEvent)

Example 2 with ReconfigurationErrorDetectedEvent

use of com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent in project couchbase-jvm-clients by couchbase.

the class Core method reconfigure.

/**
 * Reconfigures the SDK topology to align with the current server configuration.
 *
 * <p>When reconfigure is called, it will grab a current configuration and then add/remove
 * nodes/services to mirror the current topology and configuration settings.</p>
 *
 * <p>This is a eventually consistent process, so in-flight operations might still be rescheduled
 * and then picked up later (or cancelled, depending on the strategy). For those coming from 1.x,
 * it works very similar.</p>
 */
private void reconfigure() {
    if (reconfigureInProgress.compareAndSet(false, true)) {
        final ClusterConfig configForThisAttempt = currentConfig;
        if (configForThisAttempt.bucketConfigs().isEmpty() && configForThisAttempt.globalConfig() == null) {
            reconfigureDisconnectAll();
            return;
        }
        final long start = System.nanoTime();
        Flux<BucketConfig> bucketConfigFlux = Flux.just(configForThisAttempt).flatMap(cc -> Flux.fromIterable(cc.bucketConfigs().values()));
        reconfigureBuckets(bucketConfigFlux).then(reconfigureGlobal(configForThisAttempt.globalConfig())).then(Mono.defer(() -> Flux.fromIterable(new ArrayList<>(nodes)).flatMap(n -> maybeRemoveNode(n, configForThisAttempt)).then())).subscribe(v -> {
        }, e -> {
            clearReconfigureInProgress();
            eventBus.publish(new ReconfigurationErrorDetectedEvent(context(), e));
        }, () -> {
            clearReconfigureInProgress();
            eventBus.publish(new ReconfigurationCompletedEvent(Duration.ofNanos(System.nanoTime() - start), coreContext));
        });
    } else {
        moreConfigsPending.set(true);
        eventBus.publish(new ReconfigurationIgnoredEvent(coreContext));
    }
}
Also used : ReconfigurationIgnoredEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationIgnoredEvent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReconfigurationErrorDetectedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent) ReconfigurationCompletedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationCompletedEvent) BucketConfig(com.couchbase.client.core.config.BucketConfig) ClusterConfig(com.couchbase.client.core.config.ClusterConfig)

Aggregations

ReconfigurationCompletedEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationCompletedEvent)2 ReconfigurationErrorDetectedEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ReconfigurationIgnoredEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationIgnoredEvent)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)1 SeedNode (com.couchbase.client.core.env.SeedNode)1 Node (com.couchbase.client.core.node.Node)1