Browse code

Allow to configure a number of swift replicas.

Remove the scripts swift-remakerings and swift-startmain along the way.

Change-Id: I7c65303791689523f02e5ae44483a6c50b2eed1e

Chmouel Boudjnah authored on 2012/02/16 19:35:26
Showing 3 changed files
1 1
deleted file mode 100755
... ...
@@ -1,26 +0,0 @@
1
-#!/bin/bash
2
-
3
-cd %SWIFT_CONFIG_LOCATION%
4
-
5
-rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
6
-
7
-swift-ring-builder object.builder create %SWIFT_PARTITION_POWER_SIZE% 3 1
8
-swift-ring-builder object.builder add z1-127.0.0.1:6010/sdb1 1
9
-swift-ring-builder object.builder add z2-127.0.0.1:6020/sdb2 1
10
-swift-ring-builder object.builder add z3-127.0.0.1:6030/sdb3 1
11
-swift-ring-builder object.builder add z4-127.0.0.1:6040/sdb4 1
12
-swift-ring-builder object.builder rebalance
13
-
14
-swift-ring-builder container.builder create %SWIFT_PARTITION_POWER_SIZE% 3 1
15
-swift-ring-builder container.builder add z1-127.0.0.1:6011/sdb1 1
16
-swift-ring-builder container.builder add z2-127.0.0.1:6021/sdb2 1
17
-swift-ring-builder container.builder add z3-127.0.0.1:6031/sdb3 1
18
-swift-ring-builder container.builder add z4-127.0.0.1:6041/sdb4 1
19
-swift-ring-builder container.builder rebalance
20
-
21
-swift-ring-builder account.builder create %SWIFT_PARTITION_POWER_SIZE% 3 1
22
-swift-ring-builder account.builder add z1-127.0.0.1:6012/sdb1 1
23
-swift-ring-builder account.builder add z2-127.0.0.1:6022/sdb2 1
24
-swift-ring-builder account.builder add z3-127.0.0.1:6032/sdb3 1
25
-swift-ring-builder account.builder add z4-127.0.0.1:6042/sdb4 1
26
-swift-ring-builder account.builder rebalance
27 1
deleted file mode 100755
... ...
@@ -1,3 +0,0 @@
1
-#!/bin/bash
2
-
3
-swift-init all restart
... ...
@@ -404,6 +404,12 @@ SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
404 404
 # By default we define 9 for the partition count (which mean 512).
405 405
 SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
406 406
 
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
+
407 413
 # We only ask for Swift Hash if we have enabled swift service.
408 414
 if is_service_enabled swift; then
409 415
     # SWIFT_HASH is a random unique string for a swift cluster that
... ...
@@ -967,21 +973,24 @@ if is_service_enabled swift; then
967 967
 
968 968
     # We then create link to that mounted location so swift would know
969 969
     # where to go.
970
-    for x in {1..4}; do sudo ln -sf ${SWIFT_DATA_LOCATION}/drives/sdb1/$x ${SWIFT_DATA_LOCATION}/$x; done
970
+    for x in $(seq ${SWIFT_REPLICAS}); do
971
+        sudo ln -sf ${SWIFT_DATA_LOCATION}/drives/sdb1/$x ${SWIFT_DATA_LOCATION}/$x; done
971 972
 
972 973
     # We now have to emulate a few different servers into one we
973 974
     # 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
975
+    for x in $(seq ${SWIFT_REPLICAS}); do
976
+            drive=${SWIFT_DATA_LOCATION}/drives/sdb1/${x}
977
+            node=${SWIFT_DATA_LOCATION}/${x}/node
978
+            node_device=${node}/sdb1
979
+            [[ -d $node ]] && continue
980
+            [[ -d $drive ]] && continue
981
+            sudo install -o ${USER} -g $USER_GROUP -d $drive
982
+            sudo install -o ${USER} -g $USER_GROUP -d $node_device
983
+            sudo chown -R $USER: ${node}
980 984
     done
981 985
 
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}
986
+   sudo mkdir -p ${SWIFT_CONFIG_LOCATION}/{object,container,account}-server /var/run/swift
987
+   sudo chown -R $USER: ${SWIFT_CONFIG_LOCATION} /var/run/swift
985 988
 
986 989
    # swift-init has a bug using /etc/swift until bug #885595 is fixed
987 990
    # we have to create a link
... ...
@@ -1022,7 +1031,7 @@ if is_service_enabled swift; then
1022 1022
        local log_facility=$3
1023 1023
        local node_number
1024 1024
 
1025
-       for node_number in {1..4}; do
1025
+       for node_number in $(seq ${SWIFT_REPLICAS}); do
1026 1026
            node_path=${SWIFT_DATA_LOCATION}/${node_number}
1027 1027
            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}," \
1028 1028
                $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
1045 1045
        tee /etc/rsyslog.d/10-swift.conf
1046 1046
    sudo restart rsyslog
1047 1047
 
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/
1048
+   # This is where we create three different rings for swift with
1049
+   # different object servers binding on different ports.
1050
+   pushd ${SWIFT_CONFIG_LOCATION} >/dev/null && {
1051
+
1052
+       rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
1053
+
1054
+       port_number=6010
1055
+       swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1056
+       for x in $(seq ${SWIFT_REPLICAS}); do
1057
+           swift-ring-builder object.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1058
+           port_number=$[port_number + 10]
1059
+       done
1060
+       swift-ring-builder object.builder rebalance
1061
+
1062
+       port_number=6011
1063
+       swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1064
+       for x in $(seq ${SWIFT_REPLICAS}); do
1065
+           swift-ring-builder container.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1066
+           port_number=$[port_number + 10]
1067
+       done
1068
+       swift-ring-builder container.builder rebalance
1069
+
1070
+       port_number=6012
1071
+       swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1072
+       for x in $(seq ${SWIFT_REPLICAS}); do
1073
+           swift-ring-builder account.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1074
+           port_number=$[port_number + 10]
1075
+       done
1076
+       swift-ring-builder account.builder rebalance
1077
+
1078
+   } && popd >/dev/null
1079
+
1058 1080
    sudo chmod +x /usr/local/bin/swift-*
1059 1081
 
1060 1082
    # We then can start rsync.
1061 1083
    sudo /etc/init.d/rsync restart || :
1062 1084
 
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 || :
1085
+   # TODO: Bring some services in foreground.
1086
+   # Launch all services.
1087
+   swift-init all start
1069 1088
 
1070
-   unset s swift_hash swift_auth_server tmpd
1089
+   unset s swift_hash swift_auth_server
1071 1090
 fi
1072 1091
 
1073 1092
 # Volume Service