Skip to content

Commit

Permalink
diff user use diff subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
yujun777 committed Nov 7, 2024
1 parent a572247 commit 3bb176f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
45 changes: 39 additions & 6 deletions docker/runtime/doris-compose/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

import configparser
import filelock
import getpass
import hashlib
import jsonpickle
import os
import os.path
import utils

DOCKER_DORIS_PATH = "/opt/apache-doris"
LOCAL_DORIS_PATH = os.getenv("LOCAL_DORIS_PATH", "/tmp/doris")
DORIS_SUBNET_START = int(os.getenv("DORIS_SUBNET_START", 128))

# an integer between 128 and 191, generally no need to set
DORIS_SUBNET_START = os.getenv("DORIS_SUBNET_START")

LOCAL_RESOURCE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"resource")
DOCKER_RESOURCE_PATH = os.path.join(DOCKER_DORIS_PATH, "resource")
Expand Down Expand Up @@ -95,11 +100,39 @@ def gen_subnet_prefix16():
except:
pass

for i in range(DORIS_SUBNET_START, 192):
for j in range(256):
subnet = "{}.{}".format(i, j)
if not used_subnet.get(subnet, False):
return subnet
subnet_begin = 128
subnet_end = 192

subnet_part_1 = None
subnet_part_2 = None
if DORIS_SUBNET_START:
subnet_part_1 = int(DORIS_SUBNET_START)
subnet_part_2 = 0
else:
m = hashlib.md5()
m.update(getpass.getuser().encode("utf-8"))
hash_val = int(m.hexdigest(), 16)
# want subnet part ii to be a small num, just less than 100, so don't use 256 here.
small_width = 100
slot_num = (subnet_end - subnet_begin) * small_width
idx = hash_val % slot_num
if idx < 0:
idx += slot_num
subnet_part_1 = subnet_begin + int(idx / small_width)
subnet_part_2 = idx % small_width

intervals = [
[(subnet_part_1, subnet_part_1 + 1), (subnet_part_2, 256)],
[(subnet_part_1 + 1, subnet_end), (0, 256)],
[(subnet_begin, subnet_part_1), (0, 256)],
[(subnet_part_1, subnet_part_1 + 1), (0, subnet_part_2)],
]
for interval in intervals:
for i in range(interval[0][0], interval[0][1]):
for j in range(interval[1][0], interval[1][1]):
subnet = "{}.{}".format(i, j)
if not used_subnet.get(subnet, False):
return subnet

raise Exception("Failed to gen subnet")

Expand Down
3 changes: 1 addition & 2 deletions docker/runtime/doris-compose/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def run(self, args):
LOG.info(
utils.render_green("{} succ, total related node num {}".format(
show_cmd, related_node_num)))
return ""

if for_all:
related_nodes = cluster.get_all_nodes()
Expand Down Expand Up @@ -381,7 +380,7 @@ def add_parser(self, args_parsers):
group2.add_argument("--force-recreate",
default=False,
action=self._get_parser_bool_action(True),
help="Recreate containers even if their configuration" \
help="Recreate containers even if their configuration " \
"and image haven't changed. ")

parser.add_argument("--coverage-dir",
Expand Down
2 changes: 1 addition & 1 deletion docker/runtime/doris-compose/resource/init_be.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ main() {
add_be_to_cluster

health_log "run start_be.sh"
bash $DORIS_HOME/bin/start_be.sh --daemon
bash $DORIS_HOME/bin/start_be.sh --daemon | tee -a $DORIS_HOME/log/be.out

wait_process
}
Expand Down
5 changes: 2 additions & 3 deletions docker/runtime/doris-compose/resource/init_cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ main() {

check_init_cloud &

health_log "input args: $ARGS"

bash bin/start.sh $ARGS --daemon
health_log "run starts.sh with args: $ARGS"
bash bin/start.sh $ARGS --daemon | tee -a $DORIS_HOME/log/doris_cloud.out

wait_process
}
Expand Down
15 changes: 10 additions & 5 deletions docker/runtime/doris-compose/resource/init_fe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ fe_daemon() {
done
}

run_fe() {
health_log "run start_fe.sh"
bash $DORIS_HOME/bin/start_fe.sh --daemon $@ | tee -a $DORIS_HOME/log/fe.out
}

start_cloud_fe() {
if [ -f "$REGISTER_FILE" ]; then
fe_daemon &
bash $DORIS_HOME/bin/start_fe.sh --daemon
run_fe
return
fi

Expand All @@ -95,7 +100,7 @@ start_cloud_fe() {
touch $REGISTER_FILE

fe_daemon &
bash $DORIS_HOME/bin/start_fe.sh --daemon
run_fe

if [ "$MY_ID" == "1" ]; then
echo $MY_IP >$MASTER_FE_IP_FILE
Expand Down Expand Up @@ -162,7 +167,7 @@ start_cloud_fe() {
touch $REGISTER_FILE

fe_daemon &
bash $DORIS_HOME/bin/start_fe.sh --daemon
run_fe

if [ "$MY_ID" == "1" ]; then
echo $MY_IP >$MASTER_FE_IP_FILE
Expand Down Expand Up @@ -199,11 +204,11 @@ start_local_fe() {

if [ -f $REGISTER_FILE ]; then
fe_daemon &
bash $DORIS_HOME/bin/start_fe.sh --daemon
run_fe
else
add_local_fe
fe_daemon &
bash $DORIS_HOME/bin/start_fe.sh --helper $MASTER_FE_IP:$FE_EDITLOG_PORT --daemon
run_fe --helper $MASTER_FE_IP:$FE_EDITLOG_PORT
fi
}

Expand Down

0 comments on commit 3bb176f

Please sign in to comment.