rocksdb/db
Sagar Vemuri 1cd45cd1b3 FIFO Compaction with TTL
Summary:
Introducing FIFO compactions with TTL.

FIFO compaction is based on size only which makes it tricky to enable in production as use cases can have organic growth. A user requested an option to drop files based on the time of their creation instead of the total size.

To address that request:
- Added a new TTL option to FIFO compaction options.
- Updated FIFO compaction score to take TTL into consideration.
- Added a new table property, creation_time, to keep track of when the SST file is created.
- Creation_time is set as below:
  - On Flush: Set to the time of flush.
  - On Compaction: Set to the max creation_time of all the files involved in the compaction.
  - On Repair and Recovery: Set to the time of repair/recovery.
  - Old files created prior to this code change will have a creation_time of 0.
- FIFO compaction with TTL is enabled when ttl > 0. All files older than ttl will be deleted during compaction. i.e. `if (file.creation_time < (current_time - ttl)) then delete(file)`. This will enable cases where you might want to delete all files older than, say, 1 day.
- FIFO compaction will fall back to the prior way of deleting files based on size if:
  - the creation_time of all files involved in compaction is 0.
  - the total size (of all SST files combined) does not drop below `compaction_options_fifo.max_table_files_size` even if the files older than ttl are deleted.

This feature is not supported if max_open_files != -1 or with table formats other than Block-based.

**Test Plan:**
Added tests.

**Benchmark results:**
Base: FIFO with max size: 100MB ::
```
svemuri@dev15905 ~/rocksdb (fifo-compaction) $ TEST_TMPDIR=/dev/shm ./db_bench --benchmarks=readwhilewriting --num=5000000 --threads=16 --compaction_style=2 --fifo_compaction_max_table_files_size_mb=100

readwhilewriting :       1.924 micros/op 519858 ops/sec;   13.6 MB/s (1176277 of 5000000 found)
```

With TTL (a low one for testing) ::
```
svemuri@dev15905 ~/rocksdb (fifo-compaction) $ TEST_TMPDIR=/dev/shm ./db_bench --benchmarks=readwhilewriting --num=5000000 --threads=16 --compaction_style=2 --fifo_compaction_max_table_files_size_mb=100 --fifo_compaction_ttl=20

readwhilewriting :       1.902 micros/op 525817 ops/sec;   13.7 MB/s (1185057 of 5000000 found)
```
Example Log lines:
```
2017/06/26-15:17:24.609249 7fd5a45ff700 (Original Log Time 2017/06/26-15:17:24.609177) [db/compaction_picker.cc:1471] [default] FIFO compaction: picking file 40 with creation time 1498515423 for deletion
2017/06/26-15:17:24.609255 7fd5a45ff700 (Original Log Time 2017/06/26-15:17:24.609234) [db/db_impl_compaction_flush.cc:1541] [default] Deleted 1 files
...
2017/06/26-15:17:25.553185 7fd5a61a5800 [DEBUG] [db/db_impl_files.cc:309] [JOB 0] Delete /dev/shm/dbbench/000040.sst type=2 #40 -- OK
2017/06/26-15:17:25.553205 7fd5a61a5800 EVENT_LOG_v1 {"time_micros": 1498515445553199, "job": 0, "event": "table_file_deletion", "file_number": 40}
```

SST Files remaining in the dbbench dir, after db_bench execution completed:
```
svemuri@dev15905 ~/rocksdb (fifo-compaction)  $ ls -l /dev/shm//dbbench/*.sst
-rw-r--r--. 1 svemuri users 30749887 Jun 26 15:17 /dev/shm//dbbench/000042.sst
-rw-r--r--. 1 svemuri users 30768779 Jun 26 15:17 /dev/shm//dbbench/000044.sst
-rw-r--r--. 1 svemuri users 30757481 Jun 26 15:17 /dev/shm//dbbench/000046.sst
```
Closes https://github.com/facebook/rocksdb/pull/2480

Differential Revision: D5305116

Pulled By: sagar0

