Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/engine/lib/engine/search/store/backends/ets/wal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Engine.Search.Store.Backends.Ets.Wal do
@moduledoc """
A (hopefully) simple write-ahead log
"""
alias Engine.Progress
alias Forge.Identifier
alias Forge.Project
alias Forge.VM.Versions
Expand Down Expand Up @@ -330,10 +331,10 @@ defmodule Engine.Search.Store.Backends.Ets.Wal do

case :disk_log.open(name: log_name, file: String.to_charlist(checkpoint_file)) do
{:ok, log} ->
stream_checkpoint(wal, log, :start)
stream_checkpoint_with_progress(wal, log)

{:repaired, log, _recovered, _bad_bytes} ->
stream_checkpoint(wal, log, :start)
stream_checkpoint_with_progress(wal, log)

error ->
error
Expand Down Expand Up @@ -367,6 +368,13 @@ defmodule Engine.Search.Store.Backends.Ets.Wal do
:"checkpoint_log_#{Project.name(project)}"
end

defp stream_checkpoint_with_progress(%__MODULE__{} = wal, log) do
Progress.with_progress("Loading search index", fn _token ->
result = stream_checkpoint(wal, log, :start)
{:done, result}
end)
end

defp stream_checkpoint(%__MODULE__{} = wal, log, continuation) do
case :disk_log.chunk(log, continuation, @chunk_size) do
{continuation, items} when is_list(items) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Engine.Search.Store.Backends.Ets.SchemaTest do
alias Engine.Dispatch
alias Engine.Search.Store.Backends.Ets.Schema
alias Engine.Search.Store.Backends.Ets.Wal
alias Forge.Project
Expand All @@ -7,12 +8,19 @@ defmodule Engine.Search.Store.Backends.Ets.SchemaTest do
import Wal, only: :macros

use ExUnit.Case
use Patch

setup do
project = project()

destroy_index_path(project)

patch(Dispatch, :erpc_call, fn Expert.Progress, :begin, [_title, _opts] ->
{:ok, System.unique_integer([:positive])}
end)

patch(Dispatch, :erpc_cast, fn Expert.Progress, _function, _args -> true end)

on_exit(fn ->
destroy_index_path(project)
end)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Engine.Search.Store.Backends.Ets.WalTest do
alias Engine.Dispatch
alias Engine.Search.Store.Backends.Ets.Wal

import Forge.Test.Fixtures
Expand All @@ -15,6 +16,12 @@ defmodule Engine.Search.Store.Backends.Ets.WalTest do
project = project()
new_table()

patch(Dispatch, :erpc_call, fn Expert.Progress, :begin, [_title, _opts] ->
{:ok, System.unique_integer([:positive])}
end)

patch(Dispatch, :erpc_cast, fn Expert.Progress, _function, _args -> true end)

on_exit(fn ->
Wal.destroy(project, @schema_version)
end)
Expand Down
7 changes: 7 additions & 0 deletions apps/engine/test/engine/search/store/backends/ets_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Engine.Search.Store.Backend.EtsTest do
alias Forge.Test.Fixtures

use ExUnit.Case, async: false
use Patch

import EventualAssertions
import Entry.Builder
Expand All @@ -24,6 +25,12 @@ defmodule Engine.Search.Store.Backend.EtsTest do

Engine.set_project(project)

patch(Dispatch, :erpc_call, fn Expert.Progress, :begin, [_title, _opts] ->
{:ok, System.unique_integer([:positive])}
end)

patch(Dispatch, :erpc_cast, fn Expert.Progress, _function, _args -> true end)

delete_indexes(project, backend)

on_exit(fn ->
Expand Down
Loading