You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2022/09/01 16:06:00 UTC
[couchdb] 31/31: HACK: demonstrate the shards running elections in a very hackish way
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch raft_storemodule
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit c5569e7095adb283189b6c0717c8ed542989da26
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Sep 1 16:56:10 2022 +0100
HACK: demonstrate the shards running elections in a very hackish way
---
src/couch/src/couch_bt_engine.erl | 14 +++++++++++++-
src/couch/src/couch_bt_engine.hrl | 3 ++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index d93071c1e..b41f4d331 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -963,6 +963,17 @@ init_state(FilePath, Fd, Header0, Options) ->
{reduce, fun ?MODULE:raft_tree_reduce/2}
]),
+ %% ugly hack just to see the elections
+ RaftPid = case re:run(FilePath, "shards/[0-9a-f]+-[0-9a-f]+/[^.]+", [{capture, all, list}]) of
+ {match, [ShardName]} ->
+ Cohort = mem3:nodes(), %% hack
+ {ok, InitialRaftState} = couch_raft_store_sha256:init(Cohort),
+ {ok, P} = couch_raft:start(ShardName, couch_raft_store_sha256, InitialRaftState),
+ P;
+ _ ->
+ undefined
+ end,
+
ok = couch_file:set_db_pid(Fd, self()),
St = #st{
@@ -977,7 +988,8 @@ init_state(FilePath, Fd, Header0, Options) ->
compression = Compression,
purge_tree = PurgeTree,
purge_seq_tree = PurgeSeqTree,
- raft_tree = RaftTree
+ raft_tree = RaftTree,
+ raft_pid = RaftPid
},
% If this is a new database we've just created a
diff --git a/src/couch/src/couch_bt_engine.hrl b/src/couch/src/couch_bt_engine.hrl
index 0d347e99b..8d1dbca2a 100644
--- a/src/couch/src/couch_bt_engine.hrl
+++ b/src/couch/src/couch_bt_engine.hrl
@@ -24,5 +24,6 @@
compression,
purge_tree,
purge_seq_tree,
- raft_tree
+ raft_tree,
+ raft_pid
}).