aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Data.Caching.Extensions/src/Clustering
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-03-10 16:46:50 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-03-10 16:46:50 -0400
commite5bb0ee302e789cb96e7ecfe839cbbcc8e3fd5d7 (patch)
tree6f4d824eaea0f4c433f98c0685bf66c06b30e16a /lib/VNLib.Data.Caching.Extensions/src/Clustering
parent6b87785026ca57d6f41cff87ddbd066362f3cacc (diff)
Squashed commit of the following:
commit 2f7565976472f0f056db60520bf253a776112c10 Merge: 323ff67 6b87785 Author: vnugent <public@vaughnnugent.com> Date: Sun Mar 10 16:45:23 2024 -0400 merge master commit 323ff67badfc46ad638d75f059d60d9425ccb2fa Author: vnugent <public@vaughnnugent.com> Date: Sun Mar 10 15:50:07 2024 -0400 ci(server): Conainerize and add vncache server packages commit 5d4192880654fd6e00e587814169415b42621327 Author: vnugent <public@vaughnnugent.com> Date: Sat Mar 9 19:13:21 2024 -0500 chore: #2 Minor fixes and polish before release commit a4b3504bb891829074d1efde0433eae010862181 Author: vnugent <public@vaughnnugent.com> Date: Sat Mar 9 16:30:44 2024 -0500 package updates commit 4d8cfc10382105b0acbd94df93ad3d05ff91db54 Author: vnugent <public@vaughnnugent.com> Date: Wed Mar 6 21:30:58 2024 -0500 refactor: #2 Centralize server state, default discovery endpoints & more commit 016a96a80cce025a86c6cf26707738f6a2eb2658 Author: vnugent <public@vaughnnugent.com> Date: Thu Feb 29 21:22:38 2024 -0500 feat: add future support for memory diagnostics, and some docs commit 456ead9bc8b0f61357bae93152ad0403c4940101 Author: vnugent <public@vaughnnugent.com> Date: Tue Feb 13 14:46:35 2024 -0500 fix: #1 shared cluster index on linux & latested core updates commit a481d63f964a5d5204cac2e95141f37f9a28d573 Author: vnugent <public@vaughnnugent.com> Date: Tue Jan 23 15:43:50 2024 -0500 cache extension api tweaks
Diffstat (limited to 'lib/VNLib.Data.Caching.Extensions/src/Clustering')
-rw-r--r--lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheClientConfiguration.cs11
-rw-r--r--lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheNodeConfiguration.cs15
-rw-r--r--lib/VNLib.Data.Caching.Extensions/src/Clustering/ICacheDiscoveryErrorHandler.cs9
-rw-r--r--lib/VNLib.Data.Caching.Extensions/src/Clustering/INodeDiscoveryEnumerator.cs6
-rw-r--r--lib/VNLib.Data.Caching.Extensions/src/Clustering/NodeDiscoveryCollection.cs45
5 files changed, 41 insertions, 45 deletions
diff --git a/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheClientConfiguration.cs b/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheClientConfiguration.cs
index 5a15d33..263f41a 100644
--- a/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheClientConfiguration.cs
+++ b/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheClientConfiguration.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
@@ -37,14 +37,9 @@ namespace VNLib.Data.Caching.Extensions.Clustering
public class CacheClientConfiguration
{
/// <summary>
- /// Stores available cache servers to be used for discovery, and connections
- /// </summary>
- public INodeDiscoveryCollection NodeCollection { get; } = new NodeDiscoveryCollection();
-
- /// <summary>
/// The authentication manager to use for signing and verifying messages to and from the cache servers
/// </summary>
- public ICacheAuthManager AuthManager { get; private set; }
+ public ICacheAuthManager AuthManager { get; private set; } = null!;
/// <summary>
/// The error handler to use for handling errors that occur during the discovery process
@@ -89,7 +84,7 @@ namespace VNLib.Data.Caching.Extensions.Clustering
public CacheClientConfiguration WithInitialPeers(IEnumerable<Uri> peers)
{
//Check null
- _ = peers ?? throw new ArgumentNullException(nameof(peers));
+ ArgumentNullException.ThrowIfNull(peers);
//Store peer array
WellKnownNodes = peers.ToArray();
diff --git a/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheNodeConfiguration.cs b/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheNodeConfiguration.cs
index 6b7ab48..c21ed05 100644
--- a/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheNodeConfiguration.cs
+++ b/lib/VNLib.Data.Caching.Extensions/src/Clustering/CacheNodeConfiguration.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
@@ -23,6 +23,7 @@
*/
using System;
+using System.Runtime.CompilerServices;
namespace VNLib.Data.Caching.Extensions.Clustering
{
@@ -85,8 +86,14 @@ namespace VNLib.Data.Caching.Extensions.Clustering
return this;
}
+ internal StrongBox<string> NodeIdRef { get; } = new(string.Empty);
+
///<inheritdoc/>
- public string NodeId { get; private set; } = null!;
+ public string NodeId
+ {
+ get => NodeIdRef.Value!;
+ private set => NodeIdRef.Value = value;
+ }
/// <summary>
/// Specifies the current server's cluster node id. If this
@@ -99,10 +106,6 @@ namespace VNLib.Data.Caching.Extensions.Clustering
public CacheNodeConfiguration WithNodeId(string nodeId)
{
NodeId = nodeId ?? throw new ArgumentNullException(nameof(nodeId));
-
- //Update the node id in the node collection
- (NodeCollection as NodeDiscoveryCollection)!.SetSelfId(nodeId);
-
return this;
}
diff --git a/lib/VNLib.Data.Caching.Extensions/src/Clustering/ICacheDiscoveryErrorHandler.cs b/lib/VNLib.Data.Caching.Extensions/src/Clustering/ICacheDiscoveryErrorHandler.cs
index 984ce3d..f27f1fb 100644
--- a/lib/VNLib.Data.Caching.Extensions/src/Clustering/ICacheDiscoveryErrorHandler.cs
+++ b/lib/VNLib.Data.Caching.Extensions/src/Clustering/ICacheDiscoveryErrorHandler.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
@@ -37,5 +37,12 @@ namespace VNLib.Data.Caching.Extensions.Clustering
/// <param name="errorNode">The node that the error occured on</param>
/// <param name="ex">The exception that caused the invocation</param>
void OnDiscoveryError(CacheNodeAdvertisment errorNode, Exception ex);
+
+ /// <summary>
+ /// Invoked when an error occurs during the discovery process
+ /// </summary>
+ /// <param name="errorAddress">The server address that failed to connect</param>
+ /// <param name="ex">The exception that caused the invocation</param>
+ void OnDiscoveryError(Uri errorAddress, Exception ex);
}
}
diff --git a/lib/VNLib.Data.Caching.Extensions/src/Clustering/INodeDiscoveryEnumerator.cs b/lib/VNLib.Data.Caching.Extensions/src/Clustering/INodeDiscoveryEnumerator.cs
index 677088a..e57e69b 100644
--- a/lib/VNLib.Data.Caching.Extensions/src/Clustering/INodeDiscoveryEnumerator.cs
+++ b/lib/VNLib.Data.Caching.Extensions/src/Clustering/INodeDiscoveryEnumerator.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
@@ -28,7 +28,9 @@ using System.Collections.Generic;
namespace VNLib.Data.Caching.Extensions.Clustering
{
/// <summary>
- /// A custom enumerator for the node discovery process
+ /// A custom enumerator for the node discovery process. Simplifies the recursive processes
+ /// of discovering nodes in a cluster to a simple enumeration process. It allows for real-time
+ /// updates to the collection of discovered nodes as a union operation.
/// </summary>
public interface INodeDiscoveryEnumerator : IEnumerator<CacheNodeAdvertisment>
{
diff --git a/lib/VNLib.Data.Caching.Extensions/src/Clustering/NodeDiscoveryCollection.cs b/lib/VNLib.Data.Caching.Extensions/src/Clustering/NodeDiscoveryCollection.cs
index b0e53e1..16b96a3 100644
--- a/lib/VNLib.Data.Caching.Extensions/src/Clustering/NodeDiscoveryCollection.cs
+++ b/lib/VNLib.Data.Caching.Extensions/src/Clustering/NodeDiscoveryCollection.cs
@@ -1,12 +1,12 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
* File: NodeDiscoveryCollection.cs
*
-* NodeDiscoveryCollection.cs is part of VNLib.Data.Caching.Extensions which is part of the larger
-* VNLib collection of libraries and utilities.
+* NodeDiscoveryCollection.cs is part of VNLib.Data.Caching.Extensions which is part
+* of the larger VNLib collection of libraries and utilities.
*
* VNLib.Data.Caching.Extensions is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -26,24 +26,18 @@ using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+using VNLib.Utils.Extensions;
namespace VNLib.Data.Caching.Extensions.Clustering
{
/// <summary>
/// Represents a collection of available cache nodes from a discovery process
/// </summary>
- public sealed class NodeDiscoveryCollection : INodeDiscoveryCollection
+ public sealed class NodeDiscoveryCollection(StrongBox<string?>? selfId) : INodeDiscoveryCollection
{
- private string? _selfId;
- private LinkedList<CacheNodeAdvertisment> _peers;
-
- /// <summary>
- /// Initializes a new empty <see cref="NodeDiscoveryCollection"/>
- /// </summary>
- public NodeDiscoveryCollection()
- {
- _peers = new();
- }
+ private LinkedList<CacheNodeAdvertisment> _peers = new();
/// <summary>
/// Manually adds nodes to the collection that were not discovered through the discovery process
@@ -62,39 +56,34 @@ namespace VNLib.Data.Caching.Extensions.Clustering
}
/// <summary>
- /// Sets the id of the current node, so it can be excluded from discovery
+ /// Removes a vector of nodes from the internal collection
/// </summary>
- /// <param name="selfId">The id of the current node to exclude</param>
- public void SetSelfId(string? selfId) => _selfId = selfId;
+ /// <param name="nodes">The vector containg nodes to remove from the collection</param>
+ public void RemoveManualNodes(IEnumerable<CacheNodeAdvertisment> nodes) => nodes.ForEach(n => _peers.Remove(n));
///<inheritdoc/>
- public INodeDiscoveryEnumerator BeginDiscovery()
- {
- return new NodeEnumerator(new(), _selfId);
- }
+ public INodeDiscoveryEnumerator BeginDiscovery() => new NodeEnumerator(new(), selfId?.Value);
///<inheritdoc/>
public INodeDiscoveryEnumerator BeginDiscovery(IEnumerable<CacheNodeAdvertisment> initialPeers)
{
+ ArgumentNullException.ThrowIfNull(initialPeers);
+
//Init new enumerator with the initial peers
- return new NodeEnumerator(new(initialPeers), _selfId);
+ return new NodeEnumerator(new(initialPeers), selfId?.Value);
}
///<inheritdoc/>
public void CompleteDiscovery(INodeDiscoveryEnumerator enumerator)
{
- _ = enumerator ?? throw new ArgumentNullException(nameof(enumerator));
+ ArgumentNullException.ThrowIfNull(enumerator);
//Capture all nodes from the enumerator and store them as our current peers
_peers = (enumerator as NodeEnumerator)!.Peers;
}
///<inheritdoc/>
- public CacheNodeAdvertisment[] GetAllNodes()
- {
- //Capture all current peers
- return _peers.ToArray();
- }
+ public CacheNodeAdvertisment[] GetAllNodes() => _peers.ToArray();
private sealed record class NodeEnumerator(LinkedList<CacheNodeAdvertisment> Peers, string? SelfNodeId) : INodeDiscoveryEnumerator
{