Skip to content

Commit

Permalink
Cleanup datastore benchmark by switching to using flag return values.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707223593
  • Loading branch information
bvliu authored and copybara-github committed Dec 17, 2024
1 parent 13ad4e0 commit 2db1277
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@
None,
'The path to Google API JSON private key file',
)
flags.DEFINE_string(
_PROJECT_ID = flags.DEFINE_string(
'google_datastore_projectId',
None,
'The project ID that has Cloud Datastore service',
)
flags.DEFINE_string(
_DATASET_ID = flags.DEFINE_string(
'google_datastore_datasetId',
None,
'The database ID that has Cloud Datastore service',
)
flags.DEFINE_string(
_DEBUG = flags.DEFINE_string(
'google_datastore_debug', 'false', 'The logging level when running YCSB'
)
flags.DEFINE_boolean(
_REPOPULATE = flags.DEFINE_boolean(
'google_datastore_repopulate',
False,
'If True, empty database & repopulate with new data.'
Expand Down Expand Up @@ -116,21 +116,21 @@ def _Install(vm):
if _KEYFILE.value.startswith('gs://'):
vm.Install('google_cloud_sdk')
vm.RemoteCommand(
f'gsutil cp {FLAGS.google_datastore_keyfile} {_KEYFILE_LOCAL_PATH}'
f'gsutil cp {_KEYFILE.value} {_KEYFILE_LOCAL_PATH}'
)
else:
vm.RemoteCopy(FLAGS.google_datastore_keyfile, _KEYFILE_LOCAL_PATH)
vm.RemoteCopy(_KEYFILE.value, _KEYFILE_LOCAL_PATH)


def _GetCommonYcsbArgs():
"""Returns common YCSB args."""
args = {
'googledatastore.projectId': FLAGS.google_datastore_projectId,
'googledatastore.debug': FLAGS.google_datastore_debug,
'googledatastore.projectId': _PROJECT_ID.value,
'googledatastore.debug': _DEBUG.value,
}
# if not provided, use the (default) database.
if FLAGS.google_datastore_datasetId:
args['googledatastore.datasetId'] = FLAGS.google_datastore_datasetId
if _DATASET_ID.value:
args['googledatastore.datasetId'] = _DATASET_ID.value
return args


Expand All @@ -148,7 +148,7 @@ def Prepare(benchmark_spec):
benchmark_spec: The benchmark specification. Contains all data that is
required to run the benchmark.
"""
if FLAGS.google_datastore_repopulate:
if _REPOPULATE.value:
EmptyDatabase()

vms = benchmark_spec.vms
Expand All @@ -172,7 +172,7 @@ def Run(benchmark_spec):
Returns:
A list of sample.Sample instances.
"""
if FLAGS.google_datastore_repopulate and not FLAGS.ycsb_skip_run_stage:
if _REPOPULATE.value and not FLAGS.ycsb_skip_run_stage:
logging.info('Sleeping 30 minutes to allow for compaction.')
time.sleep(_SLEEP_AFTER_LOADING_SECS)

Expand All @@ -195,7 +195,7 @@ def Cleanup(_):
def EmptyDatabase():
"""Deletes all entries in a datastore database."""
if _KEYFILE.value:
dataset_id = FLAGS.google_datastore_datasetId
dataset_id = _DATASET_ID.value
executor = concurrent.futures.ThreadPoolExecutor(
max_workers=_CLEANUP_THREAD_POOL_WORKERS
)
Expand Down

0 comments on commit 2db1277

Please sign in to comment.