You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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 :)
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.
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:
Call reclaim_space_aggressively() on the log_serializer
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.
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.
Tell the LBA to inactivate the active LBA extents.
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.
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.
@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.
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
Activity
danielmewes commentedon Jan 8, 2014
@wojons noticed this.
danielmewes commentedon Jan 8, 2014
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.
wojons commentedon Jan 8, 2014
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 :)
danielmewes commentedon Jan 22, 2014
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 callingdestroy_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.
danielmewes commentedon Jan 23, 2014
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:
reclaim_space_aggressively()on the log_serializerI think this procedure should quite reliably shrink a table to close to its minimal size.
srh commentedon Feb 20, 2014
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.
danielmewes commentedon Feb 20, 2014
@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.
phil-hildebrand commentedon Apr 1, 2016
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
danielmewes commentedon Apr 1, 2016
@phil-hildebrand Yeah, the compaction operation would cover that. It's not clear yet when we'll get around to implementing this though.
[-]We never seem to delete table files[/-][+]Table file compaction[/+]danielmewes commentedon May 4, 2016
Renamed issue from "We never seem to delete table files" to "Table file compaction" because that more accurately describes the remaining issue.