Skip to content
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

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

Open
maheshreddyks opened this issue Jun 18, 2024 · 4 comments
Open

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

maheshreddyks opened this issue Jun 18, 2024 · 4 comments

Comments

@maheshreddyks
Copy link

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.

@maheshreddyks maheshreddyks changed the title Distributed Memento with Libcluster Distributed Memento with Libcluster {:no_exists, Schema} Jun 18, 2024
@forest
Copy link

forest commented Jul 23, 2024

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

@sheharyarn
Copy link
Owner

@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
Copy link

mxgrn commented Aug 14, 2024

@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
Copy link

mxgrn commented Aug 14, 2024

@maheshreddyks Maybe your problem is this line:

id: MODULE,

Should it be id: __MODULE__?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants