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

Inconsistency between behavior spec and usage #66

Open
sleipnir opened this issue Sep 11, 2022 · 0 comments · May be fixed by #67
Open

Inconsistency between behavior spec and usage #66

sleipnir opened this issue Sep 11, 2022 · 0 comments · May be fixed by #67

Comments

@sleipnir
Copy link

sleipnir commented Sep 11, 2022

I verified that the DeltaCrdt.Storage Behavior used for persistence is specifying a type called storage_format with the following representation:

defmodule DeltaCrdt.Storage do
  @moduledoc """
  This behaviour can be used to enable persistence of the CRDT.

  This can be helpful in the event of crashes.

  To use, implement this behaviour in a module, and pass it to your CRDT with the `storage_module` option.
  """

  @type t :: module()

  @opaque storage_format ::
            {node_id :: term(), sequence_number :: integer(), crdt_state :: term()}

  @callback write(name :: term(), storage_format()) :: :ok
  @callback read(name :: term()) :: storage_format() | nil
end

Note that the type is basically composed of {node_id :: term(), sequence_number :: integer(), crdt_state :: term()} but checking where this behavior is called I noticed that actually the expected return pattern of the read function is different from the type specified in the behavior. See in DeltaCrdt.CausalCrd:

defp read_from_storage(state) do
    case state.storage_module.read(state.name) do
      nil ->
        state

      {node_id, sequence_number, crdt_state, merkle_map} ->
        Map.put(state, :sequence_number, sequence_number)
        |> Map.put(:crdt_state, crdt_state)
        |> Map.put(:merkle_map, merkle_map)
        |> Map.put(:node_id, node_id)
        |> remove_crdt_state_keys()
    end
  end

In this case the expected return type pattern is {node_id, sequence_number, crdt_state, merkle_map}.

My first question is what is the correct format?

@sleipnir sleipnir linked a pull request Sep 11, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant