Skip to content

Commit

Permalink
Mirror release version alias writes [RHELDST-28333]
Browse files Browse the repository at this point in the history
During the RHEL GA process some repos would appear to temporarily
corrupt from the customer's point of view, usually appearing as 404
errors when fetching repodata files. This is due to aliases getting
updated and delay in data being flushed.

This change introduces mirroring writes on both the source and
destination, which will prevent these errors from occuring.
  • Loading branch information
amcmahon-rh committed Jan 30, 2025
1 parent 1183517 commit a04097d
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 1 deletion.
23 changes: 23 additions & 0 deletions exodus_gw/aws/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def __init__(
from_date: str,
env_obj: Environment | None = None,
deadline: datetime | None = None,
mirror_writes: bool = False
):
self.env = env
self.settings = settings
self.from_date = from_date
self.env_obj = env_obj or get_environment(env)
self.deadline = deadline
self.mirror_writes = mirror_writes
self.client = DynamoDBClientWrapper(self.env_obj.aws_profile).client
self._lock = Lock()
self._definitions = None
Expand Down Expand Up @@ -208,6 +210,14 @@ def query_definitions(self) -> dict[str, Any]:
out = json.loads(item_json)
return out

def should_mirror_write(self, uri):
# We only want to mirror writes for release ver aliases. Recalculating
# the aliases completely is a bit inefficient, but I'd rather not
# duplicate any alias logic.
print(self._aliases(["releasever_alias"]))
return self.mirror_writes and \
uri_alias(uri, self._aliases(["releasever_alias"]))[0] != uri

def create_request(
self,
items: list[models.Item],
Expand Down Expand Up @@ -255,6 +265,19 @@ def create_request(
}
}
)
if self.should_mirror_write(item.web_uri):
request[table_name].append(
{
"PutRequest": {
"Item": {
"from_date": {"S": from_date},
"web_uri": {"S": item.web_uri},
"object_key": {"S": item.object_key},
"content_type": {"S": item.content_type},
}
}
}
)
return request

def create_config_request(self, config):
Expand Down
4 changes: 4 additions & 0 deletions exodus_gw/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ class Settings(BaseSettings):
s3_pool_size: int = 3
"""Number of S3 clients to cache"""

mirror_writes_enabled: bool = True
"""Whether both the original url and release var alias are written during
phase 1 commits."""

model_config = SettingsConfigDict(env_prefix="exodus_gw_")


Expand Down
9 changes: 9 additions & 0 deletions exodus_gw/worker/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ def dynamodb(self):
self.from_date,
self.env_obj,
self.task.deadline,
self.should_mirror_writes,
)
return self._dynamodb

@property
def should_mirror_writes(self):
return False

@property
def task_ready(self) -> bool:
task = self.task
Expand Down Expand Up @@ -446,6 +451,10 @@ class CommitPhase1(CommitBase):
# phase1 commit is allowed to proceed in either of these states.
PUBLISH_STATES = [PublishStates.committing, PublishStates.pending]

@property
def should_mirror_writes(self):
return self.settings.mirror_writes_enabled

@property
def item_select(self):
# Query for items to be handled by phase1 commit.
Expand Down
Loading

0 comments on commit a04097d

Please sign in to comment.