Skip to content

Commit

Permalink
[DOCKER] adopt controller.quorum.bootstrap.servers
Browse files Browse the repository at this point in the history
  • Loading branch information
chia7712 committed Nov 25, 2024
1 parent 72c0715 commit 9fab2a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
6 changes: 3 additions & 3 deletions docker/start_broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function showHelp() {
echo "Required Argument (zk mode): "
echo " zookeeper.connect=node:22222 set zookeeper connection"
echo "Required Argument (kraft mode): "
echo " controller.quorum.voters=12310@node:14335 set controller connection"
echo " controller.quorum.bootstrap.servers=12310@node:14335 set controller connection"
echo "Optional Arguments: "
echo " num.io.threads=10 set broker I/O threads"
echo " num.network.threads=10 set broker network threads"
Expand Down Expand Up @@ -287,7 +287,7 @@ while [[ $# -gt 0 ]]; do
exit 0
fi
echo "$1" >>"$BROKER_PROPERTIES"
if [[ "$1" == "controller.quorum.voters"* ]]; then
if [[ "$1" == "controller.quorum.bootstrap.servers"* ]]; then
quorum="kraft"
fi
if [[ "$1" == "zookeeper.connect"* ]]; then
Expand All @@ -300,7 +300,7 @@ while [[ $# -gt 0 ]]; do
done

if [[ "$quorum" == "unknown" ]]; then
echo "please define either zookeeper.connect or controller.quorum.voters"
echo "please define either zookeeper.connect or controller.quorum.bootstrap.servers"
exit 2
fi

Expand Down
38 changes: 4 additions & 34 deletions docker/start_controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,8 @@ 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)"}

# 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 @@ -218,7 +196,7 @@ while [[ $# -gt 0 ]]; do
done

rejectProperty "node.id"
rejectProperty "controller.quorum.voters"
rejectProperty "controller.quorum.bootstrap.servers"
rejectProperty "listeners"
rejectProperty "process.roles"
rejectProperty "controller.listener.names"
Expand All @@ -229,11 +207,7 @@ rejectProperty "broker.id"
rejectProperty "metadata.log.dir"

setPropertyIfEmpty "node.id" "$NODE_ID"
if [[ -n "$VOTERS" ]]; then
setPropertyIfEmpty "controller.quorum.voters" "$VOTERS"
else
setPropertyIfEmpty "controller.quorum.voters" "$NODE_ID@${ADDRESS}:$CONTROLLER_PORT"
fi
setPropertyIfEmpty "controller.quorum.bootstrap.servers" "${ADDRESS}:$CONTROLLER_PORT"
# this is not allowed before 3.8 ...
#setPropertyIfEmpty "advertised.listeners" "CONTROLLER://${ADDRESS}:$CONTROLLER_PORT"
setPropertyIfEmpty "listeners" "CONTROLLER://:$CONTROLLER_PORT"
Expand Down Expand Up @@ -268,17 +242,13 @@ docker run -d --init \
-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 $release_version -c /tmp/controller.properties --ignore-formatted && ./bin/kafka-server-start.sh /tmp/controller.properties"
"$IMAGE_NAME" sh -c "./bin/kafka-storage.sh format -t $CLUSTER_ID $release_version -c /tmp/controller.properties --standalone --ignore-formatted && ./bin/kafka-server-start.sh /tmp/controller.properties"

echo "================================================="
[[ -n "$META_FOLDER" ]] && echo "mount $META_FOLDER to container: $CONTAINER_NAME"
echo "controller address: ${ADDRESS}:$CONTROLLER_PORT"
echo "jmx address: ${ADDRESS}:$CONTROLLER_JMX_PORT"
echo "exporter address: ${ADDRESS}:$EXPORTER_PORT"
echo "================================================="
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 "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.bootstrap.servers=${ADDRESS}:$CONTROLLER_PORT to join broker"
echo "================================================="

0 comments on commit 9fab2a0

Please sign in to comment.