this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rename CommitBatch to ResolveBatch and lightly refactor

+22 -26
+2 -2
lib/servers/commit_buffer.ex
··· 2 2 use Hobbes.Construct.SimServer 3 3 4 4 alias Hobbes.MetaStore 5 - alias Hobbes.Structs.{Cluster, Server, CommitBatch, CommitTxn, LogBatch} 5 + alias Hobbes.Structs.{Cluster, Server, ResolveBatch, CommitTxn, LogBatch} 6 6 7 7 alias Hobbes.Servers.{Sequencer, Resolver, TLog} 8 8 ··· 149 149 } | acc] 150 150 end) 151 151 152 - batch = %CommitBatch{ 152 + batch = %ResolveBatch{ 153 153 commit_buffer_id: state.id, 154 154 commit_version: commit_version, 155 155 prev_commit_version: prev_commit_version,
+7 -7
lib/servers/resolver.ex
··· 1 1 defmodule Hobbes.Servers.Resolver do 2 2 use Hobbes.Construct.SimServer 3 3 4 - alias Hobbes.Structs.{Cluster, CommitBatch} 4 + alias Hobbes.Structs.{Cluster, ResolveBatch} 5 5 alias Hobbes.VersionMap 6 6 7 7 alias Hobbes.Utils ··· 36 36 Meta log is a list of batches of mutations applied by other 37 37 CommitBuffers since the last request from this CommitBuffer. 38 38 """ 39 - @spec resolve_batch(pid, %CommitBatch{}) :: {[boolean], [{non_neg_integer, [Utils.mutation]}]} 40 - def resolve_batch(server, %CommitBatch{} = batch) do 39 + @spec resolve_batch(pid, %ResolveBatch{}) :: {[boolean], [{non_neg_integer, [Utils.mutation]}]} 40 + def resolve_batch(server, %ResolveBatch{} = batch) do 41 41 SimServer.call(server, {:resolve_batch, batch}) 42 42 end 43 43 ··· 59 59 {:reply, :ok, %State{state | cluster: cluster}} 60 60 end 61 61 62 - def handle_call({:resolve_batch, %CommitBatch{} = batch}, from, state) do 62 + def handle_call({:resolve_batch, %ResolveBatch{} = batch}, from, state) do 63 63 state = %State{state | buffer: Map.put_new(state.buffer, batch.prev_commit_version, {from, batch})} 64 64 {:noreply, maybe_resolve_next(state)} 65 65 end ··· 72 72 73 73 defp maybe_resolve_next(%State{} = state) do 74 74 case Map.pop(state.buffer, state.version) do 75 - {{from, %CommitBatch{} = batch}, buffer} -> 75 + {{from, %ResolveBatch{} = batch}, buffer} -> 76 76 state = %State{state | buffer: buffer} 77 77 78 78 do_resolve_batch(batch, from, state) ··· 82 82 end 83 83 end 84 84 85 - defp do_resolve_batch(%CommitBatch{} = batch, from, %State{} = state) do 85 + defp do_resolve_batch(%ResolveBatch{} = batch, from, %State{} = state) do 86 86 vm = state.version_map 87 87 commit_version = batch.commit_version 88 88 ··· 124 124 end) 125 125 126 126 # Note: we intentionally reply with results reversed because it's 127 - # better to reverse them on the CommitBuffer as it's less of a bottleneck 127 + # more efficient on CommitBuffer 128 128 SimServer.reply(from, {results, reply_meta_mutations}) 129 129 130 130 %State{state |
+13 -17
lib/structs.ex
··· 42 42 defstruct @enforce_keys 43 43 end 44 44 45 - # TODO: rename to ResolveBatch 46 - defmodule CommitBatch do 45 + defmodule CommitTxn do 46 + @type t :: %__MODULE__{ 47 + read_version: non_neg_integer, 48 + read_conflicts: [binary | {binary, binary}], 49 + write_conflicts: [binary | {binary, binary}], 50 + mutations: [Utils.mutation], 51 + from: term, 52 + } 53 + @enforce_keys [:read_version, :read_conflicts, :write_conflicts, :mutations] 54 + defstruct @enforce_keys ++ [:from] 55 + end 56 + 57 + defmodule ResolveBatch do 47 58 @type t :: %__MODULE__{ 48 59 commit_buffer_id: integer, 49 60 commit_version: non_neg_integer, ··· 60 71 } 61 72 @enforce_keys [:commit_buffer_id, :commit_version, :prev_commit_version, :transactions] 62 73 defstruct @enforce_keys 63 - end 64 - 65 - defmodule CommitTxn do 66 - @type t :: %__MODULE__{ 67 - id: term, 68 - from: term, 69 - meta: boolean, 70 - 71 - read_version: non_neg_integer, 72 - read_conflicts: [binary | {binary, binary}], 73 - write_conflicts: [binary | {binary, binary}], 74 - mutations: [Utils.mutation], 75 - } 76 - @enforce_keys [:read_version, :read_conflicts, :write_conflicts, :mutations] 77 - defstruct [:id, :from, :meta] ++ @enforce_keys 78 74 end 79 75 80 76 defmodule LogBatch do