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

Support setting replication level at destination in arv-copy options #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zoe-translates
Copy link
Contributor

arv-copy effectively used a hard-coded replication level 2 for the copied collections at the destination, bypassing the default replication level set in the destination cluster's configuration file. There was no command-line option to override this behavior.

A new command-line option, --replication, is added to the arv-copy command, following the arv-put command's semantics. If left unspecified, the destination's default replication setting is used. If that setting cannot be found, use the fallback value of 2.

Arvados-DCO-1.1-Signed-off-by: Zoë Ma [email protected]

@zoe-translates
Copy link
Contributor Author

A minor point I should add -- when encountering an invalid replication level (such as zero or a negative number), it behaves as if the command line option was not set, and will go on to use the default value obtained from the dst cluster config.

arv-copy effectively used a hard-coded replication level 2 for the
copied collections at the destination, bypassing the default replication
level set in the destination cluster's configuration file. There was no
command-line option to override this behavior.

A new command-line option, --replication, is added to the arv-copy
command, following the arv-put command's semantics. If left unspecified,
the destination's default replication setting is used. If that setting
cannot be found, use the fallback value of 2.

Arvados-DCO-1.1-Signed-off-by: Zoë Ma <[email protected]>
@zoe-translates zoe-translates force-pushed the arv-copy-respect-destination-cluster-default-replication-setting-and-add-cmdline-option-to-override branch from bc1a005 to 82c9300 Compare July 25, 2024 03:05
Copy link

sonarcloud bot commented Jul 25, 2024

@@ -111,6 111,9 @@ def main():
copy_opts.add_argument(
'--project-uuid', dest='project_uuid',
help='The UUID of the project at the destination to which the collection or workflow should be copied.')
copy_opts.add_argument(
'--replication', type=int, metavar='N',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pass a custom type function that validates that the value is a positive integer, and raises ValueError if not. With this change, argparse would immediately report the error to the user, which provides a nicer UI than an easy-to-miss debug message.

arvados.commands._util._pos_int is an example of a custom type function, and it almost does what you want, except it accepts 0 as a valid value. We could turn that function into a closure that accepts a minimum allowable value, and then use it here in addition to retry_opt below.

else:
# Obtain default or fallback collection replication setting on the
# destination
n_copies = dst.config().get("Collections", {}).get("DefaultReplication")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider instead:

try:
    n_copies = dst.config()["Collections"]["DefaultReplication"]
except KeyError:
    n_copies = 2

This way, instead of interleaving default logic and lookup logic, you can just do the lookup you prefer, and have a fallback in case it fails at any point. (It should also perform better, but for sure that basically doesn't matter for a one-time lookup outside a hot loop like this.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants