Skip to content

Table file compaction #1830

Open
Open

Description

@danielmewes

When a node loses its responsibility as a secondary or primary for a shard, it deletes the documents from its local storage (triggered by reactor_be_nothing).
However the actual storage file (as in 'rethinkdb_data/00000000-0000-0000-0000-000000000000') is never deleted.

Even though #310 has been implemented, garbage collection is not aggressive enough to actually allow shrinking the file in many cases. As a consequence, huge files keep lying around on the nodes and never get cleaned up.

We could either explicitly delete the files if the table is empty (if we can do so safely), or look into what stops the file from being shrunk in practice, despite all documents having been deleted.

Activity

  1. danielmewes commented on Jan 8, 2014

    @danielmewes
    MemberAuthor

    @wojons noticed this.

  2. danielmewes commented on Jan 8, 2014

    @danielmewes
    MemberAuthor

    The GC would basically need an "aggressive" mode where it marks all active extents as inactive. It would then garbage collect all extents. We would just have to make sure that it allocates new active extents at the beginning of the file. That would allow the file to be shrunk.

    I'm not sure how easy or difficult it would be to delete empty table files completely while the database is still running. I imagine it might be tricky. What we could definitely do as a work-around is to check for empty tables on shutdown and delete the files if possible.

  3. wojons commented on Jan 8, 2014

    @wojons
    Contributor

    well there are a few things i can see. If i am sharding. on that table and this node use to have 100% of data and now has 50% of data i need to some how hollowout the data. around whats located on this node. From what i can tell if you restart the server when you delete the file it seems to be fine and it gets replaced with the correct data i am guessing meta data of some sort its like 1mb to 3.5mb. I feel like the best way since its all file pointer based you should be able to rename the file even though u have the file pointer with out issues and then flag the file to be deleted when there are no rethinkdb file pointers open to it and have a new meta data file ready and waiting :)

  4. danielmewes commented on Jan 22, 2014

    @danielmewes
    MemberAuthor

    I was looking at the reactor_driver in a different context and noticed that we do have a delete_reactor_data() function which should actually delete the table file (by calling destroy_svs()).

    So it seems that we are just not calling it properly, at least in some cases.

    PS: I think we might only be calling it when the whole table is deleted, but not if a node loses its role as a replica.

  5. danielmewes commented on Jan 23, 2014

    @danielmewes
    MemberAuthor

    What makes deleting table files somewhat complicated is the fact that our current reactor architecture is based on the assumption that even nodes that have no share in a table's data keep the actual data file around. We will eventually get rid of that requirement, as getting rid of it is a requirement for #1861.

    The other way to solve this problem is to implement "aggressive" compaction of a table file.
    It would also be a fair amount of work, but has the advantage that it is in itself a useful feature. Furthermore, it works even if a node loses its role as a replica for only a subset of the range shards. We could not delete the file in that case, but we could still compact the table to reduce disk usage.

    It would probably work somewhat like this:

    1. Call reclaim_space_aggressively() on the log_serializer
    2. The log_serializer tells the data_block_manager to deactivate all active extents, and to put all now inactive extents into a state where they can be garbage-collected.
    3. Run the data block GC. However in contrast to a usual GC process, don't stop when reaching the GV low ratio but only when all GC'able extents have been garbage collected. This part is a bit tricky, because on a live table where other range shards are still active, it might be impossible to ever fully reach that state. We would have to detect such cases. Wait for the data block GC to finish.
    4. Tell the LBA to inactivate the active LBA extents.
    5. Run the LBA GC. It will rewrite the LBA, using the extents that were freed by the data GC.

    I think this procedure should quite reliably shrink a table to close to its minimal size.

  6. srh commented on Feb 20, 2014

    @srh
    Contributor

    I don't think aggressive compaction of a table file needs to be that much work. There's not much reason for it to be a separate phase. It certainly should not involve deactivating all active extents. We should just have GC behavior tuned to what the proportion of active data or active extents is. If it gets too sparse, it should favor collection of the extents near the end of the file. Hopefully something similar can be done with the LBA.

  7. danielmewes commented on Feb 20, 2014

    @danielmewes
    MemberAuthor

    @srh: The problem in this special case is that after deleting everything, we never write anything to the file anymore. Unfortunately that means that currently active LBA and/or data extents never become inactive. If they happen to be close to the end of the file, that's a problem.

  8. phil-hildebrand commented on Apr 1, 2016

    @phil-hildebrand

    Will this also cover issues with files that could be compacted after rebalancing shards, or reconfiguring with additional shards?

    This is something we could use given how fast our tables grow (we're predicting some to grow by 7 TB this year, so adding shards as we add nodes would be easier to manage if we new the datafiles would be compacted after the rebalance

  9. danielmewes commented on Apr 1, 2016

    @danielmewes
    MemberAuthor

    @phil-hildebrand Yeah, the compaction operation would cover that. It's not clear yet when we'll get around to implementing this though.

  10. changed the title [-]We never seem to delete table files[/-] [+]Table file compaction[/+] on May 4, 2016
  11. danielmewes commented on May 4, 2016

    @danielmewes
    MemberAuthor

    Renamed issue from "We never seem to delete table files" to "Table file compaction" because that more accurately describes the remaining issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions