From db47ee6483eeb8a217232c33491c83ab7c12fc32 Mon Sep 17 00:00:00 2001 From: kevburnsjr Date: Sat, 2 Mar 2024 03:17:36 -0800 Subject: [PATCH] Refactor exmaple config --- _example/kv1/Makefile | 14 +++++++------- _example/kv1/main.go | 31 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/_example/kv1/Makefile b/_example/kv1/Makefile index 8c1d31f..12dbcb4 100644 --- a/_example/kv1/Makefile +++ b/_example/kv1/Makefile @@ -8,22 +8,22 @@ clean-data: @rm -rf $(DATA_DIR)/node* @rm -rf $(DATA_DIR)/raft* -PEERS := 127.0.0.1:17011,127.0.0.1:17021,127.0.0.1:17031 +PEERS := 127.0.0.1:17013,127.0.0.1:17023,127.0.0.1:17033 test-node-1: - @go run *.go -d $(DATA_DIR)/node1 -a 127.0.0.1:17011 -r 127.0.0.1:17012 -g 127.0.0.1:17013 -h :8001 -p $(PEERS) -z us-west-1a + @go run *.go -d $(DATA_DIR)/node1 -g 127.0.0.1:17011 -r 127.0.0.1:17012 -a 127.0.0.1:17013 -h :8001 -p $(PEERS) -z us-west-1a test-node-2: - @go run *.go -d $(DATA_DIR)/node2 -a 127.0.0.1:17021 -r 127.0.0.1:17022 -g 127.0.0.1:17023 -h :8002 -p $(PEERS) -z us-west-1c + @go run *.go -d $(DATA_DIR)/node2 -g 127.0.0.1:17021 -r 127.0.0.1:17022 -a 127.0.0.1:17023 -h :8002 -p $(PEERS) -z us-west-1c test-node-3: - @go run *.go -d $(DATA_DIR)/node3 -a 127.0.0.1:17031 -r 127.0.0.1:17032 -g 127.0.0.1:17033 -h :8003 -p $(PEERS) -z us-west-1f + @go run *.go -d $(DATA_DIR)/node3 -g 127.0.0.1:17031 -r 127.0.0.1:17032 -a 127.0.0.1:17033 -h :8003 -p $(PEERS) -z us-west-1f test-node-4: - @go run *.go -d $(DATA_DIR)/node4 -a 127.0.0.1:17041 -r 127.0.0.1:17042 -g 127.0.0.1:17043 -h :8004 -p $(PEERS) -z us-west-1a + @go run *.go -d $(DATA_DIR)/node4 -g 127.0.0.1:17041 -r 127.0.0.1:17042 -a 127.0.0.1:17043 -h :8004 -p $(PEERS) -z us-west-1a test-node-5: - @go run *.go -d $(DATA_DIR)/node5 -a 127.0.0.1:17051 -r 127.0.0.1:17052 -g 127.0.0.1:17053 -h :8005 -p $(PEERS) -z us-west-1c + @go run *.go -d $(DATA_DIR)/node5 -g 127.0.0.1:17051 -r 127.0.0.1:17052 -a 127.0.0.1:17053 -h :8005 -p $(PEERS) -z us-west-1c test-node-6: - @go run *.go -d $(DATA_DIR)/node6 -a 127.0.0.1:17061 -r 127.0.0.1:17062 -g 127.0.0.1:17063 -h :8006 -p $(PEERS) -z us-west-1f + @go run *.go -d $(DATA_DIR)/node6 -g 127.0.0.1:17061 -r 127.0.0.1:17062 -a 127.0.0.1:17063 -h :8006 -p $(PEERS) -z us-west-1f diff --git a/_example/kv1/main.go b/_example/kv1/main.go index c93be38..96d7086 100644 --- a/_example/kv1/main.go +++ b/_example/kv1/main.go @@ -15,16 +15,17 @@ import ( ) var ( - name = flag.String("n", `kv1`, "Cluster name (base36 maxlen 12)") - peers = flag.String("p", `kv1-usc1-a-0,kv1-usc1-c-0,kv1-usc1-f-0`, "Peer nodes") - region = flag.String("re", `us-central1`, "Region") - zone = flag.String("z", `us-central1-a`, "Zone") - shards = flag.Int("s", 4, "Shard count") - apiAddr = flag.String("a", "10.0.0.1:17001", "Internal gRPC api address") + gossipAddr = flag.String("g", "10.0.0.1:17001", "Memberlist gossip address") raftAddr = flag.String("r", "10.0.0.1:17002", "Dragonboat raft address") - gossipAddr = flag.String("g", "10.0.0.1:17003", "Memberlist gossip address") + zongziAddr = flag.String("a", "10.0.0.1:17003", "Zongzi gRPC api address") httpAddr = flag.String("h", "10.0.0.1:8000", "HTTP address") - dataDir = flag.String("d", "/var/lib/zongzi", "Base data directory") + + name = flag.String("n", `kv1`, "Cluster name (base36 maxlen 12)") + peers = flag.String("p", `kv1-usc1-a-0,kv1-usc1-c-0,kv1-usc1-f-0`, "Peer nodes") + region = flag.String("re", `us-central1`, "Region") + zone = flag.String("z", `us-central1-a`, "Zone") + dataDir = flag.String("d", "/var/lib/zongzi", "Base data directory") + shards = flag.Int("s", 4, "Shard count") ) func main() { @@ -33,19 +34,19 @@ func main() { ctx := context.Background() ctrl := newController() agent, err := zongzi.NewAgent(*name, strings.Split(*peers, ","), - zongzi.WithHostTags( - fmt.Sprintf(`geo:region=%s`, *region), - fmt.Sprintf(`geo:zone=%s`, *zone)), - zongzi.WithApiAddress(*apiAddr), - zongzi.WithGossipAddress(*gossipAddr), zongzi.WithHostConfig(zongzi.HostConfig{ NodeHostDir: *dataDir + "/raft", NotifyCommit: true, - RaftAddress: *raftAddr, RTTMillisecond: 2, WALDir: *dataDir + "/wal", }), - zongzi.WithRaftEventListener(ctrl)) + zongzi.WithGossipAddress(*gossipAddr), + zongzi.WithRaftAddress(*raftAddr), + zongzi.WithApiAddress(*zongziAddr), + zongzi.WithRaftEventListener(ctrl), + zongzi.WithHostTags( + fmt.Sprintf(`geo:region=%s`, *region), + fmt.Sprintf(`geo:zone=%s`, *zone))) if err != nil { panic(err) }