Skip to content

Commit 08d976b

Browse files
authored
Fix zero creation time in keyvalue volume (#22942)
1 parent f657438 commit 08d976b

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

ydb/core/keyvalue/keyvalue_state.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void PrepareCreationUnixTime(const R& request, I& interm)
7878
}
7979
}
8080

81+
template <class R, class I>
82+
void PrepareCreationUnixTimeInNewApi(const R& request, I& interm)
83+
{
84+
Y_UNUSED(request);
85+
interm.CreationUnixTime = TAppData::TimeProvider->Now().Seconds();
86+
}
87+
8188
// Guideline:
8289
// Check SetError calls: there must be no changes made to the DB before SetError call (!)
8390

@@ -2673,6 +2680,7 @@ TPrepareResult TKeyValueState::PrepareOneCmd(const TCommand::Rename &request, TH
26732680
auto &cmd = std::get<TIntermediate::TRename>(intermediate->Commands.back());
26742681
cmd.OldKey = request.old_key();
26752682
cmd.NewKey = request.new_key();
2683+
PrepareCreationUnixTimeInNewApi(request, cmd);
26762684
return {};
26772685
}
26782686

@@ -2741,6 +2749,7 @@ TPrepareResult TKeyValueState::PrepareOneCmd(const TCommand::Write &request, THo
27412749
}
27422750
}
27432751
SplitIntoBlobs(cmd, isInline, storageChannelIdx);
2752+
PrepareCreationUnixTimeInNewApi(request, cmd);
27442753
return {};
27452754
}
27462755

ydb/core/keyvalue/keyvalue_ut.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,19 @@ void CmdSetExecutorFastLogPolicy(bool isAllowed, TTestContext &tc) {
647647
// NEW SINGLE COMMAND TEST FUNCTIONS
648648
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
649649

650+
template <typename T>
651+
struct NotEq {
652+
T Value;
653+
654+
bool Check(const T &value) const {
655+
return Value != value;
656+
}
657+
};
658+
650659
struct TKeyValuePair {
651660
TString Key;
652661
TString Value;
662+
std::variant<std::monostate, ui64, NotEq<ui64>> CreationUnixTime = std::monostate();
653663
};
654664

655665
template <typename TRequestEvent>
@@ -698,7 +708,7 @@ void SendWrite(TTestContext &tc, const TDeque<TKeyValuePair> &pairs, ui64 locked
698708
{
699709
NKikimrKeyValue::ExecuteTransactionRequest et;
700710

701-
for (auto &[key, value] : pairs) {
711+
for (auto &[key, value, creationUnixTime] : pairs) {
702712
NKikimrKeyValue::ExecuteTransactionRequest::Command *cmd = et.add_commands();
703713
NKikimrKeyValue::ExecuteTransactionRequest::Command::Write *write = cmd->mutable_write();
704714

@@ -720,7 +730,7 @@ void ExecuteWrite(TTestContext &tc, const TDeque<TKeyValuePair> &pairs, ui64 loc
720730
{
721731
TDesiredPair<TEvKeyValue::TEvExecuteTransaction> dp;
722732

723-
for (auto &[key, value] : pairs) {
733+
for (auto &[key, value, creationUnixTime] : pairs) {
724734
NKikimrKeyValue::ExecuteTransactionRequest::Command *cmd = dp.Request.add_commands();
725735
NKikimrKeyValue::ExecuteTransactionRequest::Command::Write *write = cmd->mutable_write();
726736

@@ -990,6 +1000,12 @@ void ExecuteReadRange(TTestContext &tc,
9901000
<< " msg# " << dp.Response.msg());
9911001
UNIT_ASSERT_VALUES_EQUAL_C(pair.key(), expectedPairs[idx].Key, "msg# " << dp.Response.msg());
9921002
UNIT_ASSERT_VALUES_EQUAL_C(pair.value(), expectedPairs[idx].Value, "msg# " << dp.Response.msg());
1003+
1004+
if (std::holds_alternative<ui64>(expectedPairs[idx].CreationUnixTime)) {
1005+
UNIT_ASSERT_VALUES_EQUAL_C(pair.creation_unix_time(), std::get<ui64>(expectedPairs[idx].CreationUnixTime), "msg# " << dp.Response.msg());
1006+
} else if (std::holds_alternative<NotEq<ui64>>(expectedPairs[idx].CreationUnixTime)) {
1007+
UNIT_ASSERT_VALUES_UNEQUAL_C(pair.creation_unix_time(), std::get<NotEq<ui64>>(expectedPairs[idx].CreationUnixTime).Value, "msg# " << dp.Response.msg());
1008+
}
9931009
}
9941010
}
9951011
}
@@ -2818,6 +2834,35 @@ Y_UNIT_TEST(TestWriteAndRenameWithCreationUnixTime)
28182834
tc);
28192835
}
28202836

2837+
2838+
2839+
Y_UNIT_TEST(TestWriteAndRenameWithoutCreationUnixTimeNewApi)
2840+
{
2841+
TTestContext tc;
2842+
TFinalizer finalizer(tc);
2843+
bool activeZone = false;
2844+
tc.Prepare(INITIAL_TEST_DISPATCH_NAME, [](TTestActorRuntime &runtime){
2845+
runtime.UpdateCurrentTime(TInstant::Zero() + TDuration::Seconds(1000));
2846+
}, activeZone);
2847+
2848+
ExecuteWrite(tc, {{"key-1", "value"}}, 0, 1, NKikimrKeyValue::Priorities::PRIORITY_REALTIME);
2849+
2850+
ExecuteReadRange(tc,
2851+
{"key-1"}, EBorderKind::Include,
2852+
"key-1", EBorderKind::Include,
2853+
{{"key-1", "value", NotEq<ui64>{0}}},
2854+
0, true, 65000);
2855+
2856+
ExecuteRename(tc, {{"key-1", "key-2"}}, 0);
2857+
2858+
ExecuteReadRange(tc,
2859+
{"key-2"}, EBorderKind::Include,
2860+
"key-2", EBorderKind::Include,
2861+
{{"key-2", "value", NotEq<ui64>{0}}},
2862+
0, true, 65000);
2863+
}
2864+
2865+
28212866
Y_UNIT_TEST(TestReadRequestInFlightLimit)
28222867
{
28232868
TTestContext tc;

0 commit comments

Comments
 (0)