-
Notifications
You must be signed in to change notification settings - Fork 115
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
[PR #6064/0a5ac4aa backport][3.63] [SAT-29018] Fix/corrupted RA blocks content streaming #6161
Draft
pedro-psb
wants to merge
3
commits into
pulp:3.63
Choose a base branch
from
pedro-psb:patchback/backports/3.63/0a5ac4aaf0f28b1055ee421a2ec35c65726039b0/pr-6064
base: 3.63
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+317
−43
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -euv | ||
|
||
# # See pulpcore.app.util.ENABLE_6064_BACKPORT_WORKAROUND for context. | ||
# This needs to be set here because it relies on service init. | ||
# Its being tested in only one scenario to have both cases covered. | ||
if [[ "$TEST" == "s3" ]]; then | ||
cmd_prefix pulpcore-manager backport-patch-6064 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
On a request for on-demand content in the content app, a corrupted Remote that | ||
contains the wrong binary (for that content) prevented other Remotes from being | ||
attempted on future requests. Now the last failed Remotes are temporarily ignored | ||
and others may be picked. | ||
|
||
Because the [original](https://github.com/pulp/pulpcore/pull/6064) contains a migraton, | ||
this is backported here as an optional patch which can be enabled by running the | ||
pulpcore-manager command: `backport-patch-6064`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from django.core.management.base import BaseCommand | ||
from gettext import gettext as _ | ||
from django.db import connection | ||
from pulpcore.app.models import RemoteArtifact | ||
|
||
|
||
CHECK_COL_QUERY = """ | ||
SELECT COUNT(*) | ||
FROM information_schema.columns | ||
WHERE table_name = %s | ||
AND column_name = %s; | ||
""" | ||
|
||
MODIFY_QUERY_TMPL = """ | ||
ALTER TABLE {} | ||
ADD COLUMN {} TIMESTAMPTZ DEFAULT NULL; | ||
""" | ||
|
||
HELP = _( | ||
""" | ||
Enables patch backport of #6064 (https://github.com/pulp/pulpcore/pull/6064). | ||
The fix prevents corrupted remotes from making content unreacahble by adding | ||
a cooldown time, which is tracked by a new field, 'RemoteArtifact.failed_at'. | ||
This command adds the field to the appropriate table. | ||
""" | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = HELP | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--dry-run", | ||
action="store_true", | ||
help="Run the migration in dry-run mode without saving changes", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
dry_run = options.get("dry_run", False) | ||
try: | ||
with connection.cursor() as cursor: | ||
# Check if column already exists | ||
table_name = RemoteArtifact._meta.db_table | ||
field_name = "failed_at" | ||
cursor.execute(CHECK_COL_QUERY, [table_name, field_name]) | ||
field_exists = cursor.fetchone()[0] > 0 | ||
if field_exists: | ||
self._print_success(f"Field '{table_name}.{field_name}' already exists.") | ||
self._print_success("Nothing to be done") | ||
return | ||
|
||
# Add field to table | ||
self._print_info(f"Adding {field_name!r} column to {table_name!r}...") | ||
MODIFY_QUERY = MODIFY_QUERY_TMPL.format(table_name, field_name) | ||
if not dry_run: | ||
cursor.execute(MODIFY_QUERY) | ||
self._print_success("Done") | ||
else: | ||
self._print_warn("[DRY-RUN] SQL that would be executed:") | ||
self._print_info(MODIFY_QUERY) | ||
except Exception as e: | ||
self._print_error(f"Migration failed: {str(e)}") | ||
raise | ||
|
||
def _print_info(self, msg): | ||
self.stdout.write(msg) | ||
|
||
def _print_success(self, msg): | ||
self.stdout.write(self.style.SUCCESS(msg)) | ||
|
||
def _print_error(self, msg): | ||
self.stdout.write(self.style.ERROR(msg)) | ||
|
||
def _print_warn(self, msg): | ||
self.stdout.write(self.style.WARNING(msg)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What exactly does this do?
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 know about the implementation, but the effect is like adding the field dynamically.
For example, django will be able to use the filter
RemoteArtifact.objects.exclude(failed_at__gte=Y)
. If the field really exist in the database, it succeeds, otherwise it raises a ProgrammingError.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.
And something in this PR is altering the actual db table, so this can be used?
That feels like reinventing the whole db migrations framework with out the safeguards. A subsequent upgrade is then probably going to fail. When we said "You cannot backport a migration.", that meant you cannot add db altering code to a release branch assuming that all db alteration would be done by a migration in the django framework. My gut feeling is this is way too dangerous.
Can you think of a solution that does not require changing the db schema? We should be lucky by the fact that this is kind of ephemeral data.
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.
My assumption was that a field addition (that doesn't have any other couplings) would be safe. But I can see this is a sensitive area. I'll explore those alternatives.
(I had though of per-worker cache, but concluded it would be simpler to use the db - before knowing about the backport problem).
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.
Thanks for understanding my concerns.
At this point I think postgres may even reject to apply the migration on top of this out of bounds change.
If I could choose, i'd prefer the per worker in memory caching solution. Even if it would only solve the problem half way.
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.
About the idea of repurposing another field, there is
pulp_created
andpulp_last_updated
.But I'm afraid of unexpected side-effects, like
pulp_last_updated
being updated by something and cooling down a good remote.Or something else (thus, unexpected), because those are in the system for so long.
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.
This is not about a Remote, but the RemoteArtifact, right? I'm not so concerned as this class is only used internally and never visible to the user. I highly doubt that we have any logic depending on it.