Skip to content

Commit ab0d3cd

Browse files
Merge branch 'master' into dockerfile_v1
2 parents 15f953f + a9bed81 commit ab0d3cd

File tree

7 files changed

+34
-20
lines changed

7 files changed

+34
-20
lines changed

.pullapprove.yml

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

MongoBackup/Methods/Dump.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# noinspection PyStringFormat
1313
class Dump(Process):
1414
def __init__(self, response_queue, backup_name, host_port, user, password, authdb, base_dir, binary,
15-
dump_gzip=False, verbose=False):
15+
threads=0, dump_gzip=False, verbose=False):
1616
Process.__init__(self)
1717
self.host, port = host_port.split(":")
1818
self.host_port = host_port
@@ -24,6 +24,7 @@ def __init__(self, response_queue, backup_name, host_port, user, password, authd
2424
self.authdb = authdb
2525
self.base_dir = base_dir
2626
self.binary = binary
27+
self.threads = threads
2728
self.dump_gzip = dump_gzip
2829
self.verbose = verbose
2930

@@ -52,6 +53,8 @@ def run(self):
5253
))
5354

5455
mongodump_flags = ["-h", self.host_port, "--oplog", "-o", "%s/dump" % self.backup_dir]
56+
if self.threads > 0:
57+
mongodump_flags.extend(["--numParallelCollections="+str(self.threads)])
5558
if self.dump_gzip:
5659
mongodump_flags.extend(["--gzip"])
5760
if self.authdb and self.authdb != "admin":

MongoBackup/Methods/Dumper.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import logging
22

33
from fabric.api import hide, settings, local
4-
from multiprocessing import Queue
4+
from math import floor
5+
from multiprocessing import Queue, cpu_count
56
from time import sleep
67

78

@@ -22,6 +23,7 @@ def __init__(self, secondaries, base_dir, binary, dump_gzip=False, user=None, pa
2223
self.verbose = verbose
2324

2425
self.config_replset = False
26+
self.cpu_count = cpu_count()
2527
self.response_queue = Queue()
2628
self.threads = []
2729
self._summary = {}
@@ -65,6 +67,18 @@ def wait(self):
6567
raise Exception, "Not all mongodump threads completed successfully!", None
6668

6769
def run(self):
70+
# decide how many parallel dump workers to use based on cpu count vs # of shards (if 3.2+), 8 max workers max to protect the db
71+
self.threads_per_dump = 0
72+
self.threads_per_dump_max = 8
73+
if tuple(self.version.split(".")) >= tuple("3.2.0".split(".")):
74+
self.threads_per_dump = 1
75+
if self.cpu_count > len(self.secondaries):
76+
self.threads_per_dump = int(floor(self.cpu_count / len(self.secondaries)))
77+
if self.threads_per_dump > self.threads_per_dump_max:
78+
self.threads_per_dump = self.threads_per_dump_max
79+
else:
80+
logging.warn("Threading unsupported by mongodump version %s. Use mongodump 3.2.0 or greater to enable per-dump threading." % self.version)
81+
6882
# backup a secondary from each shard:
6983
for shard in self.secondaries:
7084
secondary = self.secondaries[shard]
@@ -77,6 +91,7 @@ def run(self):
7791
self.authdb,
7892
self.base_dir,
7993
self.binary,
94+
self.threads_per_dump,
8095
self.dump_gzip,
8196
self.verbose
8297
)
@@ -87,23 +102,27 @@ def run(self):
87102

88103
# start all threads and wait
89104
logging.info(
90-
"Starting backups in threads using mongodump %s (inline gzip: %s)" % (self.version, str(self.dump_gzip)))
105+
"Starting backups using mongodump %s (inline gzip: %s, threads per dump: %i)" % (self.version, str(self.dump_gzip), self.threads_per_dump))
91106
for thread in self.threads:
92107
thread.start()
93108
self.wait()
94109

95110
# backup a single non-replset config server, if exists:
96111
if not self.config_replset and isinstance(self.config_server, dict):
97112
logging.info("Using non-replset backup method for config server mongodump")
113+
config_server = self.config_server['host']
114+
if not ":" in config_server:
115+
config_server = config_server+":27019"
98116
self.threads = [Dump(
99117
self.response_queue,
100118
'configsvr',
101-
self.config_server['host'],
119+
config_server,
102120
self.user,
103121
self.password,
104122
self.authdb,
105123
self.base_dir,
106124
self.binary,
125+
self.threads_per_dump,
107126
self.dump_gzip,
108127
self.verbose
109128
)]

MongoBackup/Oplog/Resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self):
6767
logging.info("No oplog changes to resolve for %s:%s" % (host, port))
6868
elif backup_oplog['last_ts'] > tailed_oplog['last_ts']:
6969
logging.fatal(
70-
"Backup oplog is newer than the tailed oplog! This situation is unsupported. Please retry backup")
70+
"Backup oplog is newer than the tailed oplog, this situation is unsupported! Please retry backup.\nBackup oplog: %s\nTailed oplog: %s" % (backup_oplog, tailed_oplog))
7171
raise Exception, "Backup oplog is newer than the tailed oplog!", None
7272
else:
7373
try:

MongoBackup/Sharding.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def get_config_server(self, force=False):
127127
if force or not self.config_server:
128128
configdb_hosts = self.get_configdb_hosts()
129129
try:
130-
config_host, config_port = configdb_hosts[0].split(":")
130+
config_host = configdb_hosts[0]
131+
config_port = 27019
132+
if ":" in configdb_hosts[0]:
133+
config_host, config_port = configdb_hosts[0].split(":")
131134
validate_hostname(config_host)
132135
logging.info("Found sharding config server: %s:%s" % (config_host, config_port))
133136

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0
1+
0.4.0

scripts/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ if [ -d ${srcdir} ]; then
8585
fi
8686
source ${venvdir}/bin/activate
8787

88-
${venvdir}/bin/pip install pex requests
88+
${venvdir}/bin/python2.7 ${venvdir}/bin/pip install pex requests
8989
if [ $? -gt 0 ]; then
9090
echo "Failed to install pex utility for building!"
9191
exit 1
9292
fi
9393

9494
[ ! -d ${bindir} ] && mkdir -p ${bindir}
95-
${venvdir}/bin/pex --disable-cache -o ${output_file} -m ${py_entry_point} -r ${require_file} ${builddir}
95+
${venvdir}/bin/python2.7 ${venvdir}/bin/pex --disable-cache -o ${output_file} -m ${py_entry_point} -r ${require_file} ${builddir}
9696
if [ $? -lt 1 ] && [ -x ${output_file} ]; then
9797
echo "pex executable written to '$output_file'"
9898
rm -rf ${builddir}

0 commit comments

Comments
 (0)