Skip to content

Commit ecfa697

Browse files
committed
Disable ETS persistence for Agent and CLI hubs
1 parent ce0b7b2 commit ecfa697

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

lib/livebook.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ defmodule Livebook do
157157
config :livebook, teams_url: url, warn_on_live_teams_server: false
158158
end
159159

160+
if System.get_env("LIVEBOOK_TEAMS_AUTH") do
161+
config :livebook, :persist_storage, false
162+
end
163+
160164
if Livebook.Config.boolean!("LIVEBOOK_SHUTDOWN_ENABLED", false) do
161165
config :livebook, :shutdown_callback, {System, :stop, []}
162166
end

lib/livebook/storage.ex

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,17 @@ defmodule Livebook.Storage do
186186
# in case it is persisting to disk. terminate/2 is still a no-op.
187187
Process.flag(:trap_exit, true)
188188

189-
table = load_or_create_table()
190-
:persistent_term.put(__MODULE__, table)
189+
persist_storage? = Application.get_env(:livebook, :persist_storage, true)
190+
191+
table =
192+
if persist_storage? do
193+
load_or_create_table()
194+
else
195+
:ets.new(__MODULE__, [:protected, :duplicate_bag])
196+
end
191197

192-
{:ok, %{table: table}}
198+
:persistent_term.put(__MODULE__, table)
199+
{:ok, %{table: table, persist?: persist_storage?}}
193200
end
194201

195202
@impl true
@@ -220,6 +227,10 @@ defmodule Livebook.Storage do
220227
end
221228

222229
@impl true
230+
def handle_continue(:save_to_file, %{persist?: false} = state) do
231+
{:noreply, state}
232+
end
233+
223234
def handle_continue(:save_to_file, %{table: table} = state) do
224235
file_path = String.to_charlist(config_file_path())
225236
:ok = :ets.tab2file(table, file_path)

lib/livebook_cli.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule LivebookCLI do
2121
extract_priv!()
2222

2323
:ok = Application.load(:livebook)
24+
Application.put_env(:livebook, :persist_storage, false)
2425

2526
if unix?() do
2627
Application.put_env(:elixir, :ansi_enabled, true)

test/test_helper.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Application.put_env(:livebook, Livebook.Runtime.Embedded,
3838
load_packages: {Livebook.Runtime.Embedded.Packages, :list, []}
3939
)
4040

41+
# Disable ETS disk persistence
42+
Application.put_env(:livebook, :persist_storage, false)
43+
4144
# Disable autosaving
4245
Livebook.Storage.insert(:settings, "global", autosave_path: nil)
4346

0 commit comments

Comments
 (0)