Compare commits

...

48 Commits

Author SHA1 Message Date
Hui Xiao
f6339de0d2 Clarify some SequentialFileReader::Read logic (#10002)
Summary:
**Context/Summary:**
The logic related to PositionedRead in SequentialFileReader::Read confused me a bit as discussed here https://github.com/facebook/rocksdb/pull/9973#discussion_r872869256. Therefore I added a drawing with help from cbi42.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10002

Test Plan: - no code change

Reviewed By: anand1976, cbi42

Differential Revision: D36422632

Pulled By: hx235

fbshipit-source-id: 9a8311d2365564f90d216c430f542fc11b2d9cde
2022-05-17 10:24:04 -07:00
mrambacher
b11ff347b4 Use STATIC_AVOID_DESTRUCTION for static objects with non-trivial destructors (#9958)
Summary:
Changed the static objects that had non-trivial destructors to use the STATIC_AVOID_DESTRUCTION construct.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9958

Reviewed By: pdillinger

Differential Revision: D36442982

Pulled By: mrambacher

fbshipit-source-id: 029d47b1374d30d198bfede369a4c0ae7a4eb519
2022-05-17 09:39:22 -07:00
Yanqin Jin
3f263ef536 Add a temporary option for user to opt-out enforcement of SingleDelete contract (#9983)
Summary:
PR https://github.com/facebook/rocksdb/issues/9888 started to enforce the contract of single delete described in https://github.com/facebook/rocksdb/wiki/Single-Delete.

For some of existing use cases, it is desirable to have a transition during which compaction will not fail
if the contract is violated. Therefore, we add a temporary option `enforce_single_del_contracts` to allow
application to opt out from this new strict behavior. Once transition completes, the flag can be set to `true` again.

In a future release, the option will be removed.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9983

Test Plan: make check

Reviewed By: ajkr

Differential Revision: D36333672

Pulled By: riversand963

fbshipit-source-id: dcb703ea0ed08076a1422f1bfb9914afe3c2caa2
2022-05-16 15:44:59 -07:00
Hui Xiao
e66e6d2faa Use SpecialEnv to speed up some slow BackupEngineRateLimitingTestWithParam (#9974)
Summary:
**Context:**
`BackupEngineRateLimitingTestWithParam.RateLimiting` and `BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup` involve creating backup and restoring of a big database with rate-limiting. Using the normal env with a normal clock requires real elapse of time (13702 - 19848 ms/per test). As suggested in https://github.com/facebook/rocksdb/pull/8722#discussion_r703698603, this PR is to speed it up with SpecialEnv (`time_elapse_only_sleep=true`) where its clock accepts fake elapse of time during rate-limiting (100 - 600 ms/per test)

**Summary:**
- Added TEST_ function to set clock of the default rate limiters in backup engine
- Shrunk testdb by 10 times while keeping it big enough for testing
- Renamed some test variables and reorganized some if-else branch for clarity without changing the test

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9974

Test Plan:
- Run tests pre/post PR the same time to verify the tests are sped up by 90 - 95%
`BackupEngineRateLimitingTestWithParam.RateLimiting`
Pre:
```
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/0
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/0 (11123 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/1
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/1 (9441 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/2
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/2 (11096 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/3
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/3 (9339 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/4
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/4 (11121 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/5
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/5 (9413 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/6
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/6 (11185 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/7
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/7 (9511 ms)
[----------] 8 tests from RateLimiting/BackupEngineRateLimitingTestWithParam (82230 ms total)
```
Post:
```
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/0
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/0 (395 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/1
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/1 (564 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/2
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/2 (358 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/3
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/3 (567 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/4
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/4 (173 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/5
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/5 (176 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/6
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/6 (191 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/7
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimiting/7 (177 ms)
[----------] 8 tests from RateLimiting/BackupEngineRateLimitingTestWithParam (2601 ms total)
```
`BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup`
Pre:
```
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/0
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/0 (7275 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/1
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/1 (3961 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/2
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/2 (7117 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/3
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/3 (3921 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/4
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/4 (19862 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/5
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/5 (10231 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/6
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/6 (19848 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/7
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/7 (10372 ms)
[----------] 8 tests from RateLimiting/BackupEngineRateLimitingTestWithParam (82587 ms total)
```
Post:
```
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/0
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/0 (157 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/1
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/1 (152 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/2
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/2 (160 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/3
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/3 (158 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/4
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/4 (155 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/5
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/5 (151 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/6
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/6 (146 ms)
[ RUN      ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/7
[       OK ] RateLimiting/BackupEngineRateLimitingTestWithParam.RateLimitingVerifyBackup/7 (153 ms)
[----------] 8 tests from RateLimiting/BackupEngineRateLimitingTestWithParam (1232 ms total)
```

Reviewed By: pdillinger

Differential Revision: D36336345

Pulled By: hx235

fbshipit-source-id: 724c6ba745f95f56d4440a6d2f1e4512a2987589
2022-05-16 10:54:02 -07:00
mrambacher
204a42ca97 Added GetFactoryCount/Names/Types to ObjectRegistry (#9358)
Summary:
These methods allow for more thorough testing of the ObjectRegistry and Customizable infrastructure in a simpler manner.  With this change, the Customizable tests can now check what factories are registered and attempt to create each of them in a systematic fashion.

With this change, I think all of the factories registered with the ObjectRegistry/CreateFromString are now tested via the customizable_test classes.

Note that there were a few other minor changes.  There was a "posix://*" register with the ObjectRegistry which was missed during the PatternEntry conversion -- these changes found that.  The nickname and default names for the FileSystem classes was also inverted.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9358

Reviewed By: pdillinger

Differential Revision: D33433542

Pulled By: mrambacher

fbshipit-source-id: 9a32da74e6620745b4eeffb2712be70eeeadfa7e
2022-05-16 09:44:43 -07:00
sdong
c4cd8e1acc Fix a bug handling multiget index I/O error. (#9993)
Summary:
In one path of BlockBasedTable::MultiGet(), Next() is directly called after calling Seek() against the index iterator. This might cause crash if an I/O error happens in Seek().
The bug is discovered in crash test.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9993

Test Plan: See existing CI tests pass.

Reviewed By: anand1976

Differential Revision: D36381758

fbshipit-source-id: a11e0aa48dcee168c2554c33b532646ffdb68877
2022-05-13 13:15:10 -07:00
Yanqin Jin
b58a1a035b Revert "Bugfix/fix manual flush blocking bug (#9893)" (#9992)
Summary:
This reverts commit 6d2577e567.

A proposal for resolving our current internal test failures. A fix is
being planned.

More context can be found: https://github.com/facebook/rocksdb/pull/9893#issuecomment-1126230634
TSAN error: https://github.com/facebook/rocksdb/pull/9893#issuecomment-1126233132

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9992

Reviewed By: siying

Differential Revision: D36379154

Pulled By: riversand963

fbshipit-source-id: b240261e766eff099513799cf5631832093f4cd2
2022-05-13 12:31:30 -07:00
Yanqin Jin
f6d9730ea1 Fix stress test with best-efforts-recovery (#9986)
Summary:
This PR

- since we are testing with disable_wal = true and best_efforts_recovery, we should set column family count to 1, due to the requirement of `ExpectedState` tracking and replaying logic.
- during backup and checkpoint restore, disable best-efforts-recovery. This does not matter now because db_crashtest.py always disables wal when testing best-efforts-recovery. In the future, if we enable wal, then not setting `restore_opitions.best_efforts_recovery` will cause backup db not to recover the WALs, and differ from db (that enables WAL).
- during verification of backup and checkpoint restore, print the key where inconsistency exists between expected state and db.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9986

Test Plan: TEST_TMPDIR=/dev/shm/rocksdb make crash_test_with_best_efforts_recovery

Reviewed By: siying

Differential Revision: D36353105

Pulled By: riversand963

fbshipit-source-id: a484da161273e6216a1f7e245bac15a349693917
2022-05-13 12:29:20 -07:00
mrambacher
bfc6a8ee4a Option type info functions (#9411)
Summary:
Add methods to set the various functions (Parse, Serialize, Equals) to the OptionTypeInfo.  These methods simplify the number of constructors required for OptionTypeInfo and make the code a little clearer.

Add functions to the OptionTypeInfo for Prepare and Validate.  These methods allow types other than Configurable and Customizable to have Prepare and Validate logic.  These methods could be used by an option to guarantee that its settings were in a range or that a value was initialized.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9411

Reviewed By: pdillinger

Differential Revision: D36174849

Pulled By: mrambacher

fbshipit-source-id: 72517d8c6bab4723788a4c1a9e16590bff870125
2022-05-13 04:57:08 -07:00
Peter Dillinger
cdaa9576bb Put build size checking logic in Makefile (#9989)
Summary:
... for better maintainability, in case of Makefile changes /
refactoring. This is lightly modified from rocksd-lego-determinator, and
will be used by Meta-internal CI with custom REPORT_BUILD_STATISTIC

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9989

Test Plan: some manual stuff

Reviewed By: jay-zhuang

Differential Revision: D36362362

Pulled By: pdillinger

fbshipit-source-id: 52b65b6282fe839dc6d906ff95a3ed66ca1574ba
2022-05-12 22:54:18 -07:00
Chen Xiao
07c6807113 Add pmem-rocksdb-plugin link in PLUGINs.md (#9934)
Summary:
This change adds pmem-rocksdb-plugin link in PLUGINS.md. The link is: https://github.com/pmem/pmem-rocksdb-plugin. It provides a collection plugins to enable Persistent Memory (PMEM) on RocksDB.

The pmem-rocksdb-plugin repo contains RocksDB’s plugins for LSM-tree based KV store to fit it on the PMEM by effectively utilize its characteristics. The first two basic plugins are:
1) Providing a filesystem API wrapper to write RocksDB's WAL (Write Ahead Log) files on PMEM to optimize write performance. 2) Using PMEM as secondary cache to optimize read performance.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9934

Reviewed By: jay-zhuang

Differential Revision: D36366893

Pulled By: riversand963

fbshipit-source-id: d58a39365e9b5d6a3249d4e9b377c7fb2c79badb
2022-05-12 22:02:28 -07:00
Yueh-Hsuan Chiang
bcb1287235 Port the batched version of MultiGet() to RocksDB's C API (#9952)
Summary:
The batched version of MultiGet() is not available in RocksDB's C API.
This PR implements rocksdb_batched_multi_get_cf which is a C wrapper function
that invokes the batched version of MultiGet() which takes one single column family.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9952

Test Plan: Added a new test case under "columnfamilies" test case in c_test.cc

Reviewed By: riversand963

Differential Revision: D36302888

Pulled By: ajkr

fbshipit-source-id: fa134c4a1c8e7d72dd4ae8649a74e3797b5cf4e6
2022-05-12 18:17:36 -07:00
Akanksha Mahajan
6442a62e46 Update WAL corruption test so that it fails without fix (#9942)
Summary:
In case of non-TransactionDB and avoid_flush_during_recovery = true, RocksDB won't
flush the data from WAL to L0 for all column families if possible. As a
result, not all column families can increase their log_numbers, and
min_log_number_to_keep won't change.
For transaction DB (.allow_2pc), even with the flush, there may be old WAL files that it must not delete because they can contain data of uncommitted transactions and min_log_number_to_keep won't change.
If we persist a new MANIFEST with
advanced log_numbers for some column families, then during a second
crash after persisting the MANIFEST, RocksDB will see some column
families' log_numbers larger than the corrupted WAL, and the "column family inconsistency" error will be hit, causing recovery to fail.

This PR update unit tests to emulate the errors and tests are failing without a fix.

Error:
```
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/0
db/corruption_test.cc:1190: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF test_cf
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/0, where GetParam() = (true, false) (91 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/1
db/corruption_test.cc:1190: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF test_cf
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/1, where GetParam() = (false, false) (92 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/2
db/corruption_test.cc:1190: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF test_cf
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/2, where GetParam() = (true, true) (95 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/3
db/corruption_test.cc:1190: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF test_cf
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery/3, where GetParam() = (false, true) (92 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/0
db/corruption_test.cc:1354: Failure
TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, &handles, &txn_db)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/0, where GetParam() = (true, false) (94 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/1
db/corruption_test.cc:1354: Failure
TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, &handles, &txn_db)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/1, where GetParam() = (false, false) (97 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/2
db/corruption_test.cc:1354: Failure
TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, &handles, &txn_db)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/2, where GetParam() = (true, true) (94 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/3
db/corruption_test.cc:1354: Failure
TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, &handles, &txn_db)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.TxnDbCrashDuringRecovery/3, where GetParam() = (false, true) (91 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/0
db/corruption_test.cc:1483: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/0, where GetParam() = (true, false) (93 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/1
db/corruption_test.cc:1483: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/1, where GetParam() = (false, false) (94 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/2
db/corruption_test.cc:1483: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/2, where GetParam() = (true, true) (90 ms)
[ RUN      ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/3
db/corruption_test.cc:1483: Failure
DB::Open(options, dbname_, cf_descs, &handles, &db_)
Corruption: SST file is ahead of WALs in CF default
[  FAILED  ] CorruptionTest/CrashDuringRecoveryWithCorruptionTest.CrashDuringRecoveryWithFlush/3, where GetParam() = (false, true) (93 ms)
[----------] 12 tests from CorruptionTest/CrashDuringRecoveryWithCorruptionTest (1116 ms total)

```

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9942

Test Plan: Not needed

Reviewed By: riversand963

Differential Revision: D36324112

Pulled By: akankshamahajan15

fbshipit-source-id: cab2075ac4ebe48f5ef93a6ea162558aa4fc334d
2022-05-11 16:12:55 -07:00
Peter Dillinger
e96e8e2d05 Remove slack CircleCI hook (#9982)
Summary:
Our Slack site is deprecated

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9982

Test Plan: CircleCI

Reviewed By: siying

Differential Revision: D36322050

Pulled By: pdillinger

fbshipit-source-id: 678202404d307e1547e4203d7e6bd467803ccd5e
2022-05-11 13:17:21 -07:00
Andrew Kryczka
e943bbdd2f Temporarily disable sync_fault_injection (#9979)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9979

Reviewed By: siying

Differential Revision: D36301555

Pulled By: ajkr

fbshipit-source-id: ed298d3484b6aad3ef19746e984bf4c52be33a9f
2022-05-11 12:19:07 -07:00
Peter Dillinger
e8d604cf85 Reorganize CircleCI workflows (#9981)
Summary:
Condense down to 8 groups rather than 20+ for ease of browsing
pages like
https://app.circleci.com/pipelines/github/facebook/rocksdb?branch=main&filter=all

Also, run nightly builds at 1AM or 2AM Pacific (depending on daylight
time) rather than 4PM or 5PM Pacific, so that they actually use each
day's landed changes.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9981

Test Plan:
CI
And manually inspected
```
grep -Eo 'build-[^: ]*' .circleci/config.yml | sort | uniq -c | less
```
to ensure I didn't orphan anything

Reviewed By: jay-zhuang

Differential Revision: D36317634

Pulled By: pdillinger

fbshipit-source-id: 1c10d29d6b5d60ce3dd1364cd91f175380075ff3
2022-05-11 11:16:09 -07:00
yaphet
26768edb65 Support single delete in ldb (#9469)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9469

Reviewed By: riversand963

Differential Revision: D33953484

fbshipit-source-id: f4e84a2d9865957d744c7e84ff02ffbb0a62b0a8
2022-05-10 16:37:19 -07:00
Peter Dillinger
0d1613aad6 Avoid some warnings-as-error in CircleCI+unity+AVX512F (#9978)
Summary:
Example failure when compiling on sufficiently new hardware and built-in headers:

```
In file included from /usr/local/lib/gcc/x86_64-linux-gnu/12.1.0/include/immintrin.h:49,
                 from ./util/bloom_impl.h:21,
                 from table/block_based/filter_policy.cc:31,
                 from unity.cc:167:
In function '__m512i _mm512_shuffle_epi32(__m512i, _MM_PERM_ENUM)',
    inlined from 'void XXH3_accumulate_512_avx512(void*, const void*, const void*)' at util/xxhash.h:3605:58,
    inlined from 'void XXH3_accumulate(xxh_u64*, const xxh_u8*, const xxh_u8*, size_t, XXH3_f_accumulate_512)' at util/xxhash.h:4229:17,
    inlined from 'void XXH3_hashLong_internal_loop(xxh_u64*, const xxh_u8*, size_t, const xxh_u8*, size_t, XXH3_f_accumulate_512, XXH3_f_scrambleAcc)' at util/xxhash.h:4251:24,
    inlined from 'XXH128_hash_t XXH3_hashLong_128b_internal(const void*, size_t, const xxh_u8*, size_t, XXH3_f_accumulate_512, XXH3_f_scrambleAcc)' at util/xxhash.h:5065:32,
    inlined from 'XXH128_hash_t XXH3_hashLong_128b_withSecret(const void*, size_t, XXH64_hash_t, const void*, size_t)' at util/xxhash.h:5104:39:
/usr/local/lib/gcc/x86_64-linux-gnu/12.1.0/include/avx512fintrin.h:4459:50: error: '__Y' may be used uninitialized [-Werror=maybe-uninitialized]
```

https://app.circleci.com/pipelines/github/facebook/rocksdb/13295/workflows/1695fb5c-40c1-423b-96b4-45107dc3012d/jobs/360416

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9978

Test Plan:
I was able to re-run in CircleCI with ssh, see the failure, ssh in and
verify that adding -fno-avx512f fixed the failure. Will watch build-linux-unity-and-headers

Reviewed By: riversand963

Differential Revision: D36296028

Pulled By: pdillinger

fbshipit-source-id: ba5955cf2ac730f57d1d18c2f517e92f34be77a3
2022-05-10 15:24:40 -07:00
Peter Dillinger
e78451f3f6 Increase soft open file limit for mini-crashtest on Linux (#9972)
Summary:
CircleCI was using a soft open file limit of 1024 which would
frequently be exceeded during test runs. Now using
```
ulimit -S -n `ulimit -H -n`
```
to set soft limit up to the hard limit (524288 in my test). I've also
applied this same idiom to existing applicable MacOS configurations to
reduce hard-coding numbers.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9972

Test Plan: CI

Reviewed By: riversand963

Differential Revision: D36262943

Pulled By: pdillinger

fbshipit-source-id: 86320cdf9b68a97fdb73531a7b4a59b4c2d2f73f
2022-05-10 09:51:03 -07:00
Andrew Kryczka
7b7a37c069 Add microbenchmarks for DB::GetMergeOperands() (#9971)
Summary:
The new microbenchmarks, DBGetMergeOperandsInMemtable and DBGetMergeOperandsInSstFile, correspond to the two different LSMs tested: all data in one memtable and all data in one SST file, respectively. Both cases are parameterized by thread count (1 or 8) and merge operands per key (1, 32, or 1024). The SST file case is additionally parameterized by whether data is in block cache or mmap'd memory.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9971

Test Plan:
```
$ TEST_TMPDIR=/dev/shm/db_basic_bench/ ./db_basic_bench --benchmark_filter=DBGetMergeOperands
The number of inputs is very large. DBGet will be repeated at least 192 times.
The number of inputs is very large. DBGet will be repeated at least 192 times.
2022-05-09T13:15:40-07:00
Running ./db_basic_bench
Run on (36 X 2570.91 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x18)
  L1 Instruction 32 KiB (x18)
  L2 Unified 1024 KiB (x18)
  L3 Unified 25344 KiB (x1)
Load Average: 4.50, 4.33, 4.37
----------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                  Time             CPU   Iterations UserCounters...
----------------------------------------------------------------------------------------------------------------------------
DBGetMergeOperandsInMemtable/entries_per_key:1/threads:1                 846 ns          846 ns       849893 db_size=0
DBGetMergeOperandsInMemtable/entries_per_key:32/threads:1               2436 ns         2436 ns       305779 db_size=0
DBGetMergeOperandsInMemtable/entries_per_key:1024/threads:1            77226 ns        77224 ns         8152 db_size=0
DBGetMergeOperandsInMemtable/entries_per_key:1/threads:8                 116 ns          929 ns       779368 db_size=0
DBGetMergeOperandsInMemtable/entries_per_key:32/threads:8                330 ns         2644 ns       280824 db_size=0
DBGetMergeOperandsInMemtable/entries_per_key:1024/threads:8            12466 ns        99718 ns         7200 db_size=0
DBGetMergeOperandsInSstFile/entries_per_key:1/mmap:0/threads:1          1640 ns         1640 ns       461262 db_size=21.7826M
DBGetMergeOperandsInSstFile/entries_per_key:1/mmap:1/threads:1          1693 ns         1693 ns       439936 db_size=21.7826M
DBGetMergeOperandsInSstFile/entries_per_key:32/mmap:0/threads:1         3999 ns         3999 ns       172881 db_size=19.6981M
DBGetMergeOperandsInSstFile/entries_per_key:32/mmap:1/threads:1         5544 ns         5543 ns       135657 db_size=19.6981M
DBGetMergeOperandsInSstFile/entries_per_key:1024/mmap:0/threads:1      78767 ns        78761 ns         8395 db_size=19.6389M
DBGetMergeOperandsInSstFile/entries_per_key:1024/mmap:1/threads:1     157242 ns       157238 ns         4495 db_size=19.6389M
DBGetMergeOperandsInSstFile/entries_per_key:1/mmap:0/threads:8           231 ns         1848 ns       347768 db_size=21.7826M
DBGetMergeOperandsInSstFile/entries_per_key:1/mmap:1/threads:8           214 ns         1715 ns       393312 db_size=21.7826M
DBGetMergeOperandsInSstFile/entries_per_key:32/mmap:0/threads:8          596 ns         4767 ns       142088 db_size=19.6981M
DBGetMergeOperandsInSstFile/entries_per_key:32/mmap:1/threads:8          720 ns         5757 ns       118200 db_size=19.6981M
DBGetMergeOperandsInSstFile/entries_per_key:1024/mmap:0/threads:8      11613 ns        92460 ns         7344 db_size=19.6389M
DBGetMergeOperandsInSstFile/entries_per_key:1024/mmap:1/threads:8      19989 ns       159908 ns         4440 db_size=19.6389M
```

Reviewed By: jay-zhuang

Differential Revision: D36258861

Pulled By: ajkr

fbshipit-source-id: 04b733e1cc3a4a70ed9baa894c50fdf96c0d6064
2022-05-09 15:17:19 -07:00
Peter Dillinger
c5c58708db Fix format_compatible blowing away its TEST_TMPDIR (#9970)
Summary:
https://github.com/facebook/rocksdb/issues/9961 broke format_compatible check because of `make clean`
referencing TEST_TMPDIR. The Makefile behavior seems reasonable to me,
so here's a fix in check_format_compatible.sh

Apparently I also included removing a redundant part of our CircleCI config.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9970

Test Plan: manual run: SHORT_TEST=1 ./tools/check_format_compatible.sh

Reviewed By: riversand963

Differential Revision: D36258172

Pulled By: pdillinger

fbshipit-source-id: d46507f04614e888b414ff23b88d040ae2b5c294
2022-05-09 13:38:46 -07:00
Davide Angelocola
4527bb2fed Fix conversion issues in MutableOptions (#9194)
Summary:
Removing unnecessary checks around conversion from int/long to double as it does not lose information (see https://docs.oracle.com/javase/specs/jls/se9/html/jls-5.html#jls-5.1.2).

For example, `value > Double.MAX_VALUE` is always false when value is long or int.

Can you please have a look adamretter? Also fixed some other minor issues (do you prefer a separate PR?)

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9194

Reviewed By: ajkr

Differential Revision: D36221694

fbshipit-source-id: bf327c07386560b87ddc0c98039e8d6e8f2f1e82
2022-05-09 12:34:26 -07:00
Wang Yuan
89571b30e5 Improve the precision of row entry charge in row_cache (#9337)
Summary:
- For entry charge, we should only calculate the value size instead of including key size in LRUCache
- The capacity of string could show the memory usage precisely

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9337

Reviewed By: ajkr

Differential Revision: D36219855

fbshipit-source-id: 393e48ca419d230dc552ae62dd0eb1cc9f45961d
2022-05-09 12:27:38 -07:00
Luca Giacchino
39b6c5791a Improve memkind library detection (#9134)
Summary:
Improve memkind library detection in build_detect_platform:

- The current position of -lmemkind does not work with all versions of gcc
- LDFLAGS allows specifying non-standard library path through EXTRA_LDFLAGS

After the change, the options match TBB detection.
This is a follow-up to https://github.com/facebook/rocksdb/issues/6214.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9134

Reviewed By: ajkr, mrambacher

Differential Revision: D32192028

fbshipit-source-id: 115fafe8d93f1fe6aaf80afb32b2cb67aad074c7
2022-05-09 12:26:09 -07:00
leipeng
9f7968b2ed arena.h: fix Arena::IsInInlineBlock() (#9317)
Summary:
When I enable hugepage on my box, unit test fails, this PR fixes this issue:

[  FAILED  ] ArenaTest.ApproximateMemoryUsage (1 ms)

memory/arena_test.cc:127: Failure
Value of: arena.IsInInlineBlock()
  Actual: true
Expected: false
arena.IsInInlineBlock() = 1
memory/arena_test.cc:127: Failure
Value of: arena.IsInInlineBlock()
  Actual: true
Expected: false

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9317

Reviewed By: ajkr

Differential Revision: D36219813

fbshipit-source-id: 08d040d9f37ec4c16987e4150c2db876180d163d
2022-05-09 12:21:21 -07:00
Qingyou Meng
7b55b50839 util/ribbon_alg.h: removed duplicate word "vector" (#9216)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9216

Reviewed By: riversand963

Differential Revision: D36219934

fbshipit-source-id: 8253b4e3eacceb8b040eeaa45cd5a50570a4eba6
2022-05-06 18:38:13 -07:00
aierui
d1cc91c142 typo fix: delete duplicate comment word (#9249)
Summary:
typo fix: delete duplicate comment word

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9249

Reviewed By: riversand963

Differential Revision: D36219911

fbshipit-source-id: 01e2fda65590f18fe46eefb56e049e6f2d028ae8
2022-05-06 18:29:33 -07:00
♚ PH⑦ de Soria™♛
9381436bf3 Fixed typo (#9331)
Summary:
Just fixing a very minor typo in the doc block :) Hope it will help anyway 😊

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9331

Reviewed By: riversand963

Differential Revision: D34339823

fbshipit-source-id: b76104bc3efbc9d1f38cbf5c6dd7648dc909ced3
2022-05-06 17:41:07 -07:00
Peter Dillinger
e03d958b91 Clean up variables for temporary directory (#9961)
Summary:
Having all of TMPD, TMPDIR and TEST_TMPDIR as configuration
parameters is confusing. This change simplifies a number of things by
standardizing on TEST_TMPDIR, while still recognizing the old names
also. In detail:
* crash_test.mk also needs to use TEST_TMPDIR for crash test, so put in
shared common.mk (an upgrade of python.mk)
* Always exporting TEST_TMPDIR eliminates the need to propagate TMPD or
export TEST_TMPDIR in selective places.
* Use --tmpdir option to gnu_parallel so that it doesn't need TMPDIR
environment variable
* Remove obsolete parloop and parallel_check Makefile targets
* Remove undefined, unused function ResetTmpDirForDirectIO()

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9961

Test Plan: manual + CI

Reviewed By: riversand963

Differential Revision: D36212178

Pulled By: pdillinger

fbshipit-source-id: b76c1876c4f4d38b37789c2779eaa7c3026824dd
2022-05-06 16:38:06 -07:00
Roman Puchkovskiy
00889cf8f2 Never use String#getBytes() in the production code (#9487)
Summary:
There are encodings that are not ASCII-compatible (like cp1140), so it is possible that a JVM is run with a default encoding in which String#getBytes() would return unexpected values even for ASCII strings.

A little bit of context: https://stackoverflow.com/questions/70913929/can-an-encoding-incompatible-with-ascii-encoding-be-set-as-a-default-encoding-in/70914154

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9487

Reviewed By: riversand963

Differential Revision: D34097728

fbshipit-source-id: afd654ecaf20f6d30d9fc20c6a090398de2585eb
2022-05-06 16:22:15 -07:00
sdong
736a7b5433 Remove own ToString() (#9955)
Summary:
ToString() is created as some platform doesn't support std::to_string(). However, we've already used std::to_string() by mistake for 16 months (in db/db_info_dumper.cc). This commit just remove ToString().

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9955

Test Plan: Watch CI tests

Reviewed By: riversand963

Differential Revision: D36176799

fbshipit-source-id: bdb6dcd0e3a3ab96a1ac810f5d0188f684064471
2022-05-06 13:03:58 -07:00
Andrew Kryczka
62d84e2a2b db_stress fault injection in release mode (#9957)
Summary:
Previously all fault injection was ignored in release mode. This PR adds it back except for read fault injection (`--read_fault_one_in > 0`) since its dependency (`IGNORE_STATUS_IF_ERROR`) is unavailable in release mode.

Other notable changes include:

- Moved `EnableWriteErrorInjection()` for `--write_fault_one_in > 0` so it's after `DB::Open()` without depending on `SyncPoint`
- Made `--read_fault_one_in > 0` return an error in release mode
- Updated `db_crashtest.py` to always set `--read_fault_one_in=0` in release mode

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9957

Test Plan:
```
$ DEBUG_LEVEL=0 make -j24 db_stress
$ DEBUG_LEVEL=0 TEST_TMPDIR=/dev/shm python3 tools/db_crashtest.py blackbox
```

Reviewed By: anand1976

Differential Revision: D36193830

Pulled By: ajkr

fbshipit-source-id: 0b97946b4e3f06e3e0f6e7833c2763da08ec5321
2022-05-06 11:17:08 -07:00
Otto Kekäläinen
b7aaa98762 Fix various spelling errors still found in code (#9653)
Summary:
dont -> don't
refered -> referred

This is a re-run of PR#7785 and acc9679 since these typos keep coming back.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9653

Reviewed By: jay-zhuang

Differential Revision: D34879593

fbshipit-source-id: d7631fb779ea0129beae92abfb838038e60790f8
2022-05-05 19:45:32 -07:00
Andrew Kryczka
a62506aee2 Enable unsynced data loss in crash test (#9947)
Summary:
`db_stress` already tracks expected state history to verify prefix-recoverability when `sync_fault_injection` is enabled. This PR enables `sync_fault_injection` in `db_crashtest.py`.

Previously enabling `sync_fault_injection` would cause whole unsynced files to be dropped. This PR adds a more interesting case of losing only the tail of unsynced data by implementing `TestFSWritableFile::RangeSync()` and enabling `{wal_,}bytes_per_sync`.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9947

Test Plan:
- regular blackbox, blackbox --simple
- various commands to stress this new case, such as `TEST_TMPDIR=/dev/shm python3 tools/db_crashtest.py blackbox --max_key=100000 --write_buffer_size=2097152 --avoid_flush_during_recovery=1 --disable_wal=0 --interval=10 --db_write_buffer_size=0 --sync_fault_injection=1 --wal_compression=none --delpercent=0 --delrangepercent=0 --prefixpercent=0 --iterpercent=0 --writepercent=100 --readpercent=0 --wal_bytes_per_sync=131072 --duration=36000 --sync=0 --open_write_fault_one_in=16`

Reviewed By: riversand963

Differential Revision: D36152775

Pulled By: ajkr

fbshipit-source-id: 44b68a7fad0a4cf74af9fe1f39be01baab8141d8
2022-05-05 13:21:03 -07:00
sdong
49628c9a83 Use std::numeric_limits<> (#9954)
Summary:
Right now we still don't fully use std::numeric_limits but use a macro, mainly for supporting VS 2013. Right now we only support VS 2017 and up so it is not a problem. The code comment claims that MinGW still needs it. We don't have a CI running MinGW so it's hard to validate. since we now require C++17, it's hard to imagine MinGW would still build RocksDB but doesn't support std::numeric_limits<>.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9954

Test Plan: See CI Runs.

Reviewed By: riversand963

Differential Revision: D36173954

fbshipit-source-id: a35a73af17cdcae20e258cdef57fcf29a50b49e0
2022-05-05 13:08:21 -07:00
sdong
46f8889b6a platform010 gcc (#9946)
Summary:
Make platform010 gcc build work.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9946

Test Plan:
ROCKSDB_FBCODE_BUILD_WITH_PLATFORM010=1 make release -j
ROCKSDB_FBCODE_BUILD_WITH_PLATFORM010=1 make all check -j

Reviewed By: pdillinger, mdcallag

Differential Revision: D36152684

fbshipit-source-id: ca7b0916c51501a72bb15ad33a85e8c5cac5b505
2022-05-05 11:45:51 -07:00
Trynity Mirell
e62c23cce4 Generate pkg-config file via CMake (#9945)
Summary:
Fixes https://github.com/facebook/rocksdb/issues/7934

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9945

Test Plan:
Built via Homebrew pointing to my fork/branch:

```
  ~/src/github.com/facebook/fbthrift on   main ❯ cat ~/.homebrew/opt/rocksdb/lib/pkgconfig/rocksdb.pc                                                                                                                                                     took  1h 17m 48s at  04:24:54 pm
prefix="/Users/trynity/.homebrew/Cellar/rocksdb/HEAD-968e4dd"
exec_prefix="${prefix}"
libdir="${prefix}/lib"
includedir="${prefix}/include"

Name: rocksdb
Description: An embeddable persistent key-value store for fast storage
URL: https://rocksdb.org/
Version: 7.3.0
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lrocksdb
```

Reviewed By: riversand963

Differential Revision: D36161635

Pulled By: trynity

fbshipit-source-id: 0f1a9c30e43797ee65e6696896e06fde0658456e
2022-05-05 09:03:31 -07:00
Yanqin Jin
9d634dd5b6 Rename kRemoveWithSingleDelete to kPurge (#9951)
Summary:
PR 9929 adds a new CompactionFilter::Decision, i.e.
kRemoveWithSingleDelete so that CompactionFilter can indicate to
CompactionIterator that a PUT can only be removed with SD. However, how
CompactionIterator handles such a key is implementation detail which
should not be implied in the public API. In fact,
such a PUT can just be dropped. This is an optimization which we will apply in the near future.

Discussion thread: https://github.com/facebook/rocksdb/pull/9929#discussion_r863198964

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9951

Test Plan: make check

Reviewed By: ajkr

Differential Revision: D36156590

Pulled By: riversand963

fbshipit-source-id: 7b7d01f47bba4cad7d9cca6ca52984f27f88b372
2022-05-05 08:16:20 -07:00
sdong
68ac507f96 Printing IO Error in DumpDBFileSummary (#9940)
Summary:
Right now in DumpDBFileSummary, IO error isn't printed out, but they are sometimes helpful. Print it out instead.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9940

Test Plan: Watch existing tests to pass.

Reviewed By: riversand963

Differential Revision: D36113016

fbshipit-source-id: 13002080fa4dc76589e2c1c5a1079df8a3c9391c
2022-05-04 10:19:53 -07:00
Mark Callaghan
bf68d1c93d Print elapsed time and number of operations completed (#9886)
Summary:
This is inspired by debugging a regression test that runs for ~0.05 seconds and the short
running time makes it prone to variance. While db_bench ran for ~60 seconds, 59.95 seconds
was spent opening 128 databases (and doing recovery). So it was harder to notice that the
benchmark only ran for 0.05 seconds.

Normally I add output to the end of the line to make life easier for existing tools that parse it
but in this case the output near the end of the line has two optional parts and one of the optional
parts adds an extra newline.

This is for https://github.com/facebook/rocksdb/issues/9856

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9886

Test Plan:
./db_bench --benchmarks=overwrite,readrandom --num=1000000 --threads=4

old output:
 DB path: [/tmp/rocksdbtest-2260/dbbench]
 overwrite    :      14.108 micros/op 283338 ops/sec;   31.3 MB/s
 DB path: [/tmp/rocksdbtest-2260/dbbench]
 readrandom   :       7.994 micros/op 496788 ops/sec;   55.0 MB/s (1000000 of 1000000 found)

new output:
 DB path: [/tmp/rocksdbtest-2260/dbbench]
 overwrite    :      14.117 micros/op 282862 ops/sec 14.141 seconds 4000000 operations;   31.3 MB/s
 DB path: [/tmp/rocksdbtest-2260/dbbench]
 readrandom   :       8.649 micros/op 458475 ops/sec 8.725 seconds 4000000 operations;   49.8 MB/s (981548 of 1000000 found)

Reviewed By: ajkr

Differential Revision: D36102269

Pulled By: mdcallag

fbshipit-source-id: 5cd8a9e11f5cbe2a46809571afd83335b6b0caa0
2022-05-04 10:15:49 -07:00
jsteemann
95663ff763 do not call DeleteFile for not-created sst files (#9920)
Summary:
When a memtable is flushed and the flush would lead to a 0 byte .sst
file being created, RocksDB does not write out the empty .sst file to
disk.
However it still calls Env::DeleteFile() on the file as part of some
cleanup procedure at the end of BuildTable().
Because the to-be-deleted file does not exist, this requires
implementors of the DeleteFile() API to check if the file exists on
their own code, or otherwise risk running into PathNotFound errors when
DeleteFile is invoked on non-existing files.
This PR fixes the situation so that when no .sst file is created,
Deletefile will not be called either.
TableFileCreationStarted() will still be called as before.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9920

Reviewed By: ajkr

Differential Revision: D36107102

Pulled By: riversand963

fbshipit-source-id: 15881ba3fa3192dd448f906280a1cfc7a68a114a
2022-05-04 10:15:30 -07:00
Hui Xiao
de537dcaf1 Fix a comment in RateLimiter::RequestToken (#9933)
Summary:
**Context/Summary:**
- As titled

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9933

Test Plan: - No code change

Reviewed By: ajkr

Differential Revision: D36086544

Pulled By: hx235

fbshipit-source-id: 2bdd19f67e45df1e3af4121b0c1a5e866a57826d
2022-05-04 10:10:36 -07:00
Jay Zhuang
270179bb12 Default try_load_options to true when DB is specified (#9937)
Summary:
If the DB path is specified, the user would expect ldb loads the
options from the path, but it's not:
```
$ ldb list_live_files_metadata --db=`pwd`
```
Default `try_load_options` to true in that case. The user can still
disable that by:
```
$ ldb list_live_files_metadata --db=`pwd` --try_load_options=false
```

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9937

Test Plan:
`ldb list_live_files_metadata --db=`pwd`` is able to work for
a db generated with different options.num_levels.

Reviewed By: ajkr

Differential Revision: D36106708

Pulled By: jay-zhuang

fbshipit-source-id: 2732fdc027a4d172436b2c9b6a9787b56b10c710
2022-05-04 08:49:46 -07:00
Xinyu Zeng
8b74cea7fe Reduce comparator objects init cost in BlockIter (#9611)
Summary:
This PR solves the problem discussed in https://github.com/facebook/rocksdb/issues/7149. By storing the pointer of InternalKeyComparator as icmp_ in BlockIter, the object size remains the same. And for each call to CompareCurrentKey, there is no need to create Comparator objects. One can use icmp_ directly or use the "user_comparator" from the icmp_.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9611

Test Plan:
with https://github.com/facebook/rocksdb/issues/9903,

```
$ TEST_TMPDIR=/dev/shm python3.6 ../benchmark/tools/compare.py benchmarks ./db_basic_bench ../rocksdb-pr9611/db_basic_bench --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1 --benchmark_repetitions=50
...
Comparing ./db_basic_bench to ../rocksdb-pr9611/db_basic_bench
Benchmark                                                                                                                                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
...
DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1_pvalue                 0.0001          0.0001      U Test, Repetitions: 50 vs 50
DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1_mean                  -0.0483         -0.0483          3924          3734          3924          3734
DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1_median                -0.0713         -0.0713          3971          3687          3970          3687
DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1_stddev                -0.0342         -0.0344           225           217           225           217
DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:0/negative_query:0/enable_filter:0/mmap:1/iterations:262144/threads:1_cv                    +0.0148         +0.0146             0             0             0             0
OVERALL_GEOMEAN                                                                                                                                                      -0.0483         -0.0483             0             0             0             0
```

Reviewed By: akankshamahajan15

Differential Revision: D35882037

Pulled By: ajkr

fbshipit-source-id: 9e5337bbad8f1239dff7aa9f6549020d599bfcdf
2022-05-03 17:37:19 -07:00
Siying Dong
b82edffc7b Improve comments to options.allow_mmap_reads (#9936)
Summary:
It confused users and use that with options.allow_mmap_reads = true, CPU is high with checksum verification. Add a comment to explain it.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9936

Reviewed By: anand1976

Differential Revision: D36106529

fbshipit-source-id: 3d723bd686f96a84c694c8b2d91ad28d9ccfd979
2022-05-03 16:21:31 -07:00
Andrew Kryczka
440c7f6306 db_basic_bench fix for DB object cleanup (#9939)
Summary:
Use `unique_ptr<DB>` to make sure the DB object is deleted. Previously it was not, which led to accumulating file descriptors for deleted directories because a `DBImpl::db_dir_` from each test remained alive.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9939

Test Plan: run `lsof -p $(pidof db_basic_bench)` while benchmark runs; verify no FDs for deleted directories.

Reviewed By: jay-zhuang

Differential Revision: D36108761

Pulled By: ajkr

fbshipit-source-id: cfe02646b038a445af7d5db8989eb1f40d658359
2022-05-03 13:38:38 -07:00
Peter Dillinger
bb87164db3 Fork and simplify LRUCache for developing enhancements (#9917)
Summary:
To support a project to prototype and evaluate algorithmic
enhancments and alternatives to LRUCache, here I have separated out
LRUCache into internal-only "FastLRUCache" and cut it down to
essentials, so that details like secondary cache handling and
priorities do not interfere with prototyping. These can be
re-integrated later as needed, along with refactoring to minimize code
duplication (which would slow down prototyping for now).

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9917

Test Plan:
unit tests updated to ensure basic functionality has (likely)
been preserved

Reviewed By: anand1976

Differential Revision: D35995554

Pulled By: pdillinger

fbshipit-source-id: d67b20b7ada3b5d3bfe56d897a73885894a1d9db
2022-05-03 12:32:02 -07:00
Peter Dillinger
4b9a1a2f56 Fix db_crashtest.py call inconsistency in crash_test.mk (#9935)
Summary:
Some tests crashing because not using custom DB_STRESS_CMD

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9935

Test Plan: internal tests

Reviewed By: riversand963

Differential Revision: D36104347

Pulled By: pdillinger

fbshipit-source-id: 23f080704a124174203f54ffd85578c2047effe5
2022-05-03 12:03:57 -07:00
241 changed files with 4385 additions and 2301 deletions

View File

@ -2,7 +2,6 @@ version: 2.1
orbs: orbs:
win: circleci/windows@2.4.0 win: circleci/windows@2.4.0
slack: circleci/slack@3.4.2
aliases: aliases:
- &notify-on-main-failure - &notify-on-main-failure
@ -57,7 +56,6 @@ commands:
post-steps: post-steps:
steps: steps:
- slack/status: *notify-on-main-failure
- store_test_results: # store test result if there's any - store_test_results: # store test result if there's any
path: /tmp/test-results path: /tmp/test-results
- store_artifacts: # store LOG for debugging if there's any - store_artifacts: # store LOG for debugging if there's any
@ -182,7 +180,7 @@ jobs:
- increase-max-open-files-on-macos - increase-max-open-files-on-macos
- install-gflags-on-macos - install-gflags-on-macos
- pre-steps-macos - pre-steps-macos
- run: ulimit -S -n 1048576 && OPT=-DCIRCLECI make V=1 J=32 -j32 all - run: ulimit -S -n `ulimit -H -n` && OPT=-DCIRCLECI make V=1 J=32 -j32 all
- post-steps - post-steps
build-macos-cmake: build-macos-cmake:
@ -201,7 +199,7 @@ jobs:
- pre-steps-macos - pre-steps-macos
- run: - run:
name: "cmake generate project file" name: "cmake generate project file"
command: ulimit -S -n 1048576 && mkdir build && cd build && cmake -DWITH_GFLAGS=1 .. command: ulimit -S -n `ulimit -H -n` && mkdir build && cd build && cmake -DWITH_GFLAGS=1 ..
- run: - run:
name: "Build tests" name: "Build tests"
command: cd build && make V=1 -j32 command: cd build && make V=1 -j32
@ -210,14 +208,14 @@ jobs:
steps: steps:
- run: - run:
name: "Run even tests" name: "Run even tests"
command: ulimit -S -n 1048576 && cd build && ctest -j32 -I 0,,2 command: ulimit -S -n `ulimit -H -n` && cd build && ctest -j32 -I 0,,2
- when: - when:
condition: condition:
not: << parameters.run_even_tests >> not: << parameters.run_even_tests >>
steps: steps:
- run: - run:
name: "Run odd tests" name: "Run odd tests"
command: ulimit -S -n 1048576 && cd build && ctest -j32 -I 1,,2 command: ulimit -S -n `ulimit -H -n` && cd build && ctest -j32 -I 1,,2
- post-steps - post-steps
build-linux: build-linux:
@ -413,11 +411,13 @@ jobs:
build-linux-unity-and-headers: build-linux-unity-and-headers:
docker: # executor type docker: # executor type
- image: gcc:latest - image: gcc:latest
environment:
EXTRA_CXXFLAGS: -mno-avx512f # Warnings-as-error in avx512fintrin.h, would be used on newer hardware
resource_class: large resource_class: large
steps: steps:
- checkout # check out the code in the project directory - checkout # check out the code in the project directory
- run: apt-get update -y && apt-get install -y libgflags-dev - run: apt-get update -y && apt-get install -y libgflags-dev
- run: TEST_TMPDIR=/dev/shm && make V=1 -j8 unity_test - run: make V=1 -j8 unity_test
- run: make V=1 -j8 -k check-headers # could be moved to a different build - run: make V=1 -j8 -k check-headers # could be moved to a different build
- post-steps - post-steps
@ -506,7 +506,7 @@ jobs:
- pre-steps - pre-steps
- install-gflags - install-gflags
- install-compression-libs - install-compression-libs
- run: make V=1 -j8 CRASH_TEST_EXT_ARGS=--duration=960 blackbox_crash_test_with_atomic_flush - run: ulimit -S -n `ulimit -H -n` && make V=1 -j8 CRASH_TEST_EXT_ARGS=--duration=960 blackbox_crash_test_with_atomic_flush
- post-steps - post-steps
build-windows: build-windows:
@ -828,108 +828,76 @@ jobs:
workflows: workflows:
version: 2 version: 2
build-linux: jobs-linux-run-tests:
jobs: jobs:
- build-linux - build-linux
build-linux-cmake:
jobs:
- build-linux-cmake-with-folly - build-linux-cmake-with-folly
- build-linux-gcc-7-with-folly
- build-linux-cmake-with-benchmark - build-linux-cmake-with-benchmark
build-linux-encrypted_env-no_compression:
jobs:
- build-linux-encrypted_env-no_compression - build-linux-encrypted_env-no_compression
build-linux-shared_lib-alt_namespace-status_checked:
jobs:
- build-linux-shared_lib-alt_namespace-status_checked
build-linux-lite:
jobs:
- build-linux-lite - build-linux-lite
build-linux-release: jobs-linux-run-tests-san:
jobs:
- build-linux-release
build-linux-release-rtti:
jobs:
- build-linux-release-rtti
build-linux-lite-release:
jobs:
- build-linux-lite-release
build-linux-clang10-asan:
jobs: jobs:
- build-linux-clang10-asan - build-linux-clang10-asan
build-linux-clang10-mini-tsan: - build-linux-clang10-ubsan
jobs:
- build-linux-clang10-mini-tsan: - build-linux-clang10-mini-tsan:
start_test: "" start_test: ""
end_test: "env_test" end_test: "env_test"
- build-linux-clang10-mini-tsan: - build-linux-clang10-mini-tsan:
start_test: "env_test" start_test: "env_test"
end_test: "" end_test: ""
build-linux-clang10-ubsan: - build-linux-shared_lib-alt_namespace-status_checked
jobs-linux-no-test-run:
jobs: jobs:
- build-linux-clang10-ubsan - build-linux-release
build-linux-clang10-clang-analyze: - build-linux-release-rtti
- build-linux-lite-release
- build-examples
- build-fuzzers
- build-linux-clang-no_test_run
- build-linux-clang-13-no_test_run
- build-linux-gcc-8-no_test_run
- build-linux-gcc-10-cxx20-no_test_run
- build-linux-gcc-11-no_test_run
- build-linux-arm-cmake-no_test_run
jobs-linux-other-checks:
jobs: jobs:
- build-linux-clang10-clang-analyze - build-linux-clang10-clang-analyze
build-linux-unity-and-headers:
jobs:
- build-linux-unity-and-headers - build-linux-unity-and-headers
build-linux-mini-crashtest:
jobs:
- build-linux-mini-crashtest - build-linux-mini-crashtest
build-windows-vs2019: jobs-windows:
jobs: jobs:
- build-windows: - build-windows:
name: "build-windows-vs2019" name: "build-windows-vs2019"
build-windows-vs2019-cxx20:
jobs:
- build-windows: - build-windows:
name: "build-windows-vs2019-cxx20" name: "build-windows-vs2019-cxx20"
extra_cmake_opt: -DCMAKE_CXX_STANDARD=20 extra_cmake_opt: -DCMAKE_CXX_STANDARD=20
build-windows-vs2017:
jobs:
- build-windows: - build-windows:
name: "build-windows-vs2017" name: "build-windows-vs2017"
vs_year: "2017" vs_year: "2017"
cmake_generator: "Visual Studio 15 Win64" cmake_generator: "Visual Studio 15 Win64"
build-java: - build-cmake-mingw
jobs-java:
jobs: jobs:
- build-linux-java - build-linux-java
- build-linux-java-static - build-linux-java-static
- build-macos-java - build-macos-java
- build-macos-java-static - build-macos-java-static
- build-macos-java-static-universal - build-macos-java-static-universal
build-examples: jobs-macos:
jobs:
- build-examples
build-linux-compilers-no_test_run:
jobs:
- build-linux-clang-no_test_run
- build-linux-clang-13-no_test_run
- build-linux-gcc-7-with-folly
- build-linux-gcc-8-no_test_run
- build-linux-gcc-10-cxx20-no_test_run
- build-linux-gcc-11-no_test_run
- build-linux-arm-cmake-no_test_run
build-macos:
jobs: jobs:
- build-macos - build-macos
- build-macos-cmake: - build-macos-cmake:
run_even_tests: true run_even_tests: true
- build-macos-cmake: - build-macos-cmake:
run_even_tests: false run_even_tests: false
build-cmake-mingw: jobs-linux-arm:
jobs:
- build-cmake-mingw
build-linux-arm:
jobs: jobs:
- build-linux-arm - build-linux-arm
build-fuzzers:
jobs:
- build-fuzzers
nightly: nightly:
triggers: triggers:
- schedule: - schedule:
cron: "0 0 * * *" cron: "0 9 * * *"
filters: filters:
branches: branches:
only: only:

View File

@ -40,6 +40,8 @@ include(GoogleTest)
get_rocksdb_version(rocksdb_VERSION) get_rocksdb_version(rocksdb_VERSION)
project(rocksdb project(rocksdb
VERSION ${rocksdb_VERSION} VERSION ${rocksdb_VERSION}
DESCRIPTION "An embeddable persistent key-value store for fast storage"
HOMEPAGE_URL https://rocksdb.org/
LANGUAGES CXX C ASM) LANGUAGES CXX C ASM)
if(POLICY CMP0042) if(POLICY CMP0042)
@ -596,6 +598,7 @@ set(SOURCES
cache/cache_reservation_manager.cc cache/cache_reservation_manager.cc
cache/clock_cache.cc cache/clock_cache.cc
cache/compressed_secondary_cache.cc cache/compressed_secondary_cache.cc
cache/fast_lru_cache.cc
cache/lru_cache.cc cache/lru_cache.cc
cache/sharded_cache.cc cache/sharded_cache.cc
db/arena_wrapped_db_iter.cc db/arena_wrapped_db_iter.cc
@ -1120,6 +1123,12 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
COMPATIBILITY SameMajorVersion COMPATIBILITY SameMajorVersion
) )
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY
)
install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/modules" COMPONENT devel DESTINATION ${package_config_destination}) install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/modules" COMPONENT devel DESTINATION ${package_config_destination})
@ -1158,6 +1167,13 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
COMPONENT devel COMPONENT devel
DESTINATION ${package_config_destination} DESTINATION ${package_config_destination}
) )
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
COMPONENT devel
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif() endif()
option(WITH_ALL_TESTS "Build all test, rather than a small subset" ON) option(WITH_ALL_TESTS "Build all test, rather than a small subset" ON)

View File

@ -5,6 +5,7 @@
* Fixed a bug where RocksDB could corrupt DBs with `avoid_flush_during_recovery == true` by removing valid WALs, leading to `Status::Corruption` with message like "SST file is ahead of WALs" when attempting to reopen. * Fixed a bug where RocksDB could corrupt DBs with `avoid_flush_during_recovery == true` by removing valid WALs, leading to `Status::Corruption` with message like "SST file is ahead of WALs" when attempting to reopen.
* Fixed a bug in async_io path where incorrect length of data is read by FilePrefetchBuffer if data is consumed from two populated buffers and request for more data is sent. * Fixed a bug in async_io path where incorrect length of data is read by FilePrefetchBuffer if data is consumed from two populated buffers and request for more data is sent.
* Fixed a CompactionFilter bug. Compaction filter used to use `Delete` to remove keys, even if the keys should be removed with `SingleDelete`. Mixing `Delete` and `SingleDelete` may cause undefined behavior. * Fixed a CompactionFilter bug. Compaction filter used to use `Delete` to remove keys, even if the keys should be removed with `SingleDelete`. Mixing `Delete` and `SingleDelete` may cause undefined behavior.
* Fixed a bug which might cause process crash when I/O error happens when reading an index block in MultiGet().
### New Features ### New Features
* DB::GetLiveFilesStorageInfo is ready for production use. * DB::GetLiveFilesStorageInfo is ready for production use.
@ -14,6 +15,9 @@
* Add rollback_deletion_type_callback to TransactionDBOptions so that write-prepared transactions know whether to issue a Delete or SingleDelete to cancel a previous key written during prior prepare phase. The PR aims to prevent mixing SingleDeletes and Deletes for the same key that can lead to undefined behaviors for write-prepared transactions. * Add rollback_deletion_type_callback to TransactionDBOptions so that write-prepared transactions know whether to issue a Delete or SingleDelete to cancel a previous key written during prior prepare phase. The PR aims to prevent mixing SingleDeletes and Deletes for the same key that can lead to undefined behaviors for write-prepared transactions.
* EXPERIMENTAL: Add new API AbortIO in file_system to abort the read requests submitted asynchronously. * EXPERIMENTAL: Add new API AbortIO in file_system to abort the read requests submitted asynchronously.
* CompactionFilter::Decision has a new value: kRemoveWithSingleDelete. If CompactionFilter returns this decision, then CompactionIterator will use `SingleDelete` to mark a key as removed. * CompactionFilter::Decision has a new value: kRemoveWithSingleDelete. If CompactionFilter returns this decision, then CompactionIterator will use `SingleDelete` to mark a key as removed.
* Renamed CompactionFilter::Decision::kRemoveWithSingleDelete to kPurge since the latter sounds more general and hides the implementation details of how compaction iterator handles keys.
* Added ability to specify functions for Prepare and Validate to OptionsTypeInfo. Added methods to OptionTypeInfo to set the functions via an API. These methods are intended for RocksDB plugin developers for configuration management.
* Added a new immutable db options, enforce_single_del_contracts. If set to false (default is true), compaction will NOT fail due to a single delete followed by a delete for the same key. The purpose of this temporay option is to help existing use cases migrate.
### Bug Fixes ### Bug Fixes
* RocksDB calls FileSystem::Poll API during FilePrefetchBuffer destruction which impacts performance as it waits for read requets completion which is not needed anymore. Calling FileSystem::AbortIO to abort those requests instead fixes that performance issue. * RocksDB calls FileSystem::Poll API during FilePrefetchBuffer destruction which impacts performance as it waits for read requets completion which is not needed anymore. Calling FileSystem::AbortIO to abort those requests instead fixes that performance issue.
@ -21,6 +25,7 @@
### Behavior changes ### Behavior changes
* Enforce the existing contract of SingleDelete so that SingleDelete cannot be mixed with Delete because it leads to undefined behavior. Fix a number of unit tests that violate the contract but happen to pass. * Enforce the existing contract of SingleDelete so that SingleDelete cannot be mixed with Delete because it leads to undefined behavior. Fix a number of unit tests that violate the contract but happen to pass.
* ldb `--try_load_options` default to true if `--db` is specified and not creating a new DB, the user can still explicitly disable that by `--try_load_options=false` (or explicitly enable that by `--try_load_options`).
## 7.2.0 (04/15/2022) ## 7.2.0 (04/15/2022)
### Bug Fixes ### Bug Fixes

122
Makefile
View File

@ -8,7 +8,7 @@
BASH_EXISTS := $(shell which bash) BASH_EXISTS := $(shell which bash)
SHELL := $(shell which bash) SHELL := $(shell which bash)
include python.mk include common.mk
CLEAN_FILES = # deliberately empty, so we can append below. CLEAN_FILES = # deliberately empty, so we can append below.
CFLAGS += ${EXTRA_CFLAGS} CFLAGS += ${EXTRA_CFLAGS}
@ -795,17 +795,10 @@ $(SHARED4): $(LIB_OBJECTS)
$(AM_V_CCLD) $(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(LIB_OBJECTS) $(LDFLAGS) -o $@ $(AM_V_CCLD) $(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(LIB_OBJECTS) $(LDFLAGS) -o $@
endif # PLATFORM_SHARED_EXT endif # PLATFORM_SHARED_EXT
.PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests package \ .PHONY: check clean coverage ldb_tests package dbg gen-pc build_size \
release tags tags0 valgrind_check whitebox_crash_test format static_lib shared_lib all \ release tags tags0 valgrind_check format static_lib shared_lib all \
dbg rocksdbjavastatic rocksdbjava gen-pc install install-static install-shared uninstall \ rocksdbjavastatic rocksdbjava install install-static install-shared \
analyze tools tools_lib check-headers checkout_folly \ uninstall analyze tools tools_lib check-headers checkout_folly
blackbox_crash_test_with_atomic_flush whitebox_crash_test_with_atomic_flush \
blackbox_crash_test_with_txn whitebox_crash_test_with_txn \
blackbox_crash_test_with_best_efforts_recovery \
blackbox_crash_test_with_ts whitebox_crash_test_with_ts \
blackbox_crash_test_with_multiops_wc_txn \
blackbox_crash_test_with_multiops_wp_txn
all: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(TESTS) all: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(TESTS)
@ -842,18 +835,6 @@ coverage: clean
# Delete intermediate files # Delete intermediate files
$(FIND) . -type f \( -name "*.gcda" -o -name "*.gcno" \) -exec rm -f {} \; $(FIND) . -type f \( -name "*.gcda" -o -name "*.gcno" \) -exec rm -f {} \;
ifneq (,$(filter check parallel_check,$(MAKECMDGOALS)),)
# Use /dev/shm if it has the sticky bit set (otherwise, /tmp),
# and create a randomly-named rocksdb.XXXX directory therein.
# We'll use that directory in the "make check" rules.
ifeq ($(TMPD),)
TMPDIR := $(shell echo $${TMPDIR:-/tmp})
TMPD := $(shell f=/dev/shm; test -k $$f || f=$(TMPDIR); \
perl -le 'use File::Temp "tempdir";' \
-e 'print tempdir("'$$f'/rocksdb.XXXX", CLEANUP => 0)')
endif
endif
# Run all tests in parallel, accumulating per-test logs in t/log-*. # Run all tests in parallel, accumulating per-test logs in t/log-*.
# #
# Each t/run-* file is a tiny generated bourne shell script that invokes one of # Each t/run-* file is a tiny generated bourne shell script that invokes one of
@ -893,7 +874,7 @@ $(parallel_tests):
TEST_SCRIPT=t/run-$$TEST_BINARY-$${TEST_NAME//\//-}; \ TEST_SCRIPT=t/run-$$TEST_BINARY-$${TEST_NAME//\//-}; \
printf '%s\n' \ printf '%s\n' \
'#!/bin/sh' \ '#!/bin/sh' \
"d=\$(TMPD)$$TEST_SCRIPT" \ "d=\$(TEST_TMPDIR)$$TEST_SCRIPT" \
'mkdir -p $$d' \ 'mkdir -p $$d' \
"TEST_TMPDIR=\$$d $(DRIVER) ./$$TEST_BINARY --gtest_filter=$$TEST_NAME" \ "TEST_TMPDIR=\$$d $(DRIVER) ./$$TEST_BINARY --gtest_filter=$$TEST_NAME" \
> $$TEST_SCRIPT; \ > $$TEST_SCRIPT; \
@ -953,7 +934,6 @@ endif
.PHONY: check_0 .PHONY: check_0
check_0: check_0:
$(AM_V_GEN)export TEST_TMPDIR=$(TMPD); \
printf '%s\n' '' \ printf '%s\n' '' \
'To monitor subtest <duration,pass/fail,name>,' \ 'To monitor subtest <duration,pass/fail,name>,' \
' run "make watch-log" in a separate window' ''; \ ' run "make watch-log" in a separate window' ''; \
@ -964,7 +944,8 @@ check_0:
| $(prioritize_long_running_tests) \ | $(prioritize_long_running_tests) \
| grep -E '$(tests-regexp)' \ | grep -E '$(tests-regexp)' \
| grep -E -v '$(EXCLUDE_TESTS_REGEX)' \ | grep -E -v '$(EXCLUDE_TESTS_REGEX)' \
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu '{} $(parallel_redir)' ; \ | build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu \
--tmpdir=$(TEST_TMPDIR) '{} $(parallel_redir)' ; \
parallel_retcode=$$? ; \ parallel_retcode=$$? ; \
awk '{ if ($$7 != 0 || $$8 != 0) { if ($$7 == "Exitval") { h = $$0; } else { if (!f) print h; print; f = 1 } } } END { if(f) exit 1; }' < LOG ; \ awk '{ if ($$7 != 0 || $$8 != 0) { if ($$7 == "Exitval") { h = $$0; } else { if (!f) print h; print; f = 1 } } } END { if(f) exit 1; }' < LOG ; \
awk_retcode=$$?; \ awk_retcode=$$?; \
@ -975,7 +956,6 @@ valgrind-exclude-regexp = InlineSkipTest.ConcurrentInsert|TransactionStressTest.
.PHONY: valgrind_check_0 .PHONY: valgrind_check_0
valgrind_check_0: test_log_prefix := valgrind_ valgrind_check_0: test_log_prefix := valgrind_
valgrind_check_0: valgrind_check_0:
$(AM_V_GEN)export TEST_TMPDIR=$(TMPD); \
printf '%s\n' '' \ printf '%s\n' '' \
'To monitor subtest <duration,pass/fail,name>,' \ 'To monitor subtest <duration,pass/fail,name>,' \
' run "make watch-log" in a separate window' ''; \ ' run "make watch-log" in a separate window' ''; \
@ -987,10 +967,11 @@ valgrind_check_0:
| grep -E '$(tests-regexp)' \ | grep -E '$(tests-regexp)' \
| grep -E -v '$(valgrind-exclude-regexp)' \ | grep -E -v '$(valgrind-exclude-regexp)' \
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu \ | build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu \
'(if [[ "{}" == "./"* ]] ; then $(DRIVER) {}; else {}; fi) \ --tmpdir=$(TEST_TMPDIR) \
'(if [[ "{}" == "./"* ]] ; then $(DRIVER) {}; else {}; fi) \
$(parallel_redir)' \ $(parallel_redir)' \
CLEAN_FILES += t LOG $(TMPD) CLEAN_FILES += t LOG $(TEST_TMPDIR)
# When running parallel "make check", you can monitor its progress # When running parallel "make check", you can monitor its progress
# from another window. # from another window.
@ -1013,12 +994,12 @@ check: all
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \ && (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
grep -q 'GNU Parallel'; \ grep -q 'GNU Parallel'; \
then \ then \
$(MAKE) T="$$t" TMPD=$(TMPD) check_0; \ $(MAKE) T="$$t" check_0; \
else \ else \
for t in $(TESTS); do \ for t in $(TESTS); do \
echo "===== Running $$t (`date`)"; ./$$t || exit 1; done; \ echo "===== Running $$t (`date`)"; ./$$t || exit 1; done; \
fi fi
rm -rf $(TMPD) rm -rf $(TEST_TMPDIR)
ifneq ($(PLATFORM), OS_AIX) ifneq ($(PLATFORM), OS_AIX)
$(PYTHON) tools/check_all_python.py $(PYTHON) tools/check_all_python.py
ifeq ($(filter -DROCKSDB_LITE,$(OPT)),) ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
@ -1115,11 +1096,11 @@ valgrind_test_some:
valgrind_check: $(TESTS) valgrind_check: $(TESTS)
$(MAKE) DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" gen_parallel_tests $(MAKE) DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" gen_parallel_tests
$(AM_V_GEN)if test "$(J)" != 1 \ $(AM_V_GEN)if test "$(J)" != 1 \
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \ && (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
grep -q 'GNU Parallel'; \ grep -q 'GNU Parallel'; \
then \ then \
$(MAKE) TMPD=$(TMPD) \ $(MAKE) \
DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" valgrind_check_0; \ DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" valgrind_check_0; \
else \ else \
for t in $(filter-out %skiplist_test options_settable_test,$(TESTS)); do \ for t in $(filter-out %skiplist_test options_settable_test,$(TESTS)); do \
$(VALGRIND_VER) $(VALGRIND_OPTS) ./$$t; \ $(VALGRIND_VER) $(VALGRIND_OPTS) ./$$t; \
@ -1139,27 +1120,6 @@ valgrind_check_some: $(ROCKSDBTESTS_SUBSET)
fi; \ fi; \
done done
ifneq ($(PAR_TEST),)
parloop:
ret_bad=0; \
for t in $(PAR_TEST); do \
echo "===== Running $$t in parallel $(NUM_PAR) (`date`)";\
if [ $(db_test) -eq 1 ]; then \
seq $(J) | v="$$t" build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{}; export TEST_TMPDIR=$$s;' \
'timeout 2m ./db_test --gtest_filter=$$v >> $$s/log-{} 2>1'; \
else\
seq $(J) | v="./$$t" build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{};' \
'export TEST_TMPDIR=$$s; timeout 10m $$v >> $$s/log-{} 2>1'; \
fi; \
ret_code=$$?; \
if [ $$ret_code -ne 0 ]; then \
ret_bad=$$ret_code; \
echo $$t exited with $$ret_code; \
fi; \
done; \
exit $$ret_bad;
endif
test_names = \ test_names = \
./db_test --gtest_list_tests \ ./db_test --gtest_list_tests \
| perl -n \ | perl -n \
@ -1167,24 +1127,6 @@ test_names = \
-e '/^(\s*)(\S+)/; !$$1 and do {$$p=$$2; break};' \ -e '/^(\s*)(\S+)/; !$$1 and do {$$p=$$2; break};' \
-e 'print qq! $$p$$2!' -e 'print qq! $$p$$2!'
parallel_check: $(TESTS)
$(AM_V_GEN)if test "$(J)" > 1 \
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
grep -q 'GNU Parallel'; \
then \
echo Running in parallel $(J); \
else \
echo "Need to have GNU Parallel and J > 1"; exit 1; \
fi; \
ret_bad=0; \
echo $(J);\
echo Test Dir: $(TMPD); \
seq $(J) | build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{}; rm -rf $$s; mkdir $$s'; \
$(MAKE) PAR_TEST="$(shell $(test_names))" TMPD=$(TMPD) \
J=$(J) db_test=1 parloop; \
$(MAKE) PAR_TEST="$(filter-out db_test, $(TESTS))" \
TMPD=$(TMPD) J=$(J) db_test=0 parloop;
analyze: clean analyze: clean
USE_CLANG=1 $(MAKE) analyze_incremental USE_CLANG=1 $(MAKE) analyze_incremental
@ -2404,6 +2346,38 @@ checkout_folly:
@# NOTE: this hack is not needed if using FBCODE compiler config @# NOTE: this hack is not needed if using FBCODE compiler config
perl -pi -e 's/^(#include <boost)/\/\/$$1/' third-party/folly/folly/functional/Invoke.h perl -pi -e 's/^(#include <boost)/\/\/$$1/' third-party/folly/folly/functional/Invoke.h
# ---------------------------------------------------------------------------
# Build size testing
# ---------------------------------------------------------------------------
REPORT_BUILD_STATISTIC?=echo STATISTIC:
build_size:
# === normal build, static ===
$(MAKE) clean
$(MAKE) static_lib
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.static_lib $$(stat --printf="%s" librocksdb.a)
strip librocksdb.a
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.static_lib_stripped $$(stat --printf="%s" librocksdb.a)
# === normal build, shared ===
$(MAKE) clean
$(MAKE) shared_lib
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.shared_lib $$(stat --printf="%s" `readlink -f librocksdb.so`)
strip `readlink -f librocksdb.so`
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.shared_lib_stripped $$(stat --printf="%s" `readlink -f librocksdb.so`)
# === lite build, static ===
$(MAKE) clean
$(MAKE) LITE=1 static_lib
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.static_lib_lite $$(stat --printf="%s" librocksdb.a)
strip librocksdb.a
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.static_lib_lite_stripped $$(stat --printf="%s" librocksdb.a)
# === lite build, shared ===
$(MAKE) clean
$(MAKE) LITE=1 shared_lib
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.shared_lib_lite $$(stat --printf="%s" `readlink -f librocksdb.so`)
strip `readlink -f librocksdb.so`
$(REPORT_BUILD_STATISTIC) rocksdb.build_size.shared_lib_lite_stripped $$(stat --printf="%s" `readlink -f librocksdb.so`)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Platform-specific compilation # Platform-specific compilation
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@ -4,3 +4,4 @@ This is the list of all known third-party plugins for RocksDB. If something is m
* [HDFS](https://github.com/riversand963/rocksdb-hdfs-env): an Env used for interacting with HDFS. Migrated from main RocksDB repo * [HDFS](https://github.com/riversand963/rocksdb-hdfs-env): an Env used for interacting with HDFS. Migrated from main RocksDB repo
* [ZenFS](https://github.com/westerndigitalcorporation/zenfs): a file system for zoned block devices * [ZenFS](https://github.com/westerndigitalcorporation/zenfs): a file system for zoned block devices
* [RADOS](https://github.com/riversand963/rocksdb-rados-env): an Env used for interacting with RADOS. Migrated from RocksDB main repo. * [RADOS](https://github.com/riversand963/rocksdb-rados-env): an Env used for interacting with RADOS. Migrated from RocksDB main repo.
* [PMEM](https://github.com/pmem/pmem-rocksdb-plugin): a collection of plugins to enable Persistent Memory on RocksDB.

View File

@ -15,6 +15,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
"cache/cache_reservation_manager.cc", "cache/cache_reservation_manager.cc",
"cache/clock_cache.cc", "cache/clock_cache.cc",
"cache/compressed_secondary_cache.cc", "cache/compressed_secondary_cache.cc",
"cache/fast_lru_cache.cc",
"cache/lru_cache.cc", "cache/lru_cache.cc",
"cache/sharded_cache.cc", "cache/sharded_cache.cc",
"db/arena_wrapped_db_iter.cc", "db/arena_wrapped_db_iter.cc",
@ -335,6 +336,7 @@ cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[
"cache/cache_reservation_manager.cc", "cache/cache_reservation_manager.cc",
"cache/clock_cache.cc", "cache/clock_cache.cc",
"cache/compressed_secondary_cache.cc", "cache/compressed_secondary_cache.cc",
"cache/fast_lru_cache.cc",
"cache/lru_cache.cc", "cache/lru_cache.cc",
"cache/sharded_cache.cc", "cache/sharded_cache.cc",
"db/arena_wrapped_db_iter.cc", "db/arena_wrapped_db_iter.cc",

View File

@ -469,7 +469,7 @@ EOF
if ! test $ROCKSDB_DISABLE_MEMKIND; then if ! test $ROCKSDB_DISABLE_MEMKIND; then
# Test whether memkind library is installed # Test whether memkind library is installed
$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -lmemkind -x c++ - -o test.o 2>/dev/null <<EOF $CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o test.o -lmemkind 2>/dev/null <<EOF
#include <memkind.h> #include <memkind.h>
int main() { int main() {
memkind_malloc(MEMKIND_DAX_KMEM, 1024); memkind_malloc(MEMKIND_DAX_KMEM, 1024);

View File

@ -118,10 +118,19 @@ if [ -z "$USE_CLANG" ]; then
CXX="$GCC_BASE/bin/g++" CXX="$GCC_BASE/bin/g++"
AR="$GCC_BASE/bin/gcc-ar" AR="$GCC_BASE/bin/gcc-ar"
CFLAGS+=" -B$BINUTILS -nostdinc -nostdlib"
CFLAGS+=" -B$BINUTILS" CFLAGS+=" -I$GCC_BASE/include"
CFLAGS+=" -isystem $GCC_BASE/lib/gcc/x86_64-redhat-linux-gnu/11.2.1/include"
CFLAGS+=" -isystem $GCC_BASE/lib/gcc/x86_64-redhat-linux-gnu/11.2.1/install-tools/include"
CFLAGS+=" -isystem $GCC_BASE/lib/gcc/x86_64-redhat-linux-gnu/11.2.1/include-fixed/"
CFLAGS+=" -isystem $LIBGCC_INCLUDE" CFLAGS+=" -isystem $LIBGCC_INCLUDE"
CFLAGS+=" -isystem $GLIBC_INCLUDE" CFLAGS+=" -isystem $GLIBC_INCLUDE"
CFLAGS+=" -I$GLIBC_INCLUDE"
CFLAGS+=" -I$LIBGCC_BASE/include"
CFLAGS+=" -I$LIBGCC_BASE/include/c++/11.x/"
CFLAGS+=" -I$LIBGCC_BASE/include/c++/11.x/x86_64-facebook-linux/"
CFLAGS+=" -I$LIBGCC_BASE/include/c++/11.x/backward"
CFLAGS+=" -isystem $GLIBC_INCLUDE -I$GLIBC_INCLUDE"
JEMALLOC=1 JEMALLOC=1
else else
# clang # clang

46
cache/cache_test.cc vendored
View File

@ -14,7 +14,9 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "cache/clock_cache.h" #include "cache/clock_cache.h"
#include "cache/fast_lru_cache.h"
#include "cache/lru_cache.h" #include "cache/lru_cache.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
#include "util/coding.h" #include "util/coding.h"
@ -39,6 +41,7 @@ static int DecodeValue(void* v) {
const std::string kLRU = "lru"; const std::string kLRU = "lru";
const std::string kClock = "clock"; const std::string kClock = "clock";
const std::string kFast = "fast";
void dumbDeleter(const Slice& /*key*/, void* /*value*/) {} void dumbDeleter(const Slice& /*key*/, void* /*value*/) {}
@ -83,6 +86,9 @@ class CacheTest : public testing::TestWithParam<std::string> {
if (type == kClock) { if (type == kClock) {
return NewClockCache(capacity); return NewClockCache(capacity);
} }
if (type == kFast) {
return NewFastLRUCache(capacity);
}
return nullptr; return nullptr;
} }
@ -103,6 +109,10 @@ class CacheTest : public testing::TestWithParam<std::string> {
return NewClockCache(capacity, num_shard_bits, strict_capacity_limit, return NewClockCache(capacity, num_shard_bits, strict_capacity_limit,
charge_policy); charge_policy);
} }
if (type == kFast) {
return NewFastLRUCache(capacity, num_shard_bits, strict_capacity_limit,
charge_policy);
}
return nullptr; return nullptr;
} }
@ -183,7 +193,7 @@ TEST_P(CacheTest, UsageTest) {
// make sure the cache will be overloaded // make sure the cache will be overloaded
for (uint64_t i = 1; i < kCapacity; ++i) { for (uint64_t i = 1; i < kCapacity; ++i) {
auto key = ToString(i); auto key = std::to_string(i);
ASSERT_OK(cache->Insert(key, reinterpret_cast<void*>(value), key.size() + 5, ASSERT_OK(cache->Insert(key, reinterpret_cast<void*>(value), key.size() + 5,
dumbDeleter)); dumbDeleter));
ASSERT_OK(precise_cache->Insert(key, reinterpret_cast<void*>(value), ASSERT_OK(precise_cache->Insert(key, reinterpret_cast<void*>(value),
@ -255,7 +265,7 @@ TEST_P(CacheTest, PinnedUsageTest) {
// check that overloading the cache does not change the pinned usage // check that overloading the cache does not change the pinned usage
for (uint64_t i = 1; i < 2 * kCapacity; ++i) { for (uint64_t i = 1; i < 2 * kCapacity; ++i) {
auto key = ToString(i); auto key = std::to_string(i);
ASSERT_OK(cache->Insert(key, reinterpret_cast<void*>(value), key.size() + 5, ASSERT_OK(cache->Insert(key, reinterpret_cast<void*>(value), key.size() + 5,
dumbDeleter)); dumbDeleter));
ASSERT_OK(precise_cache->Insert(key, reinterpret_cast<void*>(value), ASSERT_OK(precise_cache->Insert(key, reinterpret_cast<void*>(value),
@ -575,7 +585,7 @@ TEST_P(CacheTest, SetCapacity) {
std::vector<Cache::Handle*> handles(10); std::vector<Cache::Handle*> handles(10);
// Insert 5 entries, but not releasing. // Insert 5 entries, but not releasing.
for (size_t i = 0; i < 5; i++) { for (size_t i = 0; i < 5; i++) {
std::string key = ToString(i+1); std::string key = std::to_string(i + 1);
Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]); Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
} }
@ -590,7 +600,7 @@ TEST_P(CacheTest, SetCapacity) {
// then decrease capacity to 7, final capacity should be 7 // then decrease capacity to 7, final capacity should be 7
// and usage should be 7 // and usage should be 7
for (size_t i = 5; i < 10; i++) { for (size_t i = 5; i < 10; i++) {
std::string key = ToString(i+1); std::string key = std::to_string(i + 1);
Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]); Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
} }
@ -621,7 +631,7 @@ TEST_P(LRUCacheTest, SetStrictCapacityLimit) {
std::vector<Cache::Handle*> handles(10); std::vector<Cache::Handle*> handles(10);
Status s; Status s;
for (size_t i = 0; i < 10; i++) { for (size_t i = 0; i < 10; i++) {
std::string key = ToString(i + 1); std::string key = std::to_string(i + 1);
s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]); s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]);
ASSERT_OK(s); ASSERT_OK(s);
ASSERT_NE(nullptr, handles[i]); ASSERT_NE(nullptr, handles[i]);
@ -645,7 +655,7 @@ TEST_P(LRUCacheTest, SetStrictCapacityLimit) {
// test3: init with flag being true. // test3: init with flag being true.
std::shared_ptr<Cache> cache2 = NewCache(5, 0, true); std::shared_ptr<Cache> cache2 = NewCache(5, 0, true);
for (size_t i = 0; i < 5; i++) { for (size_t i = 0; i < 5; i++) {
std::string key = ToString(i + 1); std::string key = std::to_string(i + 1);
s = cache2->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]); s = cache2->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]);
ASSERT_OK(s); ASSERT_OK(s);
ASSERT_NE(nullptr, handles[i]); ASSERT_NE(nullptr, handles[i]);
@ -675,14 +685,14 @@ TEST_P(CacheTest, OverCapacity) {
// Insert n+1 entries, but not releasing. // Insert n+1 entries, but not releasing.
for (size_t i = 0; i < n + 1; i++) { for (size_t i = 0; i < n + 1; i++) {
std::string key = ToString(i+1); std::string key = std::to_string(i + 1);
Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]); Status s = cache->Insert(key, new Value(i + 1), 1, &deleter, &handles[i]);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
} }
// Guess what's in the cache now? // Guess what's in the cache now?
for (size_t i = 0; i < n + 1; i++) { for (size_t i = 0; i < n + 1; i++) {
std::string key = ToString(i+1); std::string key = std::to_string(i + 1);
auto h = cache->Lookup(key); auto h = cache->Lookup(key);
ASSERT_TRUE(h != nullptr); ASSERT_TRUE(h != nullptr);
if (h) cache->Release(h); if (h) cache->Release(h);
@ -703,7 +713,7 @@ TEST_P(CacheTest, OverCapacity) {
// This is consistent with the LRU policy since the element 0 // This is consistent with the LRU policy since the element 0
// was released first // was released first
for (size_t i = 0; i < n + 1; i++) { for (size_t i = 0; i < n + 1; i++) {
std::string key = ToString(i+1); std::string key = std::to_string(i + 1);
auto h = cache->Lookup(key); auto h = cache->Lookup(key);
if (h) { if (h) {
ASSERT_NE(i, 0U); ASSERT_NE(i, 0U);
@ -744,9 +754,9 @@ TEST_P(CacheTest, ApplyToAllEntriesTest) {
std::vector<std::string> callback_state; std::vector<std::string> callback_state;
const auto callback = [&](const Slice& key, void* value, size_t charge, const auto callback = [&](const Slice& key, void* value, size_t charge,
Cache::DeleterFn deleter) { Cache::DeleterFn deleter) {
callback_state.push_back(ToString(DecodeKey(key)) + "," + callback_state.push_back(std::to_string(DecodeKey(key)) + "," +
ToString(DecodeValue(value)) + "," + std::to_string(DecodeValue(value)) + "," +
ToString(charge)); std::to_string(charge));
assert(deleter == &CacheTest::Deleter); assert(deleter == &CacheTest::Deleter);
}; };
@ -755,8 +765,8 @@ TEST_P(CacheTest, ApplyToAllEntriesTest) {
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
Insert(i, i * 2, i + 1); Insert(i, i * 2, i + 1);
inserted.push_back(ToString(i) + "," + ToString(i * 2) + "," + inserted.push_back(std::to_string(i) + "," + std::to_string(i * 2) + "," +
ToString(i + 1)); std::to_string(i + 1));
} }
cache_->ApplyToAllEntries(callback, /*opts*/ {}); cache_->ApplyToAllEntries(callback, /*opts*/ {});
@ -838,11 +848,13 @@ TEST_P(CacheTest, GetChargeAndDeleter) {
std::shared_ptr<Cache> (*new_clock_cache_func)( std::shared_ptr<Cache> (*new_clock_cache_func)(
size_t, int, bool, CacheMetadataChargePolicy) = NewClockCache; size_t, int, bool, CacheMetadataChargePolicy) = NewClockCache;
INSTANTIATE_TEST_CASE_P(CacheTestInstance, CacheTest, INSTANTIATE_TEST_CASE_P(CacheTestInstance, CacheTest,
testing::Values(kLRU, kClock)); testing::Values(kLRU, kClock, kFast));
#else #else
INSTANTIATE_TEST_CASE_P(CacheTestInstance, CacheTest, testing::Values(kLRU)); INSTANTIATE_TEST_CASE_P(CacheTestInstance, CacheTest,
testing::Values(kLRU, kFast));
#endif // SUPPORT_CLOCK_CACHE #endif // SUPPORT_CLOCK_CACHE
INSTANTIATE_TEST_CASE_P(CacheTestInstance, LRUCacheTest, testing::Values(kLRU)); INSTANTIATE_TEST_CASE_P(CacheTestInstance, LRUCacheTest,
testing::Values(kLRU, kFast));
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

511
cache/fast_lru_cache.cc vendored Normal file
View File

@ -0,0 +1,511 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "cache/fast_lru_cache.h"
#include <cassert>
#include <cstdint>
#include <cstdio>
#include "monitoring/perf_context_imp.h"
#include "monitoring/statistics.h"
#include "port/lang.h"
#include "util/mutexlock.h"
namespace ROCKSDB_NAMESPACE {
namespace fast_lru_cache {
LRUHandleTable::LRUHandleTable(int max_upper_hash_bits)
: length_bits_(/* historical starting size*/ 4),
list_(new LRUHandle* [size_t{1} << length_bits_] {}),
elems_(0),
max_length_bits_(max_upper_hash_bits) {}
LRUHandleTable::~LRUHandleTable() {
ApplyToEntriesRange(
[](LRUHandle* h) {
if (!h->HasRefs()) {
h->Free();
}
},
0, uint32_t{1} << length_bits_);
}
LRUHandle* LRUHandleTable::Lookup(const Slice& key, uint32_t hash) {
return *FindPointer(key, hash);
}
LRUHandle* LRUHandleTable::Insert(LRUHandle* h) {
LRUHandle** ptr = FindPointer(h->key(), h->hash);
LRUHandle* old = *ptr;
h->next_hash = (old == nullptr ? nullptr : old->next_hash);
*ptr = h;
if (old == nullptr) {
++elems_;
if ((elems_ >> length_bits_) > 0) { // elems_ >= length
// Since each cache entry is fairly large, we aim for a small
// average linked list length (<= 1).
Resize();
}
}
return old;
}
LRUHandle* LRUHandleTable::Remove(const Slice& key, uint32_t hash) {
LRUHandle** ptr = FindPointer(key, hash);
LRUHandle* result = *ptr;
if (result != nullptr) {
*ptr = result->next_hash;
--elems_;
}
return result;
}
LRUHandle** LRUHandleTable::FindPointer(const Slice& key, uint32_t hash) {
LRUHandle** ptr = &list_[hash >> (32 - length_bits_)];
while (*ptr != nullptr && ((*ptr)->hash != hash || key != (*ptr)->key())) {
ptr = &(*ptr)->next_hash;
}
return ptr;
}
void LRUHandleTable::Resize() {
if (length_bits_ >= max_length_bits_) {
// Due to reaching limit of hash information, if we made the table bigger,
// we would allocate more addresses but only the same number would be used.
return;
}
if (length_bits_ >= 31) {
// Avoid undefined behavior shifting uint32_t by 32.
return;
}
uint32_t old_length = uint32_t{1} << length_bits_;
int new_length_bits = length_bits_ + 1;
std::unique_ptr<LRUHandle* []> new_list {
new LRUHandle* [size_t{1} << new_length_bits] {}
};
uint32_t count = 0;
for (uint32_t i = 0; i < old_length; i++) {
LRUHandle* h = list_[i];
while (h != nullptr) {
LRUHandle* next = h->next_hash;
uint32_t hash = h->hash;
LRUHandle** ptr = &new_list[hash >> (32 - new_length_bits)];
h->next_hash = *ptr;
*ptr = h;
h = next;
count++;
}
}
assert(elems_ == count);
list_ = std::move(new_list);
length_bits_ = new_length_bits;
}
LRUCacheShard::LRUCacheShard(size_t capacity, bool strict_capacity_limit,
CacheMetadataChargePolicy metadata_charge_policy,
int max_upper_hash_bits)
: capacity_(0),
strict_capacity_limit_(strict_capacity_limit),
table_(max_upper_hash_bits),
usage_(0),
lru_usage_(0) {
set_metadata_charge_policy(metadata_charge_policy);
// Make empty circular linked list.
lru_.next = &lru_;
lru_.prev = &lru_;
lru_low_pri_ = &lru_;
SetCapacity(capacity);
}
void LRUCacheShard::EraseUnRefEntries() {
autovector<LRUHandle*> last_reference_list;
{
MutexLock l(&mutex_);
while (lru_.next != &lru_) {
LRUHandle* old = lru_.next;
// LRU list contains only elements which can be evicted.
assert(old->InCache() && !old->HasRefs());
LRU_Remove(old);
table_.Remove(old->key(), old->hash);
old->SetInCache(false);
size_t total_charge = old->CalcTotalCharge(metadata_charge_policy_);
assert(usage_ >= total_charge);
usage_ -= total_charge;
last_reference_list.push_back(old);
}
}
// Free the entries here outside of mutex for performance reasons.
for (auto entry : last_reference_list) {
entry->Free();
}
}
void LRUCacheShard::ApplyToSomeEntries(
const std::function<void(const Slice& key, void* value, size_t charge,
DeleterFn deleter)>& callback,
uint32_t average_entries_per_lock, uint32_t* state) {
// The state is essentially going to be the starting hash, which works
// nicely even if we resize between calls because we use upper-most
// hash bits for table indexes.
MutexLock l(&mutex_);
uint32_t length_bits = table_.GetLengthBits();
uint32_t length = uint32_t{1} << length_bits;
assert(average_entries_per_lock > 0);
// Assuming we are called with same average_entries_per_lock repeatedly,
// this simplifies some logic (index_end will not overflow).
assert(average_entries_per_lock < length || *state == 0);
uint32_t index_begin = *state >> (32 - length_bits);
uint32_t index_end = index_begin + average_entries_per_lock;
if (index_end >= length) {
// Going to end
index_end = length;
*state = UINT32_MAX;
} else {
*state = index_end << (32 - length_bits);
}
table_.ApplyToEntriesRange(
[callback](LRUHandle* h) {
callback(h->key(), h->value, h->charge, h->deleter);
},
index_begin, index_end);
}
void LRUCacheShard::LRU_Remove(LRUHandle* e) {
assert(e->next != nullptr);
assert(e->prev != nullptr);
e->next->prev = e->prev;
e->prev->next = e->next;
e->prev = e->next = nullptr;
size_t total_charge = e->CalcTotalCharge(metadata_charge_policy_);
assert(lru_usage_ >= total_charge);
lru_usage_ -= total_charge;
}
void LRUCacheShard::LRU_Insert(LRUHandle* e) {
assert(e->next == nullptr);
assert(e->prev == nullptr);
size_t total_charge = e->CalcTotalCharge(metadata_charge_policy_);
// Inset "e" to head of LRU list.
e->next = &lru_;
e->prev = lru_.prev;
e->prev->next = e;
e->next->prev = e;
lru_usage_ += total_charge;
}
void LRUCacheShard::EvictFromLRU(size_t charge,
autovector<LRUHandle*>* deleted) {
while ((usage_ + charge) > capacity_ && lru_.next != &lru_) {
LRUHandle* old = lru_.next;
// LRU list contains only elements which can be evicted.
assert(old->InCache() && !old->HasRefs());
LRU_Remove(old);
table_.Remove(old->key(), old->hash);
old->SetInCache(false);
size_t old_total_charge = old->CalcTotalCharge(metadata_charge_policy_);
assert(usage_ >= old_total_charge);
usage_ -= old_total_charge;
deleted->push_back(old);
}
}
void LRUCacheShard::SetCapacity(size_t capacity) {
autovector<LRUHandle*> last_reference_list;
{
MutexLock l(&mutex_);
capacity_ = capacity;
EvictFromLRU(0, &last_reference_list);
}
// Free the entries here outside of mutex for performance reasons.
for (auto entry : last_reference_list) {
entry->Free();
}
}
void LRUCacheShard::SetStrictCapacityLimit(bool strict_capacity_limit) {
MutexLock l(&mutex_);
strict_capacity_limit_ = strict_capacity_limit;
}
Status LRUCacheShard::InsertItem(LRUHandle* e, Cache::Handle** handle,
bool free_handle_on_fail) {
Status s = Status::OK();
autovector<LRUHandle*> last_reference_list;
size_t total_charge = e->CalcTotalCharge(metadata_charge_policy_);
{
MutexLock l(&mutex_);
// Free the space following strict LRU policy until enough space
// is freed or the lru list is empty.
EvictFromLRU(total_charge, &last_reference_list);
if ((usage_ + total_charge) > capacity_ &&
(strict_capacity_limit_ || handle == nullptr)) {
e->SetInCache(false);
if (handle == nullptr) {
// Don't insert the entry but still return ok, as if the entry inserted
// into cache and get evicted immediately.
last_reference_list.push_back(e);
} else {
if (free_handle_on_fail) {
delete[] reinterpret_cast<char*>(e);
*handle = nullptr;
}
s = Status::Incomplete("Insert failed due to LRU cache being full.");
}
} else {
// Insert into the cache. Note that the cache might get larger than its
// capacity if not enough space was freed up.
LRUHandle* old = table_.Insert(e);
usage_ += total_charge;
if (old != nullptr) {
s = Status::OkOverwritten();
assert(old->InCache());
old->SetInCache(false);
if (!old->HasRefs()) {
// old is on LRU because it's in cache and its reference count is 0.
LRU_Remove(old);
size_t old_total_charge =
old->CalcTotalCharge(metadata_charge_policy_);
assert(usage_ >= old_total_charge);
usage_ -= old_total_charge;
last_reference_list.push_back(old);
}
}
if (handle == nullptr) {
LRU_Insert(e);
} else {
// If caller already holds a ref, no need to take one here.
if (!e->HasRefs()) {
e->Ref();
}
*handle = reinterpret_cast<Cache::Handle*>(e);
}
}
}
// Free the entries here outside of mutex for performance reasons.
for (auto entry : last_reference_list) {
entry->Free();
}
return s;
}
Cache::Handle* LRUCacheShard::Lookup(const Slice& key, uint32_t hash) {
LRUHandle* e = nullptr;
{
MutexLock l(&mutex_);
e = table_.Lookup(key, hash);
if (e != nullptr) {
assert(e->InCache());
if (!e->HasRefs()) {
// The entry is in LRU since it's in hash and has no external references
LRU_Remove(e);
}
e->Ref();
}
}
return reinterpret_cast<Cache::Handle*>(e);
}
bool LRUCacheShard::Ref(Cache::Handle* h) {
LRUHandle* e = reinterpret_cast<LRUHandle*>(h);
MutexLock l(&mutex_);
// To create another reference - entry must be already externally referenced.
assert(e->HasRefs());
e->Ref();
return true;
}
bool LRUCacheShard::Release(Cache::Handle* handle, bool erase_if_last_ref) {
if (handle == nullptr) {
return false;
}
LRUHandle* e = reinterpret_cast<LRUHandle*>(handle);
bool last_reference = false;
{
MutexLock l(&mutex_);
last_reference = e->Unref();
if (last_reference && e->InCache()) {
// The item is still in cache, and nobody else holds a reference to it.
if (usage_ > capacity_ || erase_if_last_ref) {
// The LRU list must be empty since the cache is full.
assert(lru_.next == &lru_ || erase_if_last_ref);
// Take this opportunity and remove the item.
table_.Remove(e->key(), e->hash);
e->SetInCache(false);
} else {
// Put the item back on the LRU list, and don't free it.
LRU_Insert(e);
last_reference = false;
}
}
// If it was the last reference, then decrement the cache usage.
if (last_reference) {
size_t total_charge = e->CalcTotalCharge(metadata_charge_policy_);
assert(usage_ >= total_charge);
usage_ -= total_charge;
}
}
// Free the entry here outside of mutex for performance reasons.
if (last_reference) {
e->Free();
}
return last_reference;
}
Status LRUCacheShard::Insert(const Slice& key, uint32_t hash, void* value,
size_t charge, Cache::DeleterFn deleter,
Cache::Handle** handle,
Cache::Priority /*priority*/) {
// Allocate the memory here outside of the mutex.
// If the cache is full, we'll have to release it.
// It shouldn't happen very often though.
LRUHandle* e = reinterpret_cast<LRUHandle*>(
new char[sizeof(LRUHandle) - 1 + key.size()]);
e->value = value;
e->flags = 0;
e->deleter = deleter;
e->charge = charge;
e->key_length = key.size();
e->hash = hash;
e->refs = 0;
e->next = e->prev = nullptr;
e->SetInCache(true);
memcpy(e->key_data, key.data(), key.size());
return InsertItem(e, handle, /* free_handle_on_fail */ true);
}
void LRUCacheShard::Erase(const Slice& key, uint32_t hash) {
LRUHandle* e;
bool last_reference = false;
{
MutexLock l(&mutex_);
e = table_.Remove(key, hash);
if (e != nullptr) {
assert(e->InCache());
e->SetInCache(false);
if (!e->HasRefs()) {
// The entry is in LRU since it's in hash and has no external references
LRU_Remove(e);
size_t total_charge = e->CalcTotalCharge(metadata_charge_policy_);
assert(usage_ >= total_charge);
usage_ -= total_charge;
last_reference = true;
}
}
}
// Free the entry here outside of mutex for performance reasons.
// last_reference will only be true if e != nullptr.
if (last_reference) {
e->Free();
}
}
size_t LRUCacheShard::GetUsage() const {
MutexLock l(&mutex_);
return usage_;
}
size_t LRUCacheShard::GetPinnedUsage() const {
MutexLock l(&mutex_);
assert(usage_ >= lru_usage_);
return usage_ - lru_usage_;
}
std::string LRUCacheShard::GetPrintableOptions() const { return std::string{}; }
LRUCache::LRUCache(size_t capacity, int num_shard_bits,
bool strict_capacity_limit,
CacheMetadataChargePolicy metadata_charge_policy)
: ShardedCache(capacity, num_shard_bits, strict_capacity_limit) {
num_shards_ = 1 << num_shard_bits;
shards_ = reinterpret_cast<LRUCacheShard*>(
port::cacheline_aligned_alloc(sizeof(LRUCacheShard) * num_shards_));
size_t per_shard = (capacity + (num_shards_ - 1)) / num_shards_;
for (int i = 0; i < num_shards_; i++) {
new (&shards_[i])
LRUCacheShard(per_shard, strict_capacity_limit, metadata_charge_policy,
/* max_upper_hash_bits */ 32 - num_shard_bits);
}
}
LRUCache::~LRUCache() {
if (shards_ != nullptr) {
assert(num_shards_ > 0);
for (int i = 0; i < num_shards_; i++) {
shards_[i].~LRUCacheShard();
}
port::cacheline_aligned_free(shards_);
}
}
CacheShard* LRUCache::GetShard(uint32_t shard) {
return reinterpret_cast<CacheShard*>(&shards_[shard]);
}
const CacheShard* LRUCache::GetShard(uint32_t shard) const {
return reinterpret_cast<CacheShard*>(&shards_[shard]);
}
void* LRUCache::Value(Handle* handle) {
return reinterpret_cast<const LRUHandle*>(handle)->value;
}
size_t LRUCache::GetCharge(Handle* handle) const {
return reinterpret_cast<const LRUHandle*>(handle)->charge;
}
Cache::DeleterFn LRUCache::GetDeleter(Handle* handle) const {
auto h = reinterpret_cast<const LRUHandle*>(handle);
return h->deleter;
}
uint32_t LRUCache::GetHash(Handle* handle) const {
return reinterpret_cast<const LRUHandle*>(handle)->hash;
}
void LRUCache::DisownData() {
// Leak data only if that won't generate an ASAN/valgrind warning.
if (!kMustFreeHeapAllocations) {
shards_ = nullptr;
num_shards_ = 0;
}
}
} // namespace fast_lru_cache
std::shared_ptr<Cache> NewFastLRUCache(
size_t capacity, int num_shard_bits, bool strict_capacity_limit,
CacheMetadataChargePolicy metadata_charge_policy) {
if (num_shard_bits >= 20) {
return nullptr; // The cache cannot be sharded into too many fine pieces.
}
if (num_shard_bits < 0) {
num_shard_bits = GetDefaultCacheShardBits(capacity);
}
return std::make_shared<fast_lru_cache::LRUCache>(
capacity, num_shard_bits, strict_capacity_limit, metadata_charge_policy);
}
} // namespace ROCKSDB_NAMESPACE

299
cache/fast_lru_cache.h vendored Normal file
View File

@ -0,0 +1,299 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#pragma once
#include <memory>
#include <string>
#include "cache/sharded_cache.h"
#include "port/lang.h"
#include "port/malloc.h"
#include "port/port.h"
#include "rocksdb/secondary_cache.h"
#include "util/autovector.h"
namespace ROCKSDB_NAMESPACE {
namespace fast_lru_cache {
// An experimental (under development!) alternative to LRUCache
struct LRUHandle {
void* value;
Cache::DeleterFn deleter;
LRUHandle* next_hash;
LRUHandle* next;
LRUHandle* prev;
size_t charge; // TODO(opt): Only allow uint32_t?
size_t key_length;
// The hash of key(). Used for fast sharding and comparisons.
uint32_t hash;
// The number of external refs to this entry. The cache itself is not counted.
uint32_t refs;
enum Flags : uint8_t {
// Whether this entry is referenced by the hash table.
IN_CACHE = (1 << 0),
};
uint8_t flags;
// Beginning of the key (MUST BE THE LAST FIELD IN THIS STRUCT!)
char key_data[1];
Slice key() const { return Slice(key_data, key_length); }
// Increase the reference count by 1.
void Ref() { refs++; }
// Just reduce the reference count by 1. Return true if it was last reference.
bool Unref() {
assert(refs > 0);
refs--;
return refs == 0;
}
// Return true if there are external refs, false otherwise.
bool HasRefs() const { return refs > 0; }
bool InCache() const { return flags & IN_CACHE; }
void SetInCache(bool in_cache) {
if (in_cache) {
flags |= IN_CACHE;
} else {
flags &= ~IN_CACHE;
}
}
void Free() {
assert(refs == 0);
if (deleter) {
(*deleter)(key(), value);
}
delete[] reinterpret_cast<char*>(this);
}
// Calculate the memory usage by metadata.
inline size_t CalcTotalCharge(
CacheMetadataChargePolicy metadata_charge_policy) {
size_t meta_charge = 0;
if (metadata_charge_policy == kFullChargeCacheMetadata) {
#ifdef ROCKSDB_MALLOC_USABLE_SIZE
meta_charge += malloc_usable_size(static_cast<void*>(this));
#else
// This is the size that is used when a new handle is created.
meta_charge += sizeof(LRUHandle) - 1 + key_length;
#endif
}
return charge + meta_charge;
}
};
// We provide our own simple hash table since it removes a whole bunch
// of porting hacks and is also faster than some of the built-in hash
// table implementations in some of the compiler/runtime combinations
// we have tested. E.g., readrandom speeds up by ~5% over the g++
// 4.4.3's builtin hashtable.
class LRUHandleTable {
public:
// If the table uses more hash bits than `max_upper_hash_bits`,
// it will eat into the bits used for sharding, which are constant
// for a given LRUHandleTable.
explicit LRUHandleTable(int max_upper_hash_bits);
~LRUHandleTable();
LRUHandle* Lookup(const Slice& key, uint32_t hash);
LRUHandle* Insert(LRUHandle* h);
LRUHandle* Remove(const Slice& key, uint32_t hash);
template <typename T>
void ApplyToEntriesRange(T func, uint32_t index_begin, uint32_t index_end) {
for (uint32_t i = index_begin; i < index_end; i++) {
LRUHandle* h = list_[i];
while (h != nullptr) {
auto n = h->next_hash;
assert(h->InCache());
func(h);
h = n;
}
}
}
int GetLengthBits() const { return length_bits_; }
private:
// Return a pointer to slot that points to a cache entry that
// matches key/hash. If there is no such cache entry, return a
// pointer to the trailing slot in the corresponding linked list.
LRUHandle** FindPointer(const Slice& key, uint32_t hash);
void Resize();
// Number of hash bits (upper because lower bits used for sharding)
// used for table index. Length == 1 << length_bits_
int length_bits_;
// The table consists of an array of buckets where each bucket is
// a linked list of cache entries that hash into the bucket.
std::unique_ptr<LRUHandle*[]> list_;
// Number of elements currently in the table.
uint32_t elems_;
// Set from max_upper_hash_bits (see constructor).
const int max_length_bits_;
};
// A single shard of sharded cache.
class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard final : public CacheShard {
public:
LRUCacheShard(size_t capacity, bool strict_capacity_limit,
CacheMetadataChargePolicy metadata_charge_policy,
int max_upper_hash_bits);
~LRUCacheShard() override = default;
// Separate from constructor so caller can easily make an array of LRUCache
// if current usage is more than new capacity, the function will attempt to
// free the needed space.
void SetCapacity(size_t capacity) override;
// Set the flag to reject insertion if cache if full.
void SetStrictCapacityLimit(bool strict_capacity_limit) override;
// Like Cache methods, but with an extra "hash" parameter.
Status Insert(const Slice& key, uint32_t hash, void* value, size_t charge,
Cache::DeleterFn deleter, Cache::Handle** handle,
Cache::Priority priority) override;
Status Insert(const Slice& key, uint32_t hash, void* value,
const Cache::CacheItemHelper* helper, size_t charge,
Cache::Handle** handle, Cache::Priority priority) override {
return Insert(key, hash, value, charge, helper->del_cb, handle, priority);
}
Cache::Handle* Lookup(const Slice& key, uint32_t hash,
const Cache::CacheItemHelper* /*helper*/,
const Cache::CreateCallback& /*create_cb*/,
Cache::Priority /*priority*/, bool /*wait*/,
Statistics* /*stats*/) override {
return Lookup(key, hash);
}
Cache::Handle* Lookup(const Slice& key, uint32_t hash) override;
bool Release(Cache::Handle* handle, bool /*useful*/,
bool erase_if_last_ref) override {
return Release(handle, erase_if_last_ref);
}
bool IsReady(Cache::Handle* /*handle*/) override { return true; }
void Wait(Cache::Handle* /*handle*/) override {}
bool Ref(Cache::Handle* handle) override;
bool Release(Cache::Handle* handle, bool erase_if_last_ref = false) override;
void Erase(const Slice& key, uint32_t hash) override;
size_t GetUsage() const override;
size_t GetPinnedUsage() const override;
void ApplyToSomeEntries(
const std::function<void(const Slice& key, void* value, size_t charge,
DeleterFn deleter)>& callback,
uint32_t average_entries_per_lock, uint32_t* state) override;
void EraseUnRefEntries() override;
std::string GetPrintableOptions() const override;
private:
friend class LRUCache;
// Insert an item into the hash table and, if handle is null, insert into
// the LRU list. Older items are evicted as necessary. If the cache is full
// and free_handle_on_fail is true, the item is deleted and handle is set to
// nullptr.
Status InsertItem(LRUHandle* item, Cache::Handle** handle,
bool free_handle_on_fail);
void LRU_Remove(LRUHandle* e);
void LRU_Insert(LRUHandle* e);
// Free some space following strict LRU policy until enough space
// to hold (usage_ + charge) is freed or the lru list is empty
// This function is not thread safe - it needs to be executed while
// holding the mutex_.
void EvictFromLRU(size_t charge, autovector<LRUHandle*>* deleted);
// Initialized before use.
size_t capacity_;
// Whether to reject insertion if cache reaches its full capacity.
bool strict_capacity_limit_;
// Dummy head of LRU list.
// lru.prev is newest entry, lru.next is oldest entry.
// LRU contains items which can be evicted, ie reference only by cache
LRUHandle lru_;
// Pointer to head of low-pri pool in LRU list.
LRUHandle* lru_low_pri_;
// ------------^^^^^^^^^^^^^-----------
// Not frequently modified data members
// ------------------------------------
//
// We separate data members that are updated frequently from the ones that
// are not frequently updated so that they don't share the same cache line
// which will lead into false cache sharing
//
// ------------------------------------
// Frequently modified data members
// ------------vvvvvvvvvvvvv-----------
LRUHandleTable table_;
// Memory size for entries residing in the cache.
size_t usage_;
// Memory size for entries residing only in the LRU list.
size_t lru_usage_;
// mutex_ protects the following state.
// We don't count mutex_ as the cache's internal state so semantically we
// don't mind mutex_ invoking the non-const actions.
mutable port::Mutex mutex_;
};
class LRUCache
#ifdef NDEBUG
final
#endif
: public ShardedCache {
public:
LRUCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit,
CacheMetadataChargePolicy metadata_charge_policy =
kDontChargeCacheMetadata);
~LRUCache() override;
const char* Name() const override { return "LRUCache"; }
CacheShard* GetShard(uint32_t shard) override;
const CacheShard* GetShard(uint32_t shard) const override;
void* Value(Handle* handle) override;
size_t GetCharge(Handle* handle) const override;
uint32_t GetHash(Handle* handle) const override;
DeleterFn GetDeleter(Handle* handle) const override;
void DisownData() override;
private:
LRUCacheShard* shards_ = nullptr;
int num_shards_ = 0;
};
} // namespace fast_lru_cache
std::shared_ptr<Cache> NewFastLRUCache(
size_t capacity, int num_shard_bits = -1,
bool strict_capacity_limit = false,
CacheMetadataChargePolicy metadata_charge_policy =
kDefaultCacheMetadataChargePolicy);
} // namespace ROCKSDB_NAMESPACE

3
cache/lru_cache.cc vendored
View File

@ -19,6 +19,7 @@
#include "util/mutexlock.h" #include "util/mutexlock.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
namespace lru_cache {
LRUHandleTable::LRUHandleTable(int max_upper_hash_bits) LRUHandleTable::LRUHandleTable(int max_upper_hash_bits)
: length_bits_(/* historical starting size*/ 4), : length_bits_(/* historical starting size*/ 4),
@ -759,6 +760,8 @@ void LRUCache::WaitAll(std::vector<Handle*>& handles) {
} }
} }
} // namespace lru_cache
std::shared_ptr<Cache> NewLRUCache( std::shared_ptr<Cache> NewLRUCache(
size_t capacity, int num_shard_bits, bool strict_capacity_limit, size_t capacity, int num_shard_bits, bool strict_capacity_limit,
double high_pri_pool_ratio, double high_pri_pool_ratio,

7
cache/lru_cache.h vendored
View File

@ -19,6 +19,7 @@
#include "util/autovector.h" #include "util/autovector.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
namespace lru_cache {
// LRU cache implementation. This class is not thread-safe. // LRU cache implementation. This class is not thread-safe.
@ -479,4 +480,10 @@ class LRUCache
std::shared_ptr<SecondaryCache> secondary_cache_; std::shared_ptr<SecondaryCache> secondary_cache_;
}; };
} // namespace lru_cache
using LRUCache = lru_cache::LRUCache;
using LRUHandle = lru_cache::LRUHandle;
using LRUCacheShard = lru_cache::LRUCacheShard;
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

30
common.mk Normal file
View File

@ -0,0 +1,30 @@
ifndef PYTHON
# Default to python3. Some distros like CentOS 8 do not have `python`.
ifeq ($(origin PYTHON), undefined)
PYTHON := $(shell which python3 || which python || echo python3)
endif
export PYTHON
endif
# To setup tmp directory, first recognize some old variables for setting
# test tmp directory or base tmp directory. TEST_TMPDIR is usually read
# by RocksDB tools though Env/FileSystem::GetTestDirectory.
ifeq ($(TEST_TMPDIR),)
TEST_TMPDIR := $(TMPD)
endif
ifeq ($(TEST_TMPDIR),)
ifeq ($(BASE_TMPDIR),)
BASE_TMPDIR :=$(TMPDIR)
endif
ifeq ($(BASE_TMPDIR),)
BASE_TMPDIR :=/tmp
endif
# Use /dev/shm if it has the sticky bit set (otherwise, /tmp or other
# base dir), and create a randomly-named rocksdb.XXXX directory therein.
TEST_TMPDIR := $(shell f=/dev/shm; test -k $$f || f=$(BASE_TMPDIR); \
perl -le 'use File::Temp "tempdir";' \
-e 'print tempdir("'$$f'/rocksdb.XXXX", CLEANUP => 0)')
endif
export TEST_TMPDIR

View File

@ -5,7 +5,7 @@
# build DB_STRESS_CMD so it must exist prior. # build DB_STRESS_CMD so it must exist prior.
DB_STRESS_CMD?=./db_stress DB_STRESS_CMD?=./db_stress
include python.mk include common.mk
CRASHTEST_MAKE=$(MAKE) -f crash_test.mk CRASHTEST_MAKE=$(MAKE) -f crash_test.mk
CRASHTEST_PY=$(PYTHON) -u tools/db_crashtest.py --stress_cmd=$(DB_STRESS_CMD) CRASHTEST_PY=$(PYTHON) -u tools/db_crashtest.py --stress_cmd=$(DB_STRESS_CMD)
@ -65,10 +65,10 @@ blackbox_crash_test_with_ts: $(DB_STRESS_CMD)
$(CRASHTEST_PY) --enable_ts blackbox $(CRASH_TEST_EXT_ARGS) $(CRASHTEST_PY) --enable_ts blackbox $(CRASH_TEST_EXT_ARGS)
blackbox_crash_test_with_multiops_wc_txn: $(DB_STRESS_CMD) blackbox_crash_test_with_multiops_wc_txn: $(DB_STRESS_CMD)
$(PYTHON) -u tools/db_crashtest.py --test_multiops_txn --write_policy write_committed blackbox $(CRASH_TEST_EXT_ARGS) $(CRASHTEST_PY) --test_multiops_txn --write_policy write_committed blackbox $(CRASH_TEST_EXT_ARGS)
blackbox_crash_test_with_multiops_wp_txn: $(DB_STRESS_CMD) blackbox_crash_test_with_multiops_wp_txn: $(DB_STRESS_CMD)
$(PYTHON) -u tools/db_crashtest.py --test_multiops_txn --write_policy write_prepared blackbox $(CRASH_TEST_EXT_ARGS) $(CRASHTEST_PY) --test_multiops_txn --write_policy write_prepared blackbox $(CRASH_TEST_EXT_ARGS)
ifeq ($(CRASH_TEST_KILL_ODD),) ifeq ($(CRASH_TEST_KILL_ODD),)
CRASH_TEST_KILL_ODD=888887 CRASH_TEST_KILL_ODD=888887

View File

@ -23,7 +23,7 @@ Status ArenaWrappedDBIter::GetProperty(std::string prop_name,
if (prop_name == "rocksdb.iterator.super-version-number") { if (prop_name == "rocksdb.iterator.super-version-number") {
// First try to pass the value returned from inner iterator. // First try to pass the value returned from inner iterator.
if (!db_iter_->GetProperty(prop_name, prop).ok()) { if (!db_iter_->GetProperty(prop_name, prop).ok()) {
*prop = ToString(sv_number_); *prop = std::to_string(sv_number_);
} }
return Status::OK(); return Status::OK();
} }

View File

@ -96,9 +96,9 @@ class BlobIndex {
assert(slice.size() > 0); assert(slice.size() > 0);
type_ = static_cast<Type>(*slice.data()); type_ = static_cast<Type>(*slice.data());
if (type_ >= Type::kUnknown) { if (type_ >= Type::kUnknown) {
return Status::Corruption( return Status::Corruption(kErrorMessage,
kErrorMessage, "Unknown blob index type: " +
"Unknown blob index type: " + ToString(static_cast<char>(type_))); std::to_string(static_cast<char>(type_)));
} }
slice = Slice(slice.data() + 1, slice.size() - 1); slice = Slice(slice.data() + 1, slice.size() - 1);
if (HasTTL()) { if (HasTTL()) {

View File

@ -153,11 +153,11 @@ TEST_F(DBBlobIndexTest, Write) {
key_values.reserve(num_key_values); key_values.reserve(num_key_values);
for (size_t i = 1; i <= num_key_values; ++i) { for (size_t i = 1; i <= num_key_values; ++i) {
std::string key = "key" + ToString(i); std::string key = "key" + std::to_string(i);
std::string blob_index; std::string blob_index;
BlobIndex::EncodeInlinedTTL(&blob_index, /* expiration */ 9876543210, BlobIndex::EncodeInlinedTTL(&blob_index, /* expiration */ 9876543210,
"blob" + ToString(i)); "blob" + std::to_string(i));
key_values.emplace_back(std::move(key), std::move(blob_index)); key_values.emplace_back(std::move(key), std::move(blob_index));
} }
@ -230,7 +230,7 @@ TEST_F(DBBlobIndexTest, Updated) {
DestroyAndReopen(GetTestOptions()); DestroyAndReopen(GetTestOptions());
WriteBatch batch; WriteBatch batch;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ASSERT_OK(PutBlobIndex(&batch, "key" + ToString(i), blob_index)); ASSERT_OK(PutBlobIndex(&batch, "key" + std::to_string(i), blob_index));
} }
ASSERT_OK(Write(&batch)); ASSERT_OK(Write(&batch));
// Avoid blob values from being purged. // Avoid blob values from being purged.
@ -248,7 +248,7 @@ TEST_F(DBBlobIndexTest, Updated) {
ASSERT_OK(dbfull()->DeleteRange(WriteOptions(), cfh(), "key6", "key9")); ASSERT_OK(dbfull()->DeleteRange(WriteOptions(), cfh(), "key6", "key9"));
MoveDataTo(tier); MoveDataTo(tier);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ASSERT_EQ(blob_index, GetBlobIndex("key" + ToString(i), snapshot)); ASSERT_EQ(blob_index, GetBlobIndex("key" + std::to_string(i), snapshot));
} }
ASSERT_EQ("new_value", Get("key1")); ASSERT_EQ("new_value", Get("key1"));
if (tier <= kImmutableMemtables) { if (tier <= kImmutableMemtables) {
@ -260,7 +260,7 @@ TEST_F(DBBlobIndexTest, Updated) {
ASSERT_EQ("NOT_FOUND", Get("key4")); ASSERT_EQ("NOT_FOUND", Get("key4"));
ASSERT_EQ("a,b,c", GetImpl("key5")); ASSERT_EQ("a,b,c", GetImpl("key5"));
for (int i = 6; i < 9; i++) { for (int i = 6; i < 9; i++) {
ASSERT_EQ("NOT_FOUND", Get("key" + ToString(i))); ASSERT_EQ("NOT_FOUND", Get("key" + std::to_string(i)));
} }
ASSERT_EQ(blob_index, GetBlobIndex("key9")); ASSERT_EQ(blob_index, GetBlobIndex("key9"));
dbfull()->ReleaseSnapshot(snapshot); dbfull()->ReleaseSnapshot(snapshot);
@ -301,7 +301,7 @@ TEST_F(DBBlobIndexTest, Iterate) {
}; };
auto get_value = [&](int index, int version) { auto get_value = [&](int index, int version) {
return get_key(index) + "_value" + ToString(version); return get_key(index) + "_value" + std::to_string(version);
}; };
auto check_iterator = [&](Iterator* iterator, Status::Code expected_status, auto check_iterator = [&](Iterator* iterator, Status::Code expected_status,
@ -501,7 +501,7 @@ TEST_F(DBBlobIndexTest, IntegratedBlobIterate) {
auto get_key = [](size_t index) { return ("key" + std::to_string(index)); }; auto get_key = [](size_t index) { return ("key" + std::to_string(index)); };
auto get_value = [&](size_t index, size_t version) { auto get_value = [&](size_t index, size_t version) {
return get_key(index) + "_value" + ToString(version); return get_key(index) + "_value" + std::to_string(version);
}; };
auto check_iterator = [&](Iterator* iterator, Status expected_status, auto check_iterator = [&](Iterator* iterator, Status expected_status,

View File

@ -115,6 +115,7 @@ Status BuildTable(
assert(fs); assert(fs);
TableProperties tp; TableProperties tp;
bool table_file_created = false;
if (iter->Valid() || !range_del_agg->IsEmpty()) { if (iter->Valid() || !range_del_agg->IsEmpty()) {
std::unique_ptr<CompactionFilter> compaction_filter; std::unique_ptr<CompactionFilter> compaction_filter;
if (ioptions.compaction_filter_factory != nullptr && if (ioptions.compaction_filter_factory != nullptr &&
@ -158,6 +159,8 @@ Status BuildTable(
file_checksum_func_name); file_checksum_func_name);
return s; return s;
} }
table_file_created = true;
FileTypeSet tmp_set = ioptions.checksum_handoff_file_types; FileTypeSet tmp_set = ioptions.checksum_handoff_file_types;
file->SetIOPriority(io_priority); file->SetIOPriority(io_priority);
file->SetWriteLifeTimeHint(write_hint); file->SetWriteLifeTimeHint(write_hint);
@ -193,6 +196,7 @@ Status BuildTable(
ShouldReportDetailedTime(env, ioptions.stats), ShouldReportDetailedTime(env, ioptions.stats),
true /* internal key corruption is not ok */, range_del_agg.get(), true /* internal key corruption is not ok */, range_del_agg.get(),
blob_file_builder.get(), ioptions.allow_data_in_errors, blob_file_builder.get(), ioptions.allow_data_in_errors,
ioptions.enforce_single_del_contracts,
/*compaction=*/nullptr, compaction_filter.get(), /*compaction=*/nullptr, compaction_filter.get(),
/*shutting_down=*/nullptr, /*shutting_down=*/nullptr,
/*manual_compaction_paused=*/nullptr, /*manual_compaction_paused=*/nullptr,
@ -371,15 +375,17 @@ Status BuildTable(
constexpr IODebugContext* dbg = nullptr; constexpr IODebugContext* dbg = nullptr;
Status ignored = fs->DeleteFile(fname, IOOptions(), dbg); if (table_file_created) {
ignored.PermitUncheckedError(); Status ignored = fs->DeleteFile(fname, IOOptions(), dbg);
ignored.PermitUncheckedError();
}
assert(blob_file_additions || blob_file_paths.empty()); assert(blob_file_additions || blob_file_paths.empty());
if (blob_file_additions) { if (blob_file_additions) {
for (const std::string& blob_file_path : blob_file_paths) { for (const std::string& blob_file_path : blob_file_paths) {
ignored = DeleteDBFile(&db_options, blob_file_path, dbname, Status ignored = DeleteDBFile(&db_options, blob_file_path, dbname,
/*force_bg=*/false, /*force_fg=*/false); /*force_bg=*/false, /*force_fg=*/false);
ignored.PermitUncheckedError(); ignored.PermitUncheckedError();
TEST_SYNC_POINT("BuildTable::AfterDeleteFile"); TEST_SYNC_POINT("BuildTable::AfterDeleteFile");
} }

37
db/c.cc
View File

@ -1163,6 +1163,43 @@ void rocksdb_multi_get_cf(
} }
} }
void rocksdb_batched_multi_get_cf(rocksdb_t* db,
const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family,
size_t num_keys, const char* const* keys_list,
const size_t* keys_list_sizes,
rocksdb_pinnableslice_t** values, char** errs,
const bool sorted_input) {
Slice* key_slices = new Slice[num_keys];
PinnableSlice* value_slices = new PinnableSlice[num_keys];
Status* statuses = new Status[num_keys];
for (size_t i = 0; i < num_keys; ++i) {
key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]);
}
db->rep->MultiGet(options->rep, column_family->rep, num_keys, key_slices,
value_slices, statuses, sorted_input);
for (size_t i = 0; i < num_keys; ++i) {
if (statuses[i].ok()) {
values[i] = new (rocksdb_pinnableslice_t);
values[i]->rep = std::move(value_slices[i]);
errs[i] = nullptr;
} else {
values[i] = nullptr;
if (!statuses[i].IsNotFound()) {
errs[i] = strdup(statuses[i].ToString().c_str());
} else {
errs[i] = nullptr;
}
}
}
delete[] key_slices;
delete[] value_slices;
delete[] statuses;
}
unsigned char rocksdb_key_may_exist(rocksdb_t* db, unsigned char rocksdb_key_may_exist(rocksdb_t* db,
const rocksdb_readoptions_t* options, const rocksdb_readoptions_t* options,
const char* key, size_t key_len, const char* key, size_t key_len,

View File

@ -1260,15 +1260,18 @@ int main(int argc, char** argv) {
rocksdb_writebatch_clear(wb); rocksdb_writebatch_clear(wb);
rocksdb_writebatch_put_cf(wb, handles[1], "bar", 3, "b", 1); rocksdb_writebatch_put_cf(wb, handles[1], "bar", 3, "b", 1);
rocksdb_writebatch_put_cf(wb, handles[1], "box", 3, "c", 1); rocksdb_writebatch_put_cf(wb, handles[1], "box", 3, "c", 1);
rocksdb_writebatch_put_cf(wb, handles[1], "buff", 4, "rocksdb", 7);
rocksdb_writebatch_delete_cf(wb, handles[1], "bar", 3); rocksdb_writebatch_delete_cf(wb, handles[1], "bar", 3);
rocksdb_write(db, woptions, wb, &err); rocksdb_write(db, woptions, wb, &err);
CheckNoError(err); CheckNoError(err);
CheckGetCF(db, roptions, handles[1], "baz", NULL); CheckGetCF(db, roptions, handles[1], "baz", NULL);
CheckGetCF(db, roptions, handles[1], "bar", NULL); CheckGetCF(db, roptions, handles[1], "bar", NULL);
CheckGetCF(db, roptions, handles[1], "box", "c"); CheckGetCF(db, roptions, handles[1], "box", "c");
CheckGetCF(db, roptions, handles[1], "buff", "rocksdb");
CheckPinGetCF(db, roptions, handles[1], "baz", NULL); CheckPinGetCF(db, roptions, handles[1], "baz", NULL);
CheckPinGetCF(db, roptions, handles[1], "bar", NULL); CheckPinGetCF(db, roptions, handles[1], "bar", NULL);
CheckPinGetCF(db, roptions, handles[1], "box", "c"); CheckPinGetCF(db, roptions, handles[1], "box", "c");
CheckPinGetCF(db, roptions, handles[1], "buff", "rocksdb");
rocksdb_writebatch_destroy(wb); rocksdb_writebatch_destroy(wb);
rocksdb_flush_wal(db, 1, &err); rocksdb_flush_wal(db, 1, &err);
@ -1299,6 +1302,26 @@ int main(int argc, char** argv) {
Free(&vals[i]); Free(&vals[i]);
} }
{
const char* batched_keys[4] = {"box", "buff", "barfooxx", "box"};
const size_t batched_keys_sizes[4] = {3, 4, 8, 3};
const char* expected_value[4] = {"c", "rocksdb", NULL, "c"};
char* batched_errs[4];
rocksdb_pinnableslice_t* pvals[4];
rocksdb_batched_multi_get_cf(db, roptions, handles[1], 4, batched_keys,
batched_keys_sizes, pvals, batched_errs,
false);
const char* val;
size_t val_len;
for (i = 0; i < 4; ++i) {
val = rocksdb_pinnableslice_value(pvals[i], &val_len);
CheckNoError(batched_errs[i]);
CheckEqual(expected_value[i], val, val_len);
rocksdb_pinnableslice_destroy(pvals[i]);
}
}
{ {
unsigned char value_found = 0; unsigned char value_found = 0;
@ -1330,7 +1353,7 @@ int main(int argc, char** argv) {
for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) { for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) {
i++; i++;
} }
CheckCondition(i == 3); CheckCondition(i == 4);
rocksdb_iter_get_error(iter, &err); rocksdb_iter_get_error(iter, &err);
CheckNoError(err); CheckNoError(err);
rocksdb_iter_destroy(iter); rocksdb_iter_destroy(iter);
@ -1354,7 +1377,7 @@ int main(int argc, char** argv) {
for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) { for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) {
i++; i++;
} }
CheckCondition(i == 3); CheckCondition(i == 4);
rocksdb_iter_get_error(iter, &err); rocksdb_iter_get_error(iter, &err);
CheckNoError(err); CheckNoError(err);
rocksdb_iter_destroy(iter); rocksdb_iter_destroy(iter);

View File

@ -501,7 +501,8 @@ std::vector<std::string> ColumnFamilyData::GetDbPaths() const {
return paths; return paths;
} }
const uint32_t ColumnFamilyData::kDummyColumnFamilyDataId = port::kMaxUint32; const uint32_t ColumnFamilyData::kDummyColumnFamilyDataId =
std::numeric_limits<uint32_t>::max();
ColumnFamilyData::ColumnFamilyData( ColumnFamilyData::ColumnFamilyData(
uint32_t id, const std::string& name, Version* _dummy_versions, uint32_t id, const std::string& name, Version* _dummy_versions,
@ -826,8 +827,8 @@ int GetL0ThresholdSpeedupCompaction(int level0_file_num_compaction_trigger,
// condition. // condition.
// Or twice as compaction trigger, if it is smaller. // Or twice as compaction trigger, if it is smaller.
int64_t res = std::min(twice_level0_trigger, one_fourth_trigger_slowdown); int64_t res = std::min(twice_level0_trigger, one_fourth_trigger_slowdown);
if (res >= port::kMaxInt32) { if (res >= std::numeric_limits<int32_t>::max()) {
return port::kMaxInt32; return std::numeric_limits<int32_t>::max();
} else { } else {
// res fits in int // res fits in int
return static_cast<int>(res); return static_cast<int>(res);

View File

@ -383,7 +383,7 @@ class ColumnFamilyTestBase : public testing::Test {
int NumTableFilesAtLevel(int level, int cf) { int NumTableFilesAtLevel(int level, int cf) {
return GetProperty(cf, return GetProperty(cf,
"rocksdb.num-files-at-level" + ToString(level)); "rocksdb.num-files-at-level" + std::to_string(level));
} }
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
@ -783,7 +783,7 @@ TEST_P(ColumnFamilyTest, BulkAddDrop) {
std::vector<std::string> cf_names; std::vector<std::string> cf_names;
std::vector<ColumnFamilyHandle*> cf_handles; std::vector<ColumnFamilyHandle*> cf_handles;
for (int i = 1; i <= kNumCF; i++) { for (int i = 1; i <= kNumCF; i++) {
cf_names.push_back("cf1-" + ToString(i)); cf_names.push_back("cf1-" + std::to_string(i));
} }
ASSERT_OK(db_->CreateColumnFamilies(cf_options, cf_names, &cf_handles)); ASSERT_OK(db_->CreateColumnFamilies(cf_options, cf_names, &cf_handles));
for (int i = 1; i <= kNumCF; i++) { for (int i = 1; i <= kNumCF; i++) {
@ -796,7 +796,8 @@ TEST_P(ColumnFamilyTest, BulkAddDrop) {
} }
cf_handles.clear(); cf_handles.clear();
for (int i = 1; i <= kNumCF; i++) { for (int i = 1; i <= kNumCF; i++) {
cf_descriptors.emplace_back("cf2-" + ToString(i), ColumnFamilyOptions()); cf_descriptors.emplace_back("cf2-" + std::to_string(i),
ColumnFamilyOptions());
} }
ASSERT_OK(db_->CreateColumnFamilies(cf_descriptors, &cf_handles)); ASSERT_OK(db_->CreateColumnFamilies(cf_descriptors, &cf_handles));
for (int i = 1; i <= kNumCF; i++) { for (int i = 1; i <= kNumCF; i++) {
@ -820,7 +821,7 @@ TEST_P(ColumnFamilyTest, DropTest) {
Open({"default"}); Open({"default"});
CreateColumnFamiliesAndReopen({"pikachu"}); CreateColumnFamiliesAndReopen({"pikachu"});
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
ASSERT_OK(Put(1, ToString(i), "bar" + ToString(i))); ASSERT_OK(Put(1, std::to_string(i), "bar" + std::to_string(i)));
} }
ASSERT_OK(Flush(1)); ASSERT_OK(Flush(1));
@ -1344,7 +1345,7 @@ TEST_P(ColumnFamilyTest, DifferentCompactionStyles) {
PutRandomData(1, 10, 12000); PutRandomData(1, 10, 12000);
PutRandomData(1, 1, 10); PutRandomData(1, 1, 10);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
// SETUP column family "two" -- level style with 4 levels // SETUP column family "two" -- level style with 4 levels
@ -1352,7 +1353,7 @@ TEST_P(ColumnFamilyTest, DifferentCompactionStyles) {
PutRandomData(2, 10, 12000); PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10); PutRandomData(2, 1, 10);
WaitForFlush(2); WaitForFlush(2);
AssertFilesPerLevel(ToString(i + 1), 2); AssertFilesPerLevel(std::to_string(i + 1), 2);
} }
// TRIGGER compaction "one" // TRIGGER compaction "one"
@ -1416,7 +1417,7 @@ TEST_P(ColumnFamilyTest, MultipleManualCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
bool cf_1_1 = true; bool cf_1_1 = true;
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency( ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
@ -1446,7 +1447,7 @@ TEST_P(ColumnFamilyTest, MultipleManualCompactions) {
PutRandomData(2, 10, 12000); PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10); PutRandomData(2, 1, 10);
WaitForFlush(2); WaitForFlush(2);
AssertFilesPerLevel(ToString(i + 1), 2); AssertFilesPerLevel(std::to_string(i + 1), 2);
} }
threads.emplace_back([&] { threads.emplace_back([&] {
TEST_SYNC_POINT("ColumnFamilyTest::MultiManual:1"); TEST_SYNC_POINT("ColumnFamilyTest::MultiManual:1");
@ -1533,7 +1534,7 @@ TEST_P(ColumnFamilyTest, AutomaticAndManualCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:1"); TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:1");
@ -1543,7 +1544,7 @@ TEST_P(ColumnFamilyTest, AutomaticAndManualCompactions) {
PutRandomData(2, 10, 12000); PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10); PutRandomData(2, 1, 10);
WaitForFlush(2); WaitForFlush(2);
AssertFilesPerLevel(ToString(i + 1), 2); AssertFilesPerLevel(std::to_string(i + 1), 2);
} }
ROCKSDB_NAMESPACE::port::Thread threads([&] { ROCKSDB_NAMESPACE::port::Thread threads([&] {
CompactRangeOptions compact_options; CompactRangeOptions compact_options;
@ -1615,7 +1616,7 @@ TEST_P(ColumnFamilyTest, ManualAndAutomaticCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
bool cf_1_1 = true; bool cf_1_1 = true;
bool cf_1_2 = true; bool cf_1_2 = true;
@ -1650,7 +1651,7 @@ TEST_P(ColumnFamilyTest, ManualAndAutomaticCompactions) {
PutRandomData(2, 10, 12000); PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10); PutRandomData(2, 1, 10);
WaitForFlush(2); WaitForFlush(2);
AssertFilesPerLevel(ToString(i + 1), 2); AssertFilesPerLevel(std::to_string(i + 1), 2);
} }
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:5"); TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:5");
threads.join(); threads.join();
@ -1709,7 +1710,7 @@ TEST_P(ColumnFamilyTest, SameCFManualManualCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
bool cf_1_1 = true; bool cf_1_1 = true;
bool cf_1_2 = true; bool cf_1_2 = true;
@ -1748,8 +1749,8 @@ TEST_P(ColumnFamilyTest, SameCFManualManualCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i), AssertFilesPerLevel(
1); std::to_string(one.level0_file_num_compaction_trigger + i), 1);
} }
ROCKSDB_NAMESPACE::port::Thread threads1([&] { ROCKSDB_NAMESPACE::port::Thread threads1([&] {
@ -1811,7 +1812,7 @@ TEST_P(ColumnFamilyTest, SameCFManualAutomaticCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
bool cf_1_1 = true; bool cf_1_1 = true;
bool cf_1_2 = true; bool cf_1_2 = true;
@ -1849,8 +1850,8 @@ TEST_P(ColumnFamilyTest, SameCFManualAutomaticCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i), AssertFilesPerLevel(
1); std::to_string(one.level0_file_num_compaction_trigger + i), 1);
} }
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1"); TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1");
@ -1904,7 +1905,7 @@ TEST_P(ColumnFamilyTest, SameCFManualAutomaticCompactionsLevel) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
bool cf_1_1 = true; bool cf_1_1 = true;
bool cf_1_2 = true; bool cf_1_2 = true;
@ -1942,8 +1943,8 @@ TEST_P(ColumnFamilyTest, SameCFManualAutomaticCompactionsLevel) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i), AssertFilesPerLevel(
1); std::to_string(one.level0_file_num_compaction_trigger + i), 1);
} }
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1"); TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1");
@ -2024,7 +2025,7 @@ TEST_P(ColumnFamilyTest, SameCFAutomaticManualCompactions) {
PutRandomData(1, 10, 12000, true); PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true); PutRandomData(1, 1, 10, true);
WaitForFlush(1); WaitForFlush(1);
AssertFilesPerLevel(ToString(i + 1), 1); AssertFilesPerLevel(std::to_string(i + 1), 1);
} }
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:5"); TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:5");

View File

@ -91,8 +91,8 @@ TEST_F(CompactFilesTest, L0ConflictsFiles) {
// create couple files // create couple files
// Background compaction starts and waits in BackgroundCallCompaction:0 // Background compaction starts and waits in BackgroundCallCompaction:0
for (int i = 0; i < kLevel0Trigger * 4; ++i) { for (int i = 0; i < kLevel0Trigger * 4; ++i) {
ASSERT_OK(db->Put(WriteOptions(), ToString(i), "")); ASSERT_OK(db->Put(WriteOptions(), std::to_string(i), ""));
ASSERT_OK(db->Put(WriteOptions(), ToString(100 - i), "")); ASSERT_OK(db->Put(WriteOptions(), std::to_string(100 - i), ""));
ASSERT_OK(db->Flush(FlushOptions())); ASSERT_OK(db->Flush(FlushOptions()));
} }
@ -136,7 +136,7 @@ TEST_F(CompactFilesTest, MultipleLevel) {
// create couple files in L0, L3, L4 and L5 // create couple files in L0, L3, L4 and L5
for (int i = 5; i > 2; --i) { for (int i = 5; i > 2; --i) {
collector->ClearFlushedFiles(); collector->ClearFlushedFiles();
ASSERT_OK(db->Put(WriteOptions(), ToString(i), "")); ASSERT_OK(db->Put(WriteOptions(), std::to_string(i), ""));
ASSERT_OK(db->Flush(FlushOptions())); ASSERT_OK(db->Flush(FlushOptions()));
// Ensure background work is fully finished including listener callbacks // Ensure background work is fully finished including listener callbacks
// before accessing listener state. // before accessing listener state.
@ -145,11 +145,11 @@ TEST_F(CompactFilesTest, MultipleLevel) {
ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files, i)); ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files, i));
std::string prop; std::string prop;
ASSERT_TRUE( ASSERT_TRUE(db->GetProperty(
db->GetProperty("rocksdb.num-files-at-level" + ToString(i), &prop)); "rocksdb.num-files-at-level" + std::to_string(i), &prop));
ASSERT_EQ("1", prop); ASSERT_EQ("1", prop);
} }
ASSERT_OK(db->Put(WriteOptions(), ToString(0), "")); ASSERT_OK(db->Put(WriteOptions(), std::to_string(0), ""));
ASSERT_OK(db->Flush(FlushOptions())); ASSERT_OK(db->Flush(FlushOptions()));
ColumnFamilyMetaData meta; ColumnFamilyMetaData meta;
@ -218,7 +218,7 @@ TEST_F(CompactFilesTest, ObsoleteFiles) {
// create couple files // create couple files
for (int i = 1000; i < 2000; ++i) { for (int i = 1000; i < 2000; ++i) {
ASSERT_OK(db->Put(WriteOptions(), ToString(i), ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(kWriteBufferSize / 10, 'a' + (i % 26)))); std::string(kWriteBufferSize / 10, 'a' + (i % 26))));
} }
@ -257,14 +257,14 @@ TEST_F(CompactFilesTest, NotCutOutputOnLevel0) {
// create couple files // create couple files
for (int i = 0; i < 500; ++i) { for (int i = 0; i < 500; ++i) {
ASSERT_OK(db->Put(WriteOptions(), ToString(i), ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26)))); std::string(1000, 'a' + (i % 26))));
} }
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable()); ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());
auto l0_files_1 = collector->GetFlushedFiles(); auto l0_files_1 = collector->GetFlushedFiles();
collector->ClearFlushedFiles(); collector->ClearFlushedFiles();
for (int i = 0; i < 500; ++i) { for (int i = 0; i < 500; ++i) {
ASSERT_OK(db->Put(WriteOptions(), ToString(i), ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26)))); std::string(1000, 'a' + (i % 26))));
} }
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable()); ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());
@ -295,7 +295,7 @@ TEST_F(CompactFilesTest, CapturingPendingFiles) {
// Create 5 files. // Create 5 files.
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
ASSERT_OK(db->Put(WriteOptions(), "key" + ToString(i), "value")); ASSERT_OK(db->Put(WriteOptions(), "key" + std::to_string(i), "value"));
ASSERT_OK(db->Flush(FlushOptions())); ASSERT_OK(db->Flush(FlushOptions()));
} }
@ -465,7 +465,7 @@ TEST_F(CompactFilesTest, GetCompactionJobInfo) {
// create couple files // create couple files
for (int i = 0; i < 500; ++i) { for (int i = 0; i < 500; ++i) {
ASSERT_OK(db->Put(WriteOptions(), ToString(i), ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26)))); std::string(1000, 'a' + (i % 26))));
} }
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable()); ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());

View File

@ -518,7 +518,7 @@ uint64_t Compaction::OutputFilePreallocationSize() const {
} }
} }
if (max_output_file_size_ != port::kMaxUint64 && if (max_output_file_size_ != std::numeric_limits<uint64_t>::max() &&
(immutable_options_.compaction_style == kCompactionStyleLevel || (immutable_options_.compaction_style == kCompactionStyleLevel ||
output_level() > 0)) { output_level() > 0)) {
preallocation_size = std::min(max_output_file_size_, preallocation_size); preallocation_size = std::min(max_output_file_size_, preallocation_size);
@ -616,7 +616,7 @@ bool Compaction::DoesInputReferenceBlobFiles() const {
uint64_t Compaction::MinInputFileOldestAncesterTime( uint64_t Compaction::MinInputFileOldestAncesterTime(
const InternalKey* start, const InternalKey* end) const { const InternalKey* start, const InternalKey* end) const {
uint64_t min_oldest_ancester_time = port::kMaxUint64; uint64_t min_oldest_ancester_time = std::numeric_limits<uint64_t>::max();
const InternalKeyComparator& icmp = const InternalKeyComparator& icmp =
column_family_data()->internal_comparator(); column_family_data()->internal_comparator();
for (const auto& level_files : inputs_) { for (const auto& level_files : inputs_) {

View File

@ -28,7 +28,8 @@ CompactionIterator::CompactionIterator(
Env* env, bool report_detailed_time, bool expect_valid_internal_key, Env* env, bool report_detailed_time, bool expect_valid_internal_key,
CompactionRangeDelAggregator* range_del_agg, CompactionRangeDelAggregator* range_del_agg,
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors, BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
const Compaction* compaction, const CompactionFilter* compaction_filter, bool enforce_single_del_contracts, const Compaction* compaction,
const CompactionFilter* compaction_filter,
const std::atomic<bool>* shutting_down, const std::atomic<bool>* shutting_down,
const std::atomic<int>* manual_compaction_paused, const std::atomic<int>* manual_compaction_paused,
const std::atomic<bool>* manual_compaction_canceled, const std::atomic<bool>* manual_compaction_canceled,
@ -38,7 +39,7 @@ CompactionIterator::CompactionIterator(
input, cmp, merge_helper, last_sequence, snapshots, input, cmp, merge_helper, last_sequence, snapshots,
earliest_write_conflict_snapshot, job_snapshot, snapshot_checker, env, earliest_write_conflict_snapshot, job_snapshot, snapshot_checker, env,
report_detailed_time, expect_valid_internal_key, range_del_agg, report_detailed_time, expect_valid_internal_key, range_del_agg,
blob_file_builder, allow_data_in_errors, blob_file_builder, allow_data_in_errors, enforce_single_del_contracts,
std::unique_ptr<CompactionProxy>( std::unique_ptr<CompactionProxy>(
compaction ? new RealCompaction(compaction) : nullptr), compaction ? new RealCompaction(compaction) : nullptr),
compaction_filter, shutting_down, manual_compaction_paused, compaction_filter, shutting_down, manual_compaction_paused,
@ -52,6 +53,7 @@ CompactionIterator::CompactionIterator(
Env* env, bool report_detailed_time, bool expect_valid_internal_key, Env* env, bool report_detailed_time, bool expect_valid_internal_key,
CompactionRangeDelAggregator* range_del_agg, CompactionRangeDelAggregator* range_del_agg,
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors, BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
bool enforce_single_del_contracts,
std::unique_ptr<CompactionProxy> compaction, std::unique_ptr<CompactionProxy> compaction,
const CompactionFilter* compaction_filter, const CompactionFilter* compaction_filter,
const std::atomic<bool>* shutting_down, const std::atomic<bool>* shutting_down,
@ -80,6 +82,7 @@ CompactionIterator::CompactionIterator(
manual_compaction_canceled_(manual_compaction_canceled), manual_compaction_canceled_(manual_compaction_canceled),
info_log_(info_log), info_log_(info_log),
allow_data_in_errors_(allow_data_in_errors), allow_data_in_errors_(allow_data_in_errors),
enforce_single_del_contracts_(enforce_single_del_contracts),
timestamp_size_(cmp_ ? cmp_->timestamp_size() : 0), timestamp_size_(cmp_ ? cmp_->timestamp_size() : 0),
full_history_ts_low_(full_history_ts_low), full_history_ts_low_(full_history_ts_low),
current_user_key_sequence_(0), current_user_key_sequence_(0),
@ -307,7 +310,7 @@ bool CompactionIterator::InvokeFilterIfNeeded(bool* need_skip,
// no value associated with delete // no value associated with delete
value_.clear(); value_.clear();
iter_stats_.num_record_drop_user++; iter_stats_.num_record_drop_user++;
} else if (filter == CompactionFilter::Decision::kRemoveWithSingleDelete) { } else if (filter == CompactionFilter::Decision::kPurge) {
// convert the current key to a single delete; key_ is pointing into // convert the current key to a single delete; key_ is pointing into
// current_key_ at this point, so updating current_key_ updates key() // current_key_ at this point, so updating current_key_ updates key()
ikey_.type = kTypeSingleDeletion; ikey_.type = kTypeSingleDeletion;
@ -657,10 +660,15 @@ void CompactionIterator::NextFromInput() {
"TransactionDBOptions::rollback_deletion_type_callback is " "TransactionDBOptions::rollback_deletion_type_callback is "
"configured properly. Mixing SD and DEL can lead to " "configured properly. Mixing SD and DEL can lead to "
"undefined behaviors"; "undefined behaviors";
ROCKS_LOG_ERROR(info_log_, "%s", oss.str().c_str()); ++iter_stats_.num_record_drop_obsolete;
valid_ = false; ++iter_stats_.num_single_del_mismatch;
status_ = Status::Corruption(oss.str()); if (enforce_single_del_contracts_) {
return; ROCKS_LOG_ERROR(info_log_, "%s", oss.str().c_str());
valid_ = false;
status_ = Status::Corruption(oss.str());
return;
}
ROCKS_LOG_WARN(info_log_, "%s", oss.str().c_str());
} else if (!is_timestamp_eligible_for_gc) { } else if (!is_timestamp_eligible_for_gc) {
// We cannot drop the SingleDelete as timestamp is enabled, and // We cannot drop the SingleDelete as timestamp is enabled, and
// timestamp of this key is greater than or equal to // timestamp of this key is greater than or equal to

View File

@ -176,7 +176,7 @@ class CompactionIterator {
Env* env, bool report_detailed_time, bool expect_valid_internal_key, Env* env, bool report_detailed_time, bool expect_valid_internal_key,
CompactionRangeDelAggregator* range_del_agg, CompactionRangeDelAggregator* range_del_agg,
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors, BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
const Compaction* compaction = nullptr, bool enforce_single_del_contracts, const Compaction* compaction = nullptr,
const CompactionFilter* compaction_filter = nullptr, const CompactionFilter* compaction_filter = nullptr,
const std::atomic<bool>* shutting_down = nullptr, const std::atomic<bool>* shutting_down = nullptr,
const std::atomic<int>* manual_compaction_paused = nullptr, const std::atomic<int>* manual_compaction_paused = nullptr,
@ -193,6 +193,7 @@ class CompactionIterator {
Env* env, bool report_detailed_time, bool expect_valid_internal_key, Env* env, bool report_detailed_time, bool expect_valid_internal_key,
CompactionRangeDelAggregator* range_del_agg, CompactionRangeDelAggregator* range_del_agg,
BlobFileBuilder* blob_file_builder, bool allow_data_in_errors, BlobFileBuilder* blob_file_builder, bool allow_data_in_errors,
bool enforce_single_del_contracts,
std::unique_ptr<CompactionProxy> compaction, std::unique_ptr<CompactionProxy> compaction,
const CompactionFilter* compaction_filter = nullptr, const CompactionFilter* compaction_filter = nullptr,
const std::atomic<bool>* shutting_down = nullptr, const std::atomic<bool>* shutting_down = nullptr,
@ -332,6 +333,8 @@ class CompactionIterator {
bool allow_data_in_errors_; bool allow_data_in_errors_;
const bool enforce_single_del_contracts_;
// Comes from comparator. // Comes from comparator.
const size_t timestamp_size_; const size_t timestamp_size_;

View File

@ -279,7 +279,8 @@ class CompactionIteratorTest : public testing::TestWithParam<bool> {
snapshot_checker_.get(), Env::Default(), snapshot_checker_.get(), Env::Default(),
false /* report_detailed_time */, false, range_del_agg_.get(), false /* report_detailed_time */, false, range_del_agg_.get(),
nullptr /* blob_file_builder */, true /*allow_data_in_errors*/, nullptr /* blob_file_builder */, true /*allow_data_in_errors*/,
std::move(compaction), filter, &shutting_down_, true /*enforce_single_del_contracts*/, std::move(compaction), filter,
&shutting_down_,
/*manual_compaction_paused=*/nullptr, /*manual_compaction_paused=*/nullptr,
/*manual_compaction_canceled=*/nullptr, /*info_log=*/nullptr, /*manual_compaction_canceled=*/nullptr, /*info_log=*/nullptr,
full_history_ts_low)); full_history_ts_low));
@ -313,7 +314,7 @@ class CompactionIteratorTest : public testing::TestWithParam<bool> {
key_not_exists_beyond_output_level, full_history_ts_low); key_not_exists_beyond_output_level, full_history_ts_low);
c_iter_->SeekToFirst(); c_iter_->SeekToFirst();
for (size_t i = 0; i < expected_keys.size(); i++) { for (size_t i = 0; i < expected_keys.size(); i++) {
std::string info = "i = " + ToString(i); std::string info = "i = " + std::to_string(i);
ASSERT_TRUE(c_iter_->Valid()) << info; ASSERT_TRUE(c_iter_->Valid()) << info;
ASSERT_OK(c_iter_->status()) << info; ASSERT_OK(c_iter_->status()) << info;
ASSERT_EQ(expected_keys[i], c_iter_->key().ToString()) << info; ASSERT_EQ(expected_keys[i], c_iter_->key().ToString()) << info;

View File

@ -1479,9 +1479,9 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
snapshot_checker_, env_, ShouldReportDetailedTime(env_, stats_), snapshot_checker_, env_, ShouldReportDetailedTime(env_, stats_),
/*expect_valid_internal_key=*/true, &range_del_agg, /*expect_valid_internal_key=*/true, &range_del_agg,
blob_file_builder.get(), db_options_.allow_data_in_errors, blob_file_builder.get(), db_options_.allow_data_in_errors,
sub_compact->compaction, compaction_filter, shutting_down_, db_options_.enforce_single_del_contracts, sub_compact->compaction,
manual_compaction_paused_, manual_compaction_canceled_, compaction_filter, shutting_down_, manual_compaction_paused_,
db_options_.info_log, full_history_ts_low)); manual_compaction_canceled_, db_options_.info_log, full_history_ts_low));
auto c_iter = sub_compact->c_iter.get(); auto c_iter = sub_compact->c_iter.get();
c_iter->SeekToFirst(); c_iter->SeekToFirst();
if (c_iter->Valid() && sub_compact->compaction->output_level() != 0) { if (c_iter->Valid() && sub_compact->compaction->output_level() != 0) {
@ -1974,7 +1974,8 @@ Status CompactionJob::FinishCompactionOutputFile(
refined_oldest_ancester_time = refined_oldest_ancester_time =
sub_compact->compaction->MinInputFileOldestAncesterTime( sub_compact->compaction->MinInputFileOldestAncesterTime(
&(meta->smallest), &(meta->largest)); &(meta->smallest), &(meta->largest));
if (refined_oldest_ancester_time != port::kMaxUint64) { if (refined_oldest_ancester_time !=
std::numeric_limits<uint64_t>::max()) {
meta->oldest_ancester_time = refined_oldest_ancester_time; meta->oldest_ancester_time = refined_oldest_ancester_time;
} }
} }
@ -2264,7 +2265,7 @@ Status CompactionJob::OpenCompactionOutputFile(
sub_compact->compaction->MinInputFileOldestAncesterTime( sub_compact->compaction->MinInputFileOldestAncesterTime(
(sub_compact->start != nullptr) ? &tmp_start : nullptr, (sub_compact->start != nullptr) ? &tmp_start : nullptr,
(sub_compact->end != nullptr) ? &tmp_end : nullptr); (sub_compact->end != nullptr) ? &tmp_end : nullptr);
if (oldest_ancester_time == port::kMaxUint64) { if (oldest_ancester_time == std::numeric_limits<uint64_t>::max()) {
oldest_ancester_time = current_time; oldest_ancester_time = current_time;
} }
@ -2458,7 +2459,7 @@ void CompactionJob::LogCompaction() {
<< "compaction_reason" << "compaction_reason"
<< GetCompactionReasonString(compaction->compaction_reason()); << GetCompactionReasonString(compaction->compaction_reason());
for (size_t i = 0; i < compaction->num_input_levels(); ++i) { for (size_t i = 0; i < compaction->num_input_levels(); ++i) {
stream << ("files_L" + ToString(compaction->level(i))); stream << ("files_L" + std::to_string(compaction->level(i)));
stream.StartArray(); stream.StartArray();
for (auto f : *compaction->inputs(i)) { for (auto f : *compaction->inputs(i)) {
stream << f->fd.GetNumber(); stream << f->fd.GetNumber();
@ -2951,6 +2952,7 @@ static std::unordered_map<std::string, OptionTypeInfo> cs_result_type_info = {
const void* addr1, const void* addr2, std::string* mismatch) { const void* addr1, const void* addr2, std::string* mismatch) {
const auto status1 = static_cast<const Status*>(addr1); const auto status1 = static_cast<const Status*>(addr1);
const auto status2 = static_cast<const Status*>(addr2); const auto status2 = static_cast<const Status*>(addr2);
StatusSerializationAdapter adatper1(*status1); StatusSerializationAdapter adatper1(*status1);
StatusSerializationAdapter adapter2(*status2); StatusSerializationAdapter adapter2(*status2);
return OptionTypeInfo::TypesAreEqual(opts, status_adapter_type_info, return OptionTypeInfo::TypesAreEqual(opts, status_adapter_type_info,
@ -3008,7 +3010,7 @@ Status CompactionServiceInput::Read(const std::string& data_str,
} else { } else {
return Status::NotSupported( return Status::NotSupported(
"Compaction Service Input data version not supported: " + "Compaction Service Input data version not supported: " +
ToString(format_version)); std::to_string(format_version));
} }
} }
@ -3037,7 +3039,7 @@ Status CompactionServiceResult::Read(const std::string& data_str,
} else { } else {
return Status::NotSupported( return Status::NotSupported(
"Compaction Service Result data version not supported: " + "Compaction Service Result data version not supported: " +
ToString(format_version)); std::to_string(format_version));
} }
} }

View File

@ -268,10 +268,10 @@ class CompactionJobStatsTest : public testing::Test,
if (cf == 0) { if (cf == 0) {
// default cfd // default cfd
EXPECT_TRUE(db_->GetProperty( EXPECT_TRUE(db_->GetProperty(
"rocksdb.num-files-at-level" + ToString(level), &property)); "rocksdb.num-files-at-level" + std::to_string(level), &property));
} else { } else {
EXPECT_TRUE(db_->GetProperty( EXPECT_TRUE(db_->GetProperty(
handles_[cf], "rocksdb.num-files-at-level" + ToString(level), handles_[cf], "rocksdb.num-files-at-level" + std::to_string(level),
&property)); &property));
} }
return atoi(property.c_str()); return atoi(property.c_str());
@ -672,7 +672,7 @@ TEST_P(CompactionJobStatsTest, CompactionJobStatsTest) {
snprintf(buf, kBufSize, "%d", ++num_L0_files); snprintf(buf, kBufSize, "%d", ++num_L0_files);
ASSERT_EQ(std::string(buf), FilesPerLevel(1)); ASSERT_EQ(std::string(buf), FilesPerLevel(1));
} }
ASSERT_EQ(ToString(num_L0_files), FilesPerLevel(1)); ASSERT_EQ(std::to_string(num_L0_files), FilesPerLevel(1));
// 2nd Phase: perform L0 -> L1 compaction. // 2nd Phase: perform L0 -> L1 compaction.
int L0_compaction_count = 6; int L0_compaction_count = 6;

View File

@ -236,8 +236,8 @@ class CompactionJobTestBase : public testing::Test {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
auto contents = mock::MakeMockFile(); auto contents = mock::MakeMockFile();
for (int k = 0; k < kKeysPerFile; ++k) { for (int k = 0; k < kKeysPerFile; ++k) {
auto key = ToString(i * kMatchingKeys + k); auto key = std::to_string(i * kMatchingKeys + k);
auto value = ToString(i * kKeysPerFile + k); auto value = std::to_string(i * kKeysPerFile + k);
InternalKey internal_key(key, ++sequence_number, kTypeValue); InternalKey internal_key(key, ++sequence_number, kTypeValue);
// This is how the key will look like once it's written in bottommost // This is how the key will look like once it's written in bottommost
@ -1107,6 +1107,21 @@ TEST_F(CompactionJobTest, OldestBlobFileNumber) {
/* expected_oldest_blob_file_number */ 19); /* expected_oldest_blob_file_number */ 19);
} }
TEST_F(CompactionJobTest, NoEnforceSingleDeleteContract) {
db_options_.enforce_single_del_contracts = false;
NewDB();
auto file =
mock::MakeMockFile({{KeyStr("a", 4U, kTypeSingleDeletion), ""},
{KeyStr("a", 3U, kTypeDeletion), "dontcare"}});
AddMockFile(file);
SetLastSequence(4U);
auto expected_results = mock::MakeMockFile();
auto files = cfd_->current()->storage_info()->LevelFiles(0);
RunCompaction({files}, expected_results);
}
TEST_F(CompactionJobTest, InputSerialization) { TEST_F(CompactionJobTest, InputSerialization) {
// Setup a random CompactionServiceInput // Setup a random CompactionServiceInput
CompactionServiceInput input; CompactionServiceInput input;

View File

@ -65,7 +65,7 @@ bool FindIntraL0Compaction(const std::vector<FileMetaData*>& level_files,
size_t compact_bytes = static_cast<size_t>(level_files[start]->fd.file_size); size_t compact_bytes = static_cast<size_t>(level_files[start]->fd.file_size);
uint64_t compensated_compact_bytes = uint64_t compensated_compact_bytes =
level_files[start]->compensated_file_size; level_files[start]->compensated_file_size;
size_t compact_bytes_per_del_file = port::kMaxSizet; size_t compact_bytes_per_del_file = std::numeric_limits<size_t>::max();
// Compaction range will be [start, limit). // Compaction range will be [start, limit).
size_t limit; size_t limit;
// Pull in files until the amount of compaction work per deleted file begins // Pull in files until the amount of compaction work per deleted file begins
@ -401,7 +401,7 @@ Status CompactionPicker::GetCompactionInputsFromFileNumbers(
"Cannot find matched SST files for the following file numbers:"); "Cannot find matched SST files for the following file numbers:");
for (auto fn : *input_set) { for (auto fn : *input_set) {
message += " "; message += " ";
message += ToString(fn); message += std::to_string(fn);
} }
return Status::InvalidArgument(message); return Status::InvalidArgument(message);
} }
@ -717,7 +717,7 @@ Compaction* CompactionPicker::CompactRange(
// files that are created during the current compaction. // files that are created during the current compaction.
if (compact_range_options.bottommost_level_compaction == if (compact_range_options.bottommost_level_compaction ==
BottommostLevelCompaction::kForceOptimized && BottommostLevelCompaction::kForceOptimized &&
max_file_num_to_ignore != port::kMaxUint64) { max_file_num_to_ignore != std::numeric_limits<uint64_t>::max()) {
assert(input_level == output_level); assert(input_level == output_level);
// inputs_shrunk holds a continuous subset of input files which were all // inputs_shrunk holds a continuous subset of input files which were all
// created before the current manual compaction // created before the current manual compaction
@ -1004,14 +1004,14 @@ Status CompactionPicker::SanitizeCompactionInputFiles(
return Status::InvalidArgument( return Status::InvalidArgument(
"Output level for column family " + cf_meta.name + "Output level for column family " + cf_meta.name +
" must between [0, " + " must between [0, " +
ToString(cf_meta.levels[cf_meta.levels.size() - 1].level) + "]."); std::to_string(cf_meta.levels[cf_meta.levels.size() - 1].level) + "].");
} }
if (output_level > MaxOutputLevel()) { if (output_level > MaxOutputLevel()) {
return Status::InvalidArgument( return Status::InvalidArgument(
"Exceed the maximum output level defined by " "Exceed the maximum output level defined by "
"the current compaction algorithm --- " + "the current compaction algorithm --- " +
ToString(MaxOutputLevel())); std::to_string(MaxOutputLevel()));
} }
if (output_level < 0) { if (output_level < 0) {
@ -1061,8 +1061,8 @@ Status CompactionPicker::SanitizeCompactionInputFiles(
return Status::InvalidArgument( return Status::InvalidArgument(
"Cannot compact file to up level, input file: " + "Cannot compact file to up level, input file: " +
MakeTableFileName("", file_num) + " level " + MakeTableFileName("", file_num) + " level " +
ToString(input_file_level) + " > output level " + std::to_string(input_file_level) + " > output level " +
ToString(output_level)); std::to_string(output_level));
} }
} }

View File

@ -504,7 +504,7 @@ bool LevelCompactionBuilder::PickIntraL0Compaction() {
return false; return false;
} }
return FindIntraL0Compaction(level_files, kMinFilesForIntraL0Compaction, return FindIntraL0Compaction(level_files, kMinFilesForIntraL0Compaction,
port::kMaxUint64, std::numeric_limits<uint64_t>::max(),
mutable_cf_options_.max_compaction_bytes, mutable_cf_options_.max_compaction_bytes,
&start_level_inputs_, earliest_mem_seqno_); &start_level_inputs_, earliest_mem_seqno_);
} }

View File

@ -273,9 +273,9 @@ TEST_F(CompactionPickerTest, NeedsCompactionLevel) {
// start a brand new version in each test. // start a brand new version in each test.
NewVersionStorage(kLevels, kCompactionStyleLevel); NewVersionStorage(kLevels, kCompactionStyleLevel);
for (int i = 0; i < file_count; ++i) { for (int i = 0; i < file_count; ++i) {
Add(level, i, ToString((i + 100) * 1000).c_str(), Add(level, i, std::to_string((i + 100) * 1000).c_str(),
ToString((i + 100) * 1000 + 999).c_str(), std::to_string((i + 100) * 1000 + 999).c_str(), file_size, 0,
file_size, 0, i * 100, i * 100 + 99); i * 100, i * 100 + 99);
} }
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
ASSERT_EQ(vstorage_->CompactionScoreLevel(0), level); ASSERT_EQ(vstorage_->CompactionScoreLevel(0), level);
@ -439,8 +439,8 @@ TEST_F(CompactionPickerTest, NeedsCompactionUniversal) {
for (int i = 1; for (int i = 1;
i <= mutable_cf_options_.level0_file_num_compaction_trigger * 2; ++i) { i <= mutable_cf_options_.level0_file_num_compaction_trigger * 2; ++i) {
NewVersionStorage(1, kCompactionStyleUniversal); NewVersionStorage(1, kCompactionStyleUniversal);
Add(0, i, ToString((i + 100) * 1000).c_str(), Add(0, i, std::to_string((i + 100) * 1000).c_str(),
ToString((i + 100) * 1000 + 999).c_str(), 1000000, 0, i * 100, std::to_string((i + 100) * 1000 + 999).c_str(), 1000000, 0, i * 100,
i * 100 + 99); i * 100 + 99);
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
ASSERT_EQ(level_compaction_picker.NeedsCompaction(vstorage_.get()), ASSERT_EQ(level_compaction_picker.NeedsCompaction(vstorage_.get()),
@ -852,17 +852,17 @@ TEST_F(CompactionPickerTest, UniversalIncrementalSpace4) {
// L3: (1101, 1180) (1201, 1280) ... (7901, 7908) // L3: (1101, 1180) (1201, 1280) ... (7901, 7908)
// L4: (1130, 1150) (1160, 1210) (1230, 1250) (1260 1310) ... (7960, 8010) // L4: (1130, 1150) (1160, 1210) (1230, 1250) (1260 1310) ... (7960, 8010)
for (int i = 11; i < 79; i++) { for (int i = 11; i < 79; i++) {
Add(3, 100 + i * 3, ToString(i * 100).c_str(), Add(3, 100 + i * 3, std::to_string(i * 100).c_str(),
ToString(i * 100 + 80).c_str(), kFileSize, 0, 200, 251); std::to_string(i * 100 + 80).c_str(), kFileSize, 0, 200, 251);
// Add a tie breaker // Add a tie breaker
if (i == 66) { if (i == 66) {
Add(3, 10000U, "6690", "6699", kFileSize, 0, 200, 251); Add(3, 10000U, "6690", "6699", kFileSize, 0, 200, 251);
} }
Add(4, 100 + i * 3 + 1, ToString(i * 100 + 30).c_str(), Add(4, 100 + i * 3 + 1, std::to_string(i * 100 + 30).c_str(),
ToString(i * 100 + 50).c_str(), kFileSize, 0, 200, 251); std::to_string(i * 100 + 50).c_str(), kFileSize, 0, 200, 251);
Add(4, 100 + i * 3 + 2, ToString(i * 100 + 60).c_str(), Add(4, 100 + i * 3 + 2, std::to_string(i * 100 + 60).c_str(),
ToString(i * 100 + 110).c_str(), kFileSize, 0, 200, 251); std::to_string(i * 100 + 110).c_str(), kFileSize, 0, 200, 251);
} }
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
@ -899,14 +899,14 @@ TEST_F(CompactionPickerTest, UniversalIncrementalSpace5) {
// L3: (1101, 1180) (1201, 1280) ... (7901, 7908) // L3: (1101, 1180) (1201, 1280) ... (7901, 7908)
// L4: (1130, 1150) (1160, 1210) (1230, 1250) (1260 1310) ... (7960, 8010) // L4: (1130, 1150) (1160, 1210) (1230, 1250) (1260 1310) ... (7960, 8010)
for (int i = 11; i < 70; i++) { for (int i = 11; i < 70; i++) {
Add(3, 100 + i * 3, ToString(i * 100).c_str(), Add(3, 100 + i * 3, std::to_string(i * 100).c_str(),
ToString(i * 100 + 80).c_str(), std::to_string(i * 100 + 80).c_str(),
i % 10 == 9 ? kFileSize * 100 : kFileSize, 0, 200, 251); i % 10 == 9 ? kFileSize * 100 : kFileSize, 0, 200, 251);
Add(4, 100 + i * 3 + 1, ToString(i * 100 + 30).c_str(), Add(4, 100 + i * 3 + 1, std::to_string(i * 100 + 30).c_str(),
ToString(i * 100 + 50).c_str(), kFileSize, 0, 200, 251); std::to_string(i * 100 + 50).c_str(), kFileSize, 0, 200, 251);
Add(4, 100 + i * 3 + 2, ToString(i * 100 + 60).c_str(), Add(4, 100 + i * 3 + 2, std::to_string(i * 100 + 60).c_str(),
ToString(i * 100 + 110).c_str(), kFileSize, 0, 200, 251); std::to_string(i * 100 + 110).c_str(), kFileSize, 0, 200, 251);
} }
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
@ -941,8 +941,8 @@ TEST_F(CompactionPickerTest, NeedsCompactionFIFO) {
// size of L0 files. // size of L0 files.
for (int i = 1; i <= kFileCount; ++i) { for (int i = 1; i <= kFileCount; ++i) {
NewVersionStorage(1, kCompactionStyleFIFO); NewVersionStorage(1, kCompactionStyleFIFO);
Add(0, i, ToString((i + 100) * 1000).c_str(), Add(0, i, std::to_string((i + 100) * 1000).c_str(),
ToString((i + 100) * 1000 + 999).c_str(), kFileSize, 0, i * 100, std::to_string((i + 100) * 1000 + 999).c_str(), kFileSize, 0, i * 100,
i * 100 + 99); i * 100 + 99);
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
ASSERT_EQ(fifo_compaction_picker.NeedsCompaction(vstorage_.get()), ASSERT_EQ(fifo_compaction_picker.NeedsCompaction(vstorage_.get()),
@ -2653,8 +2653,8 @@ TEST_F(CompactionPickerTest, UniversalMarkedManualCompaction) {
universal_compaction_picker.CompactRange( universal_compaction_picker.CompactRange(
cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(), cf_name_, mutable_cf_options_, mutable_db_options_, vstorage_.get(),
ColumnFamilyData::kCompactAllLevels, 6, CompactRangeOptions(), ColumnFamilyData::kCompactAllLevels, 6, CompactRangeOptions(),
nullptr, nullptr, &manual_end, &manual_conflict, port::kMaxUint64, nullptr, nullptr, &manual_end, &manual_conflict,
"")); std::numeric_limits<uint64_t>::max(), ""));
ASSERT_TRUE(compaction); ASSERT_TRUE(compaction);

View File

@ -1371,7 +1371,7 @@ Compaction* UniversalCompactionBuilder::PickPeriodicCompaction() {
uint64_t UniversalCompactionBuilder::GetMaxOverlappingBytes() const { uint64_t UniversalCompactionBuilder::GetMaxOverlappingBytes() const {
if (!mutable_cf_options_.compaction_options_universal.incremental) { if (!mutable_cf_options_.compaction_options_universal.incremental) {
return port::kMaxUint64; return std::numeric_limits<uint64_t>::max();
} else { } else {
// Try to align cutting boundary with files at the next level if the // Try to align cutting boundary with files at the next level if the
// file isn't end up with 1/2 of target size, or it would overlap // file isn't end up with 1/2 of target size, or it would overlap

View File

@ -82,8 +82,7 @@ class MyTestCompactionService : public CompactionService {
options.canceled = &canceled_; options.canceled = &canceled_;
Status s = DB::OpenAndCompact( Status s = DB::OpenAndCompact(
options, db_path_, options, db_path_, db_path_ + "/" + std::to_string(info.job_id),
db_path_ + "/" + ROCKSDB_NAMESPACE::ToString(info.job_id),
compaction_input, compaction_service_result, options_override); compaction_input, compaction_service_result, options_override);
if (is_override_wait_result_) { if (is_override_wait_result_) {
*compaction_service_result = override_wait_result_; *compaction_service_result = override_wait_result_;
@ -177,7 +176,7 @@ class CompactionServiceTest : public DBTestBase {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -187,7 +186,7 @@ class CompactionServiceTest : public DBTestBase {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -199,9 +198,9 @@ class CompactionServiceTest : public DBTestBase {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
auto result = Get(Key(i)); auto result = Get(Key(i));
if (i % 2) { if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
} }
@ -224,7 +223,7 @@ TEST_F(CompactionServiceTest, BasicCompactions) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -232,7 +231,7 @@ TEST_F(CompactionServiceTest, BasicCompactions) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -242,9 +241,9 @@ TEST_F(CompactionServiceTest, BasicCompactions) {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
auto result = Get(Key(i)); auto result = Get(Key(i));
if (i % 2) { if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
auto my_cs = GetCompactionService(); auto my_cs = GetCompactionService();
@ -281,7 +280,7 @@ TEST_F(CompactionServiceTest, BasicCompactions) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
s = Put(Key(key_id), "value_new" + ToString(key_id)); s = Put(Key(key_id), "value_new" + std::to_string(key_id));
if (s.IsAborted()) { if (s.IsAborted()) {
break; break;
} }
@ -468,7 +467,7 @@ TEST_F(CompactionServiceTest, CompactionFilter) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -476,7 +475,7 @@ TEST_F(CompactionServiceTest, CompactionFilter) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -490,9 +489,9 @@ TEST_F(CompactionServiceTest, CompactionFilter) {
if (i > 5 && i <= 105) { if (i > 5 && i <= 105) {
ASSERT_EQ(result, "NOT_FOUND"); ASSERT_EQ(result, "NOT_FOUND");
} else if (i % 2) { } else if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
auto my_cs = GetCompactionService(); auto my_cs = GetCompactionService();
@ -547,9 +546,9 @@ TEST_F(CompactionServiceTest, ConcurrentCompaction) {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
auto result = Get(Key(i)); auto result = Get(Key(i));
if (i % 2) { if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
auto my_cs = GetCompactionService(); auto my_cs = GetCompactionService();
@ -564,7 +563,7 @@ TEST_F(CompactionServiceTest, CompactionInfo) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -572,7 +571,7 @@ TEST_F(CompactionServiceTest, CompactionInfo) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -617,7 +616,7 @@ TEST_F(CompactionServiceTest, CompactionInfo) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -625,7 +624,7 @@ TEST_F(CompactionServiceTest, CompactionInfo) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -653,7 +652,7 @@ TEST_F(CompactionServiceTest, FallbackLocalAuto) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -661,7 +660,7 @@ TEST_F(CompactionServiceTest, FallbackLocalAuto) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -671,9 +670,9 @@ TEST_F(CompactionServiceTest, FallbackLocalAuto) {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
auto result = Get(Key(i)); auto result = Get(Key(i));
if (i % 2) { if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
@ -796,7 +795,7 @@ TEST_F(CompactionServiceTest, RemoteEventListener) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -804,7 +803,7 @@ TEST_F(CompactionServiceTest, RemoteEventListener) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value_new" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value_new" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -821,9 +820,9 @@ TEST_F(CompactionServiceTest, RemoteEventListener) {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
auto result = Get(Key(i)); auto result = Get(Key(i));
if (i % 2) { if (i % 2) {
ASSERT_EQ(result, "value" + ToString(i)); ASSERT_EQ(result, "value" + std::to_string(i));
} else { } else {
ASSERT_EQ(result, "value_new" + ToString(i)); ASSERT_EQ(result, "value_new" + std::to_string(i));
} }
} }
} }

View File

@ -397,7 +397,7 @@ TEST_P(ComparatorDBTest, DoubleComparator) {
for (uint32_t j = 0; j < divide_order; j++) { for (uint32_t j = 0; j < divide_order; j++) {
to_divide *= 10.0; to_divide *= 10.0;
} }
source_strings.push_back(ToString(r / to_divide)); source_strings.push_back(std::to_string(r / to_divide));
} }
DoRandomIteraratorTest(GetDB(), source_strings, &rnd, 200, 1000, 66); DoRandomIteraratorTest(GetDB(), source_strings, &rnd, 200, 1000, 66);

View File

@ -308,7 +308,7 @@ class CorruptionTest : public testing::Test {
uint64_t new_size = old_size - bytes_to_truncate; uint64_t new_size = old_size - bytes_to_truncate;
// If bytes_to_truncate == 0, it will do full truncation. // If bytes_to_truncate == 0, it will do full truncation.
if (bytes_to_truncate == 0) { if (bytes_to_truncate == 0) {
new_size = old_size; new_size = 0;
} }
ASSERT_OK(test::TruncateFile(env_, path, new_size)); ASSERT_OK(test::TruncateFile(env_, path, new_size));
} }
@ -1049,16 +1049,23 @@ INSTANTIATE_TEST_CASE_P(CorruptionTest, CrashDuringRecoveryWithCorruptionTest,
// "Column family inconsistency: SST file contains data beyond the point of // "Column family inconsistency: SST file contains data beyond the point of
// corruption" error will be hit, causing recovery to fail. // corruption" error will be hit, causing recovery to fail.
// //
// After adding the fix, corrupted WALs whose numbers are larger than the // After adding the fix, only after new WAL is synced, RocksDB persist a new
// corrupted wal and smaller than the new WAL are moved to a separate folder. // MANIFEST with column families to ensure RocksDB is in consistent state.
// Only after new WAL is synced, RocksDB persist a new MANIFEST with column
// families to ensure RocksDB is in consistent state.
// RocksDB writes an empty WriteBatch as a sentinel to the new WAL which is // RocksDB writes an empty WriteBatch as a sentinel to the new WAL which is
// synced immediately afterwards. The sequence number of the sentinel // synced immediately afterwards. The sequence number of the sentinel
// WriteBatch will be the next sequence number immediately after the largest // WriteBatch will be the next sequence number immediately after the largest
// sequence number recovered from previous WALs and MANIFEST because of which DB // sequence number recovered from previous WALs and MANIFEST because of which DB
// will be in consistent state. // will be in consistent state.
TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) { // If a future recovery starts from the new MANIFEST, then it means the new WAL
// is successfully synced. Due to the sentinel empty write batch at the
// beginning, kPointInTimeRecovery of WAL is guaranteed to go after this point.
// If future recovery starts from the old MANIFEST, it means the writing the new
// MANIFEST failed. It won't have the "SST ahead of WAL" error.
//
// The combination of corrupting a WAL and injecting an error during subsequent
// re-open exposes the bug of prematurely persisting a new MANIFEST with
// advanced ColumnFamilyData::log_number.
TEST_P(CrashDuringRecoveryWithCorruptionTest, DISABLED_CrashDuringRecovery) {
CloseDb(); CloseDb();
Options options; Options options;
options.track_and_verify_wals_in_manifest = options.track_and_verify_wals_in_manifest =
@ -1068,7 +1075,7 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
options.env = env_; options.env = env_;
ASSERT_OK(DestroyDB(dbname_, options)); ASSERT_OK(DestroyDB(dbname_, options));
options.create_if_missing = true; options.create_if_missing = true;
options.max_write_buffer_number = 3; options.max_write_buffer_number = 8;
Reopen(&options); Reopen(&options);
Status s; Status s;
@ -1094,13 +1101,15 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
// Write one key to test_cf. // Write one key to test_cf.
ASSERT_OK(db_->Put(WriteOptions(), handles[1], "old_key", "dontcare")); ASSERT_OK(db_->Put(WriteOptions(), handles[1], "old_key", "dontcare"));
ASSERT_OK(db_->Flush(FlushOptions(), handles[1]));
// Write to default_cf and flush this cf several times to advance wal // Write to default_cf and flush this cf several times to advance wal
// number. // number. TEST_SwitchMemtable makes sure WALs are not synced and test can
// corrupt un-sync WAL.
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
ASSERT_OK(db_->Put(WriteOptions(), "key" + std::to_string(i), "value")); ASSERT_OK(db_->Put(WriteOptions(), "key" + std::to_string(i), "value"));
ASSERT_OK(dbimpl->TEST_SwitchMemtable()); ASSERT_OK(dbimpl->TEST_SwitchMemtable());
} }
ASSERT_OK(db_->Put(WriteOptions(), handles[1], "dontcare", "dontcare"));
for (auto* h : handles) { for (auto* h : handles) {
delete h; delete h;
@ -1109,12 +1118,13 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
CloseDb(); CloseDb();
} }
// 2. Corrupt second last wal file to emulate power reset which caused the DB // 2. Corrupt second last un-syned wal file to emulate power reset which
// to lose the un-synced WAL. // caused the DB to lose the un-synced WAL.
{ {
std::vector<uint64_t> file_nums; std::vector<uint64_t> file_nums;
GetSortedWalFiles(file_nums); GetSortedWalFiles(file_nums);
size_t size = file_nums.size(); size_t size = file_nums.size();
assert(size >= 2);
uint64_t log_num = file_nums[size - 2]; uint64_t log_num = file_nums[size - 2];
CorruptFileWithTruncation(FileType::kWalFile, log_num, CorruptFileWithTruncation(FileType::kWalFile, log_num,
/*bytes_to_truncate=*/8); /*bytes_to_truncate=*/8);
@ -1131,25 +1141,31 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
// Case2: If avoid_flush_during_recovery = false, all column families have // Case2: If avoid_flush_during_recovery = false, all column families have
// flushed their data from WAL to L0 during recovery, and none of them will // flushed their data from WAL to L0 during recovery, and none of them will
// ever need to read the WALs again. // ever need to read the WALs again.
// 4. Fault is injected to fail the recovery.
{ {
options.avoid_flush_during_recovery = avoid_flush_during_recovery_; SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
SyncPoint::GetInstance()->SetCallBack(
"DBImpl::GetLogSizeAndMaybeTruncate:0", [&](void* arg) {
auto* tmp_s = reinterpret_cast<Status*>(arg);
assert(tmp_s);
*tmp_s = Status::IOError("Injected");
});
SyncPoint::GetInstance()->EnableProcessing();
handles.clear();
options.avoid_flush_during_recovery = true;
s = DB::Open(options, dbname_, cf_descs, &handles, &db_); s = DB::Open(options, dbname_, cf_descs, &handles, &db_);
ASSERT_OK(s); ASSERT_TRUE(s.IsIOError());
ASSERT_EQ("IO error: Injected", s.ToString());
for (auto* h : handles) { for (auto* h : handles) {
delete h; delete h;
} }
handles.clear();
CloseDb(); CloseDb();
}
// 4. Corrupt max_wal_num to emulate second power reset which caused the SyncPoint::GetInstance()->DisableProcessing();
// DB to again lose the un-synced WAL. SyncPoint::GetInstance()->ClearAllCallBacks();
{
std::vector<uint64_t> file_nums;
GetSortedWalFiles(file_nums);
size_t size = file_nums.size();
uint64_t log_num = file_nums[size - 1];
CorruptFileWithTruncation(FileType::kWalFile, log_num);
} }
// 5. After second crash reopen the db with second corruption. Default family // 5. After second crash reopen the db with second corruption. Default family
@ -1187,16 +1203,24 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
// file contains data beyond the point of corruption" error will be hit, causing // file contains data beyond the point of corruption" error will be hit, causing
// recovery to fail. // recovery to fail.
// //
// After adding the fix, corrupted WALs whose numbers are larger than the // After adding the fix, only after new WAL is synced, RocksDB persist a new
// corrupted wal and smaller than the new WAL are moved to a separate folder. // MANIFEST with column families to ensure RocksDB is in consistent state.
// Only after new WAL is synced, RocksDB persist a new MANIFEST with column
// families to ensure RocksDB is in consistent state.
// RocksDB writes an empty WriteBatch as a sentinel to the new WAL which is // RocksDB writes an empty WriteBatch as a sentinel to the new WAL which is
// synced immediately afterwards. The sequence number of the sentinel // synced immediately afterwards. The sequence number of the sentinel
// WriteBatch will be the next sequence number immediately after the largest // WriteBatch will be the next sequence number immediately after the largest
// sequence number recovered from previous WALs and MANIFEST because of which DB // sequence number recovered from previous WALs and MANIFEST because of which DB
// will be in consistent state. // will be in consistent state.
TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) { // If a future recovery starts from the new MANIFEST, then it means the new WAL
// is successfully synced. Due to the sentinel empty write batch at the
// beginning, kPointInTimeRecovery of WAL is guaranteed to go after this point.
// If future recovery starts from the old MANIFEST, it means the writing the new
// MANIFEST failed. It won't have the "SST ahead of WAL" error.
//
// The combination of corrupting a WAL and injecting an error during subsequent
// re-open exposes the bug of prematurely persisting a new MANIFEST with
// advanced ColumnFamilyData::log_number.
TEST_P(CrashDuringRecoveryWithCorruptionTest,
DISABLED_TxnDbCrashDuringRecovery) {
CloseDb(); CloseDb();
Options options; Options options;
options.wal_recovery_mode = WALRecoveryMode::kPointInTimeRecovery; options.wal_recovery_mode = WALRecoveryMode::kPointInTimeRecovery;
@ -1229,7 +1253,6 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
// advance wal number so that some column families have advanced log_number // advance wal number so that some column families have advanced log_number
// while other don't. // while other don't.
{ {
options.avoid_flush_during_recovery = avoid_flush_during_recovery_;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs,
&handles, &txn_db)); &handles, &txn_db));
@ -1238,6 +1261,8 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
ASSERT_OK(txn->Put(handles[1], "foo", "value")); ASSERT_OK(txn->Put(handles[1], "foo", "value"));
ASSERT_OK(txn->SetName("txn0")); ASSERT_OK(txn->SetName("txn0"));
ASSERT_OK(txn->Prepare()); ASSERT_OK(txn->Prepare());
ASSERT_OK(txn_db->Flush(FlushOptions()));
delete txn; delete txn;
txn = nullptr; txn = nullptr;
@ -1257,6 +1282,7 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
delete txn; delete txn;
txn = nullptr; txn = nullptr;
for (auto* h : handles) { for (auto* h : handles) {
delete h; delete h;
} }
@ -1270,6 +1296,7 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
std::vector<uint64_t> file_nums; std::vector<uint64_t> file_nums;
GetSortedWalFiles(file_nums); GetSortedWalFiles(file_nums);
size_t size = file_nums.size(); size_t size = file_nums.size();
assert(size >= 2);
uint64_t log_num = file_nums[size - 2]; uint64_t log_num = file_nums[size - 2];
CorruptFileWithTruncation(FileType::kWalFile, log_num, CorruptFileWithTruncation(FileType::kWalFile, log_num,
/*bytes_to_truncate=*/8); /*bytes_to_truncate=*/8);
@ -1279,24 +1306,38 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
// family has higher log number than corrupted wal number. There may be old // family has higher log number than corrupted wal number. There may be old
// WAL files that it must not delete because they can contain data of // WAL files that it must not delete because they can contain data of
// uncommitted transactions. As a result, min_log_number_to_keep won't change. // uncommitted transactions. As a result, min_log_number_to_keep won't change.
{
options.avoid_flush_during_recovery = avoid_flush_during_recovery_;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs,
&handles, &txn_db));
{
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
SyncPoint::GetInstance()->SetCallBack(
"DBImpl::Open::BeforeSyncWAL", [&](void* arg) {
auto* tmp_s = reinterpret_cast<Status*>(arg);
assert(tmp_s);
*tmp_s = Status::IOError("Injected");
});
SyncPoint::GetInstance()->EnableProcessing();
handles.clear();
s = TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, &handles,
&txn_db);
ASSERT_TRUE(s.IsIOError());
ASSERT_EQ("IO error: Injected", s.ToString());
for (auto* h : handles) { for (auto* h : handles) {
delete h; delete h;
} }
handles.clear(); CloseDb();
delete txn_db;
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
} }
// 4. Corrupt max_wal_num to emulate second power reset which caused the // 4. Corrupt max_wal_num.
// DB to again lose the un-synced WAL.
{ {
std::vector<uint64_t> file_nums; std::vector<uint64_t> file_nums;
GetSortedWalFiles(file_nums); GetSortedWalFiles(file_nums);
size_t size = file_nums.size(); size_t size = file_nums.size();
assert(size >= 2);
uint64_t log_num = file_nums[size - 1]; uint64_t log_num = file_nums[size - 1];
CorruptFileWithTruncation(FileType::kWalFile, log_num); CorruptFileWithTruncation(FileType::kWalFile, log_num);
} }
@ -1311,8 +1352,6 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
// recovered from previous WALs and MANIFEST, db will be in consistent state // recovered from previous WALs and MANIFEST, db will be in consistent state
// and opens successfully. // and opens successfully.
{ {
options.avoid_flush_during_recovery = false;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs, ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, cf_descs,
&handles, &txn_db)); &handles, &txn_db));
for (auto* h : handles) { for (auto* h : handles) {
@ -1322,6 +1361,134 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, TxnDbCrashDuringRecovery) {
} }
} }
// This test is similar to
// CrashDuringRecoveryWithCorruptionTest.CrashDuringRecovery except it calls
// flush and corrupts Last WAL. It calls flush to sync some of the WALs and
// remaining are unsyned one of which is then corrupted to simulate crash.
//
// In case of non-TransactionDB with avoid_flush_during_recovery = true, RocksDB
// won't flush the data from WAL to L0 for all column families if possible. As a
// result, not all column families can increase their log_numbers, and
// min_log_number_to_keep won't change.
// It may prematurely persist a new MANIFEST even before we can declare the DB
// is in consistent state after recovery (this is when the new WAL is synced)
// and advances log_numbers for some column families.
//
// If there is power failure before we sync the new WAL, we will end up in
// a situation in which after persisting the MANIFEST, RocksDB will see some
// column families' log_numbers larger than the corrupted wal, and
// "Column family inconsistency: SST file contains data beyond the point of
// corruption" error will be hit, causing recovery to fail.
//
// After adding the fix, only after new WAL is synced, RocksDB persist a new
// MANIFEST with column families to ensure RocksDB is in consistent state.
// RocksDB writes an empty WriteBatch as a sentinel to the new WAL which is
// synced immediately afterwards. The sequence number of the sentinel
// WriteBatch will be the next sequence number immediately after the largest
// sequence number recovered from previous WALs and MANIFEST because of which DB
// will be in consistent state.
// If a future recovery starts from the new MANIFEST, then it means the new WAL
// is successfully synced. Due to the sentinel empty write batch at the
// beginning, kPointInTimeRecovery of WAL is guaranteed to go after this point.
// If future recovery starts from the old MANIFEST, it means the writing the new
// MANIFEST failed. It won't have the "SST ahead of WAL" error.
// The combination of corrupting a WAL and injecting an error during subsequent
// re-open exposes the bug of prematurely persisting a new MANIFEST with
// advanced ColumnFamilyData::log_number.
TEST_P(CrashDuringRecoveryWithCorruptionTest,
DISABLED_CrashDuringRecoveryWithFlush) {
CloseDb();
Options options;
options.wal_recovery_mode = WALRecoveryMode::kPointInTimeRecovery;
options.avoid_flush_during_recovery = false;
options.env = env_;
options.create_if_missing = true;
ASSERT_OK(DestroyDB(dbname_, options));
Reopen(&options);
ColumnFamilyHandle* cfh = nullptr;
const std::string test_cf_name = "test_cf";
Status s = db_->CreateColumnFamily(options, test_cf_name, &cfh);
ASSERT_OK(s);
delete cfh;
CloseDb();
std::vector<ColumnFamilyDescriptor> cf_descs;
cf_descs.emplace_back(kDefaultColumnFamilyName, options);
cf_descs.emplace_back(test_cf_name, options);
std::vector<ColumnFamilyHandle*> handles;
{
ASSERT_OK(DB::Open(options, dbname_, cf_descs, &handles, &db_));
// Write one key to test_cf.
ASSERT_OK(db_->Put(WriteOptions(), handles[1], "old_key", "dontcare"));
// Write to default_cf and flush this cf several times to advance wal
// number.
for (int i = 0; i < 2; ++i) {
ASSERT_OK(db_->Put(WriteOptions(), "key" + std::to_string(i), "value"));
ASSERT_OK(db_->Flush(FlushOptions()));
}
ASSERT_OK(db_->Put(WriteOptions(), handles[1], "dontcare", "dontcare"));
for (auto* h : handles) {
delete h;
}
handles.clear();
CloseDb();
}
// Corrupt second last un-syned wal file to emulate power reset which
// caused the DB to lose the un-synced WAL.
{
std::vector<uint64_t> file_nums;
GetSortedWalFiles(file_nums);
size_t size = file_nums.size();
uint64_t log_num = file_nums[size - 1];
CorruptFileWithTruncation(FileType::kWalFile, log_num,
/*bytes_to_truncate=*/8);
}
// Fault is injected to fail the recovery.
{
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
SyncPoint::GetInstance()->SetCallBack(
"DBImpl::GetLogSizeAndMaybeTruncate:0", [&](void* arg) {
auto* tmp_s = reinterpret_cast<Status*>(arg);
assert(tmp_s);
*tmp_s = Status::IOError("Injected");
});
SyncPoint::GetInstance()->EnableProcessing();
handles.clear();
options.avoid_flush_during_recovery = true;
s = DB::Open(options, dbname_, cf_descs, &handles, &db_);
ASSERT_TRUE(s.IsIOError());
ASSERT_EQ("IO error: Injected", s.ToString());
for (auto* h : handles) {
delete h;
}
CloseDb();
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
}
// Reopen db again
{
options.avoid_flush_during_recovery = avoid_flush_during_recovery_;
ASSERT_OK(DB::Open(options, dbname_, cf_descs, &handles, &db_));
for (auto* h : handles) {
delete h;
}
}
}
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE
int main(int argc, char** argv) { int main(int argc, char** argv) {

View File

@ -95,8 +95,8 @@ class CuckooTableDBTest : public testing::Test {
int NumTableFilesAtLevel(int level) { int NumTableFilesAtLevel(int level) {
std::string property; std::string property;
EXPECT_TRUE(db_->GetProperty("rocksdb.num-files-at-level" + ToString(level), EXPECT_TRUE(db_->GetProperty(
&property)); "rocksdb.num-files-at-level" + std::to_string(level), &property));
return atoi(property.c_str()); return atoi(property.c_str());
} }

View File

@ -3783,7 +3783,7 @@ TEST_P(DBBasicTestDeadline, PointLookupDeadline) {
Random rnd(301); Random rnd(301);
for (int i = 0; i < 400; ++i) { for (int i = 0; i < 400; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
ASSERT_OK(Put(key, rnd.RandomString(100))); ASSERT_OK(Put(key, rnd.RandomString(100)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -3866,7 +3866,7 @@ TEST_P(DBBasicTestDeadline, IteratorDeadline) {
Random rnd(301); Random rnd(301);
for (int i = 0; i < 400; ++i) { for (int i = 0; i < 400; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
ASSERT_OK(Put(key, rnd.RandomString(100))); ASSERT_OK(Put(key, rnd.RandomString(100)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());

View File

@ -13,6 +13,7 @@
#include "cache/cache_entry_roles.h" #include "cache/cache_entry_roles.h"
#include "cache/cache_key.h" #include "cache/cache_key.h"
#include "cache/fast_lru_cache.h"
#include "cache/lru_cache.h" #include "cache/lru_cache.h"
#include "db/column_family.h" #include "db/column_family.h"
#include "db/db_impl/db_impl.h" #include "db/db_impl/db_impl.h"
@ -75,7 +76,7 @@ class DBBlockCacheTest : public DBTestBase {
void InitTable(const Options& /*options*/) { void InitTable(const Options& /*options*/) {
std::string value(kValueSize, 'a'); std::string value(kValueSize, 'a');
for (size_t i = 0; i < kNumBlocks; i++) { for (size_t i = 0; i < kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value.c_str())); ASSERT_OK(Put(std::to_string(i), value.c_str()));
} }
} }
@ -204,7 +205,7 @@ TEST_F(DBBlockCacheTest, IteratorBlockCacheUsage) {
ASSERT_EQ(0, cache->GetUsage()); ASSERT_EQ(0, cache->GetUsage());
iter = db_->NewIterator(read_options); iter = db_->NewIterator(read_options);
iter->Seek(ToString(0)); iter->Seek(std::to_string(0));
ASSERT_LT(0, cache->GetUsage()); ASSERT_LT(0, cache->GetUsage());
delete iter; delete iter;
iter = nullptr; iter = nullptr;
@ -235,7 +236,7 @@ TEST_F(DBBlockCacheTest, TestWithoutCompressedBlockCache) {
// Load blocks into cache. // Load blocks into cache.
for (size_t i = 0; i + 1 < kNumBlocks; i++) { for (size_t i = 0; i + 1 < kNumBlocks; i++) {
iter = db_->NewIterator(read_options); iter = db_->NewIterator(read_options);
iter->Seek(ToString(i)); iter->Seek(std::to_string(i));
ASSERT_OK(iter->status()); ASSERT_OK(iter->status());
CheckCacheCounters(options, 1, 0, 1, 0); CheckCacheCounters(options, 1, 0, 1, 0);
iterators[i].reset(iter); iterators[i].reset(iter);
@ -248,7 +249,7 @@ TEST_F(DBBlockCacheTest, TestWithoutCompressedBlockCache) {
// Test with strict capacity limit. // Test with strict capacity limit.
cache->SetStrictCapacityLimit(true); cache->SetStrictCapacityLimit(true);
iter = db_->NewIterator(read_options); iter = db_->NewIterator(read_options);
iter->Seek(ToString(kNumBlocks - 1)); iter->Seek(std::to_string(kNumBlocks - 1));
ASSERT_TRUE(iter->status().IsIncomplete()); ASSERT_TRUE(iter->status().IsIncomplete());
CheckCacheCounters(options, 1, 0, 0, 1); CheckCacheCounters(options, 1, 0, 0, 1);
delete iter; delete iter;
@ -262,7 +263,7 @@ TEST_F(DBBlockCacheTest, TestWithoutCompressedBlockCache) {
ASSERT_EQ(0, cache->GetPinnedUsage()); ASSERT_EQ(0, cache->GetPinnedUsage());
for (size_t i = 0; i + 1 < kNumBlocks; i++) { for (size_t i = 0; i + 1 < kNumBlocks; i++) {
iter = db_->NewIterator(read_options); iter = db_->NewIterator(read_options);
iter->Seek(ToString(i)); iter->Seek(std::to_string(i));
ASSERT_OK(iter->status()); ASSERT_OK(iter->status());
CheckCacheCounters(options, 0, 1, 0, 0); CheckCacheCounters(options, 0, 1, 0, 0);
iterators[i].reset(iter); iterators[i].reset(iter);
@ -288,7 +289,7 @@ TEST_F(DBBlockCacheTest, TestWithCompressedBlockCache) {
std::string value(kValueSize, 'a'); std::string value(kValueSize, 'a');
for (size_t i = 0; i < kNumBlocks; i++) { for (size_t i = 0; i < kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value)); ASSERT_OK(Put(std::to_string(i), value));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -312,7 +313,7 @@ TEST_F(DBBlockCacheTest, TestWithCompressedBlockCache) {
// Load blocks into cache. // Load blocks into cache.
for (size_t i = 0; i < kNumBlocks - 1; i++) { for (size_t i = 0; i < kNumBlocks - 1; i++) {
ASSERT_EQ(value, Get(ToString(i))); ASSERT_EQ(value, Get(std::to_string(i)));
CheckCacheCounters(options, 1, 0, 1, 0); CheckCacheCounters(options, 1, 0, 1, 0);
CheckCompressedCacheCounters(options, 1, 0, 1, 0); CheckCompressedCacheCounters(options, 1, 0, 1, 0);
} }
@ -333,7 +334,7 @@ TEST_F(DBBlockCacheTest, TestWithCompressedBlockCache) {
// Load last key block. // Load last key block.
ASSERT_EQ("Result incomplete: Insert failed due to LRU cache being full.", ASSERT_EQ("Result incomplete: Insert failed due to LRU cache being full.",
Get(ToString(kNumBlocks - 1))); Get(std::to_string(kNumBlocks - 1)));
// Failure will also record the miss counter. // Failure will also record the miss counter.
CheckCacheCounters(options, 1, 0, 0, 1); CheckCacheCounters(options, 1, 0, 0, 1);
CheckCompressedCacheCounters(options, 1, 0, 1, 0); CheckCompressedCacheCounters(options, 1, 0, 1, 0);
@ -342,7 +343,7 @@ TEST_F(DBBlockCacheTest, TestWithCompressedBlockCache) {
// cache and load into block cache. // cache and load into block cache.
cache->SetStrictCapacityLimit(false); cache->SetStrictCapacityLimit(false);
// Load last key block. // Load last key block.
ASSERT_EQ(value, Get(ToString(kNumBlocks - 1))); ASSERT_EQ(value, Get(std::to_string(kNumBlocks - 1)));
CheckCacheCounters(options, 1, 0, 1, 0); CheckCacheCounters(options, 1, 0, 1, 0);
CheckCompressedCacheCounters(options, 0, 1, 0, 0); CheckCompressedCacheCounters(options, 0, 1, 0, 0);
} }
@ -567,7 +568,7 @@ TEST_F(DBBlockCacheTest, FillCacheAndIterateDB) {
Iterator* iter = nullptr; Iterator* iter = nullptr;
iter = db_->NewIterator(read_options); iter = db_->NewIterator(read_options);
iter->Seek(ToString(0)); iter->Seek(std::to_string(0));
while (iter->Valid()) { while (iter->Valid()) {
iter->Next(); iter->Next();
} }
@ -645,10 +646,10 @@ TEST_F(DBBlockCacheTest, WarmCacheWithDataBlocksDuringFlush) {
std::string value(kValueSize, 'a'); std::string value(kValueSize, 'a');
for (size_t i = 1; i <= kNumBlocks; i++) { for (size_t i = 1; i <= kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value)); ASSERT_OK(Put(std::to_string(i), value));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD));
ASSERT_EQ(value, Get(ToString(i))); ASSERT_EQ(value, Get(std::to_string(i)));
ASSERT_EQ(0, options.statistics->getTickerCount(BLOCK_CACHE_DATA_MISS)); ASSERT_EQ(0, options.statistics->getTickerCount(BLOCK_CACHE_DATA_MISS));
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_HIT)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_HIT));
} }
@ -705,7 +706,7 @@ TEST_P(DBBlockCacheTest1, WarmCacheWithBlocksDuringFlush) {
std::string value(kValueSize, 'a'); std::string value(kValueSize, 'a');
for (size_t i = 1; i <= kNumBlocks; i++) { for (size_t i = 1; i <= kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value)); ASSERT_OK(Put(std::to_string(i), value));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD));
if (filter_type == 1) { if (filter_type == 1) {
@ -717,7 +718,7 @@ TEST_P(DBBlockCacheTest1, WarmCacheWithBlocksDuringFlush) {
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_INDEX_ADD)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_INDEX_ADD));
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_FILTER_ADD)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_FILTER_ADD));
} }
ASSERT_EQ(value, Get(ToString(i))); ASSERT_EQ(value, Get(std::to_string(i)));
ASSERT_EQ(0, options.statistics->getTickerCount(BLOCK_CACHE_DATA_MISS)); ASSERT_EQ(0, options.statistics->getTickerCount(BLOCK_CACHE_DATA_MISS));
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_HIT)); ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_HIT));
@ -772,12 +773,12 @@ TEST_F(DBBlockCacheTest, DynamicallyWarmCacheDuringFlush) {
std::string value(kValueSize, 'a'); std::string value(kValueSize, 'a');
for (size_t i = 1; i <= 5; i++) { for (size_t i = 1; i <= 5; i++) {
ASSERT_OK(Put(ToString(i), value)); ASSERT_OK(Put(std::to_string(i), value));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_EQ(1, ASSERT_EQ(1,
options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD)); options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
ASSERT_EQ(value, Get(ToString(i))); ASSERT_EQ(value, Get(std::to_string(i)));
ASSERT_EQ(0, ASSERT_EQ(0,
options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD)); options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
ASSERT_EQ( ASSERT_EQ(
@ -790,12 +791,12 @@ TEST_F(DBBlockCacheTest, DynamicallyWarmCacheDuringFlush) {
{{"block_based_table_factory", "{prepopulate_block_cache=kDisable;}"}})); {{"block_based_table_factory", "{prepopulate_block_cache=kDisable;}"}}));
for (size_t i = 6; i <= kNumBlocks; i++) { for (size_t i = 6; i <= kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value)); ASSERT_OK(Put(std::to_string(i), value));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_EQ(0, ASSERT_EQ(0,
options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD)); options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
ASSERT_EQ(value, Get(ToString(i))); ASSERT_EQ(value, Get(std::to_string(i)));
ASSERT_EQ(1, ASSERT_EQ(1,
options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD)); options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
ASSERT_EQ( ASSERT_EQ(
@ -934,7 +935,8 @@ TEST_F(DBBlockCacheTest, AddRedundantStats) {
int iterations_tested = 0; int iterations_tested = 0;
for (std::shared_ptr<Cache> base_cache : for (std::shared_ptr<Cache> base_cache :
{NewLRUCache(capacity, num_shard_bits), {NewLRUCache(capacity, num_shard_bits),
NewClockCache(capacity, num_shard_bits)}) { NewClockCache(capacity, num_shard_bits),
NewFastLRUCache(capacity, num_shard_bits)}) {
if (!base_cache) { if (!base_cache) {
// Skip clock cache when not supported // Skip clock cache when not supported
continue; continue;
@ -1288,7 +1290,8 @@ TEST_F(DBBlockCacheTest, CacheEntryRoleStats) {
int iterations_tested = 0; int iterations_tested = 0;
for (bool partition : {false, true}) { for (bool partition : {false, true}) {
for (std::shared_ptr<Cache> cache : for (std::shared_ptr<Cache> cache :
{NewLRUCache(capacity), NewClockCache(capacity)}) { {NewLRUCache(capacity), NewClockCache(capacity),
NewFastLRUCache(capacity)}) {
if (!cache) { if (!cache) {
// Skip clock cache when not supported // Skip clock cache when not supported
continue; continue;
@ -1406,7 +1409,7 @@ TEST_F(DBBlockCacheTest, CacheEntryRoleStats) {
for (size_t i = 0; i < kNumCacheEntryRoles; ++i) { for (size_t i = 0; i < kNumCacheEntryRoles; ++i) {
auto role = static_cast<CacheEntryRole>(i); auto role = static_cast<CacheEntryRole>(i);
EXPECT_EQ(ToString(expected[i]), EXPECT_EQ(std::to_string(expected[i]),
values[BlockCacheEntryStatsMapKeys::EntryCount(role)]); values[BlockCacheEntryStatsMapKeys::EntryCount(role)]);
} }
@ -1419,7 +1422,7 @@ TEST_F(DBBlockCacheTest, CacheEntryRoleStats) {
// re-scanning stats, but not totally aggressive. // re-scanning stats, but not totally aggressive.
// Within some time window, we will get cached entry stats // Within some time window, we will get cached entry stats
env_->MockSleepForSeconds(1); env_->MockSleepForSeconds(1);
EXPECT_EQ(ToString(prev_expected[static_cast<size_t>( EXPECT_EQ(std::to_string(prev_expected[static_cast<size_t>(
CacheEntryRole::kWriteBuffer)]), CacheEntryRole::kWriteBuffer)]),
values[BlockCacheEntryStatsMapKeys::EntryCount( values[BlockCacheEntryStatsMapKeys::EntryCount(
CacheEntryRole::kWriteBuffer)]); CacheEntryRole::kWriteBuffer)]);
@ -1429,7 +1432,7 @@ TEST_F(DBBlockCacheTest, CacheEntryRoleStats) {
ASSERT_TRUE(db_->GetMapProperty(DB::Properties::kBlockCacheEntryStats, ASSERT_TRUE(db_->GetMapProperty(DB::Properties::kBlockCacheEntryStats,
&values)); &values));
EXPECT_EQ( EXPECT_EQ(
ToString( std::to_string(
expected[static_cast<size_t>(CacheEntryRole::kWriteBuffer)]), expected[static_cast<size_t>(CacheEntryRole::kWriteBuffer)]),
values[BlockCacheEntryStatsMapKeys::EntryCount( values[BlockCacheEntryStatsMapKeys::EntryCount(
CacheEntryRole::kWriteBuffer)]); CacheEntryRole::kWriteBuffer)]);
@ -1637,7 +1640,7 @@ TEST_P(DBBlockCacheKeyTest, StableCacheKeys) {
SstFileWriter sst_file_writer(EnvOptions(), options); SstFileWriter sst_file_writer(EnvOptions(), options);
std::vector<std::string> external; std::vector<std::string> external;
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
std::string f = dbname_ + "/external" + ToString(i) + ".sst"; std::string f = dbname_ + "/external" + std::to_string(i) + ".sst";
external.push_back(f); external.push_back(f);
ASSERT_OK(sst_file_writer.Open(f)); ASSERT_OK(sst_file_writer.Open(f));
ASSERT_OK(sst_file_writer.Put(Key(key_count), "abc")); ASSERT_OK(sst_file_writer.Put(Key(key_count), "abc"));
@ -1721,7 +1724,7 @@ class CacheKeyTest : public testing::Test {
// Like SemiStructuredUniqueIdGen::GenerateNext // Like SemiStructuredUniqueIdGen::GenerateNext
tp_.db_session_id = EncodeSessionId(base_session_upper_, tp_.db_session_id = EncodeSessionId(base_session_upper_,
base_session_lower_ ^ session_counter_); base_session_lower_ ^ session_counter_);
tp_.db_id = ToString(db_id_); tp_.db_id = std::to_string(db_id_);
tp_.orig_file_number = file_number_; tp_.orig_file_number = file_number_;
bool is_stable; bool is_stable;
std::string cur_session_id = ""; // ignored std::string cur_session_id = ""; // ignored

View File

@ -858,7 +858,7 @@ TEST_F(DBBloomFilterTest, BloomFilterCompatibility) {
options.table_factory.reset(NewBlockBasedTableFactory(table_options)); options.table_factory.reset(NewBlockBasedTableFactory(table_options));
Reopen(options); Reopen(options);
std::string prefix = ToString(i) + "_"; std::string prefix = std::to_string(i) + "_";
ASSERT_OK(Put(prefix + "A", "val")); ASSERT_OK(Put(prefix + "A", "val"));
ASSERT_OK(Put(prefix + "Z", "val")); ASSERT_OK(Put(prefix + "Z", "val"));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -873,7 +873,7 @@ TEST_F(DBBloomFilterTest, BloomFilterCompatibility) {
options.table_factory.reset(NewBlockBasedTableFactory(table_options)); options.table_factory.reset(NewBlockBasedTableFactory(table_options));
Reopen(options); Reopen(options);
for (size_t j = 0; j < kCompatibilityConfigs.size(); ++j) { for (size_t j = 0; j < kCompatibilityConfigs.size(); ++j) {
std::string prefix = ToString(j) + "_"; std::string prefix = std::to_string(j) + "_";
ASSERT_EQ("val", Get(prefix + "A")); // Filter positive ASSERT_EQ("val", Get(prefix + "A")); // Filter positive
ASSERT_EQ("val", Get(prefix + "Z")); // Filter positive ASSERT_EQ("val", Get(prefix + "Z")); // Filter positive
// Filter negative, with high probability // Filter negative, with high probability
@ -1713,11 +1713,11 @@ class TestingContextCustomFilterPolicy
test_report_ += test_report_ +=
OptionsHelper::compaction_style_to_string[context.compaction_style]; OptionsHelper::compaction_style_to_string[context.compaction_style];
test_report_ += ",n="; test_report_ += ",n=";
test_report_ += ROCKSDB_NAMESPACE::ToString(context.num_levels); test_report_ += std::to_string(context.num_levels);
test_report_ += ",l="; test_report_ += ",l=";
test_report_ += ROCKSDB_NAMESPACE::ToString(context.level_at_creation); test_report_ += std::to_string(context.level_at_creation);
test_report_ += ",b="; test_report_ += ",b=";
test_report_ += ROCKSDB_NAMESPACE::ToString(int{context.is_bottommost}); test_report_ += std::to_string(int{context.is_bottommost});
test_report_ += ",r="; test_report_ += ",r=";
test_report_ += table_file_creation_reason_to_string[context.reason]; test_report_ += table_file_creation_reason_to_string[context.reason];
test_report_ += "\n"; test_report_ += "\n";

View File

@ -454,7 +454,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterDeletesAll) {
// put some data // put some data
for (int table = 0; table < 4; ++table) { for (int table = 0; table < 4; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(ToString(table * 100 + i), "val")); ASSERT_OK(Put(std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -755,7 +755,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterContextCfId) {
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
// Compaction filters aplies to all records, regardless snapshots. // Compaction filters aplies to all records, regardless snapshots.
TEST_F(DBTestCompactionFilter, CompactionFilterIgnoreSnapshot) { TEST_F(DBTestCompactionFilter, CompactionFilterIgnoreSnapshot) {
std::string five = ToString(5); std::string five = std::to_string(5);
Options options = CurrentOptions(); Options options = CurrentOptions();
options.compaction_filter_factory = std::make_shared<DeleteISFilterFactory>(); options.compaction_filter_factory = std::make_shared<DeleteISFilterFactory>();
options.disable_auto_compactions = true; options.disable_auto_compactions = true;
@ -766,7 +766,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterIgnoreSnapshot) {
const Snapshot* snapshot = nullptr; const Snapshot* snapshot = nullptr;
for (int table = 0; table < 4; ++table) { for (int table = 0; table < 4; ++table) {
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
ASSERT_OK(Put(ToString(table * 100 + i), "val")); ASSERT_OK(Put(std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -998,7 +998,7 @@ TEST_F(DBTestCompactionFilter, DropKeyWithSingleDelete) {
std::string* /*new_value*/, std::string* /*new_value*/,
std::string* /*skip_until*/) const override { std::string* /*skip_until*/) const override {
if (key.starts_with("b")) { if (key.starts_with("b")) {
return Decision::kRemoveWithSingleDelete; return Decision::kPurge;
} }
return Decision::kRemove; return Decision::kRemove;
} }

View File

@ -2817,7 +2817,7 @@ TEST_P(DBCompactionTestWithParam, DISABLED_CompactFilesOnLevelCompaction) {
Random rnd(301); Random rnd(301);
for (int key = 64 * kEntriesPerBuffer; key >= 0; --key) { for (int key = 64 * kEntriesPerBuffer; key >= 0; --key) {
ASSERT_OK(Put(1, ToString(key), rnd.RandomString(kTestValueSize))); ASSERT_OK(Put(1, std::to_string(key), rnd.RandomString(kTestValueSize)));
} }
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[1])); ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[1]));
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -2849,7 +2849,7 @@ TEST_P(DBCompactionTestWithParam, DISABLED_CompactFilesOnLevelCompaction) {
// make sure all key-values are still there. // make sure all key-values are still there.
for (int key = 64 * kEntriesPerBuffer; key >= 0; --key) { for (int key = 64 * kEntriesPerBuffer; key >= 0; --key) {
ASSERT_NE(Get(1, ToString(key)), "NOT_FOUND"); ASSERT_NE(Get(1, std::to_string(key)), "NOT_FOUND");
} }
} }
@ -4404,7 +4404,8 @@ TEST_F(DBCompactionTest, LevelPeriodicCompactionWithCompactionFilters) {
for (CompactionFilterType comp_filter_type : for (CompactionFilterType comp_filter_type :
{kUseCompactionFilter, kUseCompactionFilterFactory}) { {kUseCompactionFilter, kUseCompactionFilterFactory}) {
// Assert that periodic compactions are not enabled. // Assert that periodic compactions are not enabled.
ASSERT_EQ(port::kMaxUint64 - 1, options.periodic_compaction_seconds); ASSERT_EQ(std::numeric_limits<uint64_t>::max() - 1,
options.periodic_compaction_seconds);
if (comp_filter_type == kUseCompactionFilter) { if (comp_filter_type == kUseCompactionFilter) {
options.compaction_filter = &test_compaction_filter; options.compaction_filter = &test_compaction_filter;
@ -4667,9 +4668,9 @@ TEST_F(DBCompactionTest, CompactRangeSkipFlushAfterDelay) {
}); });
TEST_SYNC_POINT("DBCompactionTest::CompactRangeSkipFlushAfterDelay:PreFlush"); TEST_SYNC_POINT("DBCompactionTest::CompactRangeSkipFlushAfterDelay:PreFlush");
ASSERT_OK(Put(ToString(0), rnd.RandomString(1024))); ASSERT_OK(Put(std::to_string(0), rnd.RandomString(1024)));
ASSERT_OK(dbfull()->Flush(flush_opts)); ASSERT_OK(dbfull()->Flush(flush_opts));
ASSERT_OK(Put(ToString(0), rnd.RandomString(1024))); ASSERT_OK(Put(std::to_string(0), rnd.RandomString(1024)));
TEST_SYNC_POINT("DBCompactionTest::CompactRangeSkipFlushAfterDelay:PostFlush"); TEST_SYNC_POINT("DBCompactionTest::CompactRangeSkipFlushAfterDelay:PostFlush");
manual_compaction_thread.join(); manual_compaction_thread.join();
@ -4678,7 +4679,7 @@ TEST_F(DBCompactionTest, CompactRangeSkipFlushAfterDelay) {
std::string num_keys_in_memtable; std::string num_keys_in_memtable;
ASSERT_TRUE(db_->GetProperty(DB::Properties::kNumEntriesActiveMemTable, ASSERT_TRUE(db_->GetProperty(DB::Properties::kNumEntriesActiveMemTable,
&num_keys_in_memtable)); &num_keys_in_memtable));
ASSERT_EQ(ToString(1), num_keys_in_memtable); ASSERT_EQ(std::to_string(1), num_keys_in_memtable);
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
} }
@ -4827,7 +4828,7 @@ TEST_F(DBCompactionTest, SubcompactionEvent) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 10 + j; int key_id = i * 10 + j;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -4837,7 +4838,7 @@ TEST_F(DBCompactionTest, SubcompactionEvent) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
int key_id = i * 20 + j * 2; int key_id = i * 20 + j * 2;
ASSERT_OK(Put(Key(key_id), "value" + ToString(key_id))); ASSERT_OK(Put(Key(key_id), "value" + std::to_string(key_id)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -5829,7 +5830,7 @@ TEST_P(DBCompactionTestWithBottommostParam, SequenceKeysManualCompaction) {
} }
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable()); ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
ASSERT_EQ(ToString(kSstNum), FilesPerLevel(0)); ASSERT_EQ(std::to_string(kSstNum), FilesPerLevel(0));
auto cro = CompactRangeOptions(); auto cro = CompactRangeOptions();
cro.bottommost_level_compaction = bottommost_level_compaction_; cro.bottommost_level_compaction = bottommost_level_compaction_;
@ -5842,7 +5843,7 @@ TEST_P(DBCompactionTestWithBottommostParam, SequenceKeysManualCompaction) {
ASSERT_EQ("0,1", FilesPerLevel(0)); ASSERT_EQ("0,1", FilesPerLevel(0));
} else { } else {
// Just trivial move from level 0 -> 1 // Just trivial move from level 0 -> 1
ASSERT_EQ("0," + ToString(kSstNum), FilesPerLevel(0)); ASSERT_EQ("0," + std::to_string(kSstNum), FilesPerLevel(0));
} }
} }
@ -7173,7 +7174,7 @@ TEST_F(DBCompactionTest, DisableManualCompactionThreadQueueFull) {
ASSERT_OK(Put(Key(2), "value2")); ASSERT_OK(Put(Key(2), "value2"));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_EQ(ToString(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0)); ASSERT_EQ(std::to_string(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0));
db_->DisableManualCompaction(); db_->DisableManualCompaction();
@ -7230,7 +7231,7 @@ TEST_F(DBCompactionTest, DisableManualCompactionThreadQueueFullDBClose) {
ASSERT_OK(Put(Key(2), "value2")); ASSERT_OK(Put(Key(2), "value2"));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_EQ(ToString(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0)); ASSERT_EQ(std::to_string(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0));
db_->DisableManualCompaction(); db_->DisableManualCompaction();
@ -7290,7 +7291,7 @@ TEST_F(DBCompactionTest, DBCloseWithManualCompaction) {
ASSERT_OK(Put(Key(2), "value2")); ASSERT_OK(Put(Key(2), "value2"));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_EQ(ToString(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0)); ASSERT_EQ(std::to_string(kNumL0Files + (kNumL0Files / 2)), FilesPerLevel(0));
// Close DB with manual compaction and auto triggered compaction in the queue. // Close DB with manual compaction and auto triggered compaction in the queue.
auto s = db_->Close(); auto s = db_->Close();

View File

@ -177,7 +177,7 @@ Status DBImpl::GetLiveFilesStorageInfo(
VectorLogPtr live_wal_files; VectorLogPtr live_wal_files;
bool flush_memtable = true; bool flush_memtable = true;
if (!immutable_db_options_.allow_2pc) { if (!immutable_db_options_.allow_2pc) {
if (opts.wal_size_for_flush == port::kMaxUint64) { if (opts.wal_size_for_flush == std::numeric_limits<uint64_t>::max()) {
flush_memtable = false; flush_memtable = false;
} else if (opts.wal_size_for_flush > 0) { } else if (opts.wal_size_for_flush > 0) {
// If the outstanding log files are small, we skip the flush. // If the outstanding log files are small, we skip the flush.

View File

@ -2356,7 +2356,7 @@ TEST_P(DBAtomicFlushTest, PrecomputeMinLogNumberToKeepNon2PC) {
ASSERT_OK(Flush(cf_ids)); ASSERT_OK(Flush(cf_ids));
uint64_t log_num_after_flush = dbfull()->TEST_GetCurrentLogNumber(); uint64_t log_num_after_flush = dbfull()->TEST_GetCurrentLogNumber();
uint64_t min_log_number_to_keep = port::kMaxUint64; uint64_t min_log_number_to_keep = std::numeric_limits<uint64_t>::max();
autovector<ColumnFamilyData*> flushed_cfds; autovector<ColumnFamilyData*> flushed_cfds;
autovector<autovector<VersionEdit*>> flush_edits; autovector<autovector<VersionEdit*>> flush_edits;
for (size_t i = 0; i != num_cfs; ++i) { for (size_t i = 0; i != num_cfs; ++i) {

View File

@ -567,7 +567,7 @@ Status DBImpl::CloseHelper() {
// flushing by first checking if there is a need for // flushing by first checking if there is a need for
// flushing (but need to implement something // flushing (but need to implement something
// else than imm()->IsFlushPending() because the output // else than imm()->IsFlushPending() because the output
// memtables added to imm() dont trigger flushes). // memtables added to imm() don't trigger flushes).
if (immutable_db_options_.experimental_mempurge_threshold > 0.0) { if (immutable_db_options_.experimental_mempurge_threshold > 0.0) {
Status flush_ret; Status flush_ret;
mutex_.Unlock(); mutex_.Unlock();
@ -849,7 +849,8 @@ void DBImpl::PersistStats() {
if (stats_slice_.find(stat.first) != stats_slice_.end()) { if (stats_slice_.find(stat.first) != stats_slice_.end()) {
uint64_t delta = stat.second - stats_slice_[stat.first]; uint64_t delta = stat.second - stats_slice_[stat.first];
s = batch.Put(persist_stats_cf_handle_, s = batch.Put(persist_stats_cf_handle_,
Slice(key, std::min(100, length)), ToString(delta)); Slice(key, std::min(100, length)),
std::to_string(delta));
} }
} }
} }
@ -3355,7 +3356,7 @@ bool DBImpl::GetProperty(ColumnFamilyHandle* column_family,
bool ret_value = bool ret_value =
GetIntPropertyInternal(cfd, *property_info, false, &int_value); GetIntPropertyInternal(cfd, *property_info, false, &int_value);
if (ret_value) { if (ret_value) {
*value = ToString(int_value); *value = std::to_string(int_value);
} }
return ret_value; return ret_value;
} else if (property_info->handle_string) { } else if (property_info->handle_string) {
@ -3990,8 +3991,8 @@ Status DBImpl::CheckConsistency() {
} else if (fsize != md.size) { } else if (fsize != md.size) {
corruption_messages += "Sst file size mismatch: " + file_path + corruption_messages += "Sst file size mismatch: " + file_path +
". Size recorded in manifest " + ". Size recorded in manifest " +
ToString(md.size) + ", actual size " + std::to_string(md.size) + ", actual size " +
ToString(fsize) + "\n"; std::to_string(fsize) + "\n";
} }
} }
} }
@ -5338,7 +5339,7 @@ Status DBImpl::ReserveFileNumbersBeforeIngestion(
Status DBImpl::GetCreationTimeOfOldestFile(uint64_t* creation_time) { Status DBImpl::GetCreationTimeOfOldestFile(uint64_t* creation_time) {
if (mutable_db_options_.max_open_files == -1) { if (mutable_db_options_.max_open_files == -1) {
uint64_t oldest_time = port::kMaxUint64; uint64_t oldest_time = std::numeric_limits<uint64_t>::max();
for (auto cfd : *versions_->GetColumnFamilySet()) { for (auto cfd : *versions_->GetColumnFamilySet()) {
if (!cfd->IsDropped()) { if (!cfd->IsDropped()) {
uint64_t ctime; uint64_t ctime;

View File

@ -2299,7 +2299,7 @@ class DBImpl : public DB {
static const int KEEP_LOG_FILE_NUM = 1000; static const int KEEP_LOG_FILE_NUM = 1000;
// MSVC version 1800 still does not have constexpr for ::max() // MSVC version 1800 still does not have constexpr for ::max()
static const uint64_t kNoTimeOut = port::kMaxUint64; static const uint64_t kNoTimeOut = std::numeric_limits<uint64_t>::max();
std::string db_absolute_path_; std::string db_absolute_path_;

View File

@ -188,7 +188,7 @@ Status DBImpl::FlushMemTableToOutputFile(
// a memtable without knowing such snapshot(s). // a memtable without knowing such snapshot(s).
uint64_t max_memtable_id = needs_to_sync_closed_wals uint64_t max_memtable_id = needs_to_sync_closed_wals
? cfd->imm()->GetLatestMemTableID() ? cfd->imm()->GetLatestMemTableID()
: port::kMaxUint64; : std::numeric_limits<uint64_t>::max();
// If needs_to_sync_closed_wals is false, then the flush job will pick ALL // If needs_to_sync_closed_wals is false, then the flush job will pick ALL
// existing memtables of the column family when PickMemTable() is called // existing memtables of the column family when PickMemTable() is called
@ -1041,7 +1041,8 @@ Status DBImpl::CompactRangeInternal(const CompactRangeOptions& options,
} }
s = RunManualCompaction(cfd, ColumnFamilyData::kCompactAllLevels, s = RunManualCompaction(cfd, ColumnFamilyData::kCompactAllLevels,
final_output_level, options, begin, end, exclusive, final_output_level, options, begin, end, exclusive,
false, port::kMaxUint64, trim_ts); false, std::numeric_limits<uint64_t>::max(),
trim_ts);
} else { } else {
int first_overlapped_level = kInvalidLevel; int first_overlapped_level = kInvalidLevel;
int max_overlapped_level = kInvalidLevel; int max_overlapped_level = kInvalidLevel;
@ -1078,7 +1079,7 @@ Status DBImpl::CompactRangeInternal(const CompactRangeOptions& options,
if (s.ok() && first_overlapped_level != kInvalidLevel) { if (s.ok() && first_overlapped_level != kInvalidLevel) {
// max_file_num_to_ignore can be used to filter out newly created SST // max_file_num_to_ignore can be used to filter out newly created SST
// files, useful for bottom level compaction in a manual compaction // files, useful for bottom level compaction in a manual compaction
uint64_t max_file_num_to_ignore = port::kMaxUint64; uint64_t max_file_num_to_ignore = std::numeric_limits<uint64_t>::max();
uint64_t next_file_number = versions_->current_next_file_number(); uint64_t next_file_number = versions_->current_next_file_number();
final_output_level = max_overlapped_level; final_output_level = max_overlapped_level;
int output_level; int output_level;
@ -1704,11 +1705,9 @@ Status DBImpl::Flush(const FlushOptions& flush_options,
Status s; Status s;
if (immutable_db_options_.atomic_flush) { if (immutable_db_options_.atomic_flush) {
s = AtomicFlushMemTables({cfh->cfd()}, flush_options, s = AtomicFlushMemTables({cfh->cfd()}, flush_options,
FlushReason::kManualFlush, FlushReason::kManualFlush);
write_controller().IsStopped());
} else { } else {
s = FlushMemTable(cfh->cfd(), flush_options, FlushReason::kManualFlush, s = FlushMemTable(cfh->cfd(), flush_options, FlushReason::kManualFlush);
write_controller().IsStopped());
} }
ROCKS_LOG_INFO(immutable_db_options_.info_log, ROCKS_LOG_INFO(immutable_db_options_.info_log,
@ -2015,7 +2014,7 @@ Status DBImpl::FlushMemTable(ColumnFamilyData* cfd,
// be created and scheduled, status::OK() will be returned. // be created and scheduled, status::OK() will be returned.
s = SwitchMemtable(cfd, &context); s = SwitchMemtable(cfd, &context);
} }
const uint64_t flush_memtable_id = port::kMaxUint64; const uint64_t flush_memtable_id = std::numeric_limits<uint64_t>::max();
if (s.ok()) { if (s.ok()) {
if (cfd->imm()->NumNotFlushed() != 0 || !cfd->mem()->IsEmpty() || if (cfd->imm()->NumNotFlushed() != 0 || !cfd->mem()->IsEmpty() ||
!cached_recoverable_state_empty_.load()) { !cached_recoverable_state_empty_.load()) {

View File

@ -118,10 +118,11 @@ Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
cfd->ioptions()->compaction_style == kCompactionStyleFIFO) cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
? level ? level
: level + 1; : level + 1;
return RunManualCompaction(cfd, level, output_level, CompactRangeOptions(), return RunManualCompaction(
begin, end, true, disallow_trivial_move, cfd, level, output_level, CompactRangeOptions(), begin, end, true,
port::kMaxUint64 /*max_file_num_to_ignore*/, disallow_trivial_move,
"" /*trim_ts*/); std::numeric_limits<uint64_t>::max() /*max_file_num_to_ignore*/,
"" /*trim_ts*/);
} }
Status DBImpl::TEST_SwitchMemtable(ColumnFamilyData* cfd) { Status DBImpl::TEST_SwitchMemtable(ColumnFamilyData* cfd) {

View File

@ -761,7 +761,7 @@ uint64_t PrecomputeMinLogNumberToKeepNon2PC(
assert(!cfds_to_flush.empty()); assert(!cfds_to_flush.empty());
assert(cfds_to_flush.size() == edit_lists.size()); assert(cfds_to_flush.size() == edit_lists.size());
uint64_t min_log_number_to_keep = port::kMaxUint64; uint64_t min_log_number_to_keep = std::numeric_limits<uint64_t>::max();
for (const auto& edit_list : edit_lists) { for (const auto& edit_list : edit_lists) {
uint64_t log = 0; uint64_t log = 0;
for (const auto& e : edit_list) { for (const auto& e : edit_list) {
@ -773,7 +773,7 @@ uint64_t PrecomputeMinLogNumberToKeepNon2PC(
min_log_number_to_keep = std::min(min_log_number_to_keep, log); min_log_number_to_keep = std::min(min_log_number_to_keep, log);
} }
} }
if (min_log_number_to_keep == port::kMaxUint64) { if (min_log_number_to_keep == std::numeric_limits<uint64_t>::max()) {
min_log_number_to_keep = cfds_to_flush[0]->GetLogNumber(); min_log_number_to_keep = cfds_to_flush[0]->GetLogNumber();
for (size_t i = 1; i < cfds_to_flush.size(); i++) { for (size_t i = 1; i < cfds_to_flush.size(); i++) {
min_log_number_to_keep = min_log_number_to_keep =

View File

@ -760,11 +760,11 @@ Status DBImpl::PersistentStatsProcessFormatVersion() {
WriteBatch batch; WriteBatch batch;
if (s.ok()) { if (s.ok()) {
s = batch.Put(persist_stats_cf_handle_, kFormatVersionKeyString, s = batch.Put(persist_stats_cf_handle_, kFormatVersionKeyString,
ToString(kStatsCFCurrentFormatVersion)); std::to_string(kStatsCFCurrentFormatVersion));
} }
if (s.ok()) { if (s.ok()) {
s = batch.Put(persist_stats_cf_handle_, kCompatibleVersionKeyString, s = batch.Put(persist_stats_cf_handle_, kCompatibleVersionKeyString,
ToString(kStatsCFCompatibleFormatVersion)); std::to_string(kStatsCFCompatibleFormatVersion));
} }
if (s.ok()) { if (s.ok()) {
WriteOptions wo; WriteOptions wo;
@ -1326,6 +1326,7 @@ Status DBImpl::GetLogSizeAndMaybeTruncate(uint64_t wal_number, bool truncate,
Status s; Status s;
// This gets the appear size of the wals, not including preallocated space. // This gets the appear size of the wals, not including preallocated space.
s = env_->GetFileSize(fname, &log.size); s = env_->GetFileSize(fname, &log.size);
TEST_SYNC_POINT_CALLBACK("DBImpl::GetLogSizeAndMaybeTruncate:0", /*arg=*/&s);
if (s.ok() && truncate) { if (s.ok() && truncate) {
std::unique_ptr<FSWritableFile> last_log; std::unique_ptr<FSWritableFile> last_log;
Status truncate_status = fs_->ReopenWritableFile( Status truncate_status = fs_->ReopenWritableFile(
@ -1825,6 +1826,7 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname,
if (s.ok()) { if (s.ok()) {
// Need to fsync, otherwise it might get lost after a power reset. // Need to fsync, otherwise it might get lost after a power reset.
s = impl->FlushWAL(false); s = impl->FlushWAL(false);
TEST_SYNC_POINT_CALLBACK("DBImpl::Open::BeforeSyncWAL", /*arg=*/&s);
if (s.ok()) { if (s.ok()) {
s = log_writer->file()->Sync(impl->immutable_db_options_.use_fsync); s = log_writer->file()->Sync(impl->immutable_db_options_.use_fsync);
} }

View File

@ -247,15 +247,16 @@ Status DBImplSecondary::RecoverLogFiles(
if (seq_of_batch <= seq) { if (seq_of_batch <= seq) {
continue; continue;
} }
auto curr_log_num = port::kMaxUint64; auto curr_log_num = std::numeric_limits<uint64_t>::max();
if (cfd_to_current_log_.count(cfd) > 0) { if (cfd_to_current_log_.count(cfd) > 0) {
curr_log_num = cfd_to_current_log_[cfd]; curr_log_num = cfd_to_current_log_[cfd];
} }
// If the active memtable contains records added by replaying an // If the active memtable contains records added by replaying an
// earlier WAL, then we need to seal the memtable, add it to the // earlier WAL, then we need to seal the memtable, add it to the
// immutable memtable list and create a new active memtable. // immutable memtable list and create a new active memtable.
if (!cfd->mem()->IsEmpty() && (curr_log_num == port::kMaxUint64 || if (!cfd->mem()->IsEmpty() &&
curr_log_num != log_number)) { (curr_log_num == std::numeric_limits<uint64_t>::max() ||
curr_log_num != log_number)) {
const MutableCFOptions mutable_cf_options = const MutableCFOptions mutable_cf_options =
*cfd->GetLatestMutableCFOptions(); *cfd->GetLatestMutableCFOptions();
MemTable* new_mem = MemTable* new_mem =

View File

@ -35,10 +35,12 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
Header(options.info_log, "DB SUMMARY\n"); Header(options.info_log, "DB SUMMARY\n");
Header(options.info_log, "DB Session ID: %s\n", session_id.c_str()); Header(options.info_log, "DB Session ID: %s\n", session_id.c_str());
Status s;
// Get files in dbname dir // Get files in dbname dir
if (!env->GetChildren(dbname, &files).ok()) { s = env->GetChildren(dbname, &files);
Error(options.info_log, if (!s.ok()) {
"Error when reading %s dir\n", dbname.c_str()); Error(options.info_log, "Error when reading %s dir %s\n", dbname.c_str(),
s.ToString().c_str());
} }
std::sort(files.begin(), files.end()); std::sort(files.begin(), files.end());
for (const std::string& file : files) { for (const std::string& file : files) {
@ -53,24 +55,27 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
Header(options.info_log, "IDENTITY file: %s\n", file.c_str()); Header(options.info_log, "IDENTITY file: %s\n", file.c_str());
break; break;
case kDescriptorFile: case kDescriptorFile:
if (env->GetFileSize(dbname + "/" + file, &file_size).ok()) { s = env->GetFileSize(dbname + "/" + file, &file_size);
if (s.ok()) {
Header(options.info_log, Header(options.info_log,
"MANIFEST file: %s size: %" PRIu64 " Bytes\n", file.c_str(), "MANIFEST file: %s size: %" PRIu64 " Bytes\n", file.c_str(),
file_size); file_size);
} else { } else {
Error(options.info_log, "Error when reading MANIFEST file: %s/%s\n", Error(options.info_log,
dbname.c_str(), file.c_str()); "Error when reading MANIFEST file: %s/%s %s\n", dbname.c_str(),
file.c_str(), s.ToString().c_str());
} }
break; break;
case kWalFile: case kWalFile:
if (env->GetFileSize(dbname + "/" + file, &file_size).ok()) { s = env->GetFileSize(dbname + "/" + file, &file_size);
if (s.ok()) {
wal_info.append(file) wal_info.append(file)
.append(" size: ") .append(" size: ")
.append(std::to_string(file_size)) .append(std::to_string(file_size))
.append(" ; "); .append(" ; ");
} else { } else {
Error(options.info_log, "Error when reading LOG file: %s/%s\n", Error(options.info_log, "Error when reading LOG file: %s/%s %s\n",
dbname.c_str(), file.c_str()); dbname.c_str(), file.c_str(), s.ToString().c_str());
} }
break; break;
case kTableFile: case kTableFile:
@ -86,10 +91,10 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
// Get sst files in db_path dir // Get sst files in db_path dir
for (auto& db_path : options.db_paths) { for (auto& db_path : options.db_paths) {
if (dbname.compare(db_path.path) != 0) { if (dbname.compare(db_path.path) != 0) {
if (!env->GetChildren(db_path.path, &files).ok()) { s = env->GetChildren(db_path.path, &files);
Error(options.info_log, if (!s.ok()) {
"Error when reading %s dir\n", Error(options.info_log, "Error when reading %s dir %s\n",
db_path.path.c_str()); db_path.path.c_str(), s.ToString().c_str());
continue; continue;
} }
std::sort(files.begin(), files.end()); std::sort(files.begin(), files.end());
@ -111,22 +116,25 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
// Get wal file in wal_dir // Get wal file in wal_dir
const auto& wal_dir = options.GetWalDir(dbname); const auto& wal_dir = options.GetWalDir(dbname);
if (!options.IsWalDirSameAsDBPath(dbname)) { if (!options.IsWalDirSameAsDBPath(dbname)) {
if (!env->GetChildren(wal_dir, &files).ok()) { s = env->GetChildren(wal_dir, &files);
Error(options.info_log, "Error when reading %s dir\n", wal_dir.c_str()); if (!s.ok()) {
Error(options.info_log, "Error when reading %s dir %s\n", wal_dir.c_str(),
s.ToString().c_str());
return; return;
} }
wal_info.clear(); wal_info.clear();
for (const std::string& file : files) { for (const std::string& file : files) {
if (ParseFileName(file, &number, &type)) { if (ParseFileName(file, &number, &type)) {
if (type == kWalFile) { if (type == kWalFile) {
if (env->GetFileSize(wal_dir + "/" + file, &file_size).ok()) { s = env->GetFileSize(wal_dir + "/" + file, &file_size);
if (s.ok()) {
wal_info.append(file) wal_info.append(file)
.append(" size: ") .append(" size: ")
.append(std::to_string(file_size)) .append(std::to_string(file_size))
.append(" ; "); .append(" ; ");
} else { } else {
Error(options.info_log, "Error when reading LOG file %s/%s\n", Error(options.info_log, "Error when reading LOG file %s/%s %s\n",
wal_dir.c_str(), file.c_str()); wal_dir.c_str(), file.c_str(), s.ToString().c_str());
} }
} }
} }

View File

@ -414,7 +414,7 @@ TEST_F(DBIteratorStressTest, StressTest) {
a /= 10; a /= 10;
++len; ++len;
} }
std::string s = ToString(rnd.Next() % static_cast<uint64_t>(max_key)); std::string s = std::to_string(rnd.Next() % static_cast<uint64_t>(max_key));
s.insert(0, len - (int)s.size(), '0'); s.insert(0, len - (int)s.size(), '0');
return s; return s;
}; };
@ -444,12 +444,13 @@ TEST_F(DBIteratorStressTest, StressTest) {
for (double mutation_probability : {0.01, 0.5}) { for (double mutation_probability : {0.01, 0.5}) {
for (double target_hidden_fraction : {0.1, 0.5}) { for (double target_hidden_fraction : {0.1, 0.5}) {
std::string trace_str = std::string trace_str =
"entries: " + ToString(num_entries) + "entries: " + std::to_string(num_entries) +
", key_space: " + ToString(key_space) + ", key_space: " + std::to_string(key_space) +
", error_probability: " + ToString(error_probability) + ", error_probability: " + std::to_string(error_probability) +
", mutation_probability: " + ToString(mutation_probability) + ", mutation_probability: " +
std::to_string(mutation_probability) +
", target_hidden_fraction: " + ", target_hidden_fraction: " +
ToString(target_hidden_fraction); std::to_string(target_hidden_fraction);
SCOPED_TRACE(trace_str); SCOPED_TRACE(trace_str);
if (trace) { if (trace) {
std::cout << trace_str << std::endl; std::cout << trace_str << std::endl;
@ -470,7 +471,7 @@ TEST_F(DBIteratorStressTest, StressTest) {
types[rnd.Next() % (sizeof(types) / sizeof(types[0]))]; types[rnd.Next() % (sizeof(types) / sizeof(types[0]))];
} }
e.sequence = i; e.sequence = i;
e.value = "v" + ToString(i); e.value = "v" + std::to_string(i);
ParsedInternalKey internal_key(e.key, e.sequence, e.type); ParsedInternalKey internal_key(e.key, e.sequence, e.type);
AppendInternalKey(&e.ikey, internal_key); AppendInternalKey(&e.ikey, internal_key);

View File

@ -766,7 +766,7 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
internal_iter->AddMerge("b", "merge_1"); internal_iter->AddMerge("b", "merge_1");
internal_iter->AddMerge("a", "merge_2"); internal_iter->AddMerge("a", "merge_2");
for (size_t k = 0; k < 200; ++k) { for (size_t k = 0; k < 200; ++k) {
internal_iter->AddPut("c", ToString(k)); internal_iter->AddPut("c", std::to_string(k));
} }
internal_iter->Finish(); internal_iter->Finish();
@ -780,7 +780,7 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
ASSERT_TRUE(db_iter->Valid()); ASSERT_TRUE(db_iter->Valid());
ASSERT_EQ(db_iter->key().ToString(), "c"); ASSERT_EQ(db_iter->key().ToString(), "c");
ASSERT_EQ(db_iter->value().ToString(), ToString(i)); ASSERT_EQ(db_iter->value().ToString(), std::to_string(i));
db_iter->Prev(); db_iter->Prev();
ASSERT_TRUE(db_iter->Valid()); ASSERT_TRUE(db_iter->Valid());
@ -925,11 +925,11 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
internal_iter->AddMerge("b", "merge_1"); internal_iter->AddMerge("b", "merge_1");
internal_iter->AddMerge("a", "merge_2"); internal_iter->AddMerge("a", "merge_2");
for (size_t k = 0; k < 200; ++k) { for (size_t k = 0; k < 200; ++k) {
internal_iter->AddPut("d", ToString(k)); internal_iter->AddPut("d", std::to_string(k));
} }
for (size_t k = 0; k < 200; ++k) { for (size_t k = 0; k < 200; ++k) {
internal_iter->AddPut("c", ToString(k)); internal_iter->AddPut("c", std::to_string(k));
} }
internal_iter->Finish(); internal_iter->Finish();
@ -942,7 +942,7 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
ASSERT_TRUE(db_iter->Valid()); ASSERT_TRUE(db_iter->Valid());
ASSERT_EQ(db_iter->key().ToString(), "d"); ASSERT_EQ(db_iter->key().ToString(), "d");
ASSERT_EQ(db_iter->value().ToString(), ToString(i)); ASSERT_EQ(db_iter->value().ToString(), std::to_string(i));
db_iter->Prev(); db_iter->Prev();
ASSERT_TRUE(db_iter->Valid()); ASSERT_TRUE(db_iter->Valid());
@ -966,7 +966,7 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
internal_iter->AddMerge("b", "b"); internal_iter->AddMerge("b", "b");
internal_iter->AddMerge("a", "a"); internal_iter->AddMerge("a", "a");
for (size_t k = 0; k < 200; ++k) { for (size_t k = 0; k < 200; ++k) {
internal_iter->AddMerge("c", ToString(k)); internal_iter->AddMerge("c", std::to_string(k));
} }
internal_iter->Finish(); internal_iter->Finish();
@ -981,7 +981,7 @@ TEST_F(DBIteratorTest, DBIteratorUseSkip) {
ASSERT_EQ(db_iter->key().ToString(), "c"); ASSERT_EQ(db_iter->key().ToString(), "c");
std::string merge_result = "0"; std::string merge_result = "0";
for (size_t j = 1; j <= i; ++j) { for (size_t j = 1; j <= i; ++j) {
merge_result += "," + ToString(j); merge_result += "," + std::to_string(j);
} }
ASSERT_EQ(db_iter->value().ToString(), merge_result); ASSERT_EQ(db_iter->value().ToString(), merge_result);
@ -3156,7 +3156,7 @@ TEST_F(DBIteratorTest, ReverseToForwardWithDisappearingKeys) {
internal_iter->AddPut("a", "A"); internal_iter->AddPut("a", "A");
internal_iter->AddPut("b", "B"); internal_iter->AddPut("b", "B");
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
internal_iter->AddPut("c" + ToString(i), ""); internal_iter->AddPut("c" + std::to_string(i), "");
} }
internal_iter->Finish(); internal_iter->Finish();

View File

@ -3160,7 +3160,7 @@ TEST_F(DBIteratorWithReadCallbackTest, ReadCallback) {
uint64_t num_versions = uint64_t num_versions =
CurrentOptions().max_sequential_skip_in_iterations + 10; CurrentOptions().max_sequential_skip_in_iterations + 10;
for (uint64_t i = 0; i < num_versions; i++) { for (uint64_t i = 0; i < num_versions; i++) {
ASSERT_OK(Put("bar", ToString(i))); ASSERT_OK(Put("bar", std::to_string(i)));
} }
SequenceNumber seq3 = db_->GetLatestSequenceNumber(); SequenceNumber seq3 = db_->GetLatestSequenceNumber();
TestReadCallback callback2(seq3); TestReadCallback callback2(seq3);
@ -3189,7 +3189,7 @@ TEST_F(DBIteratorWithReadCallbackTest, ReadCallback) {
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
ASSERT_OK(iter->status()); ASSERT_OK(iter->status());
ASSERT_EQ("bar", iter->key()); ASSERT_EQ("bar", iter->key());
ASSERT_EQ(ToString(num_versions - 1), iter->value()); ASSERT_EQ(std::to_string(num_versions - 1), iter->value());
delete iter; delete iter;
} }

View File

@ -79,7 +79,7 @@ class DbKvChecksumTest
void CorruptNextByteCallBack(void* arg) { void CorruptNextByteCallBack(void* arg) {
Slice encoded = *static_cast<Slice*>(arg); Slice encoded = *static_cast<Slice*>(arg);
if (entry_len_ == port::kMaxSizet) { if (entry_len_ == std::numeric_limits<size_t>::max()) {
// We learn the entry size on the first attempt // We learn the entry size on the first attempt
entry_len_ = encoded.size(); entry_len_ = encoded.size();
} }
@ -96,7 +96,7 @@ class DbKvChecksumTest
WriteBatchOpType op_type_; WriteBatchOpType op_type_;
char corrupt_byte_addend_; char corrupt_byte_addend_;
size_t corrupt_byte_offset_ = 0; size_t corrupt_byte_offset_ = 0;
size_t entry_len_ = port::kMaxSizet; size_t entry_len_ = std::numeric_limits<size_t>::max();
}; };
std::string GetTestNameSuffix( std::string GetTestNameSuffix(

View File

@ -187,7 +187,7 @@ TEST_F(DBTestXactLogIterator, TransactionLogIteratorCorruptedLog) {
DestroyAndReopen(options); DestroyAndReopen(options);
for (int i = 0; i < 1024; i++) { for (int i = 0; i < 1024; i++) {
ASSERT_OK(Put("key" + ToString(i), DummyString(10))); ASSERT_OK(Put("key" + std::to_string(i), DummyString(10)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -263,20 +263,20 @@ TEST_F(DBTestXactLogIterator, TransactionLogIteratorBlobs) {
struct Handler : public WriteBatch::Handler { struct Handler : public WriteBatch::Handler {
std::string seen; std::string seen;
Status PutCF(uint32_t cf, const Slice& key, const Slice& value) override { Status PutCF(uint32_t cf, const Slice& key, const Slice& value) override {
seen += "Put(" + ToString(cf) + ", " + key.ToString() + ", " + seen += "Put(" + std::to_string(cf) + ", " + key.ToString() + ", " +
ToString(value.size()) + ")"; std::to_string(value.size()) + ")";
return Status::OK(); return Status::OK();
} }
Status MergeCF(uint32_t cf, const Slice& key, const Slice& value) override { Status MergeCF(uint32_t cf, const Slice& key, const Slice& value) override {
seen += "Merge(" + ToString(cf) + ", " + key.ToString() + ", " + seen += "Merge(" + std::to_string(cf) + ", " + key.ToString() + ", " +
ToString(value.size()) + ")"; std::to_string(value.size()) + ")";
return Status::OK(); return Status::OK();
} }
void LogData(const Slice& blob) override { void LogData(const Slice& blob) override {
seen += "LogData(" + blob.ToString() + ")"; seen += "LogData(" + blob.ToString() + ")";
} }
Status DeleteCF(uint32_t cf, const Slice& key) override { Status DeleteCF(uint32_t cf, const Slice& key) override {
seen += "Delete(" + ToString(cf) + ", " + key.ToString() + ")"; seen += "Delete(" + std::to_string(cf) + ", " + key.ToString() + ")";
return Status::OK(); return Status::OK();
} }
} handler; } handler;

View File

@ -97,7 +97,7 @@ class MockMemTableRepFactory : public MemTableRepFactory {
private: private:
MockMemTableRep* mock_rep_; MockMemTableRep* mock_rep_;
// workaround since there's no port::kMaxUint32 yet. // workaround since there's no std::numeric_limits<uint32_t>::max() yet.
uint32_t last_column_family_id_ = static_cast<uint32_t>(-1); uint32_t last_column_family_id_ = static_cast<uint32_t>(-1);
}; };
@ -171,7 +171,7 @@ TEST_F(DBMemTableTest, DuplicateSeq) {
if (!insert_dup) { if (!insert_dup) {
seq++; seq++;
} }
Status s = mem->Add(seq, kTypeValue, "foo", "value" + ToString(seq), Status s = mem->Add(seq, kTypeValue, "foo", "value" + std::to_string(seq),
nullptr /* kv_prot_info */); nullptr /* kv_prot_info */);
if (insert_dup) { if (insert_dup) {
ASSERT_TRUE(s.IsTryAgain()); ASSERT_TRUE(s.IsTryAgain());

View File

@ -424,8 +424,8 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) {
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
int i = 0; int i = 0;
for (; i < 3; i++) { for (; i < 3; i++) {
ASSERT_OK(Put("foo", ToString(i))); ASSERT_OK(Put("foo", std::to_string(i)));
ASSERT_OK(Put("bar", ToString(i))); ASSERT_OK(Put("bar", std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -442,8 +442,8 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) {
dbfull()->GetDBOptions().writable_file_max_buffer_size); dbfull()->GetDBOptions().writable_file_max_buffer_size);
i = 0; i = 0;
for (; i < 3; i++) { for (; i < 3; i++) {
ASSERT_OK(Put("foo", ToString(i))); ASSERT_OK(Put("foo", std::to_string(i)));
ASSERT_OK(Put("bar", ToString(i))); ASSERT_OK(Put("bar", std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -573,8 +573,8 @@ TEST_F(DBOptionsTest, SetOptionsMayTriggerCompaction) {
Reopen(options); Reopen(options);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
// Need to insert two keys to avoid trivial move. // Need to insert two keys to avoid trivial move.
ASSERT_OK(Put("foo", ToString(i))); ASSERT_OK(Put("foo", std::to_string(i)));
ASSERT_OK(Put("bar", ToString(i))); ASSERT_OK(Put("bar", std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_EQ("3", FilesPerLevel()); ASSERT_EQ("3", FilesPerLevel());
@ -717,8 +717,8 @@ TEST_F(DBOptionsTest, SetStatsDumpPeriodSec) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
unsigned int num = rand() % 5000 + 1; unsigned int num = rand() % 5000 + 1;
ASSERT_OK( ASSERT_OK(dbfull()->SetDBOptions(
dbfull()->SetDBOptions({{"stats_dump_period_sec", ToString(num)}})); {{"stats_dump_period_sec", std::to_string(num)}}));
ASSERT_EQ(num, dbfull()->GetDBOptions().stats_dump_period_sec); ASSERT_EQ(num, dbfull()->GetDBOptions().stats_dump_period_sec);
} }
Close(); Close();
@ -909,7 +909,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -940,7 +940,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -972,7 +972,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -1036,7 +1036,7 @@ TEST_F(DBOptionsTest, FIFOTtlBackwardCompatible) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }

View File

@ -593,9 +593,9 @@ TEST_F(DBPropertiesTest, AggregatedTablePropertiesAtLevel) {
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr)); ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr));
ResetTableProperties(&sum_tp); ResetTableProperties(&sum_tp);
for (int level = 0; level < kMaxLevel; ++level) { for (int level = 0; level < kMaxLevel; ++level) {
db_->GetProperty( db_->GetProperty(DB::Properties::kAggregatedTablePropertiesAtLevel +
DB::Properties::kAggregatedTablePropertiesAtLevel + ToString(level), std::to_string(level),
&level_tp_strings[level]); &level_tp_strings[level]);
ParseTablePropertiesString(level_tp_strings[level], &level_tps[level]); ParseTablePropertiesString(level_tp_strings[level], &level_tps[level]);
sum_tp.data_size += level_tps[level].data_size; sum_tp.data_size += level_tps[level].data_size;
sum_tp.index_size += level_tps[level].index_size; sum_tp.index_size += level_tps[level].index_size;
@ -1091,7 +1091,7 @@ TEST_F(DBPropertiesTest, EstimateCompressionRatio) {
for (int j = 0; j < kNumEntriesPerFile; ++j) { for (int j = 0; j < kNumEntriesPerFile; ++j) {
// Put common data ("key") at end to prevent delta encoding from // Put common data ("key") at end to prevent delta encoding from
// compressing the key effectively // compressing the key effectively
std::string key = ToString(i) + ToString(j) + "key"; std::string key = std::to_string(i) + std::to_string(j) + "key";
ASSERT_OK(dbfull()->Put(WriteOptions(), key, kVal)); ASSERT_OK(dbfull()->Put(WriteOptions(), key, kVal));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -1185,7 +1185,7 @@ class CountingDeleteTabPropCollector : public TablePropertiesCollector {
Status Finish(UserCollectedProperties* properties) override { Status Finish(UserCollectedProperties* properties) override {
*properties = *properties =
UserCollectedProperties{{"num_delete", ToString(num_deletes_)}}; UserCollectedProperties{{"num_delete", std::to_string(num_deletes_)}};
return Status::OK(); return Status::OK();
} }
@ -1215,7 +1215,7 @@ class BlockCountingTablePropertiesCollector : public TablePropertiesCollector {
Status Finish(UserCollectedProperties* properties) override { Status Finish(UserCollectedProperties* properties) override {
(*properties)[kNumSampledBlocksPropertyName] = (*properties)[kNumSampledBlocksPropertyName] =
ToString(num_sampled_blocks_); std::to_string(num_sampled_blocks_);
return Status::OK(); return Status::OK();
} }
@ -1235,7 +1235,7 @@ class BlockCountingTablePropertiesCollector : public TablePropertiesCollector {
UserCollectedProperties GetReadableProperties() const override { UserCollectedProperties GetReadableProperties() const override {
return UserCollectedProperties{ return UserCollectedProperties{
{kNumSampledBlocksPropertyName, ToString(num_sampled_blocks_)}, {kNumSampledBlocksPropertyName, std::to_string(num_sampled_blocks_)},
}; };
} }
@ -1272,7 +1272,8 @@ TEST_F(DBPropertiesTest, GetUserDefinedTableProperties) {
// Create 4 tables // Create 4 tables
for (int table = 0; table < 4; ++table) { for (int table = 0; table < 4; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(db_->Put(WriteOptions(), ToString(table * 100 + i), "val")); ASSERT_OK(
db_->Put(WriteOptions(), std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(db_->Flush(FlushOptions())); ASSERT_OK(db_->Flush(FlushOptions()));
} }
@ -1312,7 +1313,7 @@ TEST_F(DBPropertiesTest, UserDefinedTablePropertiesContext) {
// Create 2 files // Create 2 files
for (int table = 0; table < 2; ++table) { for (int table = 0; table < 2; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(1, ToString(table * 100 + i), "val")); ASSERT_OK(Put(1, std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush(1)); ASSERT_OK(Flush(1));
} }
@ -1322,7 +1323,7 @@ TEST_F(DBPropertiesTest, UserDefinedTablePropertiesContext) {
// Trigger automatic compactions. // Trigger automatic compactions.
for (int table = 0; table < 3; ++table) { for (int table = 0; table < 3; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(1, ToString(table * 100 + i), "val")); ASSERT_OK(Put(1, std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush(1)); ASSERT_OK(Flush(1));
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -1339,7 +1340,7 @@ TEST_F(DBPropertiesTest, UserDefinedTablePropertiesContext) {
// Create 4 tables in default column family // Create 4 tables in default column family
for (int table = 0; table < 2; ++table) { for (int table = 0; table < 2; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(ToString(table * 100 + i), "val")); ASSERT_OK(Put(std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -1349,7 +1350,7 @@ TEST_F(DBPropertiesTest, UserDefinedTablePropertiesContext) {
// Trigger automatic compactions. // Trigger automatic compactions.
for (int table = 0; table < 3; ++table) { for (int table = 0; table < 3; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(ToString(table * 100 + i), "val")); ASSERT_OK(Put(std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -1545,7 +1546,7 @@ TEST_F(DBPropertiesTest, BlockAddForCompressionSampling) {
user_props.end()); user_props.end());
ASSERT_EQ(user_props.at(BlockCountingTablePropertiesCollector:: ASSERT_EQ(user_props.at(BlockCountingTablePropertiesCollector::
kNumSampledBlocksPropertyName), kNumSampledBlocksPropertyName),
ToString(sample_for_compression ? 1 : 0)); std::to_string(sample_for_compression ? 1 : 0));
} }
} }
} }
@ -1742,11 +1743,11 @@ TEST_F(DBPropertiesTest, SstFilesSize) {
Reopen(options); Reopen(options);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ASSERT_OK(Put("key" + ToString(i), std::string(1000, 'v'))); ASSERT_OK(Put("key" + std::to_string(i), std::string(1000, 'v')));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
ASSERT_OK(Delete("key" + ToString(i))); ASSERT_OK(Delete("key" + std::to_string(i)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
uint64_t sst_size; uint64_t sst_size;

View File

@ -190,9 +190,10 @@ TEST_F(DBRangeDelTest, MaxCompactionBytesCutsOutputFiles) {
ASSERT_EQ(0, NumTableFilesAtLevel(0)); ASSERT_EQ(0, NumTableFilesAtLevel(0));
ASSERT_EQ(NumTableFilesAtLevel(2), 2); ASSERT_EQ(NumTableFilesAtLevel(2), 2);
ASSERT_OK(db_->SetOptions( ASSERT_OK(
db_->DefaultColumnFamily(), db_->SetOptions(db_->DefaultColumnFamily(),
{{"target_file_size_base", ToString(100 * opts.max_compaction_bytes)}})); {{"target_file_size_base",
std::to_string(100 * opts.max_compaction_bytes)}}));
// It spans the whole key-range, thus will be included in all output files // It spans the whole key-range, thus will be included in all output files
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(), ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(),
@ -500,7 +501,8 @@ TEST_F(DBRangeDelTest, ValidUniversalSubcompactionBoundaries) {
1 /* input_level */, 2 /* output_level */, CompactRangeOptions(), 1 /* input_level */, 2 /* output_level */, CompactRangeOptions(),
nullptr /* begin */, nullptr /* end */, true /* exclusive */, nullptr /* begin */, nullptr /* end */, true /* exclusive */,
true /* disallow_trivial_move */, true /* disallow_trivial_move */,
port::kMaxUint64 /* max_file_num_to_ignore */, "" /*trim_ts*/)); std::numeric_limits<uint64_t>::max() /* max_file_num_to_ignore */,
"" /*trim_ts*/));
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE

View File

@ -212,20 +212,20 @@ TEST_F(DBSecondaryTest, InternalCompactionMultiLevels) {
const int kRangeL2 = 10; const int kRangeL2 = 10;
const int kRangeL1 = 30; const int kRangeL1 = 30;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ASSERT_OK(Put(Key(i * kRangeL2), "value" + ToString(i))); ASSERT_OK(Put(Key(i * kRangeL2), "value" + std::to_string(i)));
ASSERT_OK(Put(Key((i + 1) * kRangeL2 - 1), "value" + ToString(i))); ASSERT_OK(Put(Key((i + 1) * kRangeL2 - 1), "value" + std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
MoveFilesToLevel(2); MoveFilesToLevel(2);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
ASSERT_OK(Put(Key(i * kRangeL1), "value" + ToString(i))); ASSERT_OK(Put(Key(i * kRangeL1), "value" + std::to_string(i)));
ASSERT_OK(Put(Key((i + 1) * kRangeL1 - 1), "value" + ToString(i))); ASSERT_OK(Put(Key((i + 1) * kRangeL1 - 1), "value" + std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
MoveFilesToLevel(1); MoveFilesToLevel(1);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ASSERT_OK(Put(Key(i * 30), "value" + ToString(i))); ASSERT_OK(Put(Key(i * 30), "value" + std::to_string(i)));
ASSERT_OK(Put(Key(i * 30 + 50), "value" + ToString(i))); ASSERT_OK(Put(Key(i * 30 + 50), "value" + std::to_string(i)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }

View File

@ -280,6 +280,58 @@ TEST_F(DBSSTTest, DeleteObsoleteFilesPendingOutputs) {
listener->VerifyMatchedCount(1); listener->VerifyMatchedCount(1);
} }
// Test that producing an empty .sst file does not write it out to
// disk, and that the DeleteFile() env method is not called for
// removing the non-existing file later.
TEST_F(DBSSTTest, DeleteFileNotCalledForNotCreatedSSTFile) {
Options options = CurrentOptions();
options.env = env_;
OnFileDeletionListener* listener = new OnFileDeletionListener();
options.listeners.emplace_back(listener);
Reopen(options);
// Flush the empty database.
ASSERT_OK(Flush());
ASSERT_EQ("", FilesPerLevel(0));
// We expect no .sst files.
std::vector<LiveFileMetaData> metadata;
db_->GetLiveFilesMetaData(&metadata);
ASSERT_EQ(metadata.size(), 0U);
// We expect no file deletions.
listener->VerifyMatchedCount(0);
}
// Test that producing a non-empty .sst file does write it out to
// disk, and that the DeleteFile() env method is not called for removing
// the file later.
TEST_F(DBSSTTest, DeleteFileNotCalledForCreatedSSTFile) {
Options options = CurrentOptions();
options.env = env_;
OnFileDeletionListener* listener = new OnFileDeletionListener();
options.listeners.emplace_back(listener);
Reopen(options);
ASSERT_OK(Put("pika", "choo"));
// Flush the non-empty database.
ASSERT_OK(Flush());
ASSERT_EQ("1", FilesPerLevel(0));
// We expect 1 .sst files.
std::vector<LiveFileMetaData> metadata;
db_->GetLiveFilesMetaData(&metadata);
ASSERT_EQ(metadata.size(), 1U);
// We expect no file deletions.
listener->VerifyMatchedCount(0);
}
TEST_F(DBSSTTest, DBWithSstFileManager) { TEST_F(DBSSTTest, DBWithSstFileManager) {
std::shared_ptr<SstFileManager> sst_file_manager(NewSstFileManager(env_)); std::shared_ptr<SstFileManager> sst_file_manager(NewSstFileManager(env_));
auto sfm = static_cast<SstFileManagerImpl*>(sst_file_manager.get()); auto sfm = static_cast<SstFileManagerImpl*>(sst_file_manager.get());
@ -947,7 +999,7 @@ TEST_F(DBSSTTest, DeleteSchedulerMultipleDBPaths) {
// Create 4 files in L0 // Create 4 files in L0
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ASSERT_OK(Put("Key" + ToString(i), DummyString(1024, 'A'), wo)); ASSERT_OK(Put("Key" + std::to_string(i), DummyString(1024, 'A'), wo));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
// We created 4 sst files in L0 // We created 4 sst files in L0
@ -963,7 +1015,7 @@ TEST_F(DBSSTTest, DeleteSchedulerMultipleDBPaths) {
// Create 4 files in L0 // Create 4 files in L0
for (int i = 4; i < 8; i++) { for (int i = 4; i < 8; i++) {
ASSERT_OK(Put("Key" + ToString(i), DummyString(1024, 'B'), wo)); ASSERT_OK(Put("Key" + std::to_string(i), DummyString(1024, 'B'), wo));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
ASSERT_EQ("4,1", FilesPerLevel(0)); ASSERT_EQ("4,1", FilesPerLevel(0));
@ -1009,7 +1061,7 @@ TEST_F(DBSSTTest, DestroyDBWithRateLimitedDelete) {
// Create 4 files in L0 // Create 4 files in L0
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ASSERT_OK(Put("Key" + ToString(i), DummyString(1024, 'A'))); ASSERT_OK(Put("Key" + std::to_string(i), DummyString(1024, 'A')));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
// We created 4 sst files in L0 // We created 4 sst files in L0
@ -1478,7 +1530,7 @@ TEST_F(DBSSTTest, GetTotalSstFilesSize) {
// Generate 5 files in L0 // Generate 5 files in L0
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
std::string val = "val_file_" + ToString(i); std::string val = "val_file_" + std::to_string(i);
ASSERT_OK(Put(Key(j), val)); ASSERT_OK(Put(Key(j), val));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());

View File

@ -84,7 +84,8 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
} }
// Build file // Build file
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(db_->Put(WriteOptions(), ToString(table * 100 + i), "val")); ASSERT_OK(
db_->Put(WriteOptions(), std::to_string(table * 100 + i), "val"));
} }
ASSERT_OK(db_->Flush(FlushOptions())); ASSERT_OK(db_->Flush(FlushOptions()));
} }
@ -113,7 +114,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
// fetch key from 1st and 2nd table, which will internally place that table to // fetch key from 1st and 2nd table, which will internally place that table to
// the table cache. // the table cache.
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
Get(ToString(i * 100 + 0)); Get(std::to_string(i * 100 + 0));
} }
VerifyTableProperties(db_, 10 + 11 + 12 + 13); VerifyTableProperties(db_, 10 + 11 + 12 + 13);
@ -122,7 +123,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
Reopen(options); Reopen(options);
// fetch key from all tables, which will place them in table cache. // fetch key from all tables, which will place them in table cache.
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
Get(ToString(i * 100 + 0)); Get(std::to_string(i * 100 + 0));
} }
VerifyTableProperties(db_, 10 + 11 + 12 + 13); VerifyTableProperties(db_, 10 + 11 + 12 + 13);
@ -156,7 +157,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
} else { } else {
bool found_corruption = false; bool found_corruption = false;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
std::string result = Get(ToString(i * 100 + 0)); std::string result = Get(std::to_string(i * 100 + 0));
if (result.find_first_of("Corruption: block checksum mismatch") != if (result.find_first_of("Corruption: block checksum mismatch") !=
std::string::npos) { std::string::npos) {
found_corruption = true; found_corruption = true;
@ -187,7 +188,7 @@ TEST_F(DBTablePropertiesTest, InvalidIgnored) {
// Build file // Build file
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
ASSERT_OK(db_->Put(WriteOptions(), ToString(i), "val")); ASSERT_OK(db_->Put(WriteOptions(), std::to_string(i), "val"));
} }
ASSERT_OK(db_->Flush(FlushOptions())); ASSERT_OK(db_->Flush(FlushOptions()));

View File

@ -2734,7 +2734,7 @@ TEST_P(MultiThreadedDBTest, MultiThreaded) {
Options options = CurrentOptions(options_override); Options options = CurrentOptions(options_override);
std::vector<std::string> cfs; std::vector<std::string> cfs;
for (int i = 1; i < kColumnFamilies; ++i) { for (int i = 1; i < kColumnFamilies; ++i) {
cfs.push_back(ToString(i)); cfs.push_back(std::to_string(i));
} }
Reopen(options); Reopen(options);
CreateAndReopenWithCF(cfs, options); CreateAndReopenWithCF(cfs, options);
@ -2786,7 +2786,7 @@ static void GCThreadBody(void* arg) {
WriteOptions wo; WriteOptions wo;
for (int i = 0; i < kGCNumKeys; ++i) { for (int i = 0; i < kGCNumKeys; ++i) {
std::string kv(ToString(i + id * kGCNumKeys)); std::string kv(std::to_string(i + id * kGCNumKeys));
ASSERT_OK(db->Put(wo, kv, kv)); ASSERT_OK(db->Put(wo, kv, kv));
} }
t->done = true; t->done = true;
@ -2822,7 +2822,7 @@ TEST_F(DBTest, GroupCommitTest) {
std::vector<std::string> expected_db; std::vector<std::string> expected_db;
for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) { for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) {
expected_db.push_back(ToString(i)); expected_db.push_back(std::to_string(i));
} }
std::sort(expected_db.begin(), expected_db.end()); std::sort(expected_db.begin(), expected_db.end());
@ -3591,7 +3591,7 @@ TEST_P(DBTestWithParam, FIFOCompactionTest) {
Random rnd(301); Random rnd(301);
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 110; ++j) { for (int j = 0; j < 110; ++j) {
ASSERT_OK(Put(ToString(i * 100 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 100 + j), rnd.RandomString(980)));
} }
// flush should happen here // flush should happen here
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable()); ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
@ -3607,7 +3607,7 @@ TEST_P(DBTestWithParam, FIFOCompactionTest) {
ASSERT_EQ(NumTableFilesAtLevel(0), 5); ASSERT_EQ(NumTableFilesAtLevel(0), 5);
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
// these keys should be deleted in previous compaction // these keys should be deleted in previous compaction
ASSERT_EQ("NOT_FOUND", Get(ToString(i))); ASSERT_EQ("NOT_FOUND", Get(std::to_string(i)));
} }
} }
} }
@ -3629,7 +3629,7 @@ TEST_F(DBTest, FIFOCompactionTestWithCompaction) {
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
// Generate and flush a file about 20KB. // Generate and flush a file about 20KB.
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3640,7 +3640,7 @@ TEST_F(DBTest, FIFOCompactionTestWithCompaction) {
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
// Generate and flush a file about 20KB. // Generate and flush a file about 20KB.
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
ASSERT_OK(Put(ToString(i * 20 + j + 2000), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j + 2000), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3670,27 +3670,27 @@ TEST_F(DBTest, FIFOCompactionStyleWithCompactionAndDelete) {
Random rnd(301); Random rnd(301);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
// Each file contains a different key which will be dropped later. // Each file contains a different key which will be dropped later.
ASSERT_OK(Put("a" + ToString(i), rnd.RandomString(500))); ASSERT_OK(Put("a" + std::to_string(i), rnd.RandomString(500)));
ASSERT_OK(Put("key" + ToString(i), "")); ASSERT_OK(Put("key" + std::to_string(i), ""));
ASSERT_OK(Put("z" + ToString(i), rnd.RandomString(500))); ASSERT_OK(Put("z" + std::to_string(i), rnd.RandomString(500)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
} }
ASSERT_EQ(NumTableFilesAtLevel(0), 1); ASSERT_EQ(NumTableFilesAtLevel(0), 1);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ASSERT_EQ("", Get("key" + ToString(i))); ASSERT_EQ("", Get("key" + std::to_string(i)));
} }
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
// Each file contains a different key which will be dropped later. // Each file contains a different key which will be dropped later.
ASSERT_OK(Put("a" + ToString(i), rnd.RandomString(500))); ASSERT_OK(Put("a" + std::to_string(i), rnd.RandomString(500)));
ASSERT_OK(Delete("key" + ToString(i))); ASSERT_OK(Delete("key" + std::to_string(i)));
ASSERT_OK(Put("z" + ToString(i), rnd.RandomString(500))); ASSERT_OK(Put("z" + std::to_string(i), rnd.RandomString(500)));
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
} }
ASSERT_EQ(NumTableFilesAtLevel(0), 2); ASSERT_EQ(NumTableFilesAtLevel(0), 2);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ASSERT_EQ("NOT_FOUND", Get("key" + ToString(i))); ASSERT_EQ("NOT_FOUND", Get("key" + std::to_string(i)));
} }
} }
@ -3759,7 +3759,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3791,7 +3791,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3807,7 +3807,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
// Create 1 more file to trigger TTL compaction. The old files are dropped. // Create 1 more file to trigger TTL compaction. The old files are dropped.
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
} }
@ -3833,7 +3833,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3848,7 +3848,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
for (int j = 0; j < 140; j++) { for (int j = 0; j < 140; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3871,7 +3871,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// Generate and flush a file about 10KB. // Generate and flush a file about 10KB.
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3890,7 +3890,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
// Create 10 more files. The old 5 files are dropped as their ttl expired. // Create 10 more files. The old 5 files are dropped as their ttl expired.
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) { for (int j = 0; j < 10; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3915,7 +3915,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
// Generate and flush a file about 20KB. // Generate and flush a file about 20KB.
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); ASSERT_OK(Put(std::to_string(i * 20 + j), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -3926,7 +3926,8 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
// Generate and flush a file about 20KB. // Generate and flush a file about 20KB.
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
ASSERT_OK(Put(ToString(i * 20 + j + 2000), rnd.RandomString(980))); ASSERT_OK(
Put(std::to_string(i * 20 + j + 2000), rnd.RandomString(980)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());
@ -4207,7 +4208,7 @@ TEST_F(DBTest, ConcurrentFlushWAL) {
std::vector<port::Thread> threads; std::vector<port::Thread> threads;
threads.emplace_back([&] { threads.emplace_back([&] {
for (size_t i = 0; i < cnt; i++) { for (size_t i = 0; i < cnt; i++) {
auto istr = ToString(i); auto istr = std::to_string(i);
ASSERT_OK(db_->Put(wopt, db_->DefaultColumnFamily(), "a" + istr, ASSERT_OK(db_->Put(wopt, db_->DefaultColumnFamily(), "a" + istr,
"b" + istr)); "b" + istr));
} }
@ -4215,7 +4216,7 @@ TEST_F(DBTest, ConcurrentFlushWAL) {
if (two_write_queues) { if (two_write_queues) {
threads.emplace_back([&] { threads.emplace_back([&] {
for (size_t i = cnt; i < 2 * cnt; i++) { for (size_t i = cnt; i < 2 * cnt; i++) {
auto istr = ToString(i); auto istr = std::to_string(i);
WriteBatch batch; WriteBatch batch;
ASSERT_OK(batch.Put("a" + istr, "b" + istr)); ASSERT_OK(batch.Put("a" + istr, "b" + istr));
ASSERT_OK( ASSERT_OK(
@ -4236,7 +4237,7 @@ TEST_F(DBTest, ConcurrentFlushWAL) {
Reopen(options); Reopen(options);
for (size_t i = 0; i < cnt; i++) { for (size_t i = 0; i < cnt; i++) {
PinnableSlice pval; PinnableSlice pval;
auto istr = ToString(i); auto istr = std::to_string(i);
ASSERT_OK( ASSERT_OK(
db_->Get(ropt, db_->DefaultColumnFamily(), "a" + istr, &pval)); db_->Get(ropt, db_->DefaultColumnFamily(), "a" + istr, &pval));
ASSERT_TRUE(pval == ("b" + istr)); ASSERT_TRUE(pval == ("b" + istr));
@ -4259,7 +4260,7 @@ TEST_F(DBTest, ManualFlushWalAndWriteRace) {
port::Thread writeThread([&]() { port::Thread writeThread([&]() {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
auto istr = ToString(i); auto istr = std::to_string(i);
ASSERT_OK(dbfull()->Put(wopts, "key_" + istr, "value_" + istr)); ASSERT_OK(dbfull()->Put(wopts, "key_" + istr, "value_" + istr));
} }
}); });
@ -4607,7 +4608,7 @@ TEST_P(DBTestWithParam, ThreadStatusSingleCompaction) {
// The Put Phase. // The Put Phase.
for (int file = 0; file < kNumL0Files; ++file) { for (int file = 0; file < kNumL0Files; ++file) {
for (int key = 0; key < kEntriesPerBuffer; ++key) { for (int key = 0; key < kEntriesPerBuffer; ++key) {
ASSERT_OK(Put(ToString(key + file * kEntriesPerBuffer), ASSERT_OK(Put(std::to_string(key + file * kEntriesPerBuffer),
rnd.RandomString(kTestValueSize))); rnd.RandomString(kTestValueSize)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -4758,7 +4759,7 @@ TEST_P(DBTestWithParam, PreShutdownMultipleCompaction) {
int operation_count[ThreadStatus::NUM_OP_TYPES] = {0}; int operation_count[ThreadStatus::NUM_OP_TYPES] = {0};
for (int file = 0; file < 16 * kNumL0Files; ++file) { for (int file = 0; file < 16 * kNumL0Files; ++file) {
for (int k = 0; k < kEntriesPerBuffer; ++k) { for (int k = 0; k < kEntriesPerBuffer; ++k) {
ASSERT_OK(Put(ToString(key++), rnd.RandomString(kTestValueSize))); ASSERT_OK(Put(std::to_string(key++), rnd.RandomString(kTestValueSize)));
} }
ASSERT_OK(env_->GetThreadList(&thread_list)); ASSERT_OK(env_->GetThreadList(&thread_list));
@ -4845,7 +4846,7 @@ TEST_P(DBTestWithParam, PreShutdownCompactionMiddle) {
int operation_count[ThreadStatus::NUM_OP_TYPES] = {0}; int operation_count[ThreadStatus::NUM_OP_TYPES] = {0};
for (int file = 0; file < 16 * kNumL0Files; ++file) { for (int file = 0; file < 16 * kNumL0Files; ++file) {
for (int k = 0; k < kEntriesPerBuffer; ++k) { for (int k = 0; k < kEntriesPerBuffer; ++k) {
ASSERT_OK(Put(ToString(key++), rnd.RandomString(kTestValueSize))); ASSERT_OK(Put(std::to_string(key++), rnd.RandomString(kTestValueSize)));
} }
ASSERT_OK(env_->GetThreadList(&thread_list)); ASSERT_OK(env_->GetThreadList(&thread_list));
@ -5156,8 +5157,9 @@ TEST_F(DBTest, DynamicCompactionOptions) {
// Writing to 64KB L0 files should trigger a compaction. Since these // Writing to 64KB L0 files should trigger a compaction. Since these
// 2 L0 files have the same key range, compaction merge them and should // 2 L0 files have the same key range, compaction merge them and should
// result in 2 32KB L1 files. // result in 2 32KB L1 files.
ASSERT_OK(dbfull()->SetOptions({{"level0_file_num_compaction_trigger", "2"}, ASSERT_OK(
{"target_file_size_base", ToString(k32KB)}})); dbfull()->SetOptions({{"level0_file_num_compaction_trigger", "2"},
{"target_file_size_base", std::to_string(k32KB)}}));
gen_l0_kb(0, 64, 1); gen_l0_kb(0, 64, 1);
ASSERT_EQ("1,1", FilesPerLevel()); ASSERT_EQ("1,1", FilesPerLevel());
@ -5176,8 +5178,8 @@ TEST_F(DBTest, DynamicCompactionOptions) {
// Increase level base size to 256KB and write enough data that will // Increase level base size to 256KB and write enough data that will
// fill L1 and L2. L1 size should be around 256KB while L2 size should be // fill L1 and L2. L1 size should be around 256KB while L2 size should be
// around 256KB x 4. // around 256KB x 4.
ASSERT_OK( ASSERT_OK(dbfull()->SetOptions(
dbfull()->SetOptions({{"max_bytes_for_level_base", ToString(k1MB)}})); {{"max_bytes_for_level_base", std::to_string(k1MB)}}));
// writing 96 x 64KB => 6 * 1024KB // writing 96 x 64KB => 6 * 1024KB
// (L1 + L2) = (1 + 4) * 1024KB // (L1 + L2) = (1 + 4) * 1024KB
@ -5196,9 +5198,9 @@ TEST_F(DBTest, DynamicCompactionOptions) {
// max_bytes_for_level_base. Now, reduce both mulitplier and level base, // max_bytes_for_level_base. Now, reduce both mulitplier and level base,
// After filling enough data that can fit in L1 - L3, we should see L1 size // After filling enough data that can fit in L1 - L3, we should see L1 size
// reduces to 128KB from 256KB which was asserted previously. Same for L2. // reduces to 128KB from 256KB which was asserted previously. Same for L2.
ASSERT_OK( ASSERT_OK(dbfull()->SetOptions(
dbfull()->SetOptions({{"max_bytes_for_level_multiplier", "2"}, {{"max_bytes_for_level_multiplier", "2"},
{"max_bytes_for_level_base", ToString(k128KB)}})); {"max_bytes_for_level_base", std::to_string(k128KB)}}));
// writing 20 x 64KB = 10 x 128KB // writing 20 x 64KB = 10 x 128KB
// (L1 + L2 + L3) = (1 + 2 + 4) * 128KB // (L1 + L2 + L3) = (1 + 2 + 4) * 128KB
@ -5854,7 +5856,7 @@ TEST_P(DBTestWithParam, FilterCompactionTimeTest) {
// put some data // put some data
for (int table = 0; table < 4; ++table) { for (int table = 0; table < 4; ++table) {
for (int i = 0; i < 10 + table; ++i) { for (int i = 0; i < 10 + table; ++i) {
ASSERT_OK(Put(ToString(table * 100 + i), "val")); ASSERT_OK(Put(std::to_string(table * 100 + i), "val"));
++n; ++n;
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
@ -6238,7 +6240,7 @@ TEST_F(DBTest, LargeBatchWithColumnFamilies) {
(write_size / 1024 / 1024), pass); (write_size / 1024 / 1024), pass);
for (;;) { for (;;) {
std::string data(3000, j++ % 127 + 20); std::string data(3000, j++ % 127 + 20);
data += ToString(j); data += std::to_string(j);
ASSERT_OK(batch.Put(handles_[0], Slice(data), Slice(data))); ASSERT_OK(batch.Put(handles_[0], Slice(data), Slice(data)));
if (batch.GetDataSize() > write_size) { if (batch.GetDataSize() > write_size) {
break; break;
@ -7034,51 +7036,6 @@ TEST_F(DBTest, MemoryUsageWithMaxWriteBufferSizeToMaintain) {
} }
} }
TEST_F(DBTest, ManualFlushWithStoppedWritesTest) {
Options options = CurrentOptions();
// Setting a small write buffer size. This will block writes
// rather quickly until a flush is made.
constexpr unsigned int memtableSize = 1000;
options.db_write_buffer_size = memtableSize;
options.max_background_flushes = 1;
Reopen(options);
std::atomic<bool> done(false);
// Will suppress future flushes.
// This simulates a situation where the writes will be stopped for any reason.
ASSERT_OK(dbfull()->PauseBackgroundWork());
port::Thread backgroundWriter([&]() {
Random rnd(301);
// These writes won't finish.
ASSERT_OK(Put("k1", rnd.RandomString(memtableSize / 2)));
ASSERT_OK(Put("k2", rnd.RandomString(memtableSize / 2)));
ASSERT_OK(Put("k3", rnd.RandomString(memtableSize / 2)));
ASSERT_OK(Put("k4", rnd.RandomString(memtableSize / 2)));
done.store(true);
});
env_->SleepForMicroseconds(1000000 / 2);
// make sure thread is stuck waiting for flush.
ASSERT_FALSE(done.load());
FlushOptions flushOptions;
flushOptions.wait = false;
flushOptions.allow_write_stall = true;
// This is the main goal of the test. This manual flush should not deadlock
// as we use wait=false, and even allow_write_stall=true for extra safety.
ASSERT_OK(dbfull()->Flush(flushOptions));
// This will re-allow background flushes.
ASSERT_OK(dbfull()->ContinueBackgroundWork());
backgroundWriter.join();
ASSERT_TRUE(done.load());
}
#endif #endif
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

View File

@ -38,10 +38,10 @@ class DBTest2 : public DBTestBase {
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
uint64_t GetSstSizeHelper(Temperature temperature) { uint64_t GetSstSizeHelper(Temperature temperature) {
std::string prop; std::string prop;
EXPECT_TRUE( EXPECT_TRUE(dbfull()->GetProperty(
dbfull()->GetProperty(DB::Properties::kLiveSstFilesSizeAtTemperature + DB::Properties::kLiveSstFilesSizeAtTemperature +
ToString(static_cast<uint8_t>(temperature)), std::to_string(static_cast<uint8_t>(temperature)),
&prop)); &prop));
return static_cast<uint64_t>(std::atoi(prop.c_str())); return static_cast<uint64_t>(std::atoi(prop.c_str()));
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
@ -1694,9 +1694,9 @@ class CompactionCompressionListener : public EventListener {
int bottommost_level = 0; int bottommost_level = 0;
for (int level = 0; level < db->NumberLevels(); level++) { for (int level = 0; level < db->NumberLevels(); level++) {
std::string files_at_level; std::string files_at_level;
ASSERT_TRUE(db->GetProperty( ASSERT_TRUE(
"rocksdb.num-files-at-level" + ROCKSDB_NAMESPACE::ToString(level), db->GetProperty("rocksdb.num-files-at-level" + std::to_string(level),
&files_at_level)); &files_at_level));
if (files_at_level != "0") { if (files_at_level != "0") {
bottommost_level = level; bottommost_level = level;
} }
@ -2492,14 +2492,14 @@ TEST_F(DBTest2, TestPerfContextIterCpuTime) {
const size_t kNumEntries = 10; const size_t kNumEntries = 10;
for (size_t i = 0; i < kNumEntries; ++i) { for (size_t i = 0; i < kNumEntries; ++i) {
ASSERT_OK(Put("k" + ToString(i), "v" + ToString(i))); ASSERT_OK(Put("k" + std::to_string(i), "v" + std::to_string(i)));
} }
ASSERT_OK(Flush()); ASSERT_OK(Flush());
for (size_t i = 0; i < kNumEntries; ++i) { for (size_t i = 0; i < kNumEntries; ++i) {
ASSERT_EQ("v" + ToString(i), Get("k" + ToString(i))); ASSERT_EQ("v" + std::to_string(i), Get("k" + std::to_string(i)));
} }
std::string last_key = "k" + ToString(kNumEntries - 1); std::string last_key = "k" + std::to_string(kNumEntries - 1);
std::string last_value = "v" + ToString(kNumEntries - 1); std::string last_value = "v" + std::to_string(kNumEntries - 1);
env_->now_cpu_count_.store(0); env_->now_cpu_count_.store(0);
env_->SetMockSleep(); env_->SetMockSleep();
@ -5553,7 +5553,7 @@ TEST_F(DBTest2, MultiDBParallelOpenTest) {
Options options = CurrentOptions(); Options options = CurrentOptions();
std::vector<std::string> dbnames; std::vector<std::string> dbnames;
for (int i = 0; i < kNumDbs; ++i) { for (int i = 0; i < kNumDbs; ++i) {
dbnames.emplace_back(test::PerThreadDBPath(env_, "db" + ToString(i))); dbnames.emplace_back(test::PerThreadDBPath(env_, "db" + std::to_string(i)));
ASSERT_OK(DestroyDB(dbnames.back(), options)); ASSERT_OK(DestroyDB(dbnames.back(), options));
} }

View File

@ -1086,12 +1086,12 @@ int DBTestBase::NumTableFilesAtLevel(int level, int cf) {
std::string property; std::string property;
if (cf == 0) { if (cf == 0) {
// default cfd // default cfd
EXPECT_TRUE(db_->GetProperty("rocksdb.num-files-at-level" + ToString(level), EXPECT_TRUE(db_->GetProperty(
&property)); "rocksdb.num-files-at-level" + std::to_string(level), &property));
} else { } else {
EXPECT_TRUE(db_->GetProperty(handles_[cf], EXPECT_TRUE(db_->GetProperty(
"rocksdb.num-files-at-level" + ToString(level), handles_[cf], "rocksdb.num-files-at-level" + std::to_string(level),
&property)); &property));
} }
return atoi(property.c_str()); return atoi(property.c_str());
} }
@ -1101,10 +1101,12 @@ double DBTestBase::CompressionRatioAtLevel(int level, int cf) {
if (cf == 0) { if (cf == 0) {
// default cfd // default cfd
EXPECT_TRUE(db_->GetProperty( EXPECT_TRUE(db_->GetProperty(
"rocksdb.compression-ratio-at-level" + ToString(level), &property)); "rocksdb.compression-ratio-at-level" + std::to_string(level),
&property));
} else { } else {
EXPECT_TRUE(db_->GetProperty( EXPECT_TRUE(db_->GetProperty(
handles_[cf], "rocksdb.compression-ratio-at-level" + ToString(level), handles_[cf],
"rocksdb.compression-ratio-at-level" + std::to_string(level),
&property)); &property));
} }
return std::stod(property); return std::stod(property);

View File

@ -549,7 +549,7 @@ TEST_P(DBTestUniversalCompaction, CompactFilesOnUniversalCompaction) {
ASSERT_EQ(options.compaction_style, kCompactionStyleUniversal); ASSERT_EQ(options.compaction_style, kCompactionStyleUniversal);
Random rnd(301); Random rnd(301);
for (int key = 1024 * kEntriesPerBuffer; key >= 0; --key) { for (int key = 1024 * kEntriesPerBuffer; key >= 0; --key) {
ASSERT_OK(Put(1, ToString(key), rnd.RandomString(kTestValueSize))); ASSERT_OK(Put(1, std::to_string(key), rnd.RandomString(kTestValueSize)));
} }
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[1])); ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[1]));
ASSERT_OK(dbfull()->TEST_WaitForCompact()); ASSERT_OK(dbfull()->TEST_WaitForCompact());

View File

@ -1009,7 +1009,7 @@ TEST_F(DBWALTest, RecoveryWithLogDataForSomeCFs) {
if (log_files.size() > 0) { if (log_files.size() > 0) {
earliest_log_nums[i] = log_files[0]->LogNumber(); earliest_log_nums[i] = log_files[0]->LogNumber();
} else { } else {
earliest_log_nums[i] = port::kMaxUint64; earliest_log_nums[i] = std::numeric_limits<uint64_t>::max();
} }
} }
// Check at least the first WAL was cleaned up during the recovery. // Check at least the first WAL was cleaned up during the recovery.
@ -1288,7 +1288,7 @@ class RecoveryTestHelper {
WriteBatch batch; WriteBatch batch;
for (int i = 0; i < kKeysPerWALFile; i++) { for (int i = 0; i < kKeysPerWALFile; i++) {
std::string key = "key" + ToString((*count)++); std::string key = "key" + std::to_string((*count)++);
std::string value = test->DummyString(kValueSize); std::string value = test->DummyString(kValueSize);
ASSERT_NE(current_log_writer.get(), nullptr); ASSERT_NE(current_log_writer.get(), nullptr);
uint64_t seq = versions->LastSequence() + 1; uint64_t seq = versions->LastSequence() + 1;
@ -1319,7 +1319,7 @@ class RecoveryTestHelper {
static size_t GetData(DBWALTestBase* test) { static size_t GetData(DBWALTestBase* test) {
size_t count = 0; size_t count = 0;
for (size_t i = 0; i < kWALFilesCount * kKeysPerWALFile; i++) { for (size_t i = 0; i < kWALFilesCount * kKeysPerWALFile; i++) {
if (test->Get("key" + ToString(i)) != "NOT_FOUND") { if (test->Get("key" + std::to_string(i)) != "NOT_FOUND") {
++count; ++count;
} }
} }
@ -1616,7 +1616,7 @@ TEST_P(DBWALTestWithParams, kPointInTimeRecovery) {
if (!trunc || corrupt_offset != 0) { if (!trunc || corrupt_offset != 0) {
bool expect_data = true; bool expect_data = true;
for (size_t k = 0; k < maxkeys; ++k) { for (size_t k = 0; k < maxkeys; ++k) {
bool found = Get("key" + ToString(k)) != "NOT_FOUND"; bool found = Get("key" + std::to_string(k)) != "NOT_FOUND";
if (expect_data && !found) { if (expect_data && !found) {
expect_data = false; expect_data = false;
} }
@ -1752,7 +1752,7 @@ TEST_F(DBWALTest, RecoverWithoutFlush) {
size_t count = RecoveryTestHelper::FillData(this, &options); size_t count = RecoveryTestHelper::FillData(this, &options);
auto validateData = [this, count]() { auto validateData = [this, count]() {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
ASSERT_NE(Get("key" + ToString(i)), "NOT_FOUND"); ASSERT_NE(Get("key" + std::to_string(i)), "NOT_FOUND");
} }
}; };
Reopen(options); Reopen(options);
@ -1891,7 +1891,7 @@ TEST_P(DBWALTestWithParamsVaryingRecoveryMode,
ASSERT_OK(TryReopen(options)); ASSERT_OK(TryReopen(options));
// Append some more data. // Append some more data.
for (int k = 0; k < kAppendKeys; k++) { for (int k = 0; k < kAppendKeys; k++) {
std::string key = "extra_key" + ToString(k); std::string key = "extra_key" + std::to_string(k);
std::string value = DummyString(RecoveryTestHelper::kValueSize); std::string value = DummyString(RecoveryTestHelper::kValueSize);
ASSERT_OK(Put(key, value)); ASSERT_OK(Put(key, value));
} }
@ -1925,7 +1925,7 @@ TEST_F(DBWALTest, RestoreTotalLogSizeAfterRecoverWithoutFlush) {
std::string value_300k(300 * kKB, 'v'); std::string value_300k(300 * kKB, 'v');
ASSERT_OK(Put(0, "foo", "v1")); ASSERT_OK(Put(0, "foo", "v1"));
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
ASSERT_OK(Put(1, "key" + ToString(i), value_100k)); ASSERT_OK(Put(1, "key" + std::to_string(i), value_100k));
} }
// Get log files before reopen. // Get log files before reopen.
VectorLogPtr log_files_before; VectorLogPtr log_files_before;

View File

@ -1492,8 +1492,8 @@ TEST_F(DBBasicTestWithTimestamp, MultiGetRangeFiltering) {
// random data // random data
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
auto key = ToString(i * 10); auto key = std::to_string(i * 10);
auto value = ToString(i * 10); auto value = std::to_string(i * 10);
Slice key_slice = key; Slice key_slice = key;
Slice value_slice = value; Slice value_slice = value;
ASSERT_OK(db_->Put(write_opts, key_slice, ts, value_slice)); ASSERT_OK(db_->Put(write_opts, key_slice, ts, value_slice));
@ -1824,8 +1824,8 @@ class DataVisibilityTest : public DBBasicTestWithTimestampBase {
DataVisibilityTest() : DBBasicTestWithTimestampBase("data_visibility_test") { DataVisibilityTest() : DBBasicTestWithTimestampBase("data_visibility_test") {
// Initialize test data // Initialize test data
for (int i = 0; i < kTestDataSize; i++) { for (int i = 0; i < kTestDataSize; i++) {
test_data_[i].key = "key" + ToString(i); test_data_[i].key = "key" + std::to_string(i);
test_data_[i].value = "value" + ToString(i); test_data_[i].value = "value" + std::to_string(i);
test_data_[i].timestamp = Timestamp(i, 0); test_data_[i].timestamp = Timestamp(i, 0);
test_data_[i].ts = i; test_data_[i].ts = i;
test_data_[i].seq_num = kMaxSequenceNumber; test_data_[i].seq_num = kMaxSequenceNumber;

View File

@ -289,7 +289,7 @@ TEST_P(DBWriteTest, IOErrorOnWALWritePropagateToWriteThreadFollower) {
threads.push_back(port::Thread( threads.push_back(port::Thread(
[&](int index) { [&](int index) {
// All threads should fail. // All threads should fail.
auto res = Put("key" + ToString(index), "value"); auto res = Put("key" + std::to_string(index), "value");
if (options.manual_wal_flush) { if (options.manual_wal_flush) {
ASSERT_TRUE(res.ok()); ASSERT_TRUE(res.ok());
// we should see fs error when we do the flush // we should see fs error when we do the flush
@ -322,13 +322,13 @@ TEST_P(DBWriteTest, ManualWalFlushInEffect) {
Options options = GetOptions(); Options options = GetOptions();
Reopen(options); Reopen(options);
// try the 1st WAL created during open // try the 1st WAL created during open
ASSERT_TRUE(Put("key" + ToString(0), "value").ok()); ASSERT_TRUE(Put("key" + std::to_string(0), "value").ok());
ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty());
ASSERT_TRUE(dbfull()->FlushWAL(false).ok()); ASSERT_TRUE(dbfull()->FlushWAL(false).ok());
ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty());
// try the 2nd wal created during SwitchWAL // try the 2nd wal created during SwitchWAL
ASSERT_OK(dbfull()->TEST_SwitchWAL()); ASSERT_OK(dbfull()->TEST_SwitchWAL());
ASSERT_TRUE(Put("key" + ToString(0), "value").ok()); ASSERT_TRUE(Put("key" + std::to_string(0), "value").ok());
ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty());
ASSERT_TRUE(dbfull()->FlushWAL(false).ok()); ASSERT_TRUE(dbfull()->FlushWAL(false).ok());
ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty());
@ -344,7 +344,7 @@ TEST_P(DBWriteTest, IOErrorOnWALWriteTriggersReadOnlyMode) {
// Forcibly fail WAL write for the first Put only. Subsequent Puts should // Forcibly fail WAL write for the first Put only. Subsequent Puts should
// fail due to read-only mode // fail due to read-only mode
mock_env->SetFilesystemActive(i != 0); mock_env->SetFilesystemActive(i != 0);
auto res = Put("key" + ToString(i), "value"); auto res = Put("key" + std::to_string(i), "value");
// TSAN reports a false alarm for lock-order-inversion but Open and // TSAN reports a false alarm for lock-order-inversion but Open and
// FlushWAL are not run concurrently. Disabling this until TSAN is // FlushWAL are not run concurrently. Disabling this until TSAN is
// fixed. // fixed.
@ -398,14 +398,14 @@ TEST_P(DBWriteTest, LockWalInEffect) {
Options options = GetOptions(); Options options = GetOptions();
Reopen(options); Reopen(options);
// try the 1st WAL created during open // try the 1st WAL created during open
ASSERT_OK(Put("key" + ToString(0), "value")); ASSERT_OK(Put("key" + std::to_string(0), "value"));
ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty());
ASSERT_OK(dbfull()->LockWAL()); ASSERT_OK(dbfull()->LockWAL());
ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty(false)); ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty(false));
ASSERT_OK(dbfull()->UnlockWAL()); ASSERT_OK(dbfull()->UnlockWAL());
// try the 2nd wal created during SwitchWAL // try the 2nd wal created during SwitchWAL
ASSERT_OK(dbfull()->TEST_SwitchWAL()); ASSERT_OK(dbfull()->TEST_SwitchWAL());
ASSERT_OK(Put("key" + ToString(0), "value")); ASSERT_OK(Put("key" + std::to_string(0), "value"));
ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty()); ASSERT_TRUE(options.manual_wal_flush != dbfull()->TEST_WALBufferIsEmpty());
ASSERT_OK(dbfull()->LockWAL()); ASSERT_OK(dbfull()->LockWAL());
ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty(false)); ASSERT_TRUE(dbfull()->TEST_WALBufferIsEmpty(false));

View File

@ -90,7 +90,8 @@ inline bool IsExtendedValueType(ValueType t) {
// can be packed together into 64-bits. // can be packed together into 64-bits.
static const SequenceNumber kMaxSequenceNumber = ((0x1ull << 56) - 1); static const SequenceNumber kMaxSequenceNumber = ((0x1ull << 56) - 1);
static const SequenceNumber kDisableGlobalSequenceNumber = port::kMaxUint64; static const SequenceNumber kDisableGlobalSequenceNumber =
std::numeric_limits<uint64_t>::max();
constexpr uint64_t kNumInternalBytes = 8; constexpr uint64_t kNumInternalBytes = 8;

View File

@ -56,7 +56,7 @@ class DeleteFileTest : public DBTestBase {
options.sync = false; options.sync = false;
ReadOptions roptions; ReadOptions roptions;
for (int i = startkey; i < (numkeys + startkey) ; i++) { for (int i = startkey; i < (numkeys + startkey) ; i++) {
std::string temp = ToString(i); std::string temp = std::to_string(i);
Slice key(temp); Slice key(temp);
Slice value(temp); Slice value(temp);
ASSERT_OK(db_->Put(options, key, value)); ASSERT_OK(db_->Put(options, key, value));

View File

@ -1583,11 +1583,11 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
std::string prop; std::string prop;
ASSERT_EQ(listener[i]->WaitForRecovery(5000000), true); ASSERT_EQ(listener[i]->WaitForRecovery(5000000), true);
ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact(true)); ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact(true));
EXPECT_TRUE( EXPECT_TRUE(db[i]->GetProperty(
db[i]->GetProperty("rocksdb.num-files-at-level" + ToString(0), &prop)); "rocksdb.num-files-at-level" + std::to_string(0), &prop));
EXPECT_EQ(atoi(prop.c_str()), 0); EXPECT_EQ(atoi(prop.c_str()), 0);
EXPECT_TRUE( EXPECT_TRUE(db[i]->GetProperty(
db[i]->GetProperty("rocksdb.num-files-at-level" + ToString(1), &prop)); "rocksdb.num-files-at-level" + std::to_string(1), &prop));
EXPECT_EQ(atoi(prop.c_str()), 1); EXPECT_EQ(atoi(prop.c_str()), 1);
} }
@ -1720,11 +1720,11 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
if (i == 1) { if (i == 1) {
ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact(true)); ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact(true));
} }
EXPECT_TRUE( EXPECT_TRUE(db[i]->GetProperty(
db[i]->GetProperty("rocksdb.num-files-at-level" + ToString(0), &prop)); "rocksdb.num-files-at-level" + std::to_string(0), &prop));
EXPECT_EQ(atoi(prop.c_str()), 0); EXPECT_EQ(atoi(prop.c_str()), 0);
EXPECT_TRUE( EXPECT_TRUE(db[i]->GetProperty(
db[i]->GetProperty("rocksdb.num-files-at-level" + ToString(1), &prop)); "rocksdb.num-files-at-level" + std::to_string(1), &prop));
EXPECT_EQ(atoi(prop.c_str()), 1); EXPECT_EQ(atoi(prop.c_str()), 1);
} }

View File

@ -91,7 +91,7 @@ class ExternalSSTFileBasicTest
bool write_global_seqno, bool verify_checksums_before_ingest, bool write_global_seqno, bool verify_checksums_before_ingest,
std::map<std::string, std::string>* true_data) { std::map<std::string, std::string>* true_data) {
assert(value_types.size() == 1 || keys.size() == value_types.size()); assert(value_types.size() == 1 || keys.size() == value_types.size());
std::string file_path = sst_files_dir_ + ToString(file_id); std::string file_path = sst_files_dir_ + std::to_string(file_id);
SstFileWriter sst_file_writer(EnvOptions(), options); SstFileWriter sst_file_writer(EnvOptions(), options);
Status s = sst_file_writer.Open(file_path); Status s = sst_file_writer.Open(file_path);
@ -123,7 +123,7 @@ class ExternalSSTFileBasicTest
} }
for (size_t i = 0; i < keys.size(); i++) { for (size_t i = 0; i < keys.size(); i++) {
std::string key = Key(keys[i]); std::string key = Key(keys[i]);
std::string value = Key(keys[i]) + ToString(file_id); std::string value = Key(keys[i]) + std::to_string(file_id);
ValueType value_type = ValueType value_type =
(value_types.size() == 1 ? value_types[0] : value_types[i]); (value_types.size() == 1 ? value_types[0] : value_types[i]);
switch (value_type) { switch (value_type) {
@ -190,10 +190,10 @@ class ExternalSSTFileBasicTest
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
uint64_t GetSstSizeHelper(Temperature temperature) { uint64_t GetSstSizeHelper(Temperature temperature) {
std::string prop; std::string prop;
EXPECT_TRUE( EXPECT_TRUE(dbfull()->GetProperty(
dbfull()->GetProperty(DB::Properties::kLiveSstFilesSizeAtTemperature + DB::Properties::kLiveSstFilesSizeAtTemperature +
ToString(static_cast<uint8_t>(temperature)), std::to_string(static_cast<uint8_t>(temperature)),
&prop)); &prop));
return static_cast<uint64_t>(std::atoi(prop.c_str())); return static_cast<uint64_t>(std::atoi(prop.c_str()));
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
@ -1184,7 +1184,7 @@ TEST_F(ExternalSSTFileBasicTest, SyncFailure) {
std::unique_ptr<SstFileWriter> sst_file_writer( std::unique_ptr<SstFileWriter> sst_file_writer(
new SstFileWriter(EnvOptions(), sst_file_writer_options)); new SstFileWriter(EnvOptions(), sst_file_writer_options));
std::string file_name = std::string file_name =
sst_files_dir_ + "sync_failure_test_" + ToString(i) + ".sst"; sst_files_dir_ + "sync_failure_test_" + std::to_string(i) + ".sst";
ASSERT_OK(sst_file_writer->Open(file_name)); ASSERT_OK(sst_file_writer->Open(file_name));
ASSERT_OK(sst_file_writer->Put("bar", "v2")); ASSERT_OK(sst_file_writer->Put("bar", "v2"));
ASSERT_OK(sst_file_writer->Finish()); ASSERT_OK(sst_file_writer->Finish());
@ -1514,13 +1514,13 @@ TEST_P(ExternalSSTFileBasicTest, IngestFileWithFirstByteTampered) {
EnvOptions env_options; EnvOptions env_options;
do { do {
Options options = CurrentOptions(); Options options = CurrentOptions();
std::string file_path = sst_files_dir_ + ToString(file_id++); std::string file_path = sst_files_dir_ + std::to_string(file_id++);
SstFileWriter sst_file_writer(env_options, options); SstFileWriter sst_file_writer(env_options, options);
Status s = sst_file_writer.Open(file_path); Status s = sst_file_writer.Open(file_path);
ASSERT_OK(s); ASSERT_OK(s);
for (int i = 0; i != 100; ++i) { for (int i = 0; i != 100; ++i) {
std::string key = Key(i); std::string key = Key(i);
std::string value = Key(i) + ToString(0); std::string value = Key(i) + std::to_string(0);
ASSERT_OK(sst_file_writer.Put(key, value)); ASSERT_OK(sst_file_writer.Put(key, value));
} }
ASSERT_OK(sst_file_writer.Finish()); ASSERT_OK(sst_file_writer.Finish());
@ -1585,14 +1585,14 @@ TEST_P(ExternalSSTFileBasicTest, IngestExternalFileWithCorruptedPropsBlock) {
int file_id = 0; int file_id = 0;
Random64 rand(time(nullptr)); Random64 rand(time(nullptr));
do { do {
std::string file_path = sst_files_dir_ + ToString(file_id++); std::string file_path = sst_files_dir_ + std::to_string(file_id++);
Options options = CurrentOptions(); Options options = CurrentOptions();
SstFileWriter sst_file_writer(EnvOptions(), options); SstFileWriter sst_file_writer(EnvOptions(), options);
Status s = sst_file_writer.Open(file_path); Status s = sst_file_writer.Open(file_path);
ASSERT_OK(s); ASSERT_OK(s);
for (int i = 0; i != 100; ++i) { for (int i = 0; i != 100; ++i) {
std::string key = Key(i); std::string key = Key(i);
std::string value = Key(i) + ToString(0); std::string value = Key(i) + std::to_string(0);
ASSERT_OK(sst_file_writer.Put(key, value)); ASSERT_OK(sst_file_writer.Put(key, value));
} }
ASSERT_OK(sst_file_writer.Finish()); ASSERT_OK(sst_file_writer.Finish());
@ -1799,7 +1799,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestWithTemperature) {
TEST_F(ExternalSSTFileBasicTest, FailIfNotBottommostLevel) { TEST_F(ExternalSSTFileBasicTest, FailIfNotBottommostLevel) {
Options options = GetDefaultOptions(); Options options = GetDefaultOptions();
std::string file_path = sst_files_dir_ + ToString(1); std::string file_path = sst_files_dir_ + std::to_string(1);
SstFileWriter sfw(EnvOptions(), options); SstFileWriter sfw(EnvOptions(), options);
ASSERT_OK(sfw.Open(file_path)); ASSERT_OK(sfw.Open(file_path));

View File

@ -118,7 +118,7 @@ class ExternalSSTFileTest
}); });
data.resize(uniq_iter - data.begin()); data.resize(uniq_iter - data.begin());
} }
std::string file_path = sst_files_dir_ + ToString(file_id); std::string file_path = sst_files_dir_ + std::to_string(file_id);
SstFileWriter sst_file_writer(EnvOptions(), options, cfh); SstFileWriter sst_file_writer(EnvOptions(), options, cfh);
Status s = sst_file_writer.Open(file_path); Status s = sst_file_writer.Open(file_path);
if (!s.ok()) { if (!s.ok()) {
@ -172,7 +172,7 @@ class ExternalSSTFileTest
}); });
data.resize(uniq_iter - data.begin()); data.resize(uniq_iter - data.begin());
} }
std::string file_path = sst_files_dir_ + ToString(file_id); std::string file_path = sst_files_dir_ + std::to_string(file_id);
SstFileWriter sst_file_writer(EnvOptions(), options, cfh); SstFileWriter sst_file_writer(EnvOptions(), options, cfh);
Status s = sst_file_writer.Open(file_path); Status s = sst_file_writer.Open(file_path);
@ -270,7 +270,7 @@ class ExternalSSTFileTest
ColumnFamilyHandle* cfh = nullptr) { ColumnFamilyHandle* cfh = nullptr) {
std::vector<std::pair<std::string, std::string>> file_data; std::vector<std::pair<std::string, std::string>> file_data;
for (auto& k : keys) { for (auto& k : keys) {
file_data.emplace_back(Key(k), Key(k) + ToString(file_id)); file_data.emplace_back(Key(k), Key(k) + std::to_string(file_id));
} }
return GenerateAndAddExternalFile(options, file_data, file_id, return GenerateAndAddExternalFile(options, file_data, file_id,
allow_global_seqno, write_global_seqno, allow_global_seqno, write_global_seqno,
@ -966,7 +966,7 @@ TEST_F(ExternalSSTFileTest, MultiThreaded) {
// Generate file names // Generate file names
std::vector<std::string> file_names; std::vector<std::string> file_names;
for (int i = 0; i < num_files; i++) { for (int i = 0; i < num_files; i++) {
std::string file_name = "file_" + ToString(i) + ".sst"; std::string file_name = "file_" + std::to_string(i) + ".sst";
file_names.push_back(sst_files_dir_ + file_name); file_names.push_back(sst_files_dir_ + file_name);
} }
@ -1116,7 +1116,7 @@ TEST_F(ExternalSSTFileTest, OverlappingRanges) {
int range_end = key_ranges[i].second; int range_end = key_ranges[i].second;
Status s; Status s;
std::string range_val = "range_" + ToString(i); std::string range_val = "range_" + std::to_string(i);
// For 20% of ranges we use DB::Put, for 80% we use DB::AddFile // For 20% of ranges we use DB::Put, for 80% we use DB::AddFile
if (i && i % 5 == 0) { if (i && i % 5 == 0) {
@ -1456,7 +1456,7 @@ TEST_F(ExternalSSTFileTest, CompactDuringAddFileRandom) {
ASSERT_EQ(Get(Key(range_start)), Key(range_start)) << rid; ASSERT_EQ(Get(Key(range_start)), Key(range_start)) << rid;
ASSERT_EQ(Get(Key(range_end)), Key(range_end)) << rid; ASSERT_EQ(Get(Key(range_end)), Key(range_end)) << rid;
for (int k = range_start + 1; k < range_end; k++) { for (int k = range_start + 1; k < range_end; k++) {
std::string v = Key(k) + ToString(rid); std::string v = Key(k) + std::to_string(rid);
ASSERT_EQ(Get(Key(k)), v) << rid; ASSERT_EQ(Get(Key(k)), v) << rid;
} }
} }
@ -2405,7 +2405,7 @@ TEST_P(ExternalSSTBlockChecksumTest, DISABLED_HugeBlockChecksum) {
SstFileWriter sst_file_writer(EnvOptions(), options); SstFileWriter sst_file_writer(EnvOptions(), options);
// 2^32 - 1, will lead to data block with more than 2^32 bytes // 2^32 - 1, will lead to data block with more than 2^32 bytes
size_t huge_size = port::kMaxUint32; size_t huge_size = std::numeric_limits<uint32_t>::max();
std::string f = sst_files_dir_ + "f.sst"; std::string f = sst_files_dir_ + "f.sst";
ASSERT_OK(sst_file_writer.Open(f)); ASSERT_OK(sst_file_writer.Open(f));

View File

@ -58,10 +58,7 @@ class FileIndexer {
void UpdateIndex(Arena* arena, const size_t num_levels, void UpdateIndex(Arena* arena, const size_t num_levels,
std::vector<FileMetaData*>* const files); std::vector<FileMetaData*>* const files);
enum { enum { kLevelMaxIndex = std::numeric_limits<int32_t>::max() };
// MSVC version 1800 still does not have constexpr for ::max()
kLevelMaxIndex = ROCKSDB_NAMESPACE::port::kMaxInt32
};
private: private:
size_t num_levels_; size_t num_levels_;

View File

@ -464,6 +464,7 @@ Status FlushJob::MemPurge() {
env, ShouldReportDetailedTime(env, ioptions->stats), env, ShouldReportDetailedTime(env, ioptions->stats),
true /* internal key corruption is not ok */, range_del_agg.get(), true /* internal key corruption is not ok */, range_del_agg.get(),
nullptr, ioptions->allow_data_in_errors, nullptr, ioptions->allow_data_in_errors,
ioptions->enforce_single_del_contracts,
/*compaction=*/nullptr, compaction_filter.get(), /*compaction=*/nullptr, compaction_filter.get(),
/*shutting_down=*/nullptr, /*shutting_down=*/nullptr,
/*manual_compaction_paused=*/nullptr, /*manual_compaction_paused=*/nullptr,
@ -931,9 +932,9 @@ Status FlushJob::WriteLevel0Table() {
assert(!s.ok() || io_s.ok()); assert(!s.ok() || io_s.ok());
io_s.PermitUncheckedError(); io_s.PermitUncheckedError();
if (num_input_entries != total_num_entries && s.ok()) { if (num_input_entries != total_num_entries && s.ok()) {
std::string msg = "Expected " + ToString(total_num_entries) + std::string msg = "Expected " + std::to_string(total_num_entries) +
" entries in memtables, but read " + " entries in memtables, but read " +
ToString(num_input_entries); std::to_string(num_input_entries);
ROCKS_LOG_WARN(db_options_.info_log, "[%s] [JOB %d] Level-0 flush %s", ROCKS_LOG_WARN(db_options_.info_log, "[%s] [JOB %d] Level-0 flush %s",
cfd_->GetName().c_str(), job_context_->job_id, cfd_->GetName().c_str(), job_context_->job_id,
msg.c_str()); msg.c_str());

View File

@ -164,12 +164,12 @@ TEST_F(FlushJobTest, Empty) {
SnapshotChecker* snapshot_checker = nullptr; // not relavant SnapshotChecker* snapshot_checker = nullptr; // not relavant
FlushJob flush_job( FlushJob flush_job(
dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_, dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_,
*cfd->GetLatestMutableCFOptions(), port::kMaxUint64 /* memtable_id */, *cfd->GetLatestMutableCFOptions(),
env_options_, versions_.get(), &mutex_, &shutting_down_, {}, std::numeric_limits<uint64_t>::max() /* memtable_id */, env_options_,
kMaxSequenceNumber, snapshot_checker, &job_context, nullptr, nullptr, versions_.get(), &mutex_, &shutting_down_, {}, kMaxSequenceNumber,
nullptr, kNoCompression, nullptr, &event_logger, false, snapshot_checker, &job_context, nullptr, nullptr, nullptr, kNoCompression,
true /* sync_output_directory */, true /* write_manifest */, nullptr, &event_logger, false, true /* sync_output_directory */,
Env::Priority::USER, nullptr /*IOTracer*/); true /* write_manifest */, Env::Priority::USER, nullptr /*IOTracer*/);
{ {
InstrumentedMutexLock l(&mutex_); InstrumentedMutexLock l(&mutex_);
flush_job.PickMemTable(); flush_job.PickMemTable();
@ -191,7 +191,7 @@ TEST_F(FlushJobTest, NonEmpty) {
// range-delete "9995" -> "9999" at seqno 10000 // range-delete "9995" -> "9999" at seqno 10000
// blob references with seqnos 10001..10006 // blob references with seqnos 10001..10006
for (int i = 1; i < 10000; ++i) { for (int i = 1; i < 10000; ++i) {
std::string key(ToString((i + 1000) % 10000)); std::string key(std::to_string((i + 1000) % 10000));
std::string value("value" + key); std::string value("value" + key);
ASSERT_OK(new_mem->Add(SequenceNumber(i), kTypeValue, key, value, ASSERT_OK(new_mem->Add(SequenceNumber(i), kTypeValue, key, value,
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
@ -214,7 +214,7 @@ TEST_F(FlushJobTest, NonEmpty) {
constexpr std::array<uint64_t, 6> blob_file_numbers{{ constexpr std::array<uint64_t, 6> blob_file_numbers{{
kInvalidBlobFileNumber, 5, 103, 17, 102, 101}}; kInvalidBlobFileNumber, 5, 103, 17, 102, 101}};
for (size_t i = 0; i < blob_file_numbers.size(); ++i) { for (size_t i = 0; i < blob_file_numbers.size(); ++i) {
std::string key(ToString(i + 10001)); std::string key(std::to_string(i + 10001));
std::string blob_index; std::string blob_index;
if (i == 0) { if (i == 0) {
BlobIndex::EncodeInlinedTTL(&blob_index, /* expiration */ 1234567890ULL, BlobIndex::EncodeInlinedTTL(&blob_index, /* expiration */ 1234567890ULL,
@ -248,11 +248,12 @@ TEST_F(FlushJobTest, NonEmpty) {
SnapshotChecker* snapshot_checker = nullptr; // not relavant SnapshotChecker* snapshot_checker = nullptr; // not relavant
FlushJob flush_job( FlushJob flush_job(
dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_, dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_,
*cfd->GetLatestMutableCFOptions(), port::kMaxUint64 /* memtable_id */, *cfd->GetLatestMutableCFOptions(),
env_options_, versions_.get(), &mutex_, &shutting_down_, {}, std::numeric_limits<uint64_t>::max() /* memtable_id */, env_options_,
kMaxSequenceNumber, snapshot_checker, &job_context, nullptr, nullptr, versions_.get(), &mutex_, &shutting_down_, {}, kMaxSequenceNumber,
nullptr, kNoCompression, db_options_.statistics.get(), &event_logger, snapshot_checker, &job_context, nullptr, nullptr, nullptr, kNoCompression,
true, true /* sync_output_directory */, true /* write_manifest */, db_options_.statistics.get(), &event_logger, true,
true /* sync_output_directory */, true /* write_manifest */,
Env::Priority::USER, nullptr /*IOTracer*/); Env::Priority::USER, nullptr /*IOTracer*/);
HistogramData hist; HistogramData hist;
@ -264,7 +265,7 @@ TEST_F(FlushJobTest, NonEmpty) {
db_options_.statistics->histogramData(FLUSH_TIME, &hist); db_options_.statistics->histogramData(FLUSH_TIME, &hist);
ASSERT_GT(hist.average, 0.0); ASSERT_GT(hist.average, 0.0);
ASSERT_EQ(ToString(0), file_meta.smallest.user_key().ToString()); ASSERT_EQ(std::to_string(0), file_meta.smallest.user_key().ToString());
ASSERT_EQ("9999a", file_meta.largest.user_key().ToString()); ASSERT_EQ("9999a", file_meta.largest.user_key().ToString());
ASSERT_EQ(1, file_meta.fd.smallest_seqno); ASSERT_EQ(1, file_meta.fd.smallest_seqno);
ASSERT_EQ(10006, file_meta.fd.largest_seqno); ASSERT_EQ(10006, file_meta.fd.largest_seqno);
@ -290,7 +291,7 @@ TEST_F(FlushJobTest, FlushMemTablesSingleColumnFamily) {
memtable_ids.push_back(mem->GetID()); memtable_ids.push_back(mem->GetID());
for (size_t j = 0; j < num_keys_per_table; ++j) { for (size_t j = 0; j < num_keys_per_table; ++j) {
std::string key(ToString(j + i * num_keys_per_table)); std::string key(std::to_string(j + i * num_keys_per_table));
std::string value("value" + key); std::string value("value" + key);
ASSERT_OK(mem->Add(SequenceNumber(j + i * num_keys_per_table), kTypeValue, ASSERT_OK(mem->Add(SequenceNumber(j + i * num_keys_per_table), kTypeValue,
key, value, nullptr /* kv_prot_info */)); key, value, nullptr /* kv_prot_info */));
@ -325,7 +326,7 @@ TEST_F(FlushJobTest, FlushMemTablesSingleColumnFamily) {
db_options_.statistics->histogramData(FLUSH_TIME, &hist); db_options_.statistics->histogramData(FLUSH_TIME, &hist);
ASSERT_GT(hist.average, 0.0); ASSERT_GT(hist.average, 0.0);
ASSERT_EQ(ToString(0), file_meta.smallest.user_key().ToString()); ASSERT_EQ(std::to_string(0), file_meta.smallest.user_key().ToString());
ASSERT_EQ("99", file_meta.largest.user_key().ToString()); ASSERT_EQ("99", file_meta.largest.user_key().ToString());
ASSERT_EQ(0, file_meta.fd.smallest_seqno); ASSERT_EQ(0, file_meta.fd.smallest_seqno);
ASSERT_EQ(SequenceNumber(num_mems_to_flush * num_keys_per_table - 1), ASSERT_EQ(SequenceNumber(num_mems_to_flush * num_keys_per_table - 1),
@ -363,7 +364,7 @@ TEST_F(FlushJobTest, FlushMemtablesMultipleColumnFamilies) {
mem->Ref(); mem->Ref();
for (size_t j = 0; j != num_keys_per_memtable; ++j) { for (size_t j = 0; j != num_keys_per_memtable; ++j) {
std::string key(ToString(j + i * num_keys_per_memtable)); std::string key(std::to_string(j + i * num_keys_per_memtable));
std::string value("value" + key); std::string value("value" + key);
ASSERT_OK(mem->Add(curr_seqno++, kTypeValue, key, value, ASSERT_OK(mem->Add(curr_seqno++, kTypeValue, key, value,
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
@ -438,7 +439,7 @@ TEST_F(FlushJobTest, FlushMemtablesMultipleColumnFamilies) {
ASSERT_GT(hist.average, 0.0); ASSERT_GT(hist.average, 0.0);
k = 0; k = 0;
for (const auto& file_meta : file_metas) { for (const auto& file_meta : file_metas) {
ASSERT_EQ(ToString(0), file_meta.smallest.user_key().ToString()); ASSERT_EQ(std::to_string(0), file_meta.smallest.user_key().ToString());
ASSERT_EQ("999", file_meta.largest.user_key() ASSERT_EQ("999", file_meta.largest.user_key()
.ToString()); // max key by bytewise comparator .ToString()); // max key by bytewise comparator
ASSERT_EQ(smallest_seqs[k], file_meta.fd.smallest_seqno); ASSERT_EQ(smallest_seqs[k], file_meta.fd.smallest_seqno);
@ -479,7 +480,7 @@ TEST_F(FlushJobTest, Snapshots) {
SequenceNumber current_seqno = 0; SequenceNumber current_seqno = 0;
auto inserted_keys = mock::MakeMockFile(); auto inserted_keys = mock::MakeMockFile();
for (int i = 1; i < keys; ++i) { for (int i = 1; i < keys; ++i) {
std::string key(ToString(i)); std::string key(std::to_string(i));
int insertions = rnd.Uniform(max_inserts_per_keys); int insertions = rnd.Uniform(max_inserts_per_keys);
for (int j = 0; j < insertions; ++j) { for (int j = 0; j < insertions; ++j) {
std::string value(rnd.HumanReadableString(10)); std::string value(rnd.HumanReadableString(10));
@ -509,11 +510,12 @@ TEST_F(FlushJobTest, Snapshots) {
SnapshotChecker* snapshot_checker = nullptr; // not relavant SnapshotChecker* snapshot_checker = nullptr; // not relavant
FlushJob flush_job( FlushJob flush_job(
dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_, dbname_, versions_->GetColumnFamilySet()->GetDefault(), db_options_,
*cfd->GetLatestMutableCFOptions(), port::kMaxUint64 /* memtable_id */, *cfd->GetLatestMutableCFOptions(),
env_options_, versions_.get(), &mutex_, &shutting_down_, snapshots, std::numeric_limits<uint64_t>::max() /* memtable_id */, env_options_,
kMaxSequenceNumber, snapshot_checker, &job_context, nullptr, nullptr, versions_.get(), &mutex_, &shutting_down_, snapshots, kMaxSequenceNumber,
nullptr, kNoCompression, db_options_.statistics.get(), &event_logger, snapshot_checker, &job_context, nullptr, nullptr, nullptr, kNoCompression,
true, true /* sync_output_directory */, true /* write_manifest */, db_options_.statistics.get(), &event_logger, true,
true /* sync_output_directory */, true /* write_manifest */,
Env::Priority::USER, nullptr /*IOTracer*/); Env::Priority::USER, nullptr /*IOTracer*/);
mutex_.Lock(); mutex_.Lock();
flush_job.PickMemTable(); flush_job.PickMemTable();
@ -577,9 +579,9 @@ TEST_F(FlushJobTimestampTest, AllKeysExpired) {
PutFixed64(&full_history_ts_low, std::numeric_limits<uint64_t>::max()); PutFixed64(&full_history_ts_low, std::numeric_limits<uint64_t>::max());
FlushJob flush_job( FlushJob flush_job(
dbname_, cfd, db_options_, *cfd->GetLatestMutableCFOptions(), dbname_, cfd, db_options_, *cfd->GetLatestMutableCFOptions(),
port::kMaxUint64 /* memtable_id */, env_options_, versions_.get(), std::numeric_limits<uint64_t>::max() /* memtable_id */, env_options_,
&mutex_, &shutting_down_, snapshots, kMaxSequenceNumber, snapshot_checker, versions_.get(), &mutex_, &shutting_down_, snapshots, kMaxSequenceNumber,
&job_context, nullptr, nullptr, nullptr, kNoCompression, snapshot_checker, &job_context, nullptr, nullptr, nullptr, kNoCompression,
db_options_.statistics.get(), &event_logger, true, db_options_.statistics.get(), &event_logger, true,
true /* sync_output_directory */, true /* write_manifest */, true /* sync_output_directory */, true /* write_manifest */,
Env::Priority::USER, nullptr /*IOTracer*/, /*db_id=*/"", Env::Priority::USER, nullptr /*IOTracer*/, /*db_id=*/"",
@ -628,9 +630,9 @@ TEST_F(FlushJobTimestampTest, NoKeyExpired) {
PutFixed64(&full_history_ts_low, 0); PutFixed64(&full_history_ts_low, 0);
FlushJob flush_job( FlushJob flush_job(
dbname_, cfd, db_options_, *cfd->GetLatestMutableCFOptions(), dbname_, cfd, db_options_, *cfd->GetLatestMutableCFOptions(),
port::kMaxUint64 /* memtable_id */, env_options_, versions_.get(), std::numeric_limits<uint64_t>::max() /* memtable_id */, env_options_,
&mutex_, &shutting_down_, snapshots, kMaxSequenceNumber, snapshot_checker, versions_.get(), &mutex_, &shutting_down_, snapshots, kMaxSequenceNumber,
&job_context, nullptr, nullptr, nullptr, kNoCompression, snapshot_checker, &job_context, nullptr, nullptr, nullptr, kNoCompression,
db_options_.statistics.get(), &event_logger, true, db_options_.statistics.get(), &event_logger, true,
true /* sync_output_directory */, true /* write_manifest */, true /* sync_output_directory */, true /* write_manifest */,
Env::Priority::USER, nullptr /*IOTracer*/, /*db_id=*/"", Env::Priority::USER, nullptr /*IOTracer*/, /*db_id=*/"",

View File

@ -604,7 +604,7 @@ bool ForwardIterator::PrepareValue() {
Status ForwardIterator::GetProperty(std::string prop_name, std::string* prop) { Status ForwardIterator::GetProperty(std::string prop_name, std::string* prop) {
assert(prop != nullptr); assert(prop != nullptr);
if (prop_name == "rocksdb.iterator.super-version-number") { if (prop_name == "rocksdb.iterator.super-version-number") {
*prop = ToString(sv_->version_number); *prop = std::to_string(sv_->version_number);
return Status::OK(); return Status::OK();
} }
return Status::InvalidArgument(); return Status::InvalidArgument();

View File

@ -704,20 +704,19 @@ void InternalStats::CacheEntryRoleStats::ToMap(
auto& v = *values; auto& v = *values;
v[BlockCacheEntryStatsMapKeys::CacheId()] = cache_id; v[BlockCacheEntryStatsMapKeys::CacheId()] = cache_id;
v[BlockCacheEntryStatsMapKeys::CacheCapacityBytes()] = v[BlockCacheEntryStatsMapKeys::CacheCapacityBytes()] =
ROCKSDB_NAMESPACE::ToString(cache_capacity); std::to_string(cache_capacity);
v[BlockCacheEntryStatsMapKeys::LastCollectionDurationSeconds()] = v[BlockCacheEntryStatsMapKeys::LastCollectionDurationSeconds()] =
ROCKSDB_NAMESPACE::ToString(GetLastDurationMicros() / 1000000.0); std::to_string(GetLastDurationMicros() / 1000000.0);
v[BlockCacheEntryStatsMapKeys::LastCollectionAgeSeconds()] = v[BlockCacheEntryStatsMapKeys::LastCollectionAgeSeconds()] =
ROCKSDB_NAMESPACE::ToString((clock->NowMicros() - last_end_time_micros_) / std::to_string((clock->NowMicros() - last_end_time_micros_) / 1000000U);
1000000U);
for (size_t i = 0; i < kNumCacheEntryRoles; ++i) { for (size_t i = 0; i < kNumCacheEntryRoles; ++i) {
auto role = static_cast<CacheEntryRole>(i); auto role = static_cast<CacheEntryRole>(i);
v[BlockCacheEntryStatsMapKeys::EntryCount(role)] = v[BlockCacheEntryStatsMapKeys::EntryCount(role)] =
ROCKSDB_NAMESPACE::ToString(entry_counts[i]); std::to_string(entry_counts[i]);
v[BlockCacheEntryStatsMapKeys::UsedBytes(role)] = v[BlockCacheEntryStatsMapKeys::UsedBytes(role)] =
ROCKSDB_NAMESPACE::ToString(total_charges[i]); std::to_string(total_charges[i]);
v[BlockCacheEntryStatsMapKeys::UsedPercent(role)] = v[BlockCacheEntryStatsMapKeys::UsedPercent(role)] =
ROCKSDB_NAMESPACE::ToString(100.0 * total_charges[i] / cache_capacity); std::to_string(100.0 * total_charges[i] / cache_capacity);
} }
} }
@ -763,7 +762,7 @@ bool InternalStats::HandleLiveSstFilesSizeAtTemperature(std::string* value,
} }
} }
*value = ToString(size); *value = std::to_string(size);
return true; return true;
} }
@ -919,7 +918,7 @@ bool InternalStats::HandleCompressionRatioAtLevelPrefix(std::string* value,
if (!ok || level >= static_cast<uint64_t>(number_levels_)) { if (!ok || level >= static_cast<uint64_t>(number_levels_)) {
return false; return false;
} }
*value = ToString( *value = std::to_string(
vstorage->GetEstimatedCompressionRatioAtLevel(static_cast<int>(level))); vstorage->GetEstimatedCompressionRatioAtLevel(static_cast<int>(level)));
return true; return true;
} }
@ -1006,7 +1005,7 @@ static std::map<std::string, std::string> MapUint64ValuesToString(
const std::map<std::string, uint64_t>& from) { const std::map<std::string, uint64_t>& from) {
std::map<std::string, std::string> to; std::map<std::string, std::string> to;
for (const auto& e : from) { for (const auto& e : from) {
to[e.first] = ToString(e.second); to[e.first] = std::to_string(e.second);
} }
return to; return to;
} }
@ -1500,7 +1499,7 @@ void InternalStats::DumpCFMapStats(
DumpCFMapStats(vstorage, &levels_stats, &compaction_stats_sum); DumpCFMapStats(vstorage, &levels_stats, &compaction_stats_sum);
for (auto const& level_ent : levels_stats) { for (auto const& level_ent : levels_stats) {
auto level_str = auto level_str =
level_ent.first == -1 ? "Sum" : "L" + ToString(level_ent.first); level_ent.first == -1 ? "Sum" : "L" + std::to_string(level_ent.first);
for (auto const& stat_ent : level_ent.second) { for (auto const& stat_ent : level_ent.second) {
auto stat_type = stat_ent.first; auto stat_type = stat_ent.first;
auto key_str = auto key_str =
@ -1651,7 +1650,8 @@ void InternalStats::DumpCFStatsNoFileHistogram(std::string* value) {
DumpCFMapStats(vstorage, &levels_stats, &compaction_stats_sum); DumpCFMapStats(vstorage, &levels_stats, &compaction_stats_sum);
for (int l = 0; l < number_levels_; ++l) { for (int l = 0; l < number_levels_; ++l) {
if (levels_stats.find(l) != levels_stats.end()) { if (levels_stats.find(l) != levels_stats.end()) {
PrintLevelStats(buf, sizeof(buf), "L" + ToString(l), levels_stats[l]); PrintLevelStats(buf, sizeof(buf), "L" + std::to_string(l),
levels_stats[l]);
value->append(buf); value->append(buf);
} }
} }

View File

@ -436,10 +436,10 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
std::vector<std::vector<ColumnFamilyHandle *>> vec_handles; std::vector<std::vector<ColumnFamilyHandle *>> vec_handles;
for (int d = 0; d < kNumDBs; ++d) { for (int d = 0; d < kNumDBs; ++d) {
ASSERT_OK(DestroyDB(dbname_ + ToString(d), options)); ASSERT_OK(DestroyDB(dbname_ + std::to_string(d), options));
DB* db; DB* db;
std::vector<ColumnFamilyHandle*> handles; std::vector<ColumnFamilyHandle*> handles;
ASSERT_OK(DB::Open(options, dbname_ + ToString(d), &db)); ASSERT_OK(DB::Open(options, dbname_ + std::to_string(d), &db));
for (size_t c = 0; c < cf_names.size(); ++c) { for (size_t c = 0; c < cf_names.size(); ++c) {
ColumnFamilyHandle* handle; ColumnFamilyHandle* handle;
ASSERT_OK(db->CreateColumnFamily(cf_opts, cf_names[c], &handle)); ASSERT_OK(db->CreateColumnFamily(cf_opts, cf_names[c], &handle));
@ -527,7 +527,8 @@ TEST_F(EventListenerTest, DisableBGCompaction) {
// keep writing until writes are forced to stop. // keep writing until writes are forced to stop.
for (int i = 0; static_cast<int>(cf_meta.file_count) < kSlowdownTrigger * 10; for (int i = 0; static_cast<int>(cf_meta.file_count) < kSlowdownTrigger * 10;
++i) { ++i) {
ASSERT_OK(Put(1, ToString(i), std::string(10000, 'x'), WriteOptions())); ASSERT_OK(
Put(1, std::to_string(i), std::string(10000, 'x'), WriteOptions()));
FlushOptions fo; FlushOptions fo;
fo.allow_write_stall = true; fo.allow_write_stall = true;
ASSERT_OK(db_->Flush(fo, handles_[1])); ASSERT_OK(db_->Flush(fo, handles_[1]));

View File

@ -140,8 +140,8 @@ size_t MemTable::ApproximateMemoryUsage() {
for (size_t usage : usages) { for (size_t usage : usages) {
// If usage + total_usage >= kMaxSizet, return kMaxSizet. // If usage + total_usage >= kMaxSizet, return kMaxSizet.
// the following variation is to avoid numeric overflow. // the following variation is to avoid numeric overflow.
if (usage >= port::kMaxSizet - total_usage) { if (usage >= std::numeric_limits<size_t>::max() - total_usage) {
return port::kMaxSizet; return std::numeric_limits<size_t>::max();
} }
total_usage += usage; total_usage += usage;
} }

View File

@ -315,7 +315,7 @@ class MemTableList {
// PickMemtablesToFlush() is called. // PickMemtablesToFlush() is called.
void FlushRequested() { void FlushRequested() {
flush_requested_ = true; flush_requested_ = true;
// If there are some memtables stored in imm() that dont trigger // If there are some memtables stored in imm() that don't trigger
// flush (eg: mempurge output memtable), then update imm_flush_needed. // flush (eg: mempurge output memtable), then update imm_flush_needed.
// Note: if race condition and imm_flush_needed is set to true // Note: if race condition and imm_flush_needed is set to true
// when there is num_flush_not_started_==0, then there is no // when there is num_flush_not_started_==0, then there is no

View File

@ -209,7 +209,8 @@ TEST_F(MemTableListTest, Empty) {
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
autovector<MemTable*> mems; autovector<MemTable*> mems;
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &mems); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &mems);
ASSERT_EQ(0, mems.size()); ASSERT_EQ(0, mems.size());
autovector<MemTable*> to_delete; autovector<MemTable*> to_delete;
@ -418,7 +419,8 @@ TEST_F(MemTableListTest, GetFromHistoryTest) {
// Flush this memtable from the list. // Flush this memtable from the list.
// (It will then be a part of the memtable history). // (It will then be a part of the memtable history).
autovector<MemTable*> to_flush; autovector<MemTable*> to_flush;
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(1, to_flush.size()); ASSERT_EQ(1, to_flush.size());
MutableCFOptions mutable_cf_options(options); MutableCFOptions mutable_cf_options(options);
@ -472,7 +474,8 @@ TEST_F(MemTableListTest, GetFromHistoryTest) {
ASSERT_EQ(0, to_delete.size()); ASSERT_EQ(0, to_delete.size());
to_flush.clear(); to_flush.clear();
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(1, to_flush.size()); ASSERT_EQ(1, to_flush.size());
// Flush second memtable // Flush second memtable
@ -575,15 +578,15 @@ TEST_F(MemTableListTest, FlushPendingTest) {
std::string value; std::string value;
MergeContext merge_context; MergeContext merge_context;
ASSERT_OK(mem->Add(++seq, kTypeValue, "key1", ToString(i), ASSERT_OK(mem->Add(++seq, kTypeValue, "key1", std::to_string(i),
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyN" + ToString(i), "valueN", ASSERT_OK(mem->Add(++seq, kTypeValue, "keyN" + std::to_string(i), "valueN",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyX" + ToString(i), "value", ASSERT_OK(mem->Add(++seq, kTypeValue, "keyX" + std::to_string(i), "value",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyM" + ToString(i), "valueM", ASSERT_OK(mem->Add(++seq, kTypeValue, "keyM" + std::to_string(i), "valueM",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeDeletion, "keyX" + ToString(i), "", ASSERT_OK(mem->Add(++seq, kTypeDeletion, "keyX" + std::to_string(i), "",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
tables.push_back(mem); tables.push_back(mem);
@ -593,7 +596,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire)); ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire));
autovector<MemTable*> to_flush; autovector<MemTable*> to_flush;
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(0, to_flush.size()); ASSERT_EQ(0, to_flush.size());
// Request a flush even though there is nothing to flush // Request a flush even though there is nothing to flush
@ -602,7 +606,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire)); ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire));
// Attempt to 'flush' to clear request for flush // Attempt to 'flush' to clear request for flush
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(0, to_flush.size()); ASSERT_EQ(0, to_flush.size());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire)); ASSERT_FALSE(list.imm_flush_needed.load(std::memory_order_acquire));
@ -626,7 +631,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_TRUE(list.imm_flush_needed.load(std::memory_order_acquire)); ASSERT_TRUE(list.imm_flush_needed.load(std::memory_order_acquire));
// Pick tables to flush // Pick tables to flush
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(2, to_flush.size()); ASSERT_EQ(2, to_flush.size());
ASSERT_EQ(2, list.NumNotFlushed()); ASSERT_EQ(2, list.NumNotFlushed());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
@ -647,7 +653,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_EQ(0, to_delete.size()); ASSERT_EQ(0, to_delete.size());
// Pick tables to flush // Pick tables to flush
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
ASSERT_EQ(3, to_flush.size()); ASSERT_EQ(3, to_flush.size());
ASSERT_EQ(3, list.NumNotFlushed()); ASSERT_EQ(3, list.NumNotFlushed());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
@ -655,7 +662,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
// Pick tables to flush again // Pick tables to flush again
autovector<MemTable*> to_flush2; autovector<MemTable*> to_flush2;
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush2); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush2);
ASSERT_EQ(0, to_flush2.size()); ASSERT_EQ(0, to_flush2.size());
ASSERT_EQ(3, list.NumNotFlushed()); ASSERT_EQ(3, list.NumNotFlushed());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
@ -673,7 +681,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_TRUE(list.imm_flush_needed.load(std::memory_order_acquire)); ASSERT_TRUE(list.imm_flush_needed.load(std::memory_order_acquire));
// Pick tables to flush again // Pick tables to flush again
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush2); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush2);
ASSERT_EQ(1, to_flush2.size()); ASSERT_EQ(1, to_flush2.size());
ASSERT_EQ(4, list.NumNotFlushed()); ASSERT_EQ(4, list.NumNotFlushed());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
@ -694,7 +703,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
ASSERT_EQ(0, to_delete.size()); ASSERT_EQ(0, to_delete.size());
// Pick tables to flush // Pick tables to flush
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush);
// Should pick 4 of 5 since 1 table has been picked in to_flush2 // Should pick 4 of 5 since 1 table has been picked in to_flush2
ASSERT_EQ(4, to_flush.size()); ASSERT_EQ(4, to_flush.size());
ASSERT_EQ(5, list.NumNotFlushed()); ASSERT_EQ(5, list.NumNotFlushed());
@ -703,7 +713,8 @@ TEST_F(MemTableListTest, FlushPendingTest) {
// Pick tables to flush again // Pick tables to flush again
autovector<MemTable*> to_flush3; autovector<MemTable*> to_flush3;
list.PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, &to_flush3); list.PickMemtablesToFlush(
std::numeric_limits<uint64_t>::max() /* memtable_id */, &to_flush3);
ASSERT_EQ(0, to_flush3.size()); // nothing not in progress of being flushed ASSERT_EQ(0, to_flush3.size()); // nothing not in progress of being flushed
ASSERT_EQ(5, list.NumNotFlushed()); ASSERT_EQ(5, list.NumNotFlushed());
ASSERT_FALSE(list.IsFlushPending()); ASSERT_FALSE(list.IsFlushPending());
@ -849,15 +860,15 @@ TEST_F(MemTableListTest, AtomicFlusTest) {
std::string value; std::string value;
ASSERT_OK(mem->Add(++seq, kTypeValue, "key1", ToString(i), ASSERT_OK(mem->Add(++seq, kTypeValue, "key1", std::to_string(i),
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyN" + ToString(i), "valueN", ASSERT_OK(mem->Add(++seq, kTypeValue, "keyN" + std::to_string(i),
"valueN", nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyX" + std::to_string(i), "value",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyX" + ToString(i), "value", ASSERT_OK(mem->Add(++seq, kTypeValue, "keyM" + std::to_string(i),
nullptr /* kv_prot_info */)); "valueM", nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeValue, "keyM" + ToString(i), "valueM", ASSERT_OK(mem->Add(++seq, kTypeDeletion, "keyX" + std::to_string(i), "",
nullptr /* kv_prot_info */));
ASSERT_OK(mem->Add(++seq, kTypeDeletion, "keyX" + ToString(i), "",
nullptr /* kv_prot_info */)); nullptr /* kv_prot_info */));
elem.push_back(mem); elem.push_back(mem);
@ -872,8 +883,9 @@ TEST_F(MemTableListTest, AtomicFlusTest) {
auto* list = lists[i]; auto* list = lists[i];
ASSERT_FALSE(list->IsFlushPending()); ASSERT_FALSE(list->IsFlushPending());
ASSERT_FALSE(list->imm_flush_needed.load(std::memory_order_acquire)); ASSERT_FALSE(list->imm_flush_needed.load(std::memory_order_acquire));
list->PickMemtablesToFlush(port::kMaxUint64 /* memtable_id */, list->PickMemtablesToFlush(
&flush_candidates[i]); std::numeric_limits<uint64_t>::max() /* memtable_id */,
&flush_candidates[i]);
ASSERT_EQ(0, flush_candidates[i].size()); ASSERT_EQ(0, flush_candidates[i].size());
} }
// Request flush even though there is nothing to flush // Request flush even though there is nothing to flush

View File

@ -41,7 +41,7 @@ class ObsoleteFilesTest : public DBTestBase {
WriteOptions options; WriteOptions options;
options.sync = false; options.sync = false;
for (int i = startkey; i < (numkeys + startkey) ; i++) { for (int i = startkey; i < (numkeys + startkey) ; i++) {
std::string temp = ToString(i); std::string temp = std::to_string(i);
Slice key(temp); Slice key(temp);
Slice value(temp); Slice value(temp);
ASSERT_OK(db_->Put(options, key, value)); ASSERT_OK(db_->Put(options, key, value));

View File

@ -75,21 +75,21 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
ReadOptions read_options; ReadOptions read_options;
for (int i = 0; i < FLAGS_total_keys; ++i) { for (int i = 0; i < FLAGS_total_keys; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string value = "v" + ToString(i); std::string value = "v" + std::to_string(i);
ASSERT_OK(db->Put(write_options, key, value)); ASSERT_OK(db->Put(write_options, key, value));
} }
for (int i = 0; i < FLAGS_total_keys -1 ; ++i) { for (int i = 0; i < FLAGS_total_keys -1 ; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
ASSERT_OK(db->Delete(write_options, key)); ASSERT_OK(db->Delete(write_options, key));
} }
HistogramImpl hist_get; HistogramImpl hist_get;
HistogramImpl hist_get_time; HistogramImpl hist_get_time;
for (int i = 0; i < FLAGS_total_keys - 1; ++i) { for (int i = 0; i < FLAGS_total_keys - 1; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string value; std::string value;
get_perf_context()->Reset(); get_perf_context()->Reset();
@ -130,7 +130,7 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
HistogramImpl hist_seek; HistogramImpl hist_seek;
for (int i = 0; i < FLAGS_total_keys; ++i) { for (int i = 0; i < FLAGS_total_keys; ++i) {
std::unique_ptr<Iterator> iter(db->NewIterator(read_options)); std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
get_perf_context()->Reset(); get_perf_context()->Reset();
StopWatchNano timer(SystemClock::Default().get(), true); StopWatchNano timer(SystemClock::Default().get(), true);
@ -265,8 +265,8 @@ void ProfileQueries(bool enabled_time = false) {
continue; continue;
} }
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string value = "v" + ToString(i); std::string value = "v" + std::to_string(i);
std::vector<std::string> values; std::vector<std::string> values;
@ -297,8 +297,8 @@ void ProfileQueries(bool enabled_time = false) {
if (i == kFlushFlag) { if (i == kFlushFlag) {
continue; continue;
} }
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string expected_value = "v" + ToString(i); std::string expected_value = "v" + std::to_string(i);
std::string value; std::string value;
std::vector<Slice> multiget_keys = {Slice(key)}; std::vector<Slice> multiget_keys = {Slice(key)};
@ -415,8 +415,8 @@ void ProfileQueries(bool enabled_time = false) {
if (i == kFlushFlag) { if (i == kFlushFlag) {
continue; continue;
} }
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string expected_value = "v" + ToString(i); std::string expected_value = "v" + std::to_string(i);
std::string value; std::string value;
std::vector<Slice> multiget_keys = {Slice(key)}; std::vector<Slice> multiget_keys = {Slice(key)};
@ -543,8 +543,8 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
SetPerfLevel(kEnableTime); SetPerfLevel(kEnableTime);
StopWatchNano timer(SystemClock::Default().get()); StopWatchNano timer(SystemClock::Default().get());
for (const int i : keys) { for (const int i : keys) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string value = "v" + ToString(i); std::string value = "v" + std::to_string(i);
get_perf_context()->Reset(); get_perf_context()->Reset();
timer.Start(); timer.Start();
@ -565,8 +565,8 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
HistogramImpl hist_next; HistogramImpl hist_next;
for (int i = 0; i < FLAGS_total_keys; ++i) { for (int i = 0; i < FLAGS_total_keys; ++i) {
std::string key = "k" + ToString(i); std::string key = "k" + std::to_string(i);
std::string value = "v" + ToString(i); std::string value = "v" + std::to_string(i);
std::unique_ptr<Iterator> iter(db->NewIterator(read_options)); std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
get_perf_context()->Reset(); get_perf_context()->Reset();
@ -841,7 +841,7 @@ TEST_F(PerfContextTest, CPUTimer) {
std::string max_str = "0"; std::string max_str = "0";
for (int i = 0; i < FLAGS_total_keys; ++i) { for (int i = 0; i < FLAGS_total_keys; ++i) {
std::string i_str = ToString(i); std::string i_str = std::to_string(i);
std::string key = "k" + i_str; std::string key = "k" + i_str;
std::string value = "v" + i_str; std::string value = "v" + i_str;
max_str = max_str > i_str ? max_str : i_str; max_str = max_str > i_str ? max_str : i_str;
@ -935,9 +935,9 @@ TEST_F(PerfContextTest, CPUTimer) {
get_perf_context()->Reset(); get_perf_context()->Reset();
auto count = get_perf_context()->iter_seek_cpu_nanos; auto count = get_perf_context()->iter_seek_cpu_nanos;
for (int i = 0; i < FLAGS_total_keys; ++i) { for (int i = 0; i < FLAGS_total_keys; ++i) {
iter->Seek("k" + ToString(i)); iter->Seek("k" + std::to_string(i));
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
ASSERT_EQ("v" + ToString(i), iter->value().ToString()); ASSERT_EQ("v" + std::to_string(i), iter->value().ToString());
auto next_count = get_perf_context()->iter_seek_cpu_nanos; auto next_count = get_perf_context()->iter_seek_cpu_nanos;
ASSERT_GT(next_count, count); ASSERT_GT(next_count, count);
count = next_count; count = next_count;

View File

@ -220,8 +220,8 @@ class PlainTableDBTest : public testing::Test,
int NumTableFilesAtLevel(int level) { int NumTableFilesAtLevel(int level) {
std::string property; std::string property;
EXPECT_TRUE(db_->GetProperty("rocksdb.num-files-at-level" + ToString(level), EXPECT_TRUE(db_->GetProperty(
&property)); "rocksdb.num-files-at-level" + std::to_string(level), &property));
return atoi(property.c_str()); return atoi(property.c_str());
} }
@ -889,7 +889,7 @@ TEST_P(PlainTableDBTest, IteratorLargeKeys) {
}; };
for (size_t i = 0; i < 7; i++) { for (size_t i = 0; i < 7; i++) {
ASSERT_OK(Put(key_list[i], ToString(i))); ASSERT_OK(Put(key_list[i], std::to_string(i)));
} }
ASSERT_OK(dbfull()->TEST_FlushMemTable()); ASSERT_OK(dbfull()->TEST_FlushMemTable());
@ -900,7 +900,7 @@ TEST_P(PlainTableDBTest, IteratorLargeKeys) {
for (size_t i = 0; i < 7; i++) { for (size_t i = 0; i < 7; i++) {
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
ASSERT_EQ(key_list[i], iter->key().ToString()); ASSERT_EQ(key_list[i], iter->key().ToString());
ASSERT_EQ(ToString(i), iter->value().ToString()); ASSERT_EQ(std::to_string(i), iter->value().ToString());
iter->Next(); iter->Next();
} }
@ -937,7 +937,7 @@ TEST_P(PlainTableDBTest, IteratorLargeKeysWithPrefix) {
MakeLongKeyWithPrefix(26, '6')}; MakeLongKeyWithPrefix(26, '6')};
for (size_t i = 0; i < 7; i++) { for (size_t i = 0; i < 7; i++) {
ASSERT_OK(Put(key_list[i], ToString(i))); ASSERT_OK(Put(key_list[i], std::to_string(i)));
} }
ASSERT_OK(dbfull()->TEST_FlushMemTable()); ASSERT_OK(dbfull()->TEST_FlushMemTable());
@ -948,7 +948,7 @@ TEST_P(PlainTableDBTest, IteratorLargeKeysWithPrefix) {
for (size_t i = 0; i < 7; i++) { for (size_t i = 0; i < 7; i++) {
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
ASSERT_EQ(key_list[i], iter->key().ToString()); ASSERT_EQ(key_list[i], iter->key().ToString());
ASSERT_EQ(ToString(i), iter->value().ToString()); ASSERT_EQ(std::to_string(i), iter->value().ToString());
iter->Next(); iter->Next();
} }

View File

@ -628,7 +628,7 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
TestKey test_key(prefix, FLAGS_items_per_prefix / 2); TestKey test_key(prefix, FLAGS_items_per_prefix / 2);
std::string s; std::string s;
Slice key = TestKeyToSlice(s, test_key); Slice key = TestKeyToSlice(s, test_key);
std::string value = "v" + ToString(0); std::string value = "v" + std::to_string(0);
get_perf_context()->Reset(); get_perf_context()->Reset();
StopWatchNano timer(SystemClock::Default().get(), true); StopWatchNano timer(SystemClock::Default().get(), true);

View File

@ -147,7 +147,7 @@ class Repairer {
const auto* cf_opts = GetColumnFamilyOptions(cf_name); const auto* cf_opts = GetColumnFamilyOptions(cf_name);
if (cf_opts == nullptr) { if (cf_opts == nullptr) {
return Status::Corruption("Encountered unknown column family with name=" + return Status::Corruption("Encountered unknown column family with name=" +
cf_name + ", id=" + ToString(cf_id)); cf_name + ", id=" + std::to_string(cf_id));
} }
Options opts(db_options_, *cf_opts); Options opts(db_options_, *cf_opts);
MutableCFOptions mut_cf_opts(opts); MutableCFOptions mut_cf_opts(opts);

View File

@ -289,7 +289,7 @@ TEST_F(RepairTest, RepairMultipleColumnFamilies) {
CreateAndReopenWithCF({"pikachu1", "pikachu2"}, CurrentOptions()); CreateAndReopenWithCF({"pikachu1", "pikachu2"}, CurrentOptions());
for (int i = 0; i < kNumCfs; ++i) { for (int i = 0; i < kNumCfs; ++i) {
for (int j = 0; j < kEntriesPerCf; ++j) { for (int j = 0; j < kEntriesPerCf; ++j) {
ASSERT_OK(Put(i, "key" + ToString(j), "val" + ToString(j))); ASSERT_OK(Put(i, "key" + std::to_string(j), "val" + std::to_string(j)));
if (j == kEntriesPerCf - 1 && i == kNumCfs - 1) { if (j == kEntriesPerCf - 1 && i == kNumCfs - 1) {
// Leave one unflushed so we can verify WAL entries are properly // Leave one unflushed so we can verify WAL entries are properly
// associated with column families. // associated with column families.
@ -313,7 +313,7 @@ TEST_F(RepairTest, RepairMultipleColumnFamilies) {
CurrentOptions()); CurrentOptions());
for (int i = 0; i < kNumCfs; ++i) { for (int i = 0; i < kNumCfs; ++i) {
for (int j = 0; j < kEntriesPerCf; ++j) { for (int j = 0; j < kEntriesPerCf; ++j) {
ASSERT_EQ(Get(i, "key" + ToString(j)), "val" + ToString(j)); ASSERT_EQ(Get(i, "key" + std::to_string(j)), "val" + std::to_string(j));
} }
} }
} }
@ -334,7 +334,7 @@ TEST_F(RepairTest, RepairColumnFamilyOptions) {
std::vector<Options>{opts, rev_opts}); std::vector<Options>{opts, rev_opts});
for (int i = 0; i < kNumCfs; ++i) { for (int i = 0; i < kNumCfs; ++i) {
for (int j = 0; j < kEntriesPerCf; ++j) { for (int j = 0; j < kEntriesPerCf; ++j) {
ASSERT_OK(Put(i, "key" + ToString(j), "val" + ToString(j))); ASSERT_OK(Put(i, "key" + std::to_string(j), "val" + std::to_string(j)));
if (i == kNumCfs - 1 && j == kEntriesPerCf - 1) { if (i == kNumCfs - 1 && j == kEntriesPerCf - 1) {
// Leave one unflushed so we can verify RepairDB's flush logic // Leave one unflushed so we can verify RepairDB's flush logic
continue; continue;
@ -352,7 +352,7 @@ TEST_F(RepairTest, RepairColumnFamilyOptions) {
std::vector<Options>{opts, rev_opts})); std::vector<Options>{opts, rev_opts}));
for (int i = 0; i < kNumCfs; ++i) { for (int i = 0; i < kNumCfs; ++i) {
for (int j = 0; j < kEntriesPerCf; ++j) { for (int j = 0; j < kEntriesPerCf; ++j) {
ASSERT_EQ(Get(i, "key" + ToString(j)), "val" + ToString(j)); ASSERT_EQ(Get(i, "key" + std::to_string(j)), "val" + std::to_string(j));
} }
} }
@ -377,7 +377,7 @@ TEST_F(RepairTest, RepairColumnFamilyOptions) {
std::vector<Options>{opts, rev_opts})); std::vector<Options>{opts, rev_opts}));
for (int i = 0; i < kNumCfs; ++i) { for (int i = 0; i < kNumCfs; ++i) {
for (int j = 0; j < kEntriesPerCf; ++j) { for (int j = 0; j < kEntriesPerCf; ++j) {
ASSERT_EQ(Get(i, "key" + ToString(j)), "val" + ToString(j)); ASSERT_EQ(Get(i, "key" + std::to_string(j)), "val" + std::to_string(j));
} }
} }
} }

View File

@ -33,10 +33,9 @@ class DisableGCSnapshotChecker : public SnapshotChecker {
// By returning kNotInSnapshot, we prevent all the values from being GCed // By returning kNotInSnapshot, we prevent all the values from being GCed
return SnapshotCheckerResult::kNotInSnapshot; return SnapshotCheckerResult::kNotInSnapshot;
} }
static DisableGCSnapshotChecker* Instance() { return &instance_; } static DisableGCSnapshotChecker* Instance();
protected: protected:
static DisableGCSnapshotChecker instance_;
explicit DisableGCSnapshotChecker() {} explicit DisableGCSnapshotChecker() {}
}; };

View File

@ -468,8 +468,7 @@ Status TableCache::Get(
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
// Put the replay log in row cache only if something was found. // Put the replay log in row cache only if something was found.
if (!done && s.ok() && row_cache_entry && !row_cache_entry->empty()) { if (!done && s.ok() && row_cache_entry && !row_cache_entry->empty()) {
size_t charge = size_t charge = row_cache_entry->capacity() + sizeof(std::string);
row_cache_key.Size() + row_cache_entry->size() + sizeof(std::string);
void* row_ptr = new std::string(std::move(*row_cache_entry)); void* row_ptr = new std::string(std::move(*row_cache_entry));
// If row cache is full, it's OK to continue. // If row cache is full, it's OK to continue.
ioptions_.row_cache ioptions_.row_cache
@ -592,8 +591,7 @@ Status TableCache::MultiGet(
user_key.size()); user_key.size());
// Put the replay log in row cache only if something was found. // Put the replay log in row cache only if something was found.
if (s.ok() && !row_cache_entry.empty()) { if (s.ok() && !row_cache_entry.empty()) {
size_t charge = size_t charge = row_cache_entry.capacity() + sizeof(std::string);
row_cache_key.Size() + row_cache_entry.size() + sizeof(std::string);
void* row_ptr = new std::string(std::move(row_cache_entry)); void* row_ptr = new std::string(std::move(row_cache_entry));
// If row cache is full, it's OK. // If row cache is full, it's OK.
ioptions_.row_cache ioptions_.row_cache

View File

@ -1144,7 +1144,7 @@ class VersionBuilder::Rep {
size_t table_cache_capacity = table_cache_->get_cache()->GetCapacity(); size_t table_cache_capacity = table_cache_->get_cache()->GetCapacity();
bool always_load = (table_cache_capacity == TableCache::kInfiniteCapacity); bool always_load = (table_cache_capacity == TableCache::kInfiniteCapacity);
size_t max_load = port::kMaxSizet; size_t max_load = std::numeric_limits<size_t>::max();
if (!always_load) { if (!always_load) {
// If it is initial loading and not set to always loading all the // If it is initial loading and not set to always loading all the

View File

@ -1702,11 +1702,9 @@ TEST_F(VersionBuilderTest, EstimatedActiveKeys) {
const uint32_t kDeletionsPerFile = 100; const uint32_t kDeletionsPerFile = 100;
for (uint32_t i = 0; i < kNumFiles; ++i) { for (uint32_t i = 0; i < kNumFiles; ++i) {
Add(static_cast<int>(i / kFilesPerLevel), i + 1, Add(static_cast<int>(i / kFilesPerLevel), i + 1,
ToString((i + 100) * 1000).c_str(), std::to_string((i + 100) * 1000).c_str(),
ToString((i + 100) * 1000 + 999).c_str(), std::to_string((i + 100) * 1000 + 999).c_str(), 100U, 0, 100, 100,
100U, 0, 100, 100, kEntriesPerFile, kDeletionsPerFile, (i < kTotalSamples));
kEntriesPerFile, kDeletionsPerFile,
(i < kTotalSamples));
} }
// minus 2X for the number of deletion entries because: // minus 2X for the number of deletion entries because:
// 1x for deletion entry does not count as a data entry. // 1x for deletion entry does not count as a data entry.

View File

@ -817,7 +817,7 @@ std::string VersionEdit::DebugString(bool hex_key) const {
r.append(" temperature: "); r.append(" temperature: ");
// Maybe change to human readable format whenthe feature becomes // Maybe change to human readable format whenthe feature becomes
// permanent // permanent
r.append(ToString(static_cast<int>(f.temperature))); r.append(std::to_string(static_cast<int>(f.temperature)));
} }
} }
@ -928,7 +928,7 @@ std::string VersionEdit::DebugJSON(int edit_num, bool hex_key) const {
jw << "FileChecksum" << Slice(f.file_checksum).ToString(true); jw << "FileChecksum" << Slice(f.file_checksum).ToString(true);
jw << "FileChecksumFuncName" << f.file_checksum_func_name; jw << "FileChecksumFuncName" << f.file_checksum_func_name;
if (f.temperature != Temperature::kUnknown) { if (f.temperature != Temperature::kUnknown) {
jw << "temperature" << ToString(static_cast<int>(f.temperature)); jw << "temperature" << std::to_string(static_cast<int>(f.temperature));
} }
if (f.oldest_blob_file_number != kInvalidBlobFileNumber) { if (f.oldest_blob_file_number != kInvalidBlobFileNumber) {
jw << "OldestBlobFile" << f.oldest_blob_file_number; jw << "OldestBlobFile" << f.oldest_blob_file_number;

View File

@ -1517,7 +1517,7 @@ uint64_t Version::GetSstFilesSize() {
} }
void Version::GetCreationTimeOfOldestFile(uint64_t* creation_time) { void Version::GetCreationTimeOfOldestFile(uint64_t* creation_time) {
uint64_t oldest_time = port::kMaxUint64; uint64_t oldest_time = std::numeric_limits<uint64_t>::max();
for (int level = 0; level < storage_info_.num_non_empty_levels_; level++) { for (int level = 0; level < storage_info_.num_non_empty_levels_; level++) {
for (FileMetaData* meta : storage_info_.LevelFiles(level)) { for (FileMetaData* meta : storage_info_.LevelFiles(level)) {
assert(meta->fd.table_reader != nullptr); assert(meta->fd.table_reader != nullptr);
@ -3986,7 +3986,7 @@ std::string Version::DebugString(bool hex, bool print_stats) const {
} }
if (print_stats) { if (print_stats) {
r.append("("); r.append("(");
r.append(ToString( r.append(std::to_string(
files[i]->stats.num_reads_sampled.load(std::memory_order_relaxed))); files[i]->stats.num_reads_sampled.load(std::memory_order_relaxed)));
r.append(")"); r.append(")");
} }

View File

@ -1213,7 +1213,7 @@ class VersionSet {
// new_log_number_for_empty_cf. // new_log_number_for_empty_cf.
uint64_t PreComputeMinLogNumberWithUnflushedData( uint64_t PreComputeMinLogNumberWithUnflushedData(
uint64_t new_log_number_for_empty_cf) const { uint64_t new_log_number_for_empty_cf) const {
uint64_t min_log_num = port::kMaxUint64; uint64_t min_log_num = std::numeric_limits<uint64_t>::max();
for (auto cfd : *column_family_set_) { for (auto cfd : *column_family_set_) {
// It's safe to ignore dropped column families here: // It's safe to ignore dropped column families here:
// cfd->IsDropped() becomes true after the drop is persisted in MANIFEST. // cfd->IsDropped() becomes true after the drop is persisted in MANIFEST.
@ -1229,7 +1229,7 @@ class VersionSet {
// file, except data from `cfd_to_skip`. // file, except data from `cfd_to_skip`.
uint64_t PreComputeMinLogNumberWithUnflushedData( uint64_t PreComputeMinLogNumberWithUnflushedData(
const ColumnFamilyData* cfd_to_skip) const { const ColumnFamilyData* cfd_to_skip) const {
uint64_t min_log_num = port::kMaxUint64; uint64_t min_log_num = std::numeric_limits<uint64_t>::max();
for (auto cfd : *column_family_set_) { for (auto cfd : *column_family_set_) {
if (cfd == cfd_to_skip) { if (cfd == cfd_to_skip) {
continue; continue;
@ -1246,7 +1246,7 @@ class VersionSet {
// file, except data from `cfds_to_skip`. // file, except data from `cfds_to_skip`.
uint64_t PreComputeMinLogNumberWithUnflushedData( uint64_t PreComputeMinLogNumberWithUnflushedData(
const std::unordered_set<const ColumnFamilyData*>& cfds_to_skip) const { const std::unordered_set<const ColumnFamilyData*>& cfds_to_skip) const {
uint64_t min_log_num = port::kMaxUint64; uint64_t min_log_num = std::numeric_limits<uint64_t>::max();
for (auto cfd : *column_family_set_) { for (auto cfd : *column_family_set_) {
if (cfds_to_skip.count(cfd)) { if (cfds_to_skip.count(cfd)) {
continue; continue;

Some files were not shown because too many files have changed in this diff Show More