fbshipit-source-id: 3e5cfcf5dd07ed2211b5b37492eb235b45139174
2017-06-27 17:11:48 -07:00
..
builder.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
builder.h FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
c_test.c support merge and delete in file ingestion 2017-05-26 12:11:21 -07:00
c.cc support merge and delete in file ingestion 2017-05-26 12:11:21 -07:00
column_family_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
column_family.cc Fix Data Race Between CreateColumnFamily() and GetAggregatedIntProperty() 2017-06-22 15:56:47 -07:00
column_family.h Fix Data Race Between CreateColumnFamily() and GetAggregatedIntProperty() 2017-06-22 15:56:47 -07:00
compact_files_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compacted_db_impl.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compacted_db_impl.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compaction_iteration_stats.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compaction_iterator_test.cc Support ingest_behind for IngestExternalFile 2017-05-17 11:42:42 -07:00
compaction_iterator.cc Fix RocksDB Lite build with CLANG 2017-06-12 06:41:27 -07:00
compaction_iterator.h Fix RocksDB Lite build with CLANG 2017-06-12 06:41:27 -07:00
compaction_job_stats_test.cc New API for background work in single thread pool 2017-05-23 11:12:27 -07:00
compaction_job_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
compaction_job.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
compaction_job.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compaction_picker_test.cc account for L0 size in estimated compaction bytes 2017-06-01 17:56:59 -07:00
compaction_picker_universal.cc fixed typo 2017-06-05 11:27:34 -07:00
compaction_picker_universal.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
compaction_picker.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
compaction_picker.h FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
compaction.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
compaction.h FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
comparator_db_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
convenience.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
corruption_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
cuckoo_table_db_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_basic_test.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_block_cache_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_bloom_filter_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
db_compaction_filter_test.cc Fix interaction between CompactionFilter::Decision::kRemoveAndSkipUnt… 2017-06-02 15:11:38 -07:00
db_compaction_test.cc fixed typo 2017-06-13 16:58:01 -07:00
db_dynamic_level_test.cc Improve write buffer manager (and allow the size to be tracked in block cache) 2017-06-02 14:26:56 -07:00
db_encryption_test.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_filesnapshot.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_flush_test.cc New API for background work in single thread pool 2017-05-23 11:12:27 -07:00
db_impl_compaction_flush.cc Introduce OnBackgroundError callback 2017-06-22 19:41:50 -07:00
db_impl_debug.cc Introduce max_background_jobs mutable option 2017-05-24 11:29:08 -07:00
db_impl_experimental.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_impl_files.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_impl_open.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
db_impl_readonly.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_impl_readonly.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_impl_write.cc Update rename of ParanoidCheck 2017-06-24 18:12:03 -07:00
db_impl.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_impl.h Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_info_dumper.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_info_dumper.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_inplace_update_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_io_failure_test.cc Fix Windows build broken by 5c97a7c066 2017-06-26 17:28:22 -07:00
db_iter_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
db_iter.cc Histogram of number of merge operands 2017-05-31 07:41:44 -07:00
db_iter.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_iterator_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
db_log_iter_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_memtable_test.cc Improve write buffer manager (and allow the size to be tracked in block cache) 2017-06-02 14:26:56 -07:00
db_merge_operator_test.cc support merge and delete in file ingestion 2017-05-26 12:11:21 -07:00
db_options_test.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_properties_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
db_range_del_test.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_sst_test.cc Limit trash directory to be 25% of total DB 2017-06-12 16:57:21 -07:00
db_statistics_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_table_properties_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_tailing_iter_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
db_test2.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_test_util.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
db_test_util.h Encryption at rest support 2017-06-26 16:56:24 -07:00
db_test.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
db_universal_compaction_test.cc Fixed some spelling mistakes 2017-05-17 23:12:36 -07:00
db_wal_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
db_write_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
dbformat_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
dbformat.cc do not read next datablock if upperbound is reached 2017-05-05 23:20:01 -07:00
dbformat.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
deletefile_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
event_helpers.cc Introduce OnBackgroundError callback 2017-06-22 19:41:50 -07:00
event_helpers.h Introduce OnBackgroundError callback 2017-06-22 19:41:50 -07:00
experimental.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
external_sst_file_basic_test.cc Support ingest file when range deletions exist 2017-05-31 13:57:19 -07:00
external_sst_file_ingestion_job.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
external_sst_file_ingestion_job.h fixed typo 2017-06-05 11:27:34 -07:00
external_sst_file_test.cc support merge and delete in file ingestion 2017-05-26 12:11:21 -07:00
fault_injection_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
file_indexer_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
file_indexer.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
file_indexer.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
filename_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
flush_job_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
flush_job.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
flush_job.h FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
flush_scheduler.cc New WriteImpl to pipeline WAL/memtable write 2017-05-19 14:26:42 -07:00
flush_scheduler.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
forward_iterator_bench.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
forward_iterator.cc do not read next datablock if upperbound is reached 2017-05-05 23:20:01 -07:00
forward_iterator.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
internal_stats.cc Sample number of reads per SST file 2017-06-12 07:12:08 -07:00
internal_stats.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
job_context.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
listener_test.cc Encryption at rest support 2017-06-26 16:56:24 -07:00
log_format.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
log_reader.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
log_reader.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
log_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
log_writer.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
log_writer.h Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
malloc_stats.cc db: avoid #includeing malloc and jemalloc simultaneously 2017-05-31 22:43:02 -07:00
malloc_stats.h db: avoid #includeing malloc and jemalloc simultaneously 2017-05-31 22:43:02 -07:00
managed_iterator.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
managed_iterator.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
manual_compaction_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
memtable_list_test.cc Pass CF ID to MemTableRepFactory 2017-06-02 12:12:06 -07:00
memtable_list.cc Fix TSAN: avoid arena mode with range deletions 2017-06-01 22:26:49 -07:00
memtable_list.h Fix TSAN: avoid arena mode with range deletions 2017-06-01 22:26:49 -07:00
memtable.cc Improve write buffer manager (and allow the size to be tracked in block cache) 2017-06-02 14:26:56 -07:00
memtable.h Improve write buffer manager (and allow the size to be tracked in block cache) 2017-06-02 14:26:56 -07:00
merge_context.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
merge_helper_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
merge_helper.cc Histogram of number of merge operands 2017-05-31 07:41:44 -07:00
merge_helper.h Histogram of number of merge operands 2017-05-31 07:41:44 -07:00
merge_operator.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
merge_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
options_file_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
perf_context_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
pinned_iterators_manager.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
plain_table_db_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
prefix_test.cc using ThreadLocalPtr to hide ROCKSDB_SUPPORT_THREAD_LOCAL from public… 2017-06-02 17:26:19 -07:00
range_del_aggregator_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
range_del_aggregator.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
range_del_aggregator.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
repair_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
repair.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
snapshot_impl.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
snapshot_impl.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
table_cache.cc fix coredump for release nullptr 2017-06-19 11:41:38 -07:00
table_cache.h Call RateLimiter for compaction reads 2017-06-13 14:56:46 -07:00
table_properties_collector_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
table_properties_collector.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
table_properties_collector.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
transaction_log_impl.cc disable direct reads for log and manifest and add direct io to tests 2017-05-22 18:41:28 -07:00
transaction_log_impl.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_builder_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_builder.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_builder.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_edit_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_edit.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
version_edit.h Sample number of reads per SST file 2017-06-12 07:12:08 -07:00
version_set_test.cc Set lower-bound on dynamic level sizes 2017-05-04 18:16:12 -07:00
version_set.cc FIFO Compaction with TTL 2017-06-27 17:11:48 -07:00
version_set.h Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
wal_manager_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
wal_manager.cc disable direct reads for log and manifest and add direct io to tests 2017-05-22 18:41:28 -07:00
wal_manager.h Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
write_batch_base.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
write_batch_internal.h Fixing blob db sequence number handling 2017-05-31 10:56:45 -07:00
write_batch_test.cc Pass CF ID to MemTableRepFactory 2017-06-02 12:12:06 -07:00
write_batch.cc Fixing blob db sequence number handling 2017-05-31 10:56:45 -07:00
write_callback_test.cc Optimize for serial commits in 2PC 2017-06-24 14:11:29 -07:00
write_callback.h Updated all copyright headers to the new format. 2016-02-09 15:12:00 -08:00
write_controller_test.cc Add GPLv2 as an alternative license. 2017-04-27 18:06:12 -07:00
write_controller.cc WriteOptions.low_pri which can throttle low pri writes if needed 2017-06-05 15:02:35 -07:00
write_controller.h WriteOptions.low_pri which can throttle low pri writes if needed 2017-06-05 15:02:35 -07:00
write_thread.cc New WriteImpl to pipeline WAL/memtable write 2017-05-19 14:26:42 -07:00
write_thread.h New WriteImpl to pipeline WAL/memtable write 2017-05-19 14:26:42 -07:00