-
Notifications
You must be signed in to change notification settings - Fork 10
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
Catch setting role exception and output a warning instead of stop migration process #33
base: main
Are you sure you want to change the base?
Conversation
747330d
to
135af39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the time to get this review. Some comments:
- What is the exact error? It's unclear from both the PR text and the commit message; this is a statement that's being performed on the target db as far as I can understand; why should this be a problem when migrating from RDS/Aurora?
- Catching "ProgrammingError" is too broad here IMHO and risks going on even when other issues arise; can't you find a more specific exception?
0e09045
to
0e871c3
Compare
0e871c3
to
da827b4
Compare
@alanfranz-at-work @carobme I've added this new flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "filtered" route is better, but will need some refinements.
please remember to dismiss stale reviews otherwise we may not notice your PR in the review queue!
message="role created", | ||
) | ||
# display warning when ProgrammingErrorERROR 42501: InsufficientPrivilege: permission denied to set parameter for a role | ||
except psycopg2.errors.InsufficientPrivilege: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you choose to go for the "filtered roles" route, why do you still need this change? Isn't this overlapping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope to keep this change, with the filtered roles flag, user needs to know exactly what roles to filter before the migration and supply that to the cli argument, should there be any special setting with this role that is unable to be set with avnadmin's permission it would stop the migration as the exception is not caught. I think failing to set a role should not stop the migration process completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is... it's quite a bold statement. We'd need to be sure that such role is not needed in the destination database. If we go on and then we discover after months that the migrated db doesn't work anymore, that's an issue. It's better to fail fast.
Again, this will impact everything: aiven_db_migrate is a library that could be used anywhere (and it's used in aiven-core as well, as a library), we're adding a very generic workaround for a very narrow use case.
This is an AWS-specific thing. Maybe an idea could be add a specific flag to the command line, something like --ignore-source-aws-roles
, and you put AWS-specific roles there, and pass them to filtered roles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds like a good idea, I could just add rdstopmgr
to the filtered_roles if --ignore-source-aws-roles
is specified, do you think we should include all the rds*
roles when the flag specified? and a similar flag such as --ignore-source-cloudsql-roles
? one concern is if aws and google changes the names of these roles, probably not something we want to maintain in the migration tool code...
1a6cc73
to
7a98a1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can go in yet :-/
Still pending question:
I still don't understand why this happens and how, can you explain your setup and some details from the rdstopmgr role? Is it got some permission that we don't allow the end-user to assign? Could you paste some more detailed traceback?
self, | ||
conn_info: Union[str, Dict[str, Any]], | ||
filtered_db: Optional[str] = None, | ||
filtered_roles: Tuple[str] = ((), ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type for filtered_roles
is wrong (tuple has fixed size, you need sequence or list or set) and the default argument type doesn't match.
if not self._pg_roles: | ||
# exclude system roles | ||
roles = self.c("SELECT quote_ident(rolname) as safe_rolname, * FROM pg_catalog.pg_roles WHERE oid > 16384") | ||
roles = self.c(f"SELECT quote_ident(rolname) as safe_rolname, * FROM pg_catalog.pg_roles WHERE oid > 16384") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove f-string as it's not used anymore, please
for r in roles: | ||
rolname = r["rolname"] | ||
|
||
if rolname in self.filtered_roles: | ||
self.log.debug(f'Skipping filtered role: [{r["rolname"]}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: loggers have their own formatting system, no need to use f-strings.
@@ -738,15 +754,20 @@ def __init__( | |||
verbose: bool = False, | |||
mangle: bool = False, | |||
filtered_db: Optional[str] = None, | |||
filtered_roles: Tuple[str] = ((), ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, typing issues
# display warning when ProgrammingErrorERROR 42501: InsufficientPrivilege: permission denied to set parameter for a role | ||
except psycopg2.errors.InsufficientPrivilege: | ||
self.log.warning( | ||
f'Setting [{role.rolname}]: [{key}] = [{value}] failed. psycopg2.errors.InsufficientPrivilege' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: logger formatting
@@ -1343,6 +1372,9 @@ def main(args=None, *, prog="pg_migrate"): | |||
else: | |||
logging.basicConfig(level=logging.INFO, format=log_format) | |||
|
|||
if not args.filtered_roles: | |||
args.filtered_roles = () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parser has already the support for default values. but this can't work. should be an empty string as default value, I think.
then, down there, you could do something like
filtered_roles=[ role for role in args.filtered_roles.split(",") if role != "" ]
(untested code)
so that the filtered_roles sequence is actually empty when passing it to the main func.
@alanfranz-at-work
where this
when the migration tool try to set This can be reproduced by creating a new aws rds or aurora and a new aiven postgresql and run the migration tool. First time the migration tool would stop as soon as it failed to set the |
Proposed changes in this pull request
Catch exception when setting role fails and output a warning instead of stop the migration process.
This is a fix for migration from AWS RDS/Aurora as it stops when setting rol_config for rdstopmgr role.
Type (put an
x
where ever applicable)Checklist
Please put an
x
against the checkboxes. Write a small comment explaining if itsN/A
(not applicable)Optional extra information