Skip to content

Commit a95efab

Browse files
committed
Allow to configure a number of swift replicas.
Remove the scripts swift-remakerings and swift-startmain along the way. Change-Id: I7c65303791689523f02e5ae44483a6c50b2eed1e
1 parent a6651e9 commit a95efab

File tree

3 files changed

+56
-57
lines changed

3 files changed

+56
-57
lines changed

files/swift/swift-remakerings

Lines changed: 0 additions & 26 deletions
This file was deleted.

files/swift/swift-startmain

Lines changed: 0 additions & 3 deletions
This file was deleted.

stack.sh

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
404404
# By default we define 9 for the partition count (which mean 512).
405405
SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
406406

407+
# This variable allows you to configure how many replicas you want to be
408+
# configured for your Swift cluster. By default the three replicas would need a
409+
# bit of IO and Memory on a VM you may want to lower that to 1 if you want to do
410+
# only some quick testing.
411+
SWIFT_REPLICAS=${SWIFT_REPLICAS:-3}
412+
407413
# We only ask for Swift Hash if we have enabled swift service.
408414
if is_service_enabled swift; then
409415
# SWIFT_HASH is a random unique string for a swift cluster that
@@ -967,21 +973,24 @@ if is_service_enabled swift; then
967973

968974
# We then create link to that mounted location so swift would know
969975
# where to go.
970-
for x in {1..4}; do sudo ln -sf ${SWIFT_DATA_LOCATION}/drives/sdb1/$x ${SWIFT_DATA_LOCATION}/$x; done
976+
for x in $(seq ${SWIFT_REPLICAS}); do
977+
sudo ln -sf ${SWIFT_DATA_LOCATION}/drives/sdb1/$x ${SWIFT_DATA_LOCATION}/$x; done
971978

972979
# We now have to emulate a few different servers into one we
973980
# create all the directories needed for swift
974-
tmpd=""
975-
for d in ${SWIFT_DATA_LOCATION}/drives/sdb1/{1..4} \
976-
${SWIFT_CONFIG_LOCATION}/{object,container,account}-server \
977-
${SWIFT_DATA_LOCATION}/{1..4}/node/sdb1 /var/run/swift; do
978-
[[ -d $d ]] && continue
979-
sudo install -o ${USER} -g $USER_GROUP -d $d
981+
for x in $(seq ${SWIFT_REPLICAS}); do
982+
drive=${SWIFT_DATA_LOCATION}/drives/sdb1/${x}
983+
node=${SWIFT_DATA_LOCATION}/${x}/node
984+
node_device=${node}/sdb1
985+
[[ -d $node ]] && continue
986+
[[ -d $drive ]] && continue
987+
sudo install -o ${USER} -g $USER_GROUP -d $drive
988+
sudo install -o ${USER} -g $USER_GROUP -d $node_device
989+
sudo chown -R $USER: ${node}
980990
done
981991

982-
# We do want to make sure this is all owned by our user.
983-
sudo chown -R $USER: ${SWIFT_DATA_LOCATION}/{1..4}/node
984-
sudo chown -R $USER: ${SWIFT_CONFIG_LOCATION}
992+
sudo mkdir -p ${SWIFT_CONFIG_LOCATION}/{object,container,account}-server /var/run/swift
993+
sudo chown -R $USER: ${SWIFT_CONFIG_LOCATION} /var/run/swift
985994

986995
# swift-init has a bug using /etc/swift until bug #885595 is fixed
987996
# we have to create a link
@@ -1022,7 +1031,7 @@ if is_service_enabled swift; then
10221031
local log_facility=$3
10231032
local node_number
10241033

1025-
for node_number in {1..4}; do
1034+
for node_number in $(seq ${SWIFT_REPLICAS}); do
10261035
node_path=${SWIFT_DATA_LOCATION}/${node_number}
10271036
sed -e "s,%SWIFT_CONFIG_LOCATION%,${SWIFT_CONFIG_LOCATION},;s,%USER%,$USER,;s,%NODE_PATH%,${node_path},;s,%BIND_PORT%,${bind_port},;s,%LOG_FACILITY%,${log_facility}," \
10281037
$FILES/swift/${server_type}-server.conf > ${SWIFT_CONFIG_LOCATION}/${server_type}-server/${node_number}.conf
@@ -1045,29 +1054,48 @@ if is_service_enabled swift; then
10451054
tee /etc/rsyslog.d/10-swift.conf
10461055
sudo restart rsyslog
10471056

1048-
# We create two helper scripts :
1049-
#
1050-
# - swift-remakerings
1051-
# Allow to recreate rings from scratch.
1052-
# - swift-startmain
1053-
# Restart your full cluster.
1054-
#
1055-
sed -e "s,%SWIFT_CONFIG_LOCATION%,${SWIFT_CONFIG_LOCATION},;s/%SWIFT_PARTITION_POWER_SIZE%/$SWIFT_PARTITION_POWER_SIZE/" $FILES/swift/swift-remakerings | \
1056-
sudo tee /usr/local/bin/swift-remakerings
1057-
sudo install -m755 $FILES/swift/swift-startmain /usr/local/bin/
1057+
# This is where we create three different rings for swift with
1058+
# different object servers binding on different ports.
1059+
pushd ${SWIFT_CONFIG_LOCATION} >/dev/null && {
1060+
1061+
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
1062+
1063+
port_number=6010
1064+
swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1065+
for x in $(seq ${SWIFT_REPLICAS}); do
1066+
swift-ring-builder object.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1067+
port_number=$[port_number + 10]
1068+
done
1069+
swift-ring-builder object.builder rebalance
1070+
1071+
port_number=6011
1072+
swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1073+
for x in $(seq ${SWIFT_REPLICAS}); do
1074+
swift-ring-builder container.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1075+
port_number=$[port_number + 10]
1076+
done
1077+
swift-ring-builder container.builder rebalance
1078+
1079+
port_number=6012
1080+
swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1081+
for x in $(seq ${SWIFT_REPLICAS}); do
1082+
swift-ring-builder account.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1083+
port_number=$[port_number + 10]
1084+
done
1085+
swift-ring-builder account.builder rebalance
1086+
1087+
} && popd >/dev/null
1088+
10581089
sudo chmod +x /usr/local/bin/swift-*
10591090

10601091
# We then can start rsync.
10611092
sudo /etc/init.d/rsync restart || :
10621093

1063-
# Create our ring for the object/container/account.
1064-
/usr/local/bin/swift-remakerings
1065-
1066-
# And now we launch swift-startmain to get our cluster running
1067-
# ready to be tested.
1068-
/usr/local/bin/swift-startmain || :
1094+
# TODO: Bring some services in foreground.
1095+
# Launch all services.
1096+
swift-init all start
10691097

1070-
unset s swift_hash swift_auth_server tmpd
1098+
unset s swift_hash swift_auth_server
10711099
fi
10721100

10731101
# Volume Service

0 commit comments

Comments
 (0)