Skip to content

Commit 9c556e0

Browse files
committed
fix config of replication supervisor
1 parent b610d42 commit 9c556e0

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

lib/phoenix/sync/sandbox/stack.ex

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,21 @@ if Phoenix.Sync.sandbox_enabled?() do
8181

8282
registry = :"#{__MODULE__}.Registry-#{stack_id}"
8383

84+
storage = {
85+
Electric.ShapeCache.InMemoryStorage,
86+
%{stack_id: stack_id, table_base_name: :"#{stack_id}"}
87+
}
88+
8489
[
8590
purge_all_shapes?: false,
8691
stack_id: stack_id,
87-
storage: {
88-
Electric.ShapeCache.InMemoryStorage,
89-
%{stack_id: stack_id, table_base_name: :"#{stack_id}"}
90-
},
92+
storage: storage,
93+
shape_status:
94+
{Electric.ShapeCache.ShapeStatus,
95+
Electric.ShapeCache.ShapeStatus.opts(
96+
shape_meta_table: Electric.ShapeCache.ShapeStatus.shape_meta_table(stack_id),
97+
storage: storage
98+
)},
9199
inspector: inspector,
92100
publication_manager: publication_manager_spec,
93101
chunk_bytes_threshold: 10_485_760,
@@ -101,17 +109,15 @@ if Phoenix.Sync.sandbox_enabled?() do
101109
end
102110

103111
def init({stack_id, repo, owner}) do
104-
# shape_cache_spec = {Electric.ShapeCache, shape_cache_opts}
105-
106112
config = config(stack_id, repo, owner)
107113
shape_cache_spec = {Electric.ShapeCache, config}
108114
persistent_kv = Electric.PersistentKV.Memory.new!()
109115

110-
shape_status_spec =
111-
{Electric.ShapeCache.ShapeStatus,
112-
%Electric.ShapeCache.ShapeStatus{
113-
shape_meta_table: shape_meta_table(stack_id)
114-
}}
116+
shape_status_owner_spec =
117+
{Electric.ShapeCache.ShapeStatusOwner,
118+
[stack_id: stack_id, shape_status: config[:shape_status]]}
119+
120+
consumer_supervisor_spec = {Electric.Shapes.DynamicConsumerSupervisor, [stack_id: stack_id]}
115121

116122
children = [
117123
{Registry, keys: :duplicate, name: config[:registry]},
@@ -120,16 +126,18 @@ if Phoenix.Sync.sandbox_enabled?() do
120126
{Electric.Shapes.Monitor,
121127
stack_id: stack_id,
122128
storage: config[:storage],
123-
shape_status: shape_status_spec,
129+
shape_status: config[:shape_status],
124130
publication_manager: config[:publication_manager]},
125131
# TODO: start an electric stack, decoupled from the db connection
126132
# with in memory storage, a mock publication_manager and inspector
127133
Supervisor.child_spec(
128134
{
129135
Electric.Replication.Supervisor,
130136
stack_id: stack_id,
137+
shape_status_owner: shape_status_owner_spec,
131138
shape_cache: shape_cache_spec,
132139
publication_manager: config[:publication_manager],
140+
consumer_supervisor: consumer_supervisor_spec,
133141
log_collector: {
134142
Electric.Replication.ShapeLogCollector,
135143
stack_id: stack_id, inspector: config[:inspector], persistent_kv: persistent_kv
@@ -147,17 +155,5 @@ if Phoenix.Sync.sandbox_enabled?() do
147155

148156
Supervisor.init(children, strategy: :one_for_one)
149157
end
150-
151-
Code.ensure_loaded(Electric.ShapeCache)
152-
153-
if function_exported?(Electric.ShapeCache, :get_shape_meta_table, 1) do
154-
defp shape_meta_table(stack_id) do
155-
Electric.ShapeCache.get_shape_meta_table(stack_id: stack_id)
156-
end
157-
else
158-
defp shape_meta_table(stack_id) do
159-
Electric.ShapeCache.ShapeStatus.shape_meta_table(stack_id)
160-
end
161-
end
162158
end
163159
end

0 commit comments

Comments
 (0)