sheharyarn / memento

Simple + Powerful interface to the Mnesia Distributed Database 💾
http://hexdocs.pm/memento/
MIT License
734 stars 23 forks source link

Distributed Memento with Libcluster {:no_exists, Schema} #34

Open maheshreddyks opened 2 months ago

maheshreddyks commented 2 months ago

I have few issues rolling out Memento on my application.

Implementation

  1. Application has 3+ pods at any point of time and is connected with Libcluster.
  2. In application.ex children are listed as follows a. {Cluster.Supervisor, [get_topologies(), [name: MyApp.ClusterSupervisor]]} b. MyApp.Mnesia.MigrateTask.child_spec()
defmodule MyApp.Mnesia.MigrateTask do
  def child_spec() do
    %{
      id: MODULE,
      start: {Task, :start_link, [fn -> setup() end]},
      type: :worker,
      restart: :temporary
    }
  end

  def setup() do
    # I inspected here, all the nodes were connected here.  
    nodes = [node() | Node.list()]

    # Stop Memento all nodes
    :rpc.multicall(nodes, Memento, :stop, [])

    # Create schema on all nodes
    Memento.Schema.create(nodes)

    # Start Memento all nodes
    :rpc.multicall(nodes, Memento, :start, [])

    # Create ram copies on all nodes
    Memento.Table.create!(MyApp.MetaSchema, ram_copies: nodes)        
  end
end  

Table Schema

defmodule QueryQuest.Mnesia.MetaSchema do
  use Memento.Table, attributes: [:key, :value]
end
  1. After the pods are up, through remote console checked Mememto.info. I see all pods are on running db nodes.

Issue

But I queryall for the Table.

    Memento.transaction!(fn ->
      Memento.Query.all(MyApp.MetaSchema)
    end)

Error

** (Memento.Error) Transaction Failed with: {:no_exists, MyApp.MetaSchema}
    (memento 0.3.2) lib/memento/transaction.ex:178: Memento.Transaction.handle_result/1

I'm trying to debug it, but its not succesful.

forest commented 1 month ago

@maheshreddyks any luck with this? Also, did you look at https://github.com/beardedeagle/mnesiac/tree/master to help with auth clustering?

sheharyarn commented 1 month ago

@maheshreddyks Are you able to verify that at the time setup() is called, all nodes are connected?

Because if they are, it should just work. If you're having issues debugging, can you share an minimal, reproducible example? I'll be in better position to help you figure out what's going on.

mxgrn commented 3 weeks ago

@sheharyarn @maheshreddyks's code works for me, but from the README I conclude I don't need to call Memento.Schema.create unless I want to use disc_copies, right? In that case, what's the minimum code I need to run if I only want ram_copies? Memento.Table.create! doesn't seem enough, as the sync isn't working b/w nodes.

If I don't call Memento.Schema.create, Memento.info always returns only one node in running db nodes.

UPD: I found my answer here.

mxgrn commented 3 weeks ago

@maheshreddyks Maybe your problem is this line:

id: MODULE,

Should it be id: __MODULE__?