Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emptyCheckInterval option to improve performance #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"batchSize": -1,
"verbosity": 0,
"continueOnError": false,
"emptyCheckInterval": 60,

"logging": {
"type": "file",
Expand Down
14 changes: 14 additions & 0 deletions mongo_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def from_config(cls, config):
collection_dump=(not config['noDump']),
batch_size=config['batchSize'],
continue_on_error=config['continueOnError'],
empty_check_interval=config['emptyCheckInterval'],
auth_username=config['authentication.adminUsername'],
auth_key=auth_key,
fields=config['fields'],
Expand Down Expand Up @@ -970,6 +971,19 @@ def apply_ssl(option, cli_values):
" set of documents due to errors may cause undefined"
" behavior. Use this flag to dump only.")

empty_check_interval = add_option(
config_key="emptyCheckInterval",
default=60,
type=int)

empty_check_interval.add_cli(
"--empty-check-interval", dest="empty_check_interval",
help="Before a collection dump, each OplogThread"
" will confirm that the connected replicaset has"
" documents in its collections that need to be"
" upserted. If none are found, it will wait this"
" many seconds before checking again.")

config_file = add_option()
config_file.add_cli(
"-c", "--config-file", dest="config_file", help=
Expand Down
18 changes: 18 additions & 0 deletions mongo_connector/oplog_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def __init__(self, primary_client, doc_managers,
# Whether the collection dump gracefully handles exceptions
self.continue_on_error = kwargs.get('continue_on_error', False)

# How often to recheck a replicaset with zero matching docs
self.empty_check_interval = kwargs.get('empty_check_interval', 60)

# Set of fields to export
self.fields = kwargs.get('fields', [])

Expand Down Expand Up @@ -412,6 +415,21 @@ def dump_collection(self):
namespace = "%s.%s" % (database, coll)
dump_set.append(namespace)

def has_docs_to_dump():
for namespace in dump_set:
database, coll = namespace.split('.', 1)
target_coll = self.primary_client[database][coll]
if util.retry_until_ok(target_coll.count) > 0:
return True
return False

while not has_docs_to_dump():
LOG.warning("No docs matching namespace %s on %s,"
" sleeping %d seconds" % (
dump_set, self.primary_client,
self.empty_check_interval))
time.sleep(self.empty_check_interval)

timestamp = util.retry_until_ok(self.get_last_oplog_timestamp)
if timestamp is None:
return None
Expand Down