Skip to content

Commit

Permalink
[COMMON] enable to run multi quorum nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
chia7712 committed Jul 10, 2024
1 parent 7394e59 commit 6d0ff84
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions docker/start_controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,30 @@ declare -r DOCKERFILE=$DOCKER_FOLDER/controller.dockerfile
declare -r EXPORTER_VERSION="0.16.1"
declare -r CLUSTER_ID=${CLUSTER_ID:-"$(randomString)"}
declare -r EXPORTER_PORT=${EXPORTER_PORT:-"$(getRandomPort)"}
declare -r VOTERS=${VOTERS:-""}
declare -r NODE_ID=${NODE_ID:-"$(getRandomPort)"}
declare -r CONTROLLER_PORT=${CONTROLLER_PORT:-"$(getRandomPort)"}

# we need to parse the controller port from pre-defined `VOTERS`
function generateControllerPort() {
if [[ -n "$VOTERS" ]]; then
port=""
IFS=',' read -ra ADDR <<< "$VOTERS"
for voter in "${ADDR[@]}"; do
if [[ "$voter" == "$NODE_ID"* ]]; then
port=${voter##*:}
break
fi
done
echo "$port"
else
echo "$(getRandomPort)"
fi
}
declare -r CONTROLLER_PORT=${CONTROLLER_PORT:-"$(generateControllerPort)"}
if [[ "$CONTROLLER_PORT" == "" ]]; then
echo "VOTERS: $VOTERS is not matched to NODE_ID: $NODE_ID"
exit 1
fi
declare -r CONTAINER_NAME="controller-$CONTROLLER_PORT"
declare -r CONTROLLER_JMX_PORT="${CONTROLLER_JMX_PORT:-"$(getRandomPort)"}"
declare -r JMX_CONFIG_FILE="${JMX_CONFIG_FILE}"
Expand Down Expand Up @@ -200,8 +222,14 @@ rejectProperty "broker.id"
rejectProperty "metadata.log.dir"

setPropertyIfEmpty "node.id" "$NODE_ID"
setPropertyIfEmpty "controller.quorum.voters" "$NODE_ID@${ADDRESS}:$CONTROLLER_PORT"
setPropertyIfEmpty "listeners" "CONTROLLER://:9093"
if [[ -n "$VOTERS" ]]; then
setPropertyIfEmpty "controller.quorum.voters" "$VOTERS"
else
setPropertyIfEmpty "controller.quorum.voters" "$NODE_ID@${ADDRESS}:$CONTROLLER_PORT"
fi
# this is not allowed before 3.8 ...
#setPropertyIfEmpty "advertised.listeners" "CONTROLLER://${ADDRESS}:$CONTROLLER_PORT"
setPropertyIfEmpty "listeners" "CONTROLLER://:$CONTROLLER_PORT"
setPropertyIfEmpty "process.roles" "controller"
setPropertyIfEmpty "controller.listener.names" "CONTROLLER"
setPropertyIfEmpty "num.partitions" "8"
Expand All @@ -224,7 +252,8 @@ docker run -d --init \
-v $CONTROLLER_PROPERTIES:/tmp/controller.properties:ro \
$(generateJmxConfigMountCommand) \
$metaMountCommand \
-p $CONTROLLER_PORT:9093 \
-h "$HOSTNAME" \
-p $CONTROLLER_PORT:$CONTROLLER_PORT \
-p $CONTROLLER_JMX_PORT:$CONTROLLER_JMX_PORT \
-p $EXPORTER_PORT:$EXPORTER_PORT \
"$IMAGE_NAME" sh -c "./bin/kafka-storage.sh format -t $CLUSTER_ID -c /tmp/controller.properties --ignore-formatted && ./bin/kafka-server-start.sh /tmp/controller.properties"
Expand All @@ -235,5 +264,9 @@ echo "controller address: ${ADDRESS}:$CONTROLLER_PORT"
echo "jmx address: ${ADDRESS}:$CONTROLLER_JMX_PORT"
echo "exporter address: ${ADDRESS}:$EXPORTER_PORT"
echo "================================================="
echo "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.voters=$NODE_ID@${ADDRESS}:$CONTROLLER_PORT to join broker"
if [[ -n "$VOTERS" ]]; then
echo "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.voters=$VOTERS to join broker"
else
echo "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.voters=$NODE_ID@${ADDRESS}:$CONTROLLER_PORT to join broker"
fi
echo "================================================="

0 comments on commit 6d0ff84

Please sign in to comment.