Skip to content

Commit e91a109

Browse files
committed
fix: fixes
1 parent b0fdb99 commit e91a109

8 files changed

Lines changed: 23 additions & 17 deletions

File tree

actor/cluster_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ func (x *ClusterConfig) WithDataCenter(config *datacenter.Config) *ClusterConfig
451451

452452
// WithCRDT enables CRDT replication on this cluster node.
453453
// When set, the actor system spawns a Replicator system actor that subscribes
454-
// to CRDT key topics via the TopicActor and replicates state across the cluster.
454+
// to the shared goakt.crdt.deltas topic via the TopicActor and replicates
455+
// state across the cluster.
455456
// If not called, no Replicator is spawned and there is zero CRDT overhead.
456457
func (x *ClusterConfig) WithCRDT(opts ...crdt.Option) *ClusterConfig {
457458
x.crdtConfig = crdt.NewConfig(opts...)

actor/replicator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ func (e *crdtConfigExtension) Config() *crdt.Config {
9696
// and replicates state across the cluster via TopicActor pub/sub.
9797
//
9898
// Each node in the cluster runs its own replicatorActor. All replicators
99-
// subscribe to the same CRDT key topics via the TopicActor. When any
100-
// replicator updates a key, it publishes the delta to that key's topic.
101-
// Because every replicator is subscribed to the same topic, they all
102-
// receive the delta automatically.
99+
// subscribe to a single shared topic (goakt.crdt.deltas) via the TopicActor.
100+
// When any replicator updates a key, it publishes the delta (which carries
101+
// the key inside the payload) to this shared topic. Because every replicator
102+
// is subscribed to the same topic, they all receive the delta automatically.
103103
type replicatorActor struct {
104104
pid *PID
105105
topicActor *PID

crdt/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func WithTombstoneTTL(duration time.Duration) Option {
127127

128128
// WithRole restricts CRDT replication to cluster nodes that advertise
129129
// the specified role. Only nodes with this role will spawn a Replicator
130-
// and subscribe to CRDT key topics. An empty string means all nodes participate.
130+
// and subscribe to the shared CRDT delta topic. An empty string means all nodes participate.
131131
func WithRole(role string) Option {
132132
return func(c *Config) {
133133
c.role = role

crdt/key.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const (
4646
//
4747
// The generic parameter T binds the key to a specific CRDT type at compile time,
4848
// providing type safety for Update, Get, Subscribe, and Changed messages.
49-
// The key's ID is used as the TopicActor topic name for replication.
49+
// The key's ID is carried inside each delta payload for routing; all deltas
50+
// are published to a single shared topic (goakt.crdt.deltas) via TopicActor.
5051
// The DataType is serialized in anti-entropy and coordination messages
5152
// so that peers can validate type consistency.
5253
//
@@ -60,7 +61,8 @@ type Key[T ReplicatedData] struct {
6061
}
6162

6263
// ID returns the key's string identifier.
63-
// This is used as the TopicActor topic name and the internal store key.
64+
// This is used as the internal store key and is embedded in delta messages
65+
// for routing; replication uses the shared goakt.crdt.deltas topic.
6466
func (k Key[T]) ID() string {
6567
return k.id
6668
}

crdt/messages.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ package crdt
2525
// Update is sent to the Replicator to create or update a CRDT key.
2626
//
2727
// The update is always applied locally first and the delta is published
28-
// to the key's topic via TopicActor. If WriteTo is set, the Replicator
28+
// to the shared goakt.crdt.deltas topic via TopicActor (the key is
29+
// carried inside the delta payload). If WriteTo is set, the Replicator
2930
// also sends the delta directly to peers and waits for acknowledgments
3031
// before returning the response.
3132
//
@@ -79,8 +80,8 @@ type Changed[T ReplicatedData] struct {
7980
}
8081

8182
// Delete is sent to the Replicator to remove a CRDT key.
82-
// Deletion publishes a tombstone to the key's topic. Tombstones are
83-
// retained for the configured TombstoneTTL before pruning.
83+
// Deletion publishes a tombstone to the shared goakt.crdt.deltas topic.
84+
// Tombstones are retained for the configured TombstoneTTL before pruning.
8485
type Delete[T ReplicatedData] struct {
8586
Key Key[T]
8687
WriteTo Coordination

docs/advanced/distributed-data.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (a *RateLimiter) Receive(ctx *actor.ReceiveContext) {
106106
Key: crdt.PNCounterKey("request-count"),
107107
Initial: crdt.NewPNCounter(),
108108
Modify: func(current *crdt.PNCounter) *crdt.PNCounter {
109-
return current.Increment(ctx.Self().Path().Name(), 1)
109+
return current.Increment(ctx.ActorSystem().PeersAddress(), 1)
110110
},
111111
})
112112
}
@@ -283,7 +283,7 @@ func (a *SessionTracker) Receive(ctx *actor.ReceiveContext) {
283283

284284
switch msg := ctx.Message().(type) {
285285
case *AddSession:
286-
nodeID := ctx.Self().Path().Name()
286+
nodeID := ctx.ActorSystem().PeersAddress()
287287
ctx.Tell(replicator, &crdt.Update[*crdt.ORSet[string]]{
288288
Key: sessionsKey,
289289
Initial: crdt.NewORSet[string](),

internal/internalpb/crdt.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/internal/crdt.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ message MVRegisterData {
127127
map<string, uint64> clock = 2;
128128
}
129129

130-
// CRDTDelta is the delta message published to a key's topic via TopicActor.
131-
// All Replicators subscribed to the same key topic receive this message.
130+
// CRDTDelta is the delta message published to the shared goakt.crdt.deltas
131+
// topic via TopicActor. The key is carried inside the payload so that
132+
// receivers can route the delta to the correct local store entry.
132133
message CRDTDelta {
133134
// Specifies the CRDT key this delta belongs to.
134135
CRDTKey key = 1;

0 commit comments

Comments
 (0)