Skip to content

Commit bb60376

Browse files
jimwwalkerdaverigby
authored andcommitted
MB-31141: Account for nmeta in deleteWithMeta
When calculating the item size in deleteWithMeta we must ensure nmeta is removed from the calculated size. Tests added for both set and del withMeta Change-Id: Iab31591c521e9556d436905be0177da773afc058 Reviewed-on: http://review.couchbase.org/99152 Tested-by: Build Bot <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 610e6d3 commit bb60376

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

engines/ep/src/ep_engine.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5122,9 +5122,12 @@ ENGINE_ERROR_CODE EventuallyPersistentEngine::deleteWithMeta(
51225122
keyOffset += 2; // 2 bytes for nmeta
51235123
nmeta = ntohs(nmeta);
51245124
if (nmeta > 0) {
5125-
emd = cb::const_byte_buffer(
5126-
request->bytes + sizeof(request->bytes) + nkey + keyOffset,
5127-
nmeta);
5125+
// Correct the vallen
5126+
vallen -= nmeta;
5127+
emd = cb::const_byte_buffer(request->bytes +
5128+
sizeof(request->bytes) + nkey +
5129+
keyOffset + vallen,
5130+
nmeta);
51285131
}
51295132
}
51305133

engines/ep/src/stored-value.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ std::ostream& operator<<(std::ostream& os, const StoredValue& sv) {
433433

434434
// seqno, revid, expiry / purge time
435435
os << "seq:" << sv.getBySeqno() << " rev:" << sv.getRevSeqno();
436+
os << " cas:" << sv.getCas();
436437
os << " key:\"" << sv.getKey() << "\"";
437438
if (sv.isOrdered() && sv.isDeleted()) {
438439
os << " del_time:" << sv.lock_expiry_or_delete_time;

engines/ep/tests/module_tests/evp_store_with_meta.cc

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class WithMetaTest : public SingleThreadedEPBucketTest {
148148
int options,
149149
protocol_binary_response_status expectedResponseStatus,
150150
const std::string& key,
151-
const std::string& value) {
151+
const std::string& value,
152+
const std::vector<char>& emd) {
152153
auto swm = buildWithMetaPacket(op,
153154
0 /*datatype*/,
154155
vbid,
@@ -157,7 +158,7 @@ class WithMetaTest : public SingleThreadedEPBucketTest {
157158
itemMeta,
158159
key,
159160
value,
160-
{},
161+
emd,
161162
options);
162163
if (expectedResponseStatus == PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET) {
163164
EXPECT_EQ(ENGINE_NOT_MY_VBUCKET, callEngine(op, swm));
@@ -175,18 +176,14 @@ class WithMetaTest : public SingleThreadedEPBucketTest {
175176
int options,
176177
bool withValue,
177178
protocol_binary_response_status expectedResponseStatus,
178-
ENGINE_ERROR_CODE expectedGetReturnValue) {
179+
ENGINE_ERROR_CODE expectedGetReturnValue,
180+
const std::vector<char>& emd = {}) {
179181
std::string key = "mykey";
180182
std::string value;
181183
if (withValue) {
182184
value = createXattrValue("myvalue"); // xattr but stored as raw
183185
}
184-
oneOp(op,
185-
itemMeta,
186-
options,
187-
expectedResponseStatus,
188-
key,
189-
value);
186+
oneOp(op, itemMeta, options, expectedResponseStatus, key, value, emd);
190187
checkGetItem(key, value, itemMeta, expectedGetReturnValue);
191188
}
192189

@@ -655,7 +652,7 @@ void WithMetaTest::conflict_lose(protocol_binary_command op,
655652
EXPECT_EQ(PROTOCOL_BINARY_RESPONSE_SUCCESS, getAddResponseStatus());
656653

657654
for (const auto& td : testData) {
658-
oneOp(op, td.meta, options, td.expectedStatus, key, value);
655+
oneOp(op, td.meta, options, td.expectedStatus, key, value, {});
659656
}
660657
}
661658

@@ -1359,6 +1356,63 @@ TEST_P(DelWithMetaTest, setting_deleteTime) {
13591356
EXPECT_EQ(itemMeta.exptime, metadata.exptime);
13601357
}
13611358

1359+
TEST_P(DelWithMetaTest, MB_31141) {
1360+
ItemMetaData itemMeta{0xdeadbeef, 0xf00dcafe, 0xfacefeed, expiry};
1361+
// Do a delete with valid extended meta
1362+
// see - ep-engine/docs/protocol/del_with_meta.md
1363+
oneOpAndCheck(op,
1364+
itemMeta,
1365+
0, // no-options
1366+
withValue,
1367+
PROTOCOL_BINARY_RESPONSE_SUCCESS,
1368+
withValue ? ENGINE_SUCCESS : ENGINE_EWOULDBLOCK,
1369+
{0x01, 0x01, 0x00, 0x01, 0x01});
1370+
1371+
EXPECT_EQ(std::make_pair(false, size_t(1)),
1372+
getEPBucket().flushVBucket(vbid));
1373+
1374+
auto options = get_options_t(QUEUE_BG_FETCH | GET_DELETED_VALUE);
1375+
auto result = store->get(
1376+
{"mykey", DocNamespace::DefaultCollection}, vbid, cookie, options);
1377+
EXPECT_EQ(ENGINE_EWOULDBLOCK, result.getStatus());
1378+
1379+
// Run the BGFetcher task
1380+
MockGlobalTask mockTask(engine->getTaskable(), TaskId::MultiBGFetcherTask);
1381+
store->getVBucket(vbid)->getShard()->getBgFetcher()->run(&mockTask);
1382+
1383+
result = store->get(
1384+
{"mykey", DocNamespace::DefaultCollection}, vbid, cookie, options);
1385+
ASSERT_EQ(ENGINE_SUCCESS, result.getStatus());
1386+
1387+
// Before the fix 5.0+ could of left the value as 5, the size of the
1388+
// extended metadata
1389+
int expectedSize = withValue ? 275 : 0;
1390+
EXPECT_EQ(expectedSize, result.item->getNBytes());
1391+
}
1392+
1393+
TEST_P(AddSetWithMetaTest, MB_31141) {
1394+
ItemMetaData itemMeta{0xdeadbeef, 0xf00dcafe, 0xfacefeed, expiry};
1395+
// Do a set/add with valid extended meta
1396+
// see - ep-engine/docs/protocol/del_with_meta.md
1397+
oneOpAndCheck(GetParam(),
1398+
itemMeta,
1399+
0, // no-options
1400+
true,
1401+
PROTOCOL_BINARY_RESPONSE_SUCCESS,
1402+
ENGINE_SUCCESS,
1403+
{0x01, 0x01, 0x00, 0x01, 0x01});
1404+
1405+
EXPECT_EQ(std::make_pair(false, size_t(1)),
1406+
getEPBucket().flushVBucket(vbid));
1407+
1408+
auto options = get_options_t(QUEUE_BG_FETCH);
1409+
auto result = store->get(
1410+
{"mykey", DocNamespace::DefaultCollection}, vbid, cookie, options);
1411+
ASSERT_EQ(ENGINE_SUCCESS, result.getStatus());
1412+
// Only the value should come back
1413+
EXPECT_EQ(275, result.item->getNBytes());
1414+
}
1415+
13621416
auto opcodeValues = ::testing::Values(PROTOCOL_BINARY_CMD_SET_WITH_META,
13631417
PROTOCOL_BINARY_CMD_SETQ_WITH_META,
13641418
PROTOCOL_BINARY_CMD_ADD_WITH_META,

0 commit comments

Comments
 (0)