Maven virtual registry Cached Responses: make the object_storage_key column unique
🔥 Problem
While working in Set up partitioning for maven virtual registry ... (!174985 - merged), we noticed that for the cached responses table, we have the following situation:
- if the record is in
statusdefault, the desired behavior is thatupstream_idandrelative_pathare unique. - if the record is in any other state, the
upstream_id+relative_pathcan be duplicated.
One example scenario that we need to support:
- a file request hits the virtual registry, a cached response with an
upstream_id+relative_pathis created withstatusdefault. - the user decides to delete this record, the cached response status is updated to
pending_destruction. - start over on step (1.) and do step (2.).
What we get, given a fixed upstream_id + relative_path, is a unique status default cached response. However, we're stacking things in the status pending_destruction (while waiting the cleanup job to do its task).
The main problem with this situation is the object_storage_key column. The key is computed out of the registry id, the upstream_id and the relative_path. As stated above, these can lack to be unique = we could have multiple records pointing to the same file on object storage.
Worse, a pending_destruction record could delete the file that is also referenced by a default record. The backend will think that it has a cached response for the request but when trying to return the file from object storage:
🚒 Solution
- Add randomness to the value stored in the
object_storage_keycolumn to guarantee that each cached response record can reference a unique file on object storage. - Add a
UNIQUEconstraint for that column in the database. - Add the related specs.