Repository navigation
Fix: Fetch ETS table info on snapshot reload #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
srzeszut
wants to merge
10
commits into
main
Choose a base branch
from
voy-294-stale-info-in-ets-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
927e1c9
add ets mock node
srzeszut 103378f
fetch table info on reload
srzeszut 45a258f
add tests
srzeszut d3d9292
add refetch info to porvate tables
srzeszut 6081339
add tests
srzeszut 85efd96
remove private records on table visibility change
srzeszut 0c885a5
cr suggestions
srzeszut 5ff4c66
cr suggestions
srzeszut 3b82a3a
fix credo
srzeszut 031a54c
cr suggestions
srzeszut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,92 +1,165 @@ | ||
| # Seeds a node with ETS tables covering every case the Voyager ETS UI handles. | ||
| # | ||
| # Run: | ||
| # elixir --name demo@127.0.0.1 --cookie demo ets_demo_node.exs | ||
| # dev/mock_nodes/ets.sh | ||
| # | ||
| # Then in Voyager connect to demo@127.0.0.1 with cookie "demo". | ||
|
|
||
| # --- Truncated-binary-key repro ------------------------------------------- | ||
| # In :truncated_key_bug, one key is an 8000-byte binary. | ||
| # 1. Open the table, set "Budget per record" to 100, Fetch records. | ||
| # 2. The long key renders as a silent ~99-byte prefix; Lookup stays enabled. | ||
| # 3. Click Lookup -> "No record with this key. It may have been deleted." | ||
| # ...but the record exists (this script prints proof on request, see below). | ||
| :ets.new(:truncated_key_bug, [:set, :named_table, :public]) | ||
| :ets.insert(:truncated_key_bug, {:binary.copy("K", 8000), :value_a}) | ||
| :ets.insert(:truncated_key_bug, {"short-key", :value_b}) | ||
|
|
||
| # --- General zoo ----------------------------------------------------------- | ||
| :ets.new(:kv_set, [:set, :named_table, :public]) | ||
|
|
||
| for i <- 1..137 do | ||
| :ets.insert(:kv_set, {i, %{name: "item_#{i}", tags: [:a, :b], score: i * 1.5}}) | ||
| # Then in Voyager connect to ets@127.0.0.1 with cookie "demo". | ||
|
|
||
| defmodule Demo do | ||
| # Protected and private tables only accept writes from their owner, so every call runs there. | ||
| def run(fun) do | ||
| Agent.get(__MODULE__, fn _ -> | ||
| try do | ||
| {:ok, fun.()} | ||
| rescue | ||
| e -> {:error, e} | ||
| end | ||
| end) | ||
| end | ||
|
|
||
| def new(name, opts \\ [:set, :named_table, :public]), do: run(fn -> :ets.new(name, opts) end) | ||
| def put(tab, records), do: run(fn -> :ets.insert(tab, records) end) | ||
| def delete(tab, key), do: run(fn -> :ets.delete(tab, key) end) | ||
| def clear(tab), do: run(fn -> :ets.delete_all_objects(tab) end) | ||
| def drop(tab), do: run(fn -> :ets.delete(tab) end) | ||
|
|
||
| def give_away(tab), do: run(fn -> :ets.give_away(tab, sleeper(), nil) end) | ||
| def heir(tab), do: run(fn -> :ets.setopts(tab, {:heir, sleeper(), nil}) end) | ||
| def heir(tab, :none), do: run(fn -> :ets.setopts(tab, {:heir, :none}) end) | ||
|
|
||
| # Type, protection, keypos, named_table, compressed and concurrency are fixed at :ets.new. | ||
| def recreate(tab, changes) do | ||
| run(fn -> | ||
| info = Keyword.merge(:ets.info(tab), changes) | ||
| rows = :ets.tab2list(tab) | ||
| options = opts(info) | ||
| registered = :ets.whereis(info[:name]) | ||
|
|
||
| if info[:named_table] and registered not in [:undefined, :ets.info(tab, :id)], | ||
| do: raise(ArgumentError, "#{inspect(info[:name])} is already a named table") | ||
|
|
||
| temporary = :ets.new(info[:name], List.delete(options, :named_table)) | ||
|
|
||
| try do | ||
| :ets.insert(temporary, rows) | ||
| after | ||
| :ets.delete(temporary) | ||
| end | ||
|
|
||
| :ets.delete(tab) | ||
| new_tab = :ets.new(info[:name], options) | ||
| :ets.insert(new_tab, rows) | ||
|
srzeszut marked this conversation as resolved.
|
||
| new_tab | ||
| end) | ||
| end | ||
|
|
||
| defp opts(info) do | ||
| flags = for flag <- [:named_table, :compressed], info[flag], do: flag | ||
| heir = if is_pid(info[:heir]), do: [{:heir, info[:heir], nil}], else: [] | ||
|
|
||
| [ | ||
| info[:type], | ||
| info[:protection], | ||
| keypos: info[:keypos], | ||
| read_concurrency: info[:read_concurrency], | ||
| write_concurrency: info[:write_concurrency], | ||
| decentralized_counters: info[:decentralized_counters] | ||
| ] ++ flags ++ heir | ||
| end | ||
|
|
||
| defp sleeper, do: spawn(fn -> Process.sleep(:infinity) end) | ||
| end | ||
|
|
||
| :ets.new(:users_ordered, [:ordered_set, :named_table, :public]) | ||
| {:ok, _} = Agent.start(fn -> nil end, name: Demo) | ||
|
|
||
| for i <- 1..23 do | ||
| :ets.insert(:users_ordered, {"user-#{String.pad_leading(to_string(i), 3, "0")}", i, :active}) | ||
| end | ||
| {:ok, _} = | ||
| Demo.run(fn -> | ||
| # --- Truncated-binary-key repro ------------------------------------------- | ||
| # In :truncated_key_bug, one key is an 8000-byte binary. | ||
| # 1. Open the table, set "Budget per record" to 100, Fetch records. | ||
| # 2. The long key renders as a silent ~99-byte prefix; Lookup stays enabled. | ||
| # 3. Click Lookup -> "No record with this key. It may have been deleted." | ||
| # ...but the record exists (this script prints proof on request, see below). | ||
| :ets.new(:truncated_key_bug, [:set, :named_table, :public]) | ||
| :ets.insert(:truncated_key_bug, {:binary.copy("K", 8000), :value_a}) | ||
| :ets.insert(:truncated_key_bug, {"short-key", :value_b}) | ||
|
|
||
| # --- General zoo ----------------------------------------------------------- | ||
| :ets.new(:kv_set, [:set, :named_table, :public]) | ||
|
|
||
| for i <- 1..137 do | ||
| :ets.insert(:kv_set, {i, %{name: "item_#{i}", tags: [:a, :b], score: i * 1.5}}) | ||
| end | ||
|
|
||
| :ets.new(:by_second_key, [:set, :named_table, :public, {:keypos, 2}]) | ||
| :ets.insert(:by_second_key, {%{payload: 1}, :alpha, "extra"}) | ||
| :ets.insert(:by_second_key, {%{payload: 2}, :beta, "extra2"}) | ||
| :ets.new(:users_ordered, [:ordered_set, :named_table, :public]) | ||
|
|
||
| :ets.new(:bag_events, [:bag, :named_table, :public]) | ||
| :ets.insert(:bag_events, for(i <- 1..60, do: {:login, "user-#{i}", i})) | ||
| :ets.insert(:bag_events, {:logout, "alice", 61}) | ||
| for i <- 1..23 do | ||
| :ets.insert( | ||
| :users_ordered, | ||
| {"user-#{String.pad_leading(to_string(i), 3, "0")}", i, :active} | ||
| ) | ||
| end | ||
|
|
||
| :ets.new(:dup_bag, [:duplicate_bag, :named_table, :public]) | ||
| :ets.insert(:dup_bag, List.duplicate({:x, 1}, 25)) | ||
| :ets.insert(:dup_bag, {:y, 2}) | ||
| :ets.new(:by_second_key, [:set, :named_table, :public, {:keypos, 2}]) | ||
| :ets.insert(:by_second_key, {%{payload: 1}, :alpha, "extra"}) | ||
| :ets.insert(:by_second_key, {%{payload: 2}, :beta, "extra2"}) | ||
|
|
||
| :ets.new(:private_tab, [:set, :named_table, :private]) | ||
| :ets.insert(:private_tab, {:secret, 42}) | ||
| :ets.new(:bag_events, [:bag, :named_table, :public]) | ||
| :ets.insert(:bag_events, for(i <- 1..60, do: {:login, "user-#{i}", i})) | ||
| :ets.insert(:bag_events, {:logout, "alice", 61}) | ||
|
|
||
| unnamed = :ets.new(:anon_data, [:set, :public]) | ||
| for i <- 1..12, do: :ets.insert(unnamed, {i, {:anon, i}}) | ||
| :ets.new(:dup_bag, [:duplicate_bag, :named_table, :public]) | ||
| :ets.insert(:dup_bag, List.duplicate({:x, 1}, 25)) | ||
| :ets.insert(:dup_bag, {:y, 2}) | ||
|
|
||
| :ets.new(:huge_records, [:set, :named_table, :public]) | ||
| :ets.insert(:huge_records, {:big_binary, :crypto.strong_rand_bytes(5_000_000)}) | ||
| :ets.new(:private_tab, [:set, :named_table, :private]) | ||
| :ets.insert(:private_tab, {:secret, 42}) | ||
|
|
||
| deep = | ||
| Enum.reduce(1..30, :leaf, fn i, acc -> %{level: i, child: acc, pad: List.duplicate(i, 50)} end) | ||
| unnamed = :ets.new(:anon_data, [:set, :public]) | ||
| for i <- 1..12, do: :ets.insert(unnamed, {i, {:anon, i}}) | ||
|
|
||
| :ets.insert(:huge_records, {:deep_term, deep}) | ||
| :ets.insert(:huge_records, {:long_list, Enum.to_list(1..100_000)}) | ||
| :ets.insert(:huge_records, {:small, :ok}) | ||
| :ets.new(:huge_records, [:set, :named_table, :public]) | ||
| :ets.insert(:huge_records, {:big_binary, :crypto.strong_rand_bytes(5_000_000)}) | ||
|
|
||
| :ets.new(:charlist_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:charlist_keys, {~c"compiler", ~c"/lib/compiler", []}) | ||
| deep = | ||
| Enum.reduce(1..30, :leaf, fn i, acc -> | ||
| %{level: i, child: acc, pad: List.duplicate(i, 50)} | ||
| end) | ||
|
|
||
| :ets.new(:tuple_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:tuple_keys, {{:user, 1}, "alice"}) | ||
| :ets.insert(:tuple_keys, {{:user, 2}, "bob"}) | ||
| :ets.insert(:huge_records, {:deep_term, deep}) | ||
| :ets.insert(:huge_records, {:long_list, Enum.to_list(1..100_000)}) | ||
| :ets.insert(:huge_records, {:small, :ok}) | ||
|
|
||
| :ets.new(:binary_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:binary_keys, {"session-abc", %{ttl: 300}}) | ||
| :ets.new(:charlist_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:charlist_keys, {~c"compiler", ~c"/lib/compiler", []}) | ||
|
|
||
| :ets.new(:truncated_struct_key, [:set, :named_table, :public]) | ||
| :ets.new(:tuple_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:tuple_keys, {{:user, 1}, "alice"}) | ||
| :ets.insert(:tuple_keys, {{:user, 2}, "bob"}) | ||
|
|
||
| :ets.insert( | ||
| :truncated_struct_key, | ||
| {%Version{major: 1, minor: 0, patch: 0, pre: [:binary.copy("P", 500)]}, :value_a} | ||
| ) | ||
| :ets.new(:binary_keys, [:set, :named_table, :public]) | ||
| :ets.insert(:binary_keys, {"session-abc", %{ttl: 300}}) | ||
|
|
||
| :ets.insert(:truncated_struct_key, {%Version{major: 2, minor: 0, patch: 0}, :value_b}) | ||
| :ets.new(:truncated_struct_key, [:set, :named_table, :public]) | ||
|
|
||
| :ets.new(:empty_set, [:set, :named_table, :public]) | ||
| :ets.insert( | ||
| :truncated_struct_key, | ||
| {%Version{major: 1, minor: 0, patch: 0, pre: [:binary.copy("P", 500)]}, :value_a} | ||
| ) | ||
|
|
||
| :ets.insert(:truncated_struct_key, {%Version{major: 2, minor: 0, patch: 0}, :value_b}) | ||
|
|
||
| :ets.new(:empty_set, [:set, :named_table, :public]) | ||
| end) | ||
|
|
||
| IO.puts(""" | ||
| node ready: #{node()} (cookie: demo) | ||
|
|
||
| repro check from another shell (proves the record the UI calls deleted exists): | ||
|
|
||
| elixir --name probe@127.0.0.1 --cookie demo -e ' | ||
| n = :"demo@127.0.0.1"; true = Node.connect(n) | ||
| n = :"#{node()}"; true = Node.connect(n) | ||
| key = :binary.copy("K", 8000) | ||
| IO.inspect(full_key: :erpc.call(n, :ets, :lookup, [:truncated_key_bug, key]) != [], | ||
| prefix_99: :erpc.call(n, :ets, :lookup, [:truncated_key_bug, :binary.part(key, 0, 99)]))' | ||
| """) | ||
|
|
||
| Process.sleep(:infinity) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| iex --name ets@127.0.0.1 --cookie demo "$(dirname "$0")/../ets_demo_node.exs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.