use of com.couchbase.client.core.error.BucketNotFoundDuringLoadException in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method retriesOnBucketNotFoundDuringLoadException.
/**
* Need to make sure that if a bucket is not found during load, we continue retrying the open
* bucket attempts.
*/
@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void retriesOnBucketNotFoundDuringLoadException() {
TestNodeConfig cfg = config().firstNodeWith(Services.KV).get();
Set<SeedNode> seeds = new HashSet<>(Collections.singletonList(SeedNode.create(cfg.hostname(), Optional.of(cfg.ports().get(Services.KV)), Optional.of(cfg.ports().get(Services.MANAGER)))));
SimpleEventBus eventBus = new SimpleEventBus(true);
environment = CoreEnvironment.builder().eventBus(eventBus).build();
core = Core.create(environment, authenticator(), seeds);
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
try {
String bucketName = "this-bucket-does-not-exist";
provider.openBucket(bucketName).subscribe(v -> {
}, e -> assertTrue(e instanceof ConfigException));
waitUntilCondition(() -> eventBus.publishedEvents().stream().anyMatch(p -> p instanceof BucketOpenRetriedEvent));
for (Event event : eventBus.publishedEvents()) {
if (event instanceof BucketOpenRetriedEvent) {
assertEquals(bucketName, ((BucketOpenRetriedEvent) event).bucketName());
assertTrue(event.cause() instanceof BucketNotFoundDuringLoadException);
}
}
} finally {
provider.shutdown().block();
}
}
use of com.couchbase.client.core.error.BucketNotFoundDuringLoadException in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method openBucket.
@Override
public Mono<Void> openBucket(final String name) {
return Mono.defer(() -> {
if (!shutdown.get()) {
bucketConfigLoadInProgress.incrementAndGet();
boolean tls = core.context().environment().securityConfig().tlsEnabled();
int kvPort = tls ? DEFAULT_KV_TLS_PORT : DEFAULT_KV_PORT;
int managerPort = tls ? DEFAULT_MANAGER_TLS_PORT : DEFAULT_MANAGER_PORT;
final Optional<String> alternate = core.context().alternateAddress();
return Flux.range(1, Math.min(MAX_PARALLEL_LOADERS, currentSeedNodes().size())).flatMap(index -> Flux.fromIterable(currentSeedNodes()).take(Math.min(index, currentSeedNodes().size())).last().flatMap(seed -> {
NodeIdentifier identifier = new NodeIdentifier(seed.address(), seed.clusterManagerPort().orElse(DEFAULT_MANAGER_PORT));
final AtomicReference<Map<ServiceType, Integer>> alternatePorts = new AtomicReference<>();
final Optional<String> alternateAddress = alternate.map(a -> mapAlternateAddress(a, seed, tls, alternatePorts));
final int mappedKvPort;
final int mappedManagerPort;
if (alternateAddress.isPresent()) {
Map<ServiceType, Integer> ports = alternatePorts.get();
mappedKvPort = ports.get(ServiceType.KV);
mappedManagerPort = ports.get(ServiceType.MANAGER);
} else {
mappedKvPort = seed.kvPort().orElse(kvPort);
mappedManagerPort = seed.clusterManagerPort().orElse(managerPort);
}
return loadBucketConfigForSeed(identifier, mappedKvPort, mappedManagerPort, name, alternateAddress);
}).retryWhen(Retry.from(companion -> companion.flatMap(rs -> {
final Throwable f = rs.failure();
if (shutdown.get()) {
return Mono.error(new AlreadyShutdownException());
}
if (f instanceof UnsupportedConfigMechanismException) {
return Mono.error(Exceptions.propagate(f));
}
boolean bucketNotFound = f instanceof BucketNotFoundDuringLoadException;
boolean bucketNotReady = f instanceof BucketNotReadyDuringLoadException;
// For bucket not found or not ready wait a bit longer, retry the rest quickly
Duration delay = bucketNotFound || bucketNotReady ? Duration.ofMillis(500) : Duration.ofMillis(1);
eventBus.publish(new BucketOpenRetriedEvent(name, delay, core.context(), f));
return Mono.just(rs.totalRetries()).delayElement(delay, core.context().environment().scheduler());
})))).take(1).switchIfEmpty(Mono.error(new ConfigException("Could not locate a single bucket configuration for bucket: " + name))).map(ctx -> {
proposeBucketConfig(ctx);
return ctx;
}).then(registerRefresher(name)).doOnTerminate(bucketConfigLoadInProgress::decrementAndGet).onErrorResume(t -> closeBucketIgnoreShutdown(name).then(Mono.error(t)));
} else {
return Mono.error(new AlreadyShutdownException());
}
});
}
Aggregations