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

Compact index #105

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if [ "$TEST" = "s3" ]; then
sed -i -e '$a s3_test: true\
minio_access_key: "'$MINIO_ACCESS_KEY'"\
minio_secret_key: "'$MINIO_SECRET_KEY'"\
pulp_scenario_settings: null\
pulp_scenario_settings: {"allowed_content_checksums": ["md5", "sha224", "sha256", "sha384", "sha512"]}\
' vars/main.yaml
export PULP_API_ROOT="/rerouted/djnd/"
fi
Expand Down
4 changes: 4 additions & 0 deletions CHANGES/96.feature
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.
3 changes: 3 additions & 0 deletions CHANGES/96.removal
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.
137 changes: 0 additions & 137 deletions README.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/_static/api.json

This file was deleted.

Empty file.
Empty file.
60 changes: 60 additions & 0 deletions pulp_gem/app/management/commands/datarepair-shallow-gems.py
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()
Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

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}")
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),
]
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",),
),
]
Loading