2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2015-07-20 23:05:28 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2015-10-12 20:05:42 +00:00
|
|
|
#include "db/db_test_util.h"
|
2015-07-20 23:05:28 +00:00
|
|
|
#include "port/stack_trace.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-07-20 23:05:28 +00:00
|
|
|
|
|
|
|
class DBTestInPlaceUpdate : public DBTestBase {
|
|
|
|
public:
|
2020-08-18 01:41:20 +00:00
|
|
|
DBTestInPlaceUpdate()
|
2021-07-23 15:37:27 +00:00
|
|
|
: DBTestBase("db_inplace_update_test", /*env_do_fsync=*/true) {}
|
2015-07-20 23:05:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdate) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Update key with values of smaller size
|
|
|
|
int numValues = 10;
|
|
|
|
for (int i = numValues; i > 0; i--) {
|
|
|
|
std::string value = DummyString(i, 'a');
|
|
|
|
ASSERT_OK(Put(1, "key", value));
|
|
|
|
ASSERT_EQ(value, Get(1, "key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 1 instance for that key.
|
|
|
|
validateNumberOfEntries(1, 1);
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdateLargeNewValue) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Update key with values of larger size
|
|
|
|
int numValues = 10;
|
|
|
|
for (int i = 0; i < numValues; i++) {
|
|
|
|
std::string value = DummyString(i, 'a');
|
|
|
|
ASSERT_OK(Put(1, "key", value));
|
|
|
|
ASSERT_EQ(value, Get(1, "key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// All 10 updates exist in the internal iterator
|
|
|
|
validateNumberOfEntries(numValues, 1);
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerSize) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
|
|
|
options.inplace_callback =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerSize;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Update key with values of smaller size
|
|
|
|
int numValues = 10;
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(numValues, 'a')));
|
|
|
|
ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key"));
|
|
|
|
|
|
|
|
for (int i = numValues; i > 0; i--) {
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
|
|
|
|
ASSERT_EQ(DummyString(i - 1, 'b'), Get(1, "key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 1 instance for that key.
|
|
|
|
validateNumberOfEntries(1, 1);
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerVarintSize) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
|
|
|
options.inplace_callback =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerVarintSize;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Update key with values of smaller varint size
|
|
|
|
int numValues = 265;
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(numValues, 'a')));
|
|
|
|
ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key"));
|
|
|
|
|
|
|
|
for (int i = numValues; i > 0; i--) {
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
|
|
|
|
ASSERT_EQ(DummyString(1, 'b'), Get(1, "key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 1 instance for that key.
|
|
|
|
validateNumberOfEntries(1, 1);
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackLargeNewValue) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
|
|
|
options.inplace_callback =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceLargerSize;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Update key with values of larger size
|
|
|
|
int numValues = 10;
|
|
|
|
for (int i = 0; i < numValues; i++) {
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
|
|
|
|
ASSERT_EQ(DummyString(i, 'c'), Get(1, "key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// No inplace updates. All updates are puts with new seq number
|
|
|
|
// All 10 updates exist in the internal iterator
|
|
|
|
validateNumberOfEntries(numValues, 1);
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackNoAction) {
|
|
|
|
do {
|
2016-03-24 19:45:50 +00:00
|
|
|
Options options = CurrentOptions();
|
2015-07-20 23:05:28 +00:00
|
|
|
options.create_if_missing = true;
|
|
|
|
options.inplace_update_support = true;
|
|
|
|
|
|
|
|
options.env = env_;
|
|
|
|
options.write_buffer_size = 100000;
|
|
|
|
options.inplace_callback =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceNoAction;
|
2016-11-16 17:24:52 +00:00
|
|
|
options.allow_concurrent_memtable_write = false;
|
|
|
|
Reopen(options);
|
2015-07-20 23:05:28 +00:00
|
|
|
CreateAndReopenWithCF({"pikachu"}, options);
|
|
|
|
|
|
|
|
// Callback function requests no actions from db
|
|
|
|
ASSERT_OK(Put(1, "key", DummyString(1, 'a')));
|
|
|
|
ASSERT_EQ(Get(1, "key"), "NOT_FOUND");
|
|
|
|
} while (ChangeCompactOptions());
|
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2015-07-20 23:05:28 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2015-07-20 23:05:28 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|