Persistence Defragmentation
Overview
Apache Ignite memory management mechanism can only create or reuse pages for user data, but it never frees them. So the files, where Ignite persists data, can only grow and never shrink.
In most use cases, it does not cause any problem as once created page can be reused multiple times. However, in certain cases, it is possible that cache contains very little data but occupies large chunks of disk space because a significant volume of data was removed from the cache.
Defragmentation enables a user to shrink data files and claim back disk space.
|
Note
|
Defragmentation itself does not require historical rebalancing. However, when the node returns to the cluster after defragmentation, it has to rebalance its partitions. If historical rebalancing is unavailable, the node performs a full rebalance, which transfers complete partitions from other nodes and can overwrite the defragmented files, negating the reclaimed disk space. Make sure that the required WAL history remains available on the supplier nodes until the defragmented node rejoins the cluster. |
Performing Defragmentation
Defragmentation is a costly operation in terms of disk IO. To avoid slowing down user operations, note that defragmentation cannot be executed on a regular node joined to the cluster. To perform defragmentation, you need to request it first on a particular node or set of nodes and then restart them.
Starting Defragmentation
To request defragmentation, use the following command:
control.sh --defragmentation schedule --nodes <consistentIds> [--caches <cacheNames>]
control.bat --defragmentation schedule --nodes <consistentIds> [--caches <cacheNames>]
After the manual restart, the node with the requested defragmentation enters a special mode called maintenance mode. The node in maintenance mode does not join the rest of the cluster but remains isolated until defragmentation is completed (or canceled by explicit user request). After that, the user has to restart the node one more time: it exits maintenance mode and returns to normal operations (joining the cluster and starting to serve regular workload).
|
Note
|
Nodes in maintenance mode do not participate in serving the regular workload. It is not recommended to execute defragmentation on several nodes simultaneously as it reduces the number of backups, thus increasing the risk of partition loss. |
Checking Defragmentation Status
To check the status of an ongoing defragmentation operation, run the following command against the node in Maintenance Mode:
control.sh --host <host> --port <port> --defragmentation status
control.bat --host <host> --port <port> --defragmentation status
Stopping Defragmentation
When a node executes defragmentation, it is possible to cancel it. To stop defragmentation, run the following command available in the control utility:
control.sh --host <host> --port <port> --defragmentation cancel
control.bat --host <host> --port <port> --defragmentation cancel
|
Note
|
During defragmentation, the original partition and index files coexist with their defragmented copies. Cache groups are processed one at a time, and the original files are replaced only after the whole cache group has been defragmented. Reserve free disk space approximately equal to the on-disk size of the largest cache group being defragmented. If little space can be reclaimed, the peak disk usage for that cache group can approach twice its original size, plus temporary link-mapping files. If a cache belongs to a shared cache group, selecting that cache for defragmentation causes the entire cache group to be defragmented. |
Conclusion
In most situations, defragmentation is not necessary as existing memory management mechanism effectively reuses memory left after data deletion. But in rare cases, it may be necessary to employ it to free up disk space up.
Persistence defragmentation requires taking nodes out of their normal operations, so a careful planning is recommended.
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.