Skip to content

Commit bc23ba1

Browse files
committed
fix(engine): don't attempt search when ETS checkpoint is loading
The checkpoint file can be quite large (1.2G in my case) and it may take quite a while to load it (8.2s in my case). During that time, all the GenServer calls with the default timeout of 5000ms might timeout, leading to the whole GenServer termination and general instability of the search functionality. This adds guards for state.loaded? which return {:error, :loading} if it's not loaded.
1 parent 03ec5c6 commit bc23ba1

File tree

1 file changed

+24
-0
lines changed
  • apps/engine/lib/engine/search/store

1 file changed

+24
-0
lines changed

apps/engine/lib/engine/search/store/state.ex

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ defmodule Engine.Search.Store.State do
8383
end
8484
end
8585

86+
def exact(%__MODULE__{loaded?: false}, _subject, _constraints) do
87+
{:error, :loading}
88+
end
89+
8690
def exact(%__MODULE__{} = state, subject, constraints) do
8791
type = Keyword.get(constraints, :type, :_)
8892
subtype = Keyword.get(constraints, :subtype, :_)
@@ -93,6 +97,10 @@ defmodule Engine.Search.Store.State do
9397
end
9498
end
9599

100+
def prefix(%__MODULE__{loaded?: false}, _prefix, _constraints) do
101+
{:error, :loading}
102+
end
103+
96104
def prefix(%__MODULE__{} = state, prefix, constraints) do
97105
type = Keyword.get(constraints, :type, :_)
98106
subtype = Keyword.get(constraints, :subtype, :_)
@@ -106,6 +114,10 @@ defmodule Engine.Search.Store.State do
106114
end
107115
end
108116

117+
def fuzzy(%__MODULE__{loaded?: false}, _subject, _constraints) do
118+
{:error, :loading}
119+
end
120+
109121
def fuzzy(%__MODULE__{} = state, subject, constraints) do
110122
case Fuzzy.match(state.fuzzy, subject) do
111123
[] ->
@@ -122,6 +134,10 @@ defmodule Engine.Search.Store.State do
122134
end
123135
end
124136

137+
def all(%__MODULE__{loaded?: false}, _) do
138+
{:error, :loading}
139+
end
140+
125141
def all(%__MODULE__{} = state, constraints) do
126142
type = Keyword.get(constraints, :type, :_)
127143
subtype = Keyword.get(constraints, :subtype, :_)
@@ -146,13 +162,21 @@ defmodule Engine.Search.Store.State do
146162
(type == :_ or t == type) and (subtype == :_ or st == subtype)
147163
end
148164

165+
def siblings(%__MODULE__{loaded?: false}, _entry) do
166+
{:error, :loading}
167+
end
168+
149169
def siblings(%__MODULE__{} = state, entry) do
150170
case state.backend.siblings(entry) do
151171
l when is_list(l) -> {:ok, l}
152172
error -> error
153173
end
154174
end
155175

176+
def parent(%__MODULE__{loaded?: false}, _entry) do
177+
{:error, :loading}
178+
end
179+
156180
def parent(%__MODULE__{} = state, entry) do
157181
case state.backend.parent(entry) do
158182
%Entry{} = entry -> {:ok, entry}

0 commit comments

Comments
 (0)