]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
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 | ||
f67539c2 | 12 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
13 | |
14 | class DBTestInPlaceUpdate : public DBTestBase { | |
15 | public: | |
16 | DBTestInPlaceUpdate() : DBTestBase("/db_inplace_update_test") {} | |
17 | }; | |
18 | ||
19 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdate) { | |
20 | do { | |
21 | Options options = CurrentOptions(); | |
22 | options.create_if_missing = true; | |
23 | options.inplace_update_support = true; | |
24 | options.env = env_; | |
25 | options.write_buffer_size = 100000; | |
26 | options.allow_concurrent_memtable_write = false; | |
27 | Reopen(options); | |
28 | CreateAndReopenWithCF({"pikachu"}, options); | |
29 | ||
30 | // Update key with values of smaller size | |
31 | int numValues = 10; | |
32 | for (int i = numValues; i > 0; i--) { | |
33 | std::string value = DummyString(i, 'a'); | |
34 | ASSERT_OK(Put(1, "key", value)); | |
35 | ASSERT_EQ(value, Get(1, "key")); | |
36 | } | |
37 | ||
38 | // Only 1 instance for that key. | |
39 | validateNumberOfEntries(1, 1); | |
40 | } while (ChangeCompactOptions()); | |
41 | } | |
42 | ||
43 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdateLargeNewValue) { | |
44 | do { | |
45 | Options options = CurrentOptions(); | |
46 | options.create_if_missing = true; | |
47 | options.inplace_update_support = true; | |
48 | options.env = env_; | |
49 | options.write_buffer_size = 100000; | |
50 | options.allow_concurrent_memtable_write = false; | |
51 | Reopen(options); | |
52 | CreateAndReopenWithCF({"pikachu"}, options); | |
53 | ||
54 | // Update key with values of larger size | |
55 | int numValues = 10; | |
56 | for (int i = 0; i < numValues; i++) { | |
57 | std::string value = DummyString(i, 'a'); | |
58 | ASSERT_OK(Put(1, "key", value)); | |
59 | ASSERT_EQ(value, Get(1, "key")); | |
60 | } | |
61 | ||
62 | // All 10 updates exist in the internal iterator | |
63 | validateNumberOfEntries(numValues, 1); | |
64 | } while (ChangeCompactOptions()); | |
65 | } | |
66 | ||
67 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerSize) { | |
68 | do { | |
69 | Options options = CurrentOptions(); | |
70 | options.create_if_missing = true; | |
71 | options.inplace_update_support = true; | |
72 | ||
73 | options.env = env_; | |
74 | options.write_buffer_size = 100000; | |
75 | options.inplace_callback = | |
f67539c2 | 76 | ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerSize; |
7c673cae FG |
77 | options.allow_concurrent_memtable_write = false; |
78 | Reopen(options); | |
79 | CreateAndReopenWithCF({"pikachu"}, options); | |
80 | ||
81 | // Update key with values of smaller size | |
82 | int numValues = 10; | |
83 | ASSERT_OK(Put(1, "key", DummyString(numValues, 'a'))); | |
84 | ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key")); | |
85 | ||
86 | for (int i = numValues; i > 0; i--) { | |
87 | ASSERT_OK(Put(1, "key", DummyString(i, 'a'))); | |
88 | ASSERT_EQ(DummyString(i - 1, 'b'), Get(1, "key")); | |
89 | } | |
90 | ||
91 | // Only 1 instance for that key. | |
92 | validateNumberOfEntries(1, 1); | |
93 | } while (ChangeCompactOptions()); | |
94 | } | |
95 | ||
96 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackSmallerVarintSize) { | |
97 | do { | |
98 | Options options = CurrentOptions(); | |
99 | options.create_if_missing = true; | |
100 | options.inplace_update_support = true; | |
101 | ||
102 | options.env = env_; | |
103 | options.write_buffer_size = 100000; | |
104 | options.inplace_callback = | |
f67539c2 | 105 | ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceSmallerVarintSize; |
7c673cae FG |
106 | options.allow_concurrent_memtable_write = false; |
107 | Reopen(options); | |
108 | CreateAndReopenWithCF({"pikachu"}, options); | |
109 | ||
110 | // Update key with values of smaller varint size | |
111 | int numValues = 265; | |
112 | ASSERT_OK(Put(1, "key", DummyString(numValues, 'a'))); | |
113 | ASSERT_EQ(DummyString(numValues, 'c'), Get(1, "key")); | |
114 | ||
115 | for (int i = numValues; i > 0; i--) { | |
116 | ASSERT_OK(Put(1, "key", DummyString(i, 'a'))); | |
117 | ASSERT_EQ(DummyString(1, 'b'), Get(1, "key")); | |
118 | } | |
119 | ||
120 | // Only 1 instance for that key. | |
121 | validateNumberOfEntries(1, 1); | |
122 | } while (ChangeCompactOptions()); | |
123 | } | |
124 | ||
125 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackLargeNewValue) { | |
126 | do { | |
127 | Options options = CurrentOptions(); | |
128 | options.create_if_missing = true; | |
129 | options.inplace_update_support = true; | |
130 | ||
131 | options.env = env_; | |
132 | options.write_buffer_size = 100000; | |
133 | options.inplace_callback = | |
f67539c2 | 134 | ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceLargerSize; |
7c673cae FG |
135 | options.allow_concurrent_memtable_write = false; |
136 | Reopen(options); | |
137 | CreateAndReopenWithCF({"pikachu"}, options); | |
138 | ||
139 | // Update key with values of larger size | |
140 | int numValues = 10; | |
141 | for (int i = 0; i < numValues; i++) { | |
142 | ASSERT_OK(Put(1, "key", DummyString(i, 'a'))); | |
143 | ASSERT_EQ(DummyString(i, 'c'), Get(1, "key")); | |
144 | } | |
145 | ||
146 | // No inplace updates. All updates are puts with new seq number | |
147 | // All 10 updates exist in the internal iterator | |
148 | validateNumberOfEntries(numValues, 1); | |
149 | } while (ChangeCompactOptions()); | |
150 | } | |
151 | ||
152 | TEST_F(DBTestInPlaceUpdate, InPlaceUpdateCallbackNoAction) { | |
153 | do { | |
154 | Options options = CurrentOptions(); | |
155 | options.create_if_missing = true; | |
156 | options.inplace_update_support = true; | |
157 | ||
158 | options.env = env_; | |
159 | options.write_buffer_size = 100000; | |
160 | options.inplace_callback = | |
f67539c2 | 161 | ROCKSDB_NAMESPACE::DBTestInPlaceUpdate::updateInPlaceNoAction; |
7c673cae FG |
162 | options.allow_concurrent_memtable_write = false; |
163 | Reopen(options); | |
164 | CreateAndReopenWithCF({"pikachu"}, options); | |
165 | ||
166 | // Callback function requests no actions from db | |
167 | ASSERT_OK(Put(1, "key", DummyString(1, 'a'))); | |
168 | ASSERT_EQ(Get(1, "key"), "NOT_FOUND"); | |
169 | } while (ChangeCompactOptions()); | |
170 | } | |
f67539c2 | 171 | } // namespace ROCKSDB_NAMESPACE |
7c673cae FG |
172 | |
173 | int main(int argc, char** argv) { | |
f67539c2 | 174 | ROCKSDB_NAMESPACE::port::InstallStackTraceHandler(); |
7c673cae FG |
175 | ::testing::InitGoogleTest(&argc, argv); |
176 | return RUN_ALL_TESTS(); | |
177 | } |