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
This commit is contained in:
Orvid King 2017-12-14 11:57:11 -08:00 committed by Facebook Github Bot
parent def6a00740
commit b4d88d7128
7 changed files with 67 additions and 57 deletions

View file

@ -125,7 +125,7 @@ bool RandomTransactionInserter::DoInsert(DB* db, Transaction* txn,
bool unexpected_error = false; bool unexpected_error = false;
std::vector<uint16_t> set_vec(num_sets_); std::vector<uint16_t> set_vec(num_sets_);
std::iota(set_vec.begin(), set_vec.end(), 0); std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
std::random_shuffle(set_vec.begin(), set_vec.end(), std::random_shuffle(set_vec.begin(), set_vec.end(),
[&](uint64_t r) { return rand_->Uniform(r); }); [&](uint64_t r) { return rand_->Uniform(r); });
// For each set, pick a key at random and increment it // 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<uint16_t> set_vec(num_sets); std::vector<uint16_t> set_vec(num_sets);
std::iota(set_vec.begin(), set_vec.end(), 0); std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
if (rand) { if (rand) {
std::random_shuffle(set_vec.begin(), set_vec.end(), std::random_shuffle(set_vec.begin(), set_vec.end(),
[&](uint64_t r) { return rand->Uniform(r); }); [&](uint64_t r) { return rand->Uniform(r); });

View file

@ -317,10 +317,10 @@ TEST(RowValueTest, PurgeTtlShouldRemvoeAllColumnsExpired) {
int64_t now = time(nullptr); int64_t now = time(nullptr);
auto row_value = CreateTestRowValue({ auto row_value = CreateTestRowValue({
std::make_tuple(kColumn, 0, ToMicroSeconds(now)), CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now)),
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired
std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired
std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now))
}); });
bool changed = false; bool changed = false;
@ -339,10 +339,10 @@ TEST(RowValueTest, ExpireTtlShouldConvertExpiredColumnsToTombstones) {
int64_t now = time(nullptr); int64_t now = time(nullptr);
auto row_value = CreateTestRowValue({ auto row_value = CreateTestRowValue({
std::make_tuple(kColumn, 0, ToMicroSeconds(now)), CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now)),
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 10)), //expired
std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now)), // not expired
std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now))
}); });
bool changed = false; bool changed = false;

View file

@ -145,21 +145,21 @@ TEST_F(CassandraFunctionalTest, SimpleMergeTest) {
int64_t now = time(nullptr); int64_t now = time(nullptr);
store.Append("k1", CreateTestRowValue({ store.Append("k1", CreateTestRowValue({
std::make_tuple(kTombstone, 0, ToMicroSeconds(now + 5)), CreateTestColumnSpec(kTombstone, 0, ToMicroSeconds(now + 5)),
std::make_tuple(kColumn, 1, ToMicroSeconds(now + 8)), CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now + 8)),
std::make_tuple(kExpiringColumn, 2, ToMicroSeconds(now + 5)), CreateTestColumnSpec(kExpiringColumn, 2, ToMicroSeconds(now + 5)),
})); }));
store.Append("k1",CreateTestRowValue({ store.Append("k1",CreateTestRowValue({
std::make_tuple(kColumn, 0, ToMicroSeconds(now + 2)), CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now + 2)),
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now + 5)), CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now + 5)),
std::make_tuple(kTombstone, 2, ToMicroSeconds(now + 7)), CreateTestColumnSpec(kTombstone, 2, ToMicroSeconds(now + 7)),
std::make_tuple(kExpiringColumn, 7, ToMicroSeconds(now + 17)), CreateTestColumnSpec(kExpiringColumn, 7, ToMicroSeconds(now + 17)),
})); }));
store.Append("k1", CreateTestRowValue({ store.Append("k1", CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now + 6)), CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now + 6)),
std::make_tuple(kTombstone, 1, ToMicroSeconds(now + 5)), CreateTestColumnSpec(kTombstone, 1, ToMicroSeconds(now + 5)),
std::make_tuple(kColumn, 2, ToMicroSeconds(now + 4)), CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now + 4)),
std::make_tuple(kTombstone, 11, ToMicroSeconds(now + 11)), CreateTestColumnSpec(kTombstone, 11, ToMicroSeconds(now + 11)),
})); }));
auto ret = store.Get("k1"); auto ret = store.Get("k1");
@ -180,16 +180,16 @@ TEST_F(CassandraFunctionalTest,
int64_t now= time(nullptr); int64_t now= time(nullptr);
store.Append("k1", CreateTestRowValue({ store.Append("k1", CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl + 10)), // not expired CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl + 10)), // not expired
std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now))
})); }));
store.Flush(); store.Flush();
store.Append("k1",CreateTestRowValue({ store.Append("k1",CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired
std::make_tuple(kColumn, 2, ToMicroSeconds(now)) CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now))
})); }));
store.Flush(); store.Flush();
@ -213,16 +213,16 @@ TEST_F(CassandraFunctionalTest,
int64_t now = time(nullptr); int64_t now = time(nullptr);
store.Append("k1", CreateTestRowValue({ store.Append("k1", CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), //expired
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now)), // not expired CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now)), // not expired
std::make_tuple(kTombstone, 3, ToMicroSeconds(now)) CreateTestColumnSpec(kTombstone, 3, ToMicroSeconds(now))
})); }));
store.Flush(); store.Flush();
store.Append("k1",CreateTestRowValue({ store.Append("k1",CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), //expired
std::make_tuple(kColumn, 2, ToMicroSeconds(now)) CreateTestColumnSpec(kColumn, 2, ToMicroSeconds(now))
})); }));
store.Flush(); store.Flush();
@ -244,14 +244,14 @@ TEST_F(CassandraFunctionalTest,
int64_t now = time(nullptr); int64_t now = time(nullptr);
store.Append("k1", CreateTestRowValue({ store.Append("k1", CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)), CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 20)),
std::make_tuple(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 20)), CreateTestColumnSpec(kExpiringColumn, 1, ToMicroSeconds(now - kTtl - 20)),
})); }));
store.Flush(); store.Flush();
store.Append("k1",CreateTestRowValue({ store.Append("k1",CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)), CreateTestColumnSpec(kExpiringColumn, 0, ToMicroSeconds(now - kTtl - 10)),
})); }));
store.Flush(); store.Flush();
@ -266,18 +266,18 @@ TEST_F(CassandraFunctionalTest,
int64_t now = time(nullptr); int64_t now = time(nullptr);
store.Append("k1", CreateTestRowValue({ store.Append("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)),
std::make_tuple(kColumn, 1, ToMicroSeconds(now)) CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now))
})); }));
store.Append("k2", CreateTestRowValue({ store.Append("k2", CreateTestRowValue({
std::make_tuple(kColumn, 0, ToMicroSeconds(now)) CreateTestColumnSpec(kColumn, 0, ToMicroSeconds(now))
})); }));
store.Flush(); store.Flush();
store.Append("k1",CreateTestRowValue({ store.Append("k1",CreateTestRowValue({
std::make_tuple(kColumn, 1, ToMicroSeconds(now)), CreateTestColumnSpec(kColumn, 1, ToMicroSeconds(now)),
})); }));
store.Flush(); store.Flush();
@ -296,7 +296,7 @@ TEST_F(CassandraFunctionalTest, CompactionShouldRemoveTombstoneFromPut) {
int64_t now = time(nullptr); int64_t now = time(nullptr);
store.Put("k1", CreateTestRowValue({ 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(); store.Flush();

View file

@ -15,27 +15,27 @@ TEST(RowValueMergeTest, Merge) {
std::vector<RowValue> row_values; std::vector<RowValue> row_values;
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kTombstone, 0, 5), CreateTestColumnSpec(kTombstone, 0, 5),
std::make_tuple(kColumn, 1, 8), CreateTestColumnSpec(kColumn, 1, 8),
std::make_tuple(kExpiringColumn, 2, 5), CreateTestColumnSpec(kExpiringColumn, 2, 5),
}) })
); );
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kColumn, 0, 2), CreateTestColumnSpec(kColumn, 0, 2),
std::make_tuple(kExpiringColumn, 1, 5), CreateTestColumnSpec(kExpiringColumn, 1, 5),
std::make_tuple(kTombstone, 2, 7), CreateTestColumnSpec(kTombstone, 2, 7),
std::make_tuple(kExpiringColumn, 7, 17), CreateTestColumnSpec(kExpiringColumn, 7, 17),
}) })
); );
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kExpiringColumn, 0, 6), CreateTestColumnSpec(kExpiringColumn, 0, 6),
std::make_tuple(kTombstone, 1, 5), CreateTestColumnSpec(kTombstone, 1, 5),
std::make_tuple(kColumn, 2, 4), CreateTestColumnSpec(kColumn, 2, 4),
std::make_tuple(kTombstone, 11, 11), CreateTestColumnSpec(kTombstone, 11, 11),
}) })
); );
@ -60,24 +60,24 @@ TEST(RowValueMergeTest, MergeWithRowTombstone) {
// This row's timestamp is smaller than tombstone. // This row's timestamp is smaller than tombstone.
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kColumn, 0, 5), CreateTestColumnSpec(kColumn, 0, 5),
std::make_tuple(kColumn, 1, 6), CreateTestColumnSpec(kColumn, 1, 6),
}) })
); );
// Some of the column's row is smaller, some is larger. // Some of the column's row is smaller, some is larger.
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kColumn, 2, 10), CreateTestColumnSpec(kColumn, 2, 10),
std::make_tuple(kColumn, 3, 12), CreateTestColumnSpec(kColumn, 3, 12),
}) })
); );
// All of the column's rows are larger than tombstone. // All of the column's rows are larger than tombstone.
row_values.push_back( row_values.push_back(
CreateTestRowValue({ CreateTestRowValue({
std::make_tuple(kColumn, 4, 13), CreateTestColumnSpec(kColumn, 4, 13),
std::make_tuple(kColumn, 5, 14), CreateTestColumnSpec(kColumn, 5, 14),
}) })
); );

View file

@ -129,7 +129,7 @@ std::shared_ptr<Tombstone> ExpiringColumn::ToTombstone() const {
int64_t marked_for_delete_at = int64_t marked_for_delete_at =
std::chrono::duration_cast<std::chrono::microseconds>(expired_at).count(); std::chrono::duration_cast<std::chrono::microseconds>(expired_at).count();
return std::make_shared<Tombstone>( return std::make_shared<Tombstone>(
ColumnTypeMask::DELETION_MASK, static_cast<int8_t>(ColumnTypeMask::DELETION_MASK),
Index(), Index(),
local_deletion_time, local_deletion_time,
marked_for_delete_at); marked_for_delete_at);

View file

@ -29,6 +29,12 @@ std::shared_ptr<ColumnBase> CreateTestColumn(int8_t mask,
} }
} }
std::tuple<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask,
int8_t index,
int64_t timestamp) {
return std::make_tuple(mask, index, timestamp);
}
RowValue CreateTestRowValue( RowValue CreateTestRowValue(
std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs) { std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs) {
std::vector<std::shared_ptr<ColumnBase>> columns; std::vector<std::shared_ptr<ColumnBase>> columns;

View file

@ -23,6 +23,10 @@ std::shared_ptr<ColumnBase> CreateTestColumn(int8_t mask,
int8_t index, int8_t index,
int64_t timestamp); int64_t timestamp);
std::tuple<int8_t, int8_t, int64_t> CreateTestColumnSpec(int8_t mask,
int8_t index,
int64_t timestamp);
RowValue CreateTestRowValue( RowValue CreateTestRowValue(
std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs); std::vector<std::tuple<int8_t, int8_t, int64_t>> column_specs);