Skip to content
Snippets Groups Projects

Implement Shard.delete()

In order to be able to remove objects from objstorage–in the case of takedown notices–we add a new Shard.delete() method.

As Shard files uses a perfect hash function computed on creation, and fixed offsets, completely removing an object would amount to recreate a new Shard from scratch. As these files are meant to be quite large and removals should be rare, we just overwrite the object size and data with zeros.

The object position in the hash table is also replaced with UINT64_MAX in order to signal that the object has been removed. Shard.lookup() has been updated accordingly and will throw a KeyError if the object matching a key has been deleted.

The interface is not ideal but it is due to a more general problem of the design of API. The caller must be careful not to run delete() on a “created” or “loaded” Shard as the method will take care of opening the Shard file in read/write mode, overwrite the right bytes and close the file again.

Related to swh-alter#4 (closed) (for Winery)

Edited by Jérémy Bobbio (Lunar)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
56 56 int shard_load(shard_t *shard);
57 57 int shard_find_object(shard_t *shard, const char *key, uint64_t *object_size);
58 58 int shard_read_object(shard_t *shard, char *object, uint64_t object_size);
59
60 int shard_delete(shard_t *shard, const char *key);
  • With the new API neatly separating shard creation from usage, it feels a bit inconsistent to have delete as a staticmethod of the (used-to-be readonly) Shard instead of having a separate helper class with access to the delete method.

    We'll probably also want to be able to delete multiple objects from the shard, opening and closing it only once. What do you think?

  • Yeah, I am a bit lost on the right way to do this. Using a static method felt the easiest semantically because deleting is about taking an existing shard (so using the Shard class instead of ShardCreator felt better) but changing it. Having delete as an instance method of Shard felt wrong, as to do the change we need to open the file in r+ mode. My impression was that deletion was infrequent enough that we could just take the extra cost of opening and closing the file multiple times for each object… I weighted for code simplicity and interface safety, but if you have another idea I'll gladly give it a shot.

  • Oh, also ObjStorageInterface.delete takes a single obj_id (source)

  • mentioned in merge request swh-objstorage!166 (merged)

  • Nicolas Dandrimont approved this merge request

    approved this merge request

  • Meh, yeah, I don't really have a better idea.

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading