Skip to content

Commit 68271a6

Browse files
committed
MB-31070: Append should not reset exptime
Fix regression where expiry time is reset as part of append. Change-Id: I785e963dafeac74dd12498274cd4d092fb9f9459 Reviewed-on: http://review.couchbase.org/99213 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Jim Walker <[email protected]>
1 parent 610e6d3 commit 68271a6

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

daemon/protocol/mcbp/appendprepend_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ ENGINE_ERROR_CODE AppendPrependCommandContext::allocateNewItem() {
183183
old.len + value.len,
184184
priv_size,
185185
oldItemInfo.flags,
186-
0,
186+
(rel_time_t)oldItemInfo.exptime,
187187
datatype,
188188
vbucket);
189189

tests/testapp/testapp_regression.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,51 @@ TEST_P(RegressionTest, MB_26828_SetIsFixed) {
132132
conn.executeCommand(cmd, resp);
133133
EXPECT_TRUE(resp.isSuccess());
134134
}
135+
136+
/**
137+
* https://issues.couchbase.com/browse/MB-31070
138+
*
139+
* Expiry time becomes 0 after append.
140+
*
141+
* This test validates that it is fixed by:
142+
* 1. Store a document with 30 seconds expiry time
143+
* 2. Fetch the expiry time of the document (absolute time)
144+
* 3. Performs an append
145+
* 4. Fetch the expiry time of the document and verifies that it is unchanged
146+
*/
147+
TEST_P(RegressionTest, MB_31070) {
148+
auto& conn = getConnection();
149+
150+
Document document;
151+
document.info.cas = mcbp::cas::Wildcard;
152+
document.info.flags = 0xcaffee;
153+
document.info.id = name;
154+
document.info.expiration = 30;
155+
document.value = "hello";
156+
157+
conn.mutate(document, 0, MutationType::Set);
158+
159+
BinprotSubdocMultiLookupCommand cmd;
160+
cmd.setKey(name);
161+
cmd.addGet("$document.exptime", SUBDOC_FLAG_XATTR_PATH);
162+
163+
BinprotSubdocMultiLookupResponse multiResp;
164+
conn.executeCommand(cmd, multiResp);
165+
166+
auto& results = multiResp.getResults();
167+
168+
EXPECT_EQ(PROTOCOL_BINARY_RESPONSE_SUCCESS, multiResp.getStatus());
169+
EXPECT_EQ(PROTOCOL_BINARY_RESPONSE_SUCCESS, results[0].status);
170+
const auto exptime = std::stol(results[0].value);
171+
EXPECT_LT(0, exptime);
172+
173+
document.value = " world";
174+
document.info.expiration = 0;
175+
conn.mutate(document, 0, MutationType::Append);
176+
177+
conn.executeCommand(cmd, multiResp);
178+
179+
EXPECT_EQ(PROTOCOL_BINARY_RESPONSE_SUCCESS, multiResp.getStatus());
180+
EXPECT_EQ(PROTOCOL_BINARY_RESPONSE_SUCCESS, results[0].status);
181+
EXPECT_EQ(exptime, std::stol(results[0].value));
182+
}

0 commit comments

Comments
 (0)