Save ETS table to file using RPC

I trying to make a dump for a remote ETS table using RPC call, but without success.
I connected 2 nodes, and this: :rpc.call(:"remote_node@127.0.0.1", :ets, :info, [:some_table]) works, but :rpc.call(:"remote_node@127.0.0.1", :ets, :tab2file, [:some_table, 'table.dump']) doesn’t. And response is:

{:badrpc,
 {:EXIT,
  {:badarg,
   [{:ets, :safe_fixtable, [:some_table, true], []},
    {:ets, :tab2file, 3, [file: 'ets.erl', line: 812]},
    {:rpc, :"-handle_call_call/6-fun-0-", 5, [file: 'rpc.erl', line: 197]}]}}}

Am I doing something wrong?

1 Like

Does it work without rpc? Directly from the host owning the table?

1 Like

To be honest, I don’t know how to execute the code directly from the host. I have a production application, so I established a ssh tunnel and run iex with a correct cookie, then I can connected to a remote node, but only way to interact there I know is RPC calls :102:

Either connect via ssh to the host and start using iex -S app or use a remote she’ll as described here http://joeellis.la/iex-remsh-shells/

What does :ets.info return? Is the table public or protected? A private table can be only “touched” by the owner process.

1 Like

It returns:

[read_concurrency: false, write_concurrency: false, compressed: false,
 memory: 1095343, owner: #PID<9519.1720.0>, heir: :none,
 name: :some_table, size: 57645, node: :"remote_node@127.0.0.1",
 named_table: true, type: :ordered_set, keypos: 1, protection: :private]

So you might right, as it’s private, but how can I dump a table from outside of an application (I mean from my iex session)

The table is owned by a process, which is in an receive loop, I hope. So send it a message which commands it to dump the table.

Only the owner process can do it when the table is private.

1 Like

Thanks! it’s really sad that impossible to debug ETS table.

Of course you can debug it. But you have to have it either not private or prepare the owning process to dump it into a file or a list or whatever you want to have to debug it.

1 Like

What does :observer table viewer do to let you browse arbitrary tables? Or does that only work for :protected and :public tables?

After :ets.new/:foo, [:private]), :foo did not show up in observers table pane. Also Systems and memory pane tell me I had ~750 kB in ETS, the tables visible at the table pane have a sum-size of ~20 kB.

1 Like