public class DefaultConfigurationProvider extends Object implements ConfigurationProvider
ConfigurationProvider
that is used by default.
This provider has been around since the 1.x days, but it has been revamped and reworked for the 2.x breakage - the overall functionality remains very similar though.
Modifier and Type | Class and Description |
---|---|
static class |
DefaultConfigurationProvider.AlternateAddressHolder
This class is needed since both port info and node info need to be abstracted for alternate address resolving.
|
TRIGGERED_BY_CONFIG_CHANGE_NOTIFICATION
Constructor and Description |
---|
DefaultConfigurationProvider(Core core,
Set<SeedNode> seedNodes) |
DefaultConfigurationProvider(Core core,
Set<SeedNode> seedNodes,
ConnectionString connectionString)
Creates a new configuration provider.
|
Modifier and Type | Method and Description |
---|---|
boolean |
bucketConfigLoadInProgress()
Returns true if a bucket config load attempt is in progress.
|
Mono<Void> |
closeBucket(String name,
boolean pushConfig)
Initiates the bucket closing process.
|
CollectionMap |
collectionMap()
Returns the attached collection map.
|
boolean |
collectionRefreshInProgress()
Returns true while a collection refresh is in progress at all.
|
boolean |
collectionRefreshInProgress(CollectionIdentifier identifier)
Returns true if a collection refresh is in progress for the given identifier.
|
ClusterConfig |
config()
Returns the current
ClusterConfig . |
Flux<Long> |
configChangeNotifications()
Returns a feed that emits -1L
whenever someone calls
ConfigurationProvider.signalConfigChanged() . |
Flux<ClusterConfig> |
configs()
This is a hot stream which when attached will return the current config as well as
all subsequent ones.
|
static String |
determineNetworkResolution(List<DefaultConfigurationProvider.AlternateAddressHolder> nodes,
NetworkResolution nr,
Set<String> seedHosts)
Helper method to figure out which network resolution should be used.
|
static List<DefaultConfigurationProvider.AlternateAddressHolder> |
extractAlternateAddressInfos(ClusterConfig config)
Helper method to turn either the port info or the node info into a list of hosts to use for the
alternate address resolution.
|
boolean |
globalConfigLoadInProgress()
Returns true if an initial global config load attempt is in progress.
|
Mono<Void> |
loadAndRefreshGlobalConfig()
Instructs the provider to try and load the global config, and then manage it.
|
protected Mono<ProposedBucketConfigContext> |
loadBucketConfigForSeed(NodeIdentifier identifier,
int mappedKvPort,
int mappedManagerPort,
String name,
Optional<String> alternateAddress)
Encapsulates the logic to load the bucket config from kv and then fall back to manager.
|
Mono<Void> |
openBucket(String name)
Initiates the bucket opening process.
|
protected List<String> |
performDnsSrvLookup(boolean tlsEnabled)
Performs DNS SRV lookups - and can be overridden by test classes.
|
void |
proposeBucketConfig(ProposedBucketConfigContext ctx)
Allows to propose a bucket config to the provider from an external context.
|
void |
proposeGlobalConfig(ProposedGlobalConfigContext ctx)
Allows to propose a global config to the provider from an external context.
|
void |
refreshCollectionId(CollectionIdentifier identifier)
Helper method to refresh the collection map for the given collection.
|
protected Mono<Void> |
registerRefresher(String bucket)
Registers the given bucket for refreshing.
|
void |
republishCurrentConfig()
Shouldn't be necessary, but gives
InvalidStateWatchdog something to do. |
Flux<Set<SeedNode>> |
seedNodes()
Returns a stream of seed node sets sourced from the server's global config or bucket config.
|
Mono<Void> |
shutdown()
Shuts down the configuration provider and all its associated resources and timers.
|
void |
signalConfigChanged()
Signals to the config provider that the server sent a notification
that the cluster topology or bucket config changed.
|
void |
signalConfigRefreshFailed(ConfigRefreshFailure failure)
Signals to the config provider that certain types of config refreshes failed and action might need to be taken.
|
public DefaultConfigurationProvider(Core core, Set<SeedNode> seedNodes)
public DefaultConfigurationProvider(Core core, Set<SeedNode> seedNodes, ConnectionString connectionString)
core
- the core against which all ops are executed.public CollectionMap collectionMap()
ConfigurationProvider
collectionMap
in interface ConfigurationProvider
public Flux<ClusterConfig> configs()
ConfigurationProvider
configs
in interface ConfigurationProvider
public ClusterConfig config()
ConfigurationProvider
ClusterConfig
.config
in interface ConfigurationProvider
public Flux<Set<SeedNode>> seedNodes()
ConfigurationProvider
Only nodes running the KV service are present in the set.
This is a hot stream which when attached will return the current set of seed nodes as well as all subsequent sets. The returned Flux does not emit any items until the client has received at least one config from the server.
seedNodes
in interface ConfigurationProvider
public Mono<Void> openBucket(String name)
ConfigurationProvider
Note that when this mono completes, it does not mean that the process is completely finished yet, just that it has been initiated and no hard error has been found at the time.
openBucket
in interface ConfigurationProvider
name
- the name of the bucket to open.protected Mono<ProposedBucketConfigContext> loadBucketConfigForSeed(NodeIdentifier identifier, int mappedKvPort, int mappedManagerPort, String name, Optional<String> alternateAddress)
This method can be overridden in tests to simulate various states/errors from the loaders.
identifier
- the identifier to load it from.mappedKvPort
- the port of the kv loader.mappedManagerPort
- the port for the manager.name
- the name of the bucket.alternateAddress
- the alternate address, if present.public Mono<Void> loadAndRefreshGlobalConfig()
ConfigurationProvider
loadAndRefreshGlobalConfig
in interface ConfigurationProvider
public void proposeBucketConfig(ProposedBucketConfigContext ctx)
ConfigurationProvider
This method is usually only called when a "not my vbucket" response is received and the corresponding config is extracted. Do not call this method with arbitrary configs.
proposeBucketConfig
in interface ConfigurationProvider
ctx
- the bucket config and surrounding context.public void proposeGlobalConfig(ProposedGlobalConfigContext ctx)
ConfigurationProvider
proposeGlobalConfig
in interface ConfigurationProvider
ctx
- the context with the global config.public Mono<Void> closeBucket(String name, boolean pushConfig)
ConfigurationProvider
closeBucket
in interface ConfigurationProvider
name
- the name of the bucket.pushConfig
- whether this should result in a config being pushed. Not needed during e.g. shutdown.public Mono<Void> shutdown()
ConfigurationProvider
shutdown
in interface ConfigurationProvider
public void refreshCollectionId(CollectionIdentifier identifier)
ConfigurationProvider
refreshCollectionId
in interface ConfigurationProvider
identifier
- the identifier to refresh.public boolean collectionRefreshInProgress()
ConfigurationProvider
collectionRefreshInProgress
in interface ConfigurationProvider
public boolean collectionRefreshInProgress(CollectionIdentifier identifier)
ConfigurationProvider
collectionRefreshInProgress
in interface ConfigurationProvider
identifier
- the collection identifier to check.public static List<DefaultConfigurationProvider.AlternateAddressHolder> extractAlternateAddressInfos(ClusterConfig config)
public static String determineNetworkResolution(List<DefaultConfigurationProvider.AlternateAddressHolder> nodes, NetworkResolution nr, Set<String> seedHosts)
If DEFAULT is selected, then null is returned which is equal to the "internal" or default config mode. If AUTO is used then we perform the select heuristic based off of the seed hosts given. All other resolution settings (i.e. EXTERNAL) are returned directly and are considered to be part of the alternate address configs.
nodes
- the list of nodes to check.nr
- the network resolution setting from the environmentseedHosts
- the seed hosts from bootstrap for autoconfig.public void republishCurrentConfig()
ConfigurationProvider
InvalidStateWatchdog
something to do.republishCurrentConfig
in interface ConfigurationProvider
protected Mono<Void> registerRefresher(String bucket)
Note that this changes the implementation from the 1.x series a bit. In the past, whatever loader succeeded automatically registered the same type of refresher. This is still the case for situations like a memcache bucket, but in cases where we bootstrap from i.e. a query node only the manager loader will work but we'll be able to use the key value refresher going forward.
As a result, this method is a bit more intelligent in selecting the right refresher based on the loaded configuration.
bucket
- the name of the bucket.Mono
once registered.public boolean globalConfigLoadInProgress()
ConfigurationProvider
globalConfigLoadInProgress
in interface ConfigurationProvider
public boolean bucketConfigLoadInProgress()
ConfigurationProvider
bucketConfigLoadInProgress
in interface ConfigurationProvider
public void signalConfigRefreshFailed(ConfigRefreshFailure failure)
ConfigurationProvider
signalConfigRefreshFailed
in interface ConfigurationProvider
failure
- the type of config refresh failure.public void signalConfigChanged()
ConfigurationProvider
signalConfigChanged
in interface ConfigurationProvider
public Flux<Long> configChangeNotifications()
ConfigurationProvider
ConfigurationProvider.signalConfigChanged()
.configChangeNotifications
in interface ConfigurationProvider
protected List<String> performDnsSrvLookup(boolean tlsEnabled) throws NamingException
NamingException
Copyright © 2024 Couchbase, Inc.. All rights reserved.