From 1b4c104a678ce211fb919a701f9aa35843b6278f Mon Sep 17 00:00:00 2001 From: Pratik Dhandharia Date: Tue, 27 Aug 2019 10:57:28 -0700 Subject: [PATCH] replace some reinterpret_cast with static_cast_with_check (#5740) Summary: This PR focuses on replacing some of the reinterpret_cast to static_cast_with_check. Files impacted: ./db/db_impl/db_impl_compaction_flush.cc ./db/write_batch.cc ./utilities/blob_db/blob_db_impl.cc ./utilities/transactions/pessimistic_transaction_db.cc ./utilities/transactions/transaction_base.cc ./utilities/transactions/write_prepared_txn_db.cc ./utilities/transactions/write_unprepared_txn_db.cc Pull Request resolved: https://github.com/facebook/rocksdb/pull/5740 Differential Revision: D17055691 Pulled By: pdhandharia fbshipit-source-id: 0f8034d1b32eade56e37d59c04b7bf236a81d8e8 --- db/db_impl/db_impl_compaction_flush.cc | 6 ++++-- db/write_batch.cc | 3 ++- utilities/blob_db/blob_db_impl.cc | 2 +- utilities/transactions/pessimistic_transaction_db.cc | 2 +- utilities/transactions/transaction_base.cc | 3 ++- utilities/transactions/write_prepared_txn_db.cc | 2 +- utilities/transactions/write_unprepared_txn_db.cc | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index ffb6b2b60..1b862e033 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -19,6 +19,7 @@ #include "monitoring/thread_status_updater.h" #include "monitoring/thread_status_util.h" #include "test_util/sync_point.h" +#include "util/cast_util.h" #include "util/concurrent_task_limiter_impl.h" namespace rocksdb { @@ -2072,7 +2073,8 @@ void DBImpl::BGWorkFlush(void* arg) { IOSTATS_SET_THREAD_POOL_ID(fta.thread_pri_); TEST_SYNC_POINT("DBImpl::BGWorkFlush"); - reinterpret_cast(fta.db_)->BackgroundCallFlush(fta.thread_pri_); + static_cast_with_check(fta.db_)->BackgroundCallFlush( + fta.thread_pri_); TEST_SYNC_POINT("DBImpl::BGWorkFlush:done"); } @@ -2083,7 +2085,7 @@ void DBImpl::BGWorkCompaction(void* arg) { TEST_SYNC_POINT("DBImpl::BGWorkCompaction"); auto prepicked_compaction = static_cast(ca.prepicked_compaction); - reinterpret_cast(ca.db)->BackgroundCallCompaction( + static_cast_with_check(ca.db)->BackgroundCallCompaction( prepicked_compaction, Env::Priority::LOW); delete prepicked_compaction; } diff --git a/db/write_batch.cc b/db/write_batch.cc index 2a1bf1948..396f8e44a 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -54,6 +54,7 @@ #include "monitoring/statistics.h" #include "rocksdb/merge_operator.h" #include "util/autovector.h" +#include "util/cast_util.h" #include "util/coding.h" #include "util/duplicate_detector.h" #include "util/string_util.h" @@ -1265,7 +1266,7 @@ class MemTableInserter : public WriteBatch::Handler { ignore_missing_column_families_(ignore_missing_column_families), recovering_log_number_(recovering_log_number), log_number_ref_(0), - db_(reinterpret_cast(db)), + db_(static_cast_with_check(db)), concurrent_memtable_writes_(concurrent_memtable_writes), post_info_created_(false), has_valid_writes_(has_valid_writes), diff --git a/utilities/blob_db/blob_db_impl.cc b/utilities/blob_db/blob_db_impl.cc index 8088e4273..574338e52 100644 --- a/utilities/blob_db/blob_db_impl.cc +++ b/utilities/blob_db/blob_db_impl.cc @@ -1431,7 +1431,7 @@ class BlobDBImpl::GarbageCollectionWriteCallback : public WriteCallback { : cfd_(cfd), key_(key), upper_bound_(upper_bound) {} Status Callback(DB* db) override { - auto* db_impl = reinterpret_cast(db); + auto* db_impl = static_cast_with_check(db); auto* sv = db_impl->GetAndRefSuperVersion(cfd_); SequenceNumber latest_seq = 0; bool found_record_for_key = false; diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index caac2ab18..4aee1147b 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -113,7 +113,7 @@ Status PessimisticTransactionDB::Initialize( Status s = EnableAutoCompaction(compaction_enabled_cf_handles); // create 'real' transactions from recovered shell transactions - auto dbimpl = reinterpret_cast(GetRootDB()); + auto dbimpl = static_cast_with_check(GetRootDB()); assert(dbimpl != nullptr); auto rtrxs = dbimpl->recovered_transactions(); diff --git a/utilities/transactions/transaction_base.cc b/utilities/transactions/transaction_base.cc index 30861f091..81f398124 100644 --- a/utilities/transactions/transaction_base.cc +++ b/utilities/transactions/transaction_base.cc @@ -14,6 +14,7 @@ #include "rocksdb/comparator.h" #include "rocksdb/db.h" #include "rocksdb/status.h" +#include "util/cast_util.h" #include "util/string_util.h" namespace rocksdb { @@ -21,7 +22,7 @@ namespace rocksdb { TransactionBaseImpl::TransactionBaseImpl(DB* db, const WriteOptions& write_options) : db_(db), - dbimpl_(reinterpret_cast(db)), + dbimpl_(static_cast_with_check(db)), write_options_(write_options), cmp_(GetColumnFamilyUserComparator(db->DefaultColumnFamily())), start_time_(db_->GetEnv()->NowMicros()), diff --git a/utilities/transactions/write_prepared_txn_db.cc b/utilities/transactions/write_prepared_txn_db.cc index 7ff89a4f8..f58305de2 100644 --- a/utilities/transactions/write_prepared_txn_db.cc +++ b/utilities/transactions/write_prepared_txn_db.cc @@ -29,7 +29,7 @@ namespace rocksdb { Status WritePreparedTxnDB::Initialize( const std::vector& compaction_enabled_cf_indices, const std::vector& handles) { - auto dbimpl = reinterpret_cast(GetRootDB()); + auto dbimpl = static_cast_with_check(GetRootDB()); assert(dbimpl != nullptr); auto rtxns = dbimpl->recovered_transactions(); std::map ordered_seq_cnt; diff --git a/utilities/transactions/write_unprepared_txn_db.cc b/utilities/transactions/write_unprepared_txn_db.cc index 3a8eff5ec..f6809faeb 100644 --- a/utilities/transactions/write_unprepared_txn_db.cc +++ b/utilities/transactions/write_unprepared_txn_db.cc @@ -179,7 +179,7 @@ Status WriteUnpreparedTxnDB::Initialize( const std::vector& compaction_enabled_cf_indices, const std::vector& handles) { // TODO(lth): Reduce code duplication in this function. - auto dbimpl = reinterpret_cast(GetRootDB()); + auto dbimpl = static_cast_with_check(GetRootDB()); assert(dbimpl != nullptr); db_impl_->SetSnapshotChecker(new WritePreparedSnapshotChecker(this));