From b4d88d712878de25a74b68c0475de473f76db462 Mon Sep 17 00:00:00 2001 From: Orvid King Date: Thu, 14 Dec 2017 11:57:11 -0800 Subject: [PATCH] Fix the build with MSVC 2017 Summary: There were a few places where MSVC's implicit truncation warnings were getting triggered, which was causing the MSVC build to fail due to warnings being treated as errors. This resolves the issues by making the truncations in some places explicit, and by making it so there are no truncations of literals. Fixes #3239 Supersedes #3259 Closes https://github.com/facebook/rocksdb/pull/3273 Reviewed By: yiwu-arbug Differential Revision: D6569204 Pulled By: Orvid fbshipit-source-id: c188cf1cf98d9acb6d94b71875041cc81f8ff088 --- util/transaction_test_util.cc | 4 +- utilities/cassandra/cassandra_format_test.cc | 16 ++--- .../cassandra/cassandra_functional_test.cc | 58 +++++++++---------- .../cassandra/cassandra_row_merge_test.cc | 34 +++++------ utilities/cassandra/format.cc | 2 +- utilities/cassandra/test_utils.cc | 6 ++ utilities/cassandra/test_utils.h | 4 ++ 7 files changed, 67 insertions(+), 57 deletions(-) diff --git a/util/transaction_test_util.cc b/util/transaction_test_util.cc index f95305196..bcda70514 100644 --- a/util/transaction_test_util.cc +++ b/util/transaction_test_util.cc @@ -125,7 +125,7 @@ bool RandomTransactionInserter::DoInsert(DB* db, Transaction* txn, bool unexpected_error = false; std::vector set_vec(num_sets_); - std::iota(set_vec.begin(), set_vec.end(), 0); + std::iota(set_vec.begin(), set_vec.end(), static_cast(0)); std::random_shuffle(set_vec.begin(), set_vec.end(), [&](uint64_t r) { return rand_->Uniform(r); }); // For each set, pick a key at random and increment it @@ -255,7 +255,7 @@ Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets, } std::vector set_vec(num_sets); - std::iota(set_vec.begin(), set_vec.end(), 0); + std::iota(set_vec.begin(), set_vec.end(), static_cast(0)); if (rand) { std::random_shuffle(set_vec.begin(), set_vec.end(), [&](uint64_t r) { return rand->Uniform(r); }); diff --git a/utilities/cassandra/cassandra_format_test.cc b/utilities/cassandra/cassandra_format_test.cc index 4687c8106..e0fe28b3a 100644 --- a/utilities/cassandra/cassandra_format_test.cc +++ b/utilities/cassandra/cassandra_format_test.cc @@ -317,10 +317,10 @@ TEST(RowValueTest, PurgeTtlShouldRemvoeAllColumnsExpired) { int64_t now = time(nullptr); auto row_value = CreateTestRowValue({ - std::make_tuple(kColumn, 0, ToMicroSeconds(now)), - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired - std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired - std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) + CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now)), + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired + CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired + CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now)) }); bool changed = false; @@ -339,10 +339,10 @@ TEST(RowValueTest, ExpireTtlShouldConvertExpiredColumnsToTombstones) { int64_t now = time(nullptr); auto row_value = CreateTestRowValue({ - std::make_tuple(kColumn, 0, ToMicroSeconds(now)), - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired - std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired - std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) + CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now)), + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired + CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired + CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now)) }); bool changed = false; diff --git a/utilities/cassandra/cassandra_functional_test.cc b/utilities/cassandra/cassandra_functional_test.cc index 4a1c46f6b..5bd19cadb 100644 --- a/utilities/cassandra/cassandra_functional_test.cc +++ b/utilities/cassandra/cassandra_functional_test.cc @@ -145,21 +145,21 @@ TEST_F(CassandraFunctionalTest, SimpleMergeTest) { int64_t now = time(nullptr); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kTombstone, 0, ToMicroSeconds(now + 5)), - std::make_tuple(kColumn, 1, ToMicroSeconds(now + 8)), - std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now + 5)), + CreateTestColumnSpec(kTombstone, 0, ToMicroSeconds(now + 5)), + CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now + 8)), + CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now + 5)), })); store.Append("k1",CreateTestRowValue({ - std::make_tuple(kColumn, 0, ToMicroSeconds(now + 2)), - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now + 5)), - std::make_tuple(kTombstone, 2, ToMicroSeconds(now + 7)), - std::make_tuple(kExpiringColumn, 7, ToMicroSeconds(now + 17)), + CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now + 2)), + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now + 5)), + CreateTestColumnSpec(kTombstone, 2, ToMicroSeconds(now + 7)), + CreateTestColumnSpec(kExpiringColumn, 7, ToMicroSeconds(now + 17)), })); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now + 6)), - std::make_tuple(kTombstone, 1, ToMicroSeconds(now + 5)), - std::make_tuple(kColumn, 2, ToMicroSeconds(now + 4)), - std::make_tuple(kTombstone, 11, ToMicroSeconds(now + 11)), + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now + 6)), + CreateTestColumnSpec(kTombstone, 1, ToMicroSeconds(now + 5)), + CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now + 4)), + CreateTestColumnSpec(kTombstone, 11, ToMicroSeconds(now + 11)), })); auto ret = store.Get("k1"); @@ -180,16 +180,16 @@ TEST_F(CassandraFunctionalTest, int64_t now= time(nullptr); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl + 10)), // not expired - std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl + 10)), // not expired + CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now)) })); store.Flush(); store.Append("k1",CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired - std::make_tuple(kColumn, 2, ToMicroSeconds(now)) + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired + CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now)) })); store.Flush(); @@ -213,16 +213,16 @@ TEST_F(CassandraFunctionalTest, int64_t now = time(nullptr); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now)), // not expired - std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now)), // not expired + CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now)) })); store.Flush(); store.Append("k1",CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired - std::make_tuple(kColumn, 2, ToMicroSeconds(now)) + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired + CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now)) })); store.Flush(); @@ -244,14 +244,14 @@ TEST_F(CassandraFunctionalTest, int64_t now = time(nullptr); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), - std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 20)), + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), + CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 20)), })); store.Flush(); store.Append("k1",CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), + CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), })); store.Flush(); @@ -266,18 +266,18 @@ TEST_F(CassandraFunctionalTest, int64_t now = time(nullptr); store.Append("k1", CreateTestRowValue({ - std::make_tuple(kTombstone, 0, ToMicroSeconds(now - gc_grace_period_in_seconds_ - 1)), - std::make_tuple(kColumn, 1, ToMicroSeconds(now)) + CreateTestColumnSpec(kTombstone, 0, ToMicroSeconds(now - gc_grace_period_in_seconds_ - 1)), + CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now)) })); store.Append("k2", CreateTestRowValue({ - std::make_tuple(kColumn, 0, ToMicroSeconds(now)) + CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now)) })); store.Flush(); store.Append("k1",CreateTestRowValue({ - std::make_tuple(kColumn, 1, ToMicroSeconds(now)), + CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now)), })); store.Flush(); @@ -296,7 +296,7 @@ TEST_F(CassandraFunctionalTest, CompactionShouldRemoveTombstoneFromPut) { int64_t now = time(nullptr); store.Put("k1", CreateTestRowValue({ - std::make_tuple(kTombstone, 0, ToMicroSeconds(now - gc_grace_period_in_seconds_ - 1)), + CreateTestColumnSpec(kTombstone, 0, ToMicroSeconds(now - gc_grace_period_in_seconds_ - 1)), })); store.Flush(); diff --git a/utilities/cassandra/cassandra_row_merge_test.cc b/utilities/cassandra/cassandra_row_merge_test.cc index 78c7d8e57..8d6dc10de 100644 --- a/utilities/cassandra/cassandra_row_merge_test.cc +++ b/utilities/cassandra/cassandra_row_merge_test.cc @@ -15,27 +15,27 @@ TEST(RowValueMergeTest, Merge) { std::vector row_values; row_values.push_back( CreateTestRowValue({ - std::make_tuple(kTombstone, 0, 5), - std::make_tuple(kColumn, 1, 8), - std::make_tuple(kExpiringColumn, 2, 5), + CreateTestColumnSpec(kTombstone, 0, 5), + CreateTestColumnSpec(kColumn, 1, 8), + CreateTestColumnSpec(kExpiringColumn, 2, 5), }) ); row_values.push_back( CreateTestRowValue({ - std::make_tuple(kColumn, 0, 2), - std::make_tuple(kExpiringColumn, 1, 5), - std::make_tuple(kTombstone, 2, 7), - std::make_tuple(kExpiringColumn, 7, 17), + CreateTestColumnSpec(kColumn, 0, 2), + CreateTestColumnSpec(kExpiringColumn, 1, 5), + CreateTestColumnSpec(kTombstone, 2, 7), + CreateTestColumnSpec(kExpiringColumn, 7, 17), }) ); row_values.push_back( CreateTestRowValue({ - std::make_tuple(kExpiringColumn, 0, 6), - std::make_tuple(kTombstone, 1, 5), - std::make_tuple(kColumn, 2, 4), - std::make_tuple(kTombstone, 11, 11), + CreateTestColumnSpec(kExpiringColumn, 0, 6), + CreateTestColumnSpec(kTombstone, 1, 5), + CreateTestColumnSpec(kColumn, 2, 4), + CreateTestColumnSpec(kTombstone, 11, 11), }) ); @@ -60,24 +60,24 @@ TEST(RowValueMergeTest, MergeWithRowTombstone) { // This row's timestamp is smaller than tombstone. row_values.push_back( CreateTestRowValue({ - std::make_tuple(kColumn, 0, 5), - std::make_tuple(kColumn, 1, 6), + CreateTestColumnSpec(kColumn, 0, 5), + CreateTestColumnSpec(kColumn, 1, 6), }) ); // Some of the column's row is smaller, some is larger. row_values.push_back( CreateTestRowValue({ - std::make_tuple(kColumn, 2, 10), - std::make_tuple(kColumn, 3, 12), + CreateTestColumnSpec(kColumn, 2, 10), + CreateTestColumnSpec(kColumn, 3, 12), }) ); // All of the column's rows are larger than tombstone. row_values.push_back( CreateTestRowValue({ - std::make_tuple(kColumn, 4, 13), - std::make_tuple(kColumn, 5, 14), + CreateTestColumnSpec(kColumn, 4, 13), + CreateTestColumnSpec(kColumn, 5, 14), }) ); diff --git a/utilities/cassandra/format.cc b/utilities/cassandra/format.cc index c5657e280..4a22658de 100644 --- a/utilities/cassandra/format.cc +++ b/utilities/cassandra/format.cc @@ -129,7 +129,7 @@ std::shared_ptr ExpiringColumn::ToTombstone() const { int64_t marked_for_delete_at = std::chrono::duration_cast(expired_at).count(); return std::make_shared( - ColumnTypeMask::DELETION_MASK, + static_cast(ColumnTypeMask::DELETION_MASK), Index(), local_deletion_time, marked_for_delete_at); diff --git a/utilities/cassandra/test_utils.cc b/utilities/cassandra/test_utils.cc index 9ee1115d2..d4dc8f00a 100644 --- a/utilities/cassandra/test_utils.cc +++ b/utilities/cassandra/test_utils.cc @@ -29,6 +29,12 @@ std::shared_ptr CreateTestColumn(int8_t mask, } } +std::tuple CreateTestColumnSpec(int8_t mask, + int8_t index, + int64_t timestamp) { + return std::make_tuple(mask, index, timestamp); +} + RowValue CreateTestRowValue( std::vector> column_specs) { std::vector> columns; diff --git a/utilities/cassandra/test_utils.h b/utilities/cassandra/test_utils.h index a65b34430..80374b0cb 100644 --- a/utilities/cassandra/test_utils.h +++ b/utilities/cassandra/test_utils.h @@ -23,6 +23,10 @@ std::shared_ptr CreateTestColumn(int8_t mask, int8_t index, int64_t timestamp); +std::tuple CreateTestColumnSpec(int8_t mask, + int8_t index, + int64_t timestamp); + RowValue CreateTestRowValue( std::vector> column_specs);