Skip to content

Commit

Permalink
wal as part of a supervision tree
Browse files Browse the repository at this point in the history
  • Loading branch information
scohen committed Feb 7, 2024
1 parent 4192658 commit a216adb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
17 changes: 11 additions & 6 deletions apps/remote_control/lib/lexical/remote_control/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ defmodule Lexical.RemoteControl.Application do
RemoteControl.Plugin.Runner.Coordinator,
maybe_search_store()
]
|> Enum.reject(&is_nil/1)
|> List.flatten()
else
[]
end
Expand All @@ -39,16 +41,19 @@ defmodule Lexical.RemoteControl.Application do

defp maybe_search_store do
if Features.indexing_enabled?() do
{RemoteControl.Search.Store,
[
&RemoteControl.Search.Indexer.create_index/1,
&RemoteControl.Search.Indexer.update_index/2
]}
[
RemoteControl.Search.Store.Backends.Ets,
{RemoteControl.Search.Store,
[
&RemoteControl.Search.Indexer.create_index/1,
&RemoteControl.Search.Indexer.update_index/2
]}
]
end
end

defp maybe_reindex do
if Features.indexing_enabled? do
if Features.indexing_enabled?() do
{RemoteControl.Commands.Reindex, nil}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule Lexical.RemoteControl.Search.Store.Backends.Ets do
@behaviour Backend

@impl Backend
def new(%Project{} = project) do
start_link(project)
def new(%Project{}) do
{:ok, Process.whereis(__MODULE__)}
end

@impl Backend
Expand Down Expand Up @@ -85,7 +85,19 @@ defmodule Lexical.RemoteControl.Search.Store.Backends.Ets do
end

def start_link(%Project{} = project) do
GenServer.start_link(__MODULE__, [project])
GenServer.start_link(__MODULE__, [project], name: __MODULE__)
end

def start_link do
start_link(RemoteControl.get_project())
end

def child_spec([%Project{}] = init_args) do
%{id: __MODULE__, start: {__MODULE__, :start_link, init_args}}
end

def child_spec(_) do
child_spec([RemoteControl.get_project()])
end

@impl GenServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ defmodule Lexical.RemoteControl.Search.Store.Backends.Ets.State do
end

def drop(%__MODULE__{leader?: true} = state) do
with_wal state.wal_state do
:ets.delete_all_objects(state.table_name)
end
Wal.truncate(state.wal_state)
:ets.delete_all_objects(state.table_name)
end

def insert(%__MODULE__{leader?: true} = state, entries) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ defmodule Lexical.RemoteControl.Search.Store.Backends.Ets.Wal do
end
end

def truncate(%__MODULE__{} = wal) do
:disk_log.truncate(wal.update_log)
end

def destroy(%__MODULE__{} = wal) do
close(wal)
destroy(wal.project, wal.schema_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Lexical.RemoteControl.CodeIntelligence.ReferencesTest do

start_supervised!(Document.Store)
start_supervised!(RemoteControl.Dispatch)
start_supervised!(Backends.Ets)

start_supervised!(
{Search.Store, [project, fn _ -> {:ok, []} end, fn _, _ -> {:ok, [], []} end, Backends.Ets]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Lexical.RemoteControl.Dispatch.Handlers.IndexingTest do

start_supervised!(RemoteControl.Dispatch)
start_supervised!(Commands.Reindex)
start_supervised!(Search.Store.Backends.Ets)
start_supervised!({Search.Store, [project, create_index, update_index]})
start_supervised!({Document.Store, derive: [analysis: &Lexical.Ast.analyze/1]})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ defmodule Lexical.RemoteControl.Search.Store.Backend.EtsTest do

defp start_supervised_store(%Project{} = project, create_fn, update_fn, backend) do
start_supervised!(Dispatch)
start_supervised!(Backends.Ets)
start_supervised!({Store, [project, create_fn, update_fn, backend]})
assert_eventually alive?(), 1500
Store.enable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ defmodule Lexical.RemoteControl.Search.StoreTest do
destroy_backend(backend, project)

start_supervised!(Dispatch)
start_supervised!(backend)
start_supervised!({Store, [project, &default_create/1, &default_update/2, backend]})

assert_eventually alive?()
Expand Down

0 comments on commit a216adb

Please sign in to comment.