etcd-raft-test

command module
v0.0.0-...-e27656c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 1 Imported by: 0

README

etcd-raft-test

try out etcd raft implementation

Setup

From the directory containing this README.md:


TEST_BINARY_NAME="etcd-raft-test"
go build -o $TEST_BINARY_NAME
mkdir test
cd test

Usage for static cluster


TEST_BINARY_PATH="../$TEST_BINARY_NAME"
STATIC_LIST="http://127.0.0.1:12379,http://127.0.0.1:22379,http://127.0.0.1:32379"
echo "Add 1 to cluster: $STATIC_LIST"
( $TEST_BINARY_PATH --id 1 --cluster "$STATIC_LIST" --port 12380 1>& 1.log ) &
echo "Add 2 to cluster: $STATIC_LIST"
( $TEST_BINARY_PATH --id 2 --cluster "$STATIC_LIST" --port 22380 1>& 2.log ) &
echo "Add 3 to cluster: $STATIC_LIST"
( $TEST_BINARY_PATH --id 3 --cluster "$STATIC_LIST" --port 32380 1>& 3.log ) &
sleep 2s
cat *.log | grep "became leader" | sort
cat *.log | grep "LEADERSHIP-TRACKER-POLLING" | sort
cat *.log | grep "LEADERSHIP-TRACKER-NOTIFICATION" | sort

Dynamically add to static cluster


STATIC_LIST_AS_ARRAY=($(echo $STATIC_LIST | tr "," "\n"))
LEADER_INDEX=$(cat *.log | grep "became leader" | sort | tail -1 | sed 's/.* \([0-9]*\) became leader at term .*/\1/')
LEADER_PORT=$(ps -aux | grep $TEST_BINARY_NAME | grep "\-\-id $LEADER_INDEX" | sed 's/.* --port \([0-9]*\).*/\1/')
LEADER_URL="http://127.0.0.1:$LEADER_PORT"

NEW_URL="http://127.0.0.1:42379"
NEW_STATIC_LIST="$STATIC_LIST,$NEW_URL"
echo "Add 4 to cluster: $NEW_STATIC_LIST"
curl -L "$LEADER_URL/4" -XPOST -d "$NEW_URL"
( $TEST_BINARY_PATH --id 4 --cluster "$NEW_STATIC_LIST" --port 42380 --join 1>&4.log ) &

Force election by removing leader


LEADER_INDEX=$(cat *.log | grep "became leader" | sort | tail -1 | sed 's/.* \([0-9]*\) became leader at term .*/\1/')
NON_LEADER_PORT=$(ps -aux | grep $TEST_BINARY_NAME | grep "\-\-id" | grep -v "\-\-id $LEADER_INDEX" | tail -1 | sed 's/.* --port \([0-9]*\).*/\1/')
NON_LEADER_URL="http://127.0.0.1:$NON_LEADER_PORT"

echo "Non-leader URL: $NON_LEADER_URL"
echo "Deleting leader: $LEADER_INDEX"
curl -L "$NON_LEADER_URL/$LEADER_INDEX" -XDELETE

sleep 2s
cat *.log | grep "4 elected leader" | sort
cat *.log | grep "became leader" | sort
cat *.log | grep "LEADERSHIP-TRACKER-POLLING" | sort
cat *.log | grep "LEADERSHIP-TRACKER-NOTIFICATION" | sort

Cleanup


kill $(ps | grep $TEST_BINARY_NAME | awk '{print $1}')
rm -rf *.log
rm -rf raftexample-*

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL