There are 1024 vBuckets in each bucket and therefore 1024 data files under each bucket. Couchbase’s append-only engine can eventually lead to gaps within the data file (particularly when data is deleted) which can be reclaimed using a process called compaction.
Auto-Compaction is enabled by default for all Couchbase buckets. However, settings can be overridden on a per bucket basis.
Couchbase compacts views and data files. For database compaction, a new file is created into which the active (non-stale) information is written. Meanwhile, the existing database files stay in place and continue to be used for storing information and updating the index data. This process ensures that the database continues to be available while compaction takes place. Once compaction is completed, the old database is disabled and saved. Then any incoming updates continue in the newly created database files. The old database is then deleted from the system.
View compaction occurs in the same way. Couchbase creates a new index file for each active design document. Then Couchbase takes this new index file and writes active index information into it. Old index files are handled in the same way old data files are handled during compaction. Once compaction is complete, the old index files are deleted from the system.
While compaction takes place in the background, you need to pay attention to certain factors.
Make sure you perform compaction…
• …on every server
• …during off-peak hours (The compaction process is both disk and CPU intensive)
• …with adequate disk space
Regarding the last point, because compaction occurs by creating new files and updating the information, you may need as much as twice the disk space of your current database and index files for compaction to take place.
–>changes during compaction will also need to be written to the updated data files.
–>By default, compaction operates sequentially, executing first on the database and then the Views if both are configured for auto-compaction. If you enable parallel compaction, both the databases and the views can be compacted at the same time. This requires more CPU and database activity for both to be processed simultaneously
–>Another setting for compaction is the metadata purge interval. You can remove tombstones for expired and deleted items as part of the auto-compaction process. Tombstones are records containing the key and metadata for deleted and expired items and are used for eventually consistency between clusters and for views.
Only Couchbase buckets can be compacted: Ephemeral and Memcached buckets cannot be compacted.