Skip to content

Example snippet does not work #5

Description

@ostinelli

I'm curious to give this a try but the lack of docs makes it hard to get started with. So I'm trying to use the snippet provided in the readme with the added ETS options from the kvstore example:

(watest@127.0.0.1)1> Spec = wa_raft_sup:child_spec([#{table => watest, partition => 1, nodes => [node()], log_module => wa_raft_log_ets, storage_module => wa_raft_storage_ets}]).
** exception error: no match of right hand side value undefined
     in function  wa_raft_sup:child_spec/1 (/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_sup.erl, line 74)

As I'm running this in a console per the example, but apparently the method needs to know the application name, I pass in the app name:

(watest@127.0.0.1)2> Spec = wa_raft_sup:child_spec(watest, [#{table => watest, partition => 1, nodes => [node()]}]).
#{id => wa_raft_sup,restart => permanent,shutdown => infinity,
  start =>
      {wa_raft_sup,start_link,
                   [watest,
                    [#{table => watest,nodes => ['watest@127.0.0.1'],partition => 1}],
                    #{}]},
  type => supervisor,
  modules => [wa_raft_sup]}

Then start the supervisor:

(watest@127.0.0.1)3> supervisor:start_child(kernel_sup, Spec).
{error,{{'EXIT',{{'EXIT',{{no_configured_database_path,watest},
                          [{wa_raft_env,database_path,1,
                                        [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_env.erl"},
                                         {line,38}]},
                           {wa_raft_part_sup,normalize_spec,2,
                                             [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_part_sup.erl"},
                                              {line,124}]},
                           {wa_raft_part_sup,start_link,2,
                                             [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_part_sup.erl"},
                                              {line,69}]},
                           {supervisor,do_start_child_i,3,
                                       [{file,"supervisor.erl"},{line,420}]},
                           {supervisor,handle_call,3,
                                       [{file,"supervisor.erl"},{line,445}]},
                           {gen_server,try_handle_call,4,
                                       [{file,"gen_server.erl"},{line,1113}]},
                           {gen_server,handle_msg,6,
                                       [{file,"gen_server.erl"},{line,1142}]},
                           {proc_lib,init_p_do_apply,3,
                                     [{file,"proc_lib.erl"},{line,241}]}]}},
                 [{wa_raft_sup,'-start_link/3-lc$^0/1-0-',2,
                               [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_sup.erl"},
                                {line,102}]},
                  {wa_raft_sup,start_link,3,
                               [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_sup.erl"},
                                {line,104}]},
                  {supervisor,do_start_child_i,3,
                              [{file,"supervisor.erl"},{line,420}]},
                  {supervisor,do_start_child,2,
                              [{file,"supervisor.erl"},{line,406}]},
                  {supervisor,handle_start_child,2,
                              [{file,"supervisor.erl"},{line,712}]},
                  {supervisor,handle_call,3,
                              [{file,"supervisor.erl"},{line,461}]},
                  {gen_server,try_handle_call,4,
                              [{file,"gen_server.erl"},{line,1113}]},
                  {gen_server,handle_msg,6,
                              [{file,"gen_server.erl"},{line,1142}]}]}},
        {child,undefined,wa_raft_sup,
               {wa_raft_sup,start_link,
                            [watest,
                             [#{table => watest,nodes => ['watest@127.0.0.1'],partition => 1}],
                             #{}]},
               permanent,false,infinity,supervisor,
               [wa_raft_sup]}}}

Browsing through code, I set the application env key raft_database to "/Users/roberto/workspace" (even though I am setting the ETS in-memory only options for log and storage) and then I get:

=ERROR REPORT==== 11-Sep-2023::18:03:47.182676 ===
** State machine raft_server_watest_1 terminating
** Last event = {internal,init_state}
** When server state  = {stalled,
                            {raft_state,watest,raft_server_watest_1,
                                {raft_identity,raft_server_watest_1,
                                    'watest@127.0.0.1'},
                                watest,1,"/Users/roberto/workspace/watest.1",
                                {log_view,watest,raft_log_watest_1,wa_raft_log_ets,
                                    0,0,[],undefined,undefined},
                                wa_raft_distribution,raft_storage_watest_1,
                                raft_log_catchup_watest_1,0,0,undefined,
                                undefined,0,undefined,#{},undefined,
                                -576460751864,#{},#{},#{},#{},0,undefined,
                                undefined,false}}
** Reason for termination = error:badarg
** Callback modules = [wa_raft_server]
** Callback mode = [state_functions,state_enter]
** Stacktrace =
**  [{ets,delete,
          [wa_raft_info,{state,watest,1}],
          [{error_info,#{cause => id,module => erl_stdlib_errors}}]},
     {wa_raft_info,delete_state,2,
                   [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_info.erl"},
                    {line,62}]},
     {wa_raft_server,terminate,3,
                     [{file,"/Users/roberto/workspace/watest/_build/default/lib/waraft/src/wa_raft_server.erl"},
                      {line,1502}]},
     {gen_statem,terminate,7,[{file,"gen_statem.erl"},{line,2553}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,241}]}]

I can keep this going (and I'll try to) but is there any chance there's a proper working example on how to use waraft?

Thank you,
r.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions