]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_inplace_update_test.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / db_inplace_update_test.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9 #include "db/db_test_util.h"
10 #include "port/stack_trace.h"
11
12 namespace ROCKSDB_NAMESPACE {
13
14 class DBTestInPlaceUpdate : public DBTestBase {
15 public:
16 DBTestInPlaceUpdate()
17 : DBTestBase("/db_inplace_update_test", /*env_do_fsync=*/true) {}
18 };
19
20 TEST_F(DBTestInPlaceUpdate, InPlaceUpdate) {
21 do {
22 Options options = CurrentOptions();
23 options.create_if_missing = true;
24 options.inplace_update_support = true;
25 options.env = env_;
26 options.write_buffer_size = 100000;
27 options.allow_concurrent_memtable_write = false;
28 Reopen(options);
29 CreateAndReopenWithCF({"pikachu"}, options);
30
31 // Update key with values of smaller size
32 int numValues = 10;
33 for (int i = numValues; i > 0; i--) {
34 std::string value = DummyString(i, 'a');
35 ASSERT_OK(Put(1, "key", value));
36 ASSERT_EQ(value, Get(1, "key"));
37 }
38
39 // Only 1 instance for that key.
40 validateNumberOfEntries(1, 1);
41 } while (ChangeCompactOptions());
42 }
43
44 TEST_F(DBTestInPlaceUpdate, InPlaceUpdateLargeNewValue) {
45 do {
46 Options options = CurrentOptions();
47 options.create_if_missing = true;
48 options.inplace_update_support = true;
49 options.env = env_;
50 options.write_buffer_size = 100000;
51 options.allow_concurrent_memtable_write = false;
52 Reopen(options);
53 CreateAndReopenWithCF({"pikachu"}, options);
54
55 // Update key with values of larger size
56 int numValues = 10;
57 for (int i = 0; i < numValues; i++) {
58 std::string value = DummyString(i, 'a');
59 ASSERT_OK(Put(1, "key", value));
60 ASSERT_EQ(value, Get(1, "key"));
61 }
62
63 // All 10 updates exist in the internal iterator
64 validateNumberOfEntries(numValues, 1);
65 } while (ChangeCompactOptions());
66 }
67
68 TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerSize) {
69 do {
70 Options options = CurrentOptions();
71 options.create_if_missing = true;
72 options.inplace_update_support = true;
73
74 options.env = env_;
75 options.write_buffer_size = 100000;
76 options.inplace_callback =
77 ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerSize;
78 options.allow_concurrent_memtable_write = false;
79 Reopen(options);
80 CreateAndReopenWithCF({"pikachu"}, options);
81
82 // Update key with values of smaller size
83 int numValues = 10;
84 ASSERT_OK(Put(1, "key", DummyString(numValues, 'a')));
85 ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key"));
86
87 for (int i = numValues; i > 0; i--) {
88 ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
89 ASSERT_EQ(DummyString(i - 1, 'b'), Get(1, "key"));
90 }
91
92 // Only 1 instance for that key.
93 validateNumberOfEntries(1, 1);
94 } while (ChangeCompactOptions());
95 }
96
97 TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerVarintSize) {
98 do {
99 Options options = CurrentOptions();
100 options.create_if_missing = true;
101 options.inplace_update_support = true;
102
103 options.env = env_;
104 options.write_buffer_size = 100000;
105 options.inplace_callback =
106 ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerVarintSize;
107 options.allow_concurrent_memtable_write = false;
108 Reopen(options);
109 CreateAndReopenWithCF({"pikachu"}, options);
110
111 // Update key with values of smaller varint size
112 int numValues = 265;
113 ASSERT_OK(Put(1, "key", DummyString(numValues, 'a')));
114 ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key"));
115
116 for (int i = numValues; i > 0; i--) {
117 ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
118 ASSERT_EQ(DummyString(1, 'b'), Get(1, "key"));
119 }
120
121 // Only 1 instance for that key.
122 validateNumberOfEntries(1, 1);
123 } while (ChangeCompactOptions());
124 }
125
126 TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackLargeNewValue) {
127 do {
128 Options options = CurrentOptions();
129 options.create_if_missing = true;
130 options.inplace_update_support = true;
131
132 options.env = env_;
133 options.write_buffer_size = 100000;
134 options.inplace_callback =
135 ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceLargerSize;
136 options.allow_concurrent_memtable_write = false;
137 Reopen(options);
138 CreateAndReopenWithCF({"pikachu"}, options);
139
140 // Update key with values of larger size
141 int numValues = 10;
142 for (int i = 0; i < numValues; i++) {
143 ASSERT_OK(Put(1, "key", DummyString(i, 'a')));
144 ASSERT_EQ(DummyString(i, 'c'), Get(1, "key"));
145 }
146
147 // No inplace updates. All updates are puts with new seq number
148 // All 10 updates exist in the internal iterator
149 validateNumberOfEntries(numValues, 1);
150 } while (ChangeCompactOptions());
151 }
152
153 TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackNoAction) {
154 do {
155 Options options = CurrentOptions();
156 options.create_if_missing = true;
157 options.inplace_update_support = true;
158
159 options.env = env_;
160 options.write_buffer_size = 100000;
161 options.inplace_callback =
162 ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceNoAction;
163 options.allow_concurrent_memtable_write = false;
164 Reopen(options);
165 CreateAndReopenWithCF({"pikachu"}, options);
166
167 // Callback function requests no actions from db
168 ASSERT_OK(Put(1, "key", DummyString(1, 'a')));
169 ASSERT_EQ(Get(1, "key"), "NOT_FOUND");
170 } while (ChangeCompactOptions());
171 }
172 } // namespace ROCKSDB_NAMESPACE
173
174 int main(int argc, char** argv) {
175 ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
176 ::testing::InitGoogleTest(&argc, argv);
177 return RUN_ALL_TESTS();
178 }