diff options
Diffstat (limited to 'plugins/VNLib.Data.Caching.Providers.VNCache/src')
3 files changed, 23 insertions, 12 deletions
diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/Clustering/ClusterNodeIndex.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/Clustering/ClusterNodeIndex.cs index e9dcbc5..effa4d7 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/Clustering/ClusterNodeIndex.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/Clustering/ClusterNodeIndex.cs @@ -124,7 +124,9 @@ namespace VNLib.Data.Caching.Providers.VNCache.Clustering //Get all discovered nodes CacheNodeAdvertisment[] ads = cluster.DiscoveredNodes.GetAllNodes(); //Just get a random node from the collection for now - return ads.Length > 0 ? ads.SelectRandom() : null; + return ads.Length > 0 + ? ads.SelectRandom() + : null; } ///<inheritdoc/> @@ -145,22 +147,28 @@ namespace VNLib.Data.Caching.Providers.VNCache.Clustering internal string? SerializeNextNode() { CacheNodeAdvertisment? nextNode = GetNextNode(); - return nextNode == null ? null : JsonSerializer.Serialize(nextNode); + return nextNode is not null + ? JsonSerializer.Serialize(nextNode) + : null; } } sealed class RemoteHandler(object RemoteIndex) : IClusterNodeIndex { - private readonly Func<string?> _remoteSerializer = ManagedLibrary.GetMethod<Func<string?>>(RemoteIndex, nameof(LocalHandler.SerializeNextNode), BindingFlags.NonPublic); + private readonly Func<string?> _remoteSerializer + = ManagedLibrary.GetMethod<Func<string?>>(RemoteIndex, nameof(LocalHandler.SerializeNextNode), BindingFlags.NonPublic); - private readonly Func<CancellationToken, Task> _waitTask = ManagedLibrary.GetMethod<Func<CancellationToken, Task>>(RemoteIndex, nameof(WaitForDiscoveryAsync), BindingFlags.Public); + private readonly Func<CancellationToken, Task> _waitTask + = ManagedLibrary.GetMethod<Func<CancellationToken, Task>>(RemoteIndex, nameof(LocalHandler.WaitForDiscoveryAsync), BindingFlags.Public); ///<inheritdoc/> public CacheNodeAdvertisment? GetNextNode() { //Deserialize the next node from the remote index string? nexNode = _remoteSerializer(); - return nexNode == null ? null : JsonSerializer.Deserialize<CacheNodeAdvertisment>(nexNode); + return nexNode is not null + ? JsonSerializer.Deserialize<CacheNodeAdvertisment>(nexNode) + : null; } ///<inheritdoc/> diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs index af12b32..fc4b111 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs @@ -79,7 +79,7 @@ namespace VNLib.Data.Caching.Providers.VNCache public FBMCacheClient(PluginBase plugin, IConfigScope config) : this( config.Deserialze<VnCacheClientConfig>(), - plugin.IsDebug() ? plugin.Log : null, + plugin.IsDebug() ? plugin.Log.CreateScope("FBM-DEBUG") : null, plugin ) { @@ -117,15 +117,17 @@ namespace VNLib.Data.Caching.Providers.VNCache _config = config; //Set a default node delay if null - _initNodeDelay = _config.InitialNodeDelay.HasValue ? TimeSpan.FromSeconds(_config.InitialNodeDelay.Value) : InitialDelay; + _initNodeDelay = _config.InitialNodeDelay.HasValue + ? TimeSpan.FromSeconds(_config.InitialNodeDelay.Value) + : InitialDelay; //Init the client with default settings FBMClientConfig conf = FBMDataCacheExtensions.GetDefaultConfig(BufferHeap, (int)config.MaxBlobSize, config.RequestTimeout, debugLog); FBMClientFactory clientFactory = new( in conf, - new FBMFallbackClientWsFactory(), - 10 + webSocketManager: new FBMFallbackClientWsFactory(), + maxClients: 10 ); _cluster = (new CacheClientConfiguration()) @@ -421,10 +423,10 @@ namespace VNLib.Data.Caching.Providers.VNCache private sealed record class DiscoveryErrHAndler(ILogProvider Logger) : ICacheDiscoveryErrorHandler { public void OnDiscoveryError(CacheNodeAdvertisment errorNode, Exception ex) - => OnDiscoveryError(errorNode, ex); + => OnDiscoveryError(ex, errorNode, address: null); public void OnDiscoveryError(Uri errorAddress, Exception ex) - => OnDiscoveryError(ex, null, errorAddress); + => OnDiscoveryError(ex, errorNode: null, errorAddress); public void OnDiscoveryError(Exception ex, CacheNodeAdvertisment? errorNode, Uri? address) { diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs index 6ee410c..2731833 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VnCacheClientConfig.cs @@ -91,7 +91,8 @@ namespace VNLib.Data.Caching.Providers.VNCache /// <exception cref="InvalidOperationException"></exception> public Uri[] GetInitialNodeUris() { - _ = InitialNodes ?? throw new InvalidOperationException("Initial nodes have not been set"); + Validate.NotNull(InitialNodes, "Initial nodes have not been set"); + return InitialNodes.Select(static x => { //Append a default well known endpoint if the path is just a root |