-
Notifications
You must be signed in to change notification settings - Fork 13
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
Compact index #105
Merged
Merged
Compact index #105
Changes from all commits
Commits
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
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,4 @@ | ||
Implemented new synching and publishing the compact index format. | ||
Rubymarshal and quick index will still be generated when publishing, but synching is exclusive to the new format. | ||
Added checksum and dependency information to gem content. | ||
Added ``prereleases`` and ``includes`` / ``excludes`` filter to remotes. |
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,3 @@ | ||
Disabled synching without compact index format. | ||
Existing content will still be downloadable. | ||
There is a ``pulpcore-manager datarepair-shallow-gems`` command that will reindex content to the new format given their artifacts are persisted. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
60 changes: 60 additions & 0 deletions
60
pulp_gem/app/management/commands/datarepair-shallow-gems.py
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,60 @@ | ||
from gettext import gettext as _ | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from pulpcore.plugin.util import get_url | ||
from pulpcore.plugin.models import RepositoryContent | ||
from pulp_gem.app.models import ShallowGemContent | ||
from pulp_gem.app.serializers import GemContentSerializer | ||
|
||
|
||
def replace_content(old_content, new_content): | ||
"""Exchange all occurances of `old_content` in repository versions with `new_content`.""" | ||
RepositoryContent.objects.filter(content_id=old_content.pk).update(content_id=new_content.pk) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Django management command for migrating shallow gems. | ||
""" | ||
|
||
help = "This script migrates the pre GA generated gem content if artifacts are available." | ||
|
||
def add_arguments(self, parser): | ||
"""Set up arguments.""" | ||
parser.add_argument( | ||
"--dry-run", | ||
action="store_true", | ||
help=_("Don't modify anything, just collect results."), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
dry_run = options["dry_run"] | ||
failed_gems = 0 | ||
migrated_gems = 0 | ||
|
||
shallow_gem_qs = ShallowGemContent.objects.all() | ||
count = shallow_gem_qs.count() | ||
print(f"Shallow Gems count: {count}") | ||
if count == 0: | ||
return | ||
|
||
for sgem in shallow_gem_qs: | ||
try: | ||
artifact = sgem.contentartifact_set.get(relative_path=sgem.relative_path).artifact | ||
serializer = GemContentSerializer(data={"artifact": get_url(artifact)}) | ||
serializer.is_valid(raise_exception=True) | ||
assert serializer.validated_data["name"] == sgem.name | ||
assert serializer.validated_data["version"] == sgem.version | ||
if not dry_run: | ||
gem = serializer.create(serializer.validated_data) | ||
replace_content(sgem, gem) | ||
sgem.delete() | ||
except Exception as e: | ||
failed_gems += 1 | ||
print(f"Failed to migrate gem '{sgem.name}' '{sgem.version}': {e}") | ||
else: | ||
migrated_gems += 1 | ||
|
||
print(f"Successfully migrated gems: {migrated_gems}") | ||
print(f"Gems failed to migrate: {failed_gems}") |
27 changes: 27 additions & 0 deletions
27
pulp_gem/app/migrations/0005_rename_gemcontent_shallowgemcontent.py
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,27 @@ | ||
# Generated by Django 4.2.1 on 2023-06-14 14:37 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def rename_gem_up(apps, schema_editor): | ||
Content = apps.get_model("core", "Content") | ||
Content.objects.filter(pulp_type="gem.gem").update(pulp_type="gem.shallow-gem") | ||
|
||
|
||
def rename_gem_down(apps, schema_editor): | ||
Content = apps.get_model("core", "Content") | ||
Content.objects.filter(pulp_type="gem.shallow-gem").update(pulp_type="gem.gem") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("gem", "0004_alter_gemcontent_content_ptr_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name="GemContent", | ||
new_name="ShallowGemContent", | ||
), | ||
migrations.RunPython(code=rename_gem_up, reverse_code=rename_gem_down, elidable=True), | ||
] |
57 changes: 57 additions & 0 deletions
57
pulp_gem/app/migrations/0006_gemremote_excludes_gemremote_includes_and_more.py
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,57 @@ | ||
# Generated by Django 4.2.1 on 2023-06-14 14:53 | ||
|
||
import django.contrib.postgres.fields.hstore | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("gem", "0005_rename_gemcontent_shallowgemcontent"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="gemremote", | ||
name="excludes", | ||
field=django.contrib.postgres.fields.hstore.HStoreField(null=True), | ||
), | ||
migrations.AddField( | ||
model_name="gemremote", | ||
name="includes", | ||
field=django.contrib.postgres.fields.hstore.HStoreField(null=True), | ||
), | ||
migrations.AddField( | ||
model_name="gemremote", | ||
name="prereleases", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.CreateModel( | ||
name="GemContent", | ||
fields=[ | ||
( | ||
"content_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="core.content", | ||
), | ||
), | ||
("name", models.TextField()), | ||
("version", models.TextField()), | ||
("checksum", models.CharField(db_index=True, max_length=64)), | ||
("dependencies", django.contrib.postgres.fields.hstore.HStoreField(default=dict)), | ||
("required_ruby_version", models.TextField(null=True)), | ||
("required_rubygems_version", models.TextField(null=True)), | ||
("prerelease", models.BooleanField(default=False)), | ||
], | ||
options={ | ||
"default_related_name": "%(app_label)s_%(model_name)s", | ||
"unique_together": {("checksum",)}, | ||
}, | ||
bases=("core.content",), | ||
), | ||
] |
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.
Is this allowed inside a loop? (I'm pretty sure the
delete()
method doesn't delete the python object, but just want to check)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.
you mean changing the loop variable? Absolutely.
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 was talking about potentially deleting an element from a list that you are iterating over, this would raise an error.
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.
But we don't do that. What python does not like is if you change the list you are iterating over.