From 9b0c04d2224ae474c06339f0268b5d476813b60e Mon Sep 17 00:00:00 2001 From: Leon Hartley Date: Fri, 1 Mar 2024 18:26:52 +0000 Subject: [PATCH] init --- Cargo.lock | 4 ++++ Cargo.toml | 8 ++++---- coerce/src/remote/cluster/node.rs | 4 +++- coerce/src/singleton/manager/mod.rs | 8 +++++++- examples/coerce-sharded-chat-example/Cargo.toml | 2 +- .../scripts/run-server-1.ps1 | 2 +- .../scripts/run-server-2.ps1 | 2 +- .../discovery/coerce-k8s/Cargo.toml | 0 .../discovery/coerce-k8s/src/config.rs | 0 .../discovery/coerce-k8s/src/lib.rs | 0 .../persistence/coerce-redis/Cargo.toml | 0 .../coerce-redis/src/journal/actor.rs | 0 .../persistence/coerce-redis/src/journal/mod.rs | 0 .../persistence/coerce-redis/src/lib.rs | 0 .../tests/test_redis_journal_storage.rs | 0 .../replication/coerce-replication/Cargo.toml | 8 ++++++++ .../replication/coerce-replication/src/lib.rs | 16 ++++++++++++++++ .../coerce-replication/src/simple/mod.rs | 10 ++++++++++ 18 files changed, 55 insertions(+), 9 deletions(-) rename {providers => modules}/discovery/coerce-k8s/Cargo.toml (100%) rename {providers => modules}/discovery/coerce-k8s/src/config.rs (100%) rename {providers => modules}/discovery/coerce-k8s/src/lib.rs (100%) rename {providers => modules}/persistence/coerce-redis/Cargo.toml (100%) rename {providers => modules}/persistence/coerce-redis/src/journal/actor.rs (100%) rename {providers => modules}/persistence/coerce-redis/src/journal/mod.rs (100%) rename {providers => modules}/persistence/coerce-redis/src/lib.rs (100%) rename {providers => modules}/persistence/coerce-redis/tests/test_redis_journal_storage.rs (100%) create mode 100644 modules/replication/coerce-replication/Cargo.toml create mode 100644 modules/replication/coerce-replication/src/lib.rs create mode 100644 modules/replication/coerce-replication/src/simple/mod.rs diff --git a/Cargo.lock b/Cargo.lock index e39703f2..66e6bbfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -542,6 +542,10 @@ dependencies = [ "tokio", ] +[[package]] +name = "coerce-replication" +version = "0.1.0" + [[package]] name = "coerce-sharded-chat-example" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b59ffee8..3c192010 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ members = [ "examples/coerce-cluster-example", "examples/coerce-sharded-chat-example", "coerce/tools/coerce-proto-build", - "providers/persistence/coerce-redis", - "providers/discovery/coerce-k8s" -] + "modules/persistence/coerce-redis", + "modules/discovery/coerce-k8s" +, "modules/replication/coerce-replication"] -resolver = "2" \ No newline at end of file +resolver = "2" diff --git a/coerce/src/remote/cluster/node.rs b/coerce/src/remote/cluster/node.rs index d240cbce..5fc78cf0 100644 --- a/coerce/src/remote/cluster/node.rs +++ b/coerce/src/remote/cluster/node.rs @@ -7,7 +7,7 @@ use crate::remote::net::message::{datetime_to_timestamp, timestamp_to_datetime}; use crate::remote::net::proto::network; use crate::remote::stream::system::ClusterEvent::NodeAdded; use chrono::{DateTime, Utc}; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::fmt::Display; use std::hash::{Hash, Hasher}; use std::sync::Arc; @@ -62,6 +62,7 @@ pub struct RemoteNode { pub enum NodeSelector { All, Attribute(NodeAttribute), + Ids(HashSet) } impl NodeSelector { @@ -73,6 +74,7 @@ impl NodeSelector { match &self { NodeSelector::All => true, NodeSelector::Attribute((key, value)) => node.attributes.get(key) == Some(value), + NodeSelector::Ids(ids) => ids.contains(&node.id), } } } diff --git a/coerce/src/singleton/manager/mod.rs b/coerce/src/singleton/manager/mod.rs index 9aad6107..d3a31876 100644 --- a/coerce/src/singleton/manager/mod.rs +++ b/coerce/src/singleton/manager/mod.rs @@ -7,7 +7,7 @@ use crate::actor::message::{ FromBytes, Handler, Message, MessageUnwrapErr, MessageWrapErr, ToBytes, }; use crate::actor::{Actor, ActorFactory, ActorId, ActorRef, IntoActor, LocalActorRef, ToActorId}; -use crate::remote::cluster::node::NodeSelector; +use crate::remote::cluster::node::{NodeSelector, RemoteNodeRef}; use crate::remote::stream::pubsub::{PubSub, Receive, Subscription}; use crate::remote::stream::system::{ClusterEvent, ClusterMemberUp, SystemEvent, SystemTopic}; use crate::remote::system::{NodeId, RemoteActorSystem}; @@ -37,6 +37,12 @@ pub struct Manager { cluster_up: bool, } +struct NodeGroup { + node_id: NodeId, + manager_actor: ActorRef, + node: RemoteNodeRef, +} + impl Manager { pub fn new( sys: RemoteActorSystem, diff --git a/examples/coerce-sharded-chat-example/Cargo.toml b/examples/coerce-sharded-chat-example/Cargo.toml index 02eb00f6..a1f95d81 100644 --- a/examples/coerce-sharded-chat-example/Cargo.toml +++ b/examples/coerce-sharded-chat-example/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] coerce = { path = "../../coerce", features = ["full"] } coerce-macros = { version = "0.2.0" } -coerce-redis = { path = "../../providers/persistence/coerce-redis" } +coerce-redis = { path = "../../modules/persistence/coerce-redis" } coerce-k8s = { version = "0.1.7" } tokio = { version = "1.28.1", features = ["full"] } diff --git a/examples/coerce-sharded-chat-example/scripts/run-server-1.ps1 b/examples/coerce-sharded-chat-example/scripts/run-server-1.ps1 index f2f53e06..adbddb8a 100644 --- a/examples/coerce-sharded-chat-example/scripts/run-server-1.ps1 +++ b/examples/coerce-sharded-chat-example/scripts/run-server-1.ps1 @@ -1 +1 @@ -cargo run --bin sharded-chat-server -- --node_id 0 --remote_seed_addr 127.0.0.1:31101 --remote_listen_addr 0.0.0.0:31101 --websocket_listen_addr localhost:31102 --cluster_api_listen_addr 127.0.0.1:31103 --log_level DEBUG \ No newline at end of file +cargo run --bin sharded-chat-server -- --node_id 0 --remote_seed_addr 127.0.0.1:31101 --remote_listen_addr 0.0.0.0:31101 --websocket_listen_addr localhost:31102 --cluster_api_listen_addr 127.0.0.1:31103 --log_level DEBUG --redis_addr redis://localhost:6379 \ No newline at end of file diff --git a/examples/coerce-sharded-chat-example/scripts/run-server-2.ps1 b/examples/coerce-sharded-chat-example/scripts/run-server-2.ps1 index 803c37e6..a91776db 100755 --- a/examples/coerce-sharded-chat-example/scripts/run-server-2.ps1 +++ b/examples/coerce-sharded-chat-example/scripts/run-server-2.ps1 @@ -1 +1 @@ -cargo run --bin sharded-chat-server -- --node_id 2 --remote_listen_addr 0.0.0.0:32101 --websocket_listen_addr localhost:32102 --cluster_api_listen_addr 127.0.0.1:32103 --remote_seed_addr 127.0.0.1:33101 --log_level DEBUG +cargo run --bin sharded-chat-server -- --node_id 2 --remote_listen_addr 0.0.0.0:32101 --websocket_listen_addr localhost:32102 --cluster_api_listen_addr 127.0.0.1:32103 --remote_seed_addr 127.0.0.1:31101 --log_level DEBUG --redis_addr redis://localhost:6379 diff --git a/providers/discovery/coerce-k8s/Cargo.toml b/modules/discovery/coerce-k8s/Cargo.toml similarity index 100% rename from providers/discovery/coerce-k8s/Cargo.toml rename to modules/discovery/coerce-k8s/Cargo.toml diff --git a/providers/discovery/coerce-k8s/src/config.rs b/modules/discovery/coerce-k8s/src/config.rs similarity index 100% rename from providers/discovery/coerce-k8s/src/config.rs rename to modules/discovery/coerce-k8s/src/config.rs diff --git a/providers/discovery/coerce-k8s/src/lib.rs b/modules/discovery/coerce-k8s/src/lib.rs similarity index 100% rename from providers/discovery/coerce-k8s/src/lib.rs rename to modules/discovery/coerce-k8s/src/lib.rs diff --git a/providers/persistence/coerce-redis/Cargo.toml b/modules/persistence/coerce-redis/Cargo.toml similarity index 100% rename from providers/persistence/coerce-redis/Cargo.toml rename to modules/persistence/coerce-redis/Cargo.toml diff --git a/providers/persistence/coerce-redis/src/journal/actor.rs b/modules/persistence/coerce-redis/src/journal/actor.rs similarity index 100% rename from providers/persistence/coerce-redis/src/journal/actor.rs rename to modules/persistence/coerce-redis/src/journal/actor.rs diff --git a/providers/persistence/coerce-redis/src/journal/mod.rs b/modules/persistence/coerce-redis/src/journal/mod.rs similarity index 100% rename from providers/persistence/coerce-redis/src/journal/mod.rs rename to modules/persistence/coerce-redis/src/journal/mod.rs diff --git a/providers/persistence/coerce-redis/src/lib.rs b/modules/persistence/coerce-redis/src/lib.rs similarity index 100% rename from providers/persistence/coerce-redis/src/lib.rs rename to modules/persistence/coerce-redis/src/lib.rs diff --git a/providers/persistence/coerce-redis/tests/test_redis_journal_storage.rs b/modules/persistence/coerce-redis/tests/test_redis_journal_storage.rs similarity index 100% rename from providers/persistence/coerce-redis/tests/test_redis_journal_storage.rs rename to modules/persistence/coerce-redis/tests/test_redis_journal_storage.rs diff --git a/modules/replication/coerce-replication/Cargo.toml b/modules/replication/coerce-replication/Cargo.toml new file mode 100644 index 00000000..842dc9cb --- /dev/null +++ b/modules/replication/coerce-replication/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "coerce-replication" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/modules/replication/coerce-replication/src/lib.rs b/modules/replication/coerce-replication/src/lib.rs new file mode 100644 index 00000000..eb516ec3 --- /dev/null +++ b/modules/replication/coerce-replication/src/lib.rs @@ -0,0 +1,16 @@ +mod simple; + +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/modules/replication/coerce-replication/src/simple/mod.rs b/modules/replication/coerce-replication/src/simple/mod.rs new file mode 100644 index 00000000..6293f037 --- /dev/null +++ b/modules/replication/coerce-replication/src/simple/mod.rs @@ -0,0 +1,10 @@ +//! Simple Replicator is a basic system that allows state to be safely replicated +//! across a collection of Coerce nodes. +//! +//! + +pub struct SimpleReplicator { + +} + +