Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ydb/core/persqueue/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,6 @@ TConsumerSnapshot TPartition::CreateSnapshot(TUserInfo& userInfo) const {
if (userInfo.Offset >= static_cast<i64>(EndOffset)) {
result.LastCommittedMessage.CreateTimestamp = now;
result.LastCommittedMessage.WriteTimestamp = now;
} else if (userInfo.ActualTimestamps) {
result.LastCommittedMessage.CreateTimestamp = userInfo.CreateTimestamp;
result.LastCommittedMessage.WriteTimestamp = userInfo.WriteTimestamp;
} else {
auto timestamp = GetWriteTimeEstimate(userInfo.Offset);
result.LastCommittedMessage.CreateTimestamp = timestamp;
Expand All @@ -782,14 +779,14 @@ TConsumerSnapshot TPartition::CreateSnapshot(TUserInfo& userInfo) const {
result.LastReadMessage.WriteTimestamp = userInfo.ReadWriteTimestamp;
} else {
auto timestamp = GetWriteTimeEstimate(readOffset);
result.LastCommittedMessage.CreateTimestamp = timestamp;
result.LastCommittedMessage.WriteTimestamp = timestamp;
result.LastReadMessage.CreateTimestamp = timestamp;
result.LastReadMessage.WriteTimestamp = timestamp;
}

if (readOffset < (i64)EndOffset) {
result.ReadLag = result.LastReadTimestamp - result.LastReadMessage.WriteTimestamp;
}
result.CommitedLag = result.LastCommittedMessage.WriteTimestamp - now;
result.CommitedLag = now - result.LastCommittedMessage.WriteTimestamp;
result.TotalLag = TDuration::MilliSeconds(userInfo.GetWriteLagMs()) + result.ReadLag + (now - result.LastReadTimestamp);

return result;
Expand Down
27 changes: 15 additions & 12 deletions ydb/core/persqueue/ut/ut_with_sdk/topic_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Y_UNIT_TEST_SUITE(WithSDK) {
session->Close(TDuration::Seconds(5));
};

// Check describe for empty topic
Cerr << ">>>>> Check describe for empty topic\n";
{
auto d = describe();
UNIT_ASSERT_STRINGS_EQUAL(TEST_CONSUMER, d.GetConsumer().GetConsumerName());
Expand All @@ -75,44 +75,47 @@ Y_UNIT_TEST_SUITE(WithSDK) {
}

write(3);
Sleep(TDuration::Seconds(2));
write(7);
Sleep(TDuration::Seconds(2));
write(11);

// Check describe for topic which contains messages, but consumer hasn`t read
Cerr << ">>>>> Check describe for topic which contains messages, but consumer hasn`t read\n";
{
auto d = describe();
UNIT_ASSERT_STRINGS_EQUAL(TEST_CONSUMER, d.GetConsumer().GetConsumerName());
UNIT_ASSERT_VALUES_EQUAL(1, d.GetPartitions().size());
auto& p = d.GetPartitions()[0];
UNIT_ASSERT_VALUES_EQUAL(0, p.GetPartitionId());
UNIT_ASSERT_VALUES_EQUAL(true, p.GetActive());
UNIT_ASSERT_VALUES_EQUAL(2, p.GetPartitionStats()->GetEndOffset());
UNIT_ASSERT_VALUES_EQUAL(3, p.GetPartitionStats()->GetEndOffset());
auto& c = p.GetPartitionConsumerStats();
UNIT_ASSERT_VALUES_EQUAL(true, c.has_value());
UNIT_ASSERT_VALUES_EQUAL(0, c->GetCommittedOffset());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7), c->GetMaxWriteTimeLag()); //
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxReadTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(4), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_TIME_EQUAL(TInstant::Now(), c->GetLastReadTime(), TDuration::Seconds(3)); // why not zero?
UNIT_ASSERT_VALUES_EQUAL(1, c->GetLastReadOffset());
}

UNIT_ASSERT(setup.Commit(TString{TEST_TOPIC}, TEST_CONSUMER, 0, 1).IsSuccess());

// Check describe for topic whis contains messages, has commited offset but hasn`t read (restart tablet for example)
Cerr << ">>>>> Check describe for topic whis contains messages, has commited offset but hasn`t read (restart tablet for example)\n";
{
auto d = describe();
UNIT_ASSERT_STRINGS_EQUAL(TEST_CONSUMER, d.GetConsumer().GetConsumerName());
UNIT_ASSERT_VALUES_EQUAL(1, d.GetPartitions().size());
auto& p = d.GetPartitions()[0];
UNIT_ASSERT_VALUES_EQUAL(0, p.GetPartitionId());
UNIT_ASSERT_VALUES_EQUAL(true, p.GetActive());
UNIT_ASSERT_VALUES_EQUAL(2, p.GetPartitionStats()->GetEndOffset());
UNIT_ASSERT_VALUES_EQUAL(3, p.GetPartitionStats()->GetEndOffset());
auto& c = p.GetPartitionConsumerStats();
UNIT_ASSERT_VALUES_EQUAL(true, c.has_value());
UNIT_ASSERT_VALUES_EQUAL(1, c->GetCommittedOffset());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7), c->GetMaxWriteTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxReadTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(4), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_TIME_EQUAL(TInstant::Now(), c->GetLastReadTime(), TDuration::Seconds(3)); // why not zero?
UNIT_ASSERT_VALUES_EQUAL(1, c->GetLastReadOffset());
}
Expand Down Expand Up @@ -143,23 +146,23 @@ Y_UNIT_TEST_SUITE(WithSDK) {
session->Close(TDuration::Seconds(1));
}

// Check describe for topic wich contains messages, has commited offset of first message and read second message
Cerr << ">>>>> Check describe for topic wich contains messages, has commited offset of first message and read second message\n";
{
auto d = describe();
UNIT_ASSERT_STRINGS_EQUAL(TEST_CONSUMER, d.GetConsumer().GetConsumerName());
UNIT_ASSERT_VALUES_EQUAL(1, d.GetPartitions().size());
auto& p = d.GetPartitions()[0];
UNIT_ASSERT_VALUES_EQUAL(0, p.GetPartitionId());
UNIT_ASSERT_VALUES_EQUAL(true, p.GetActive());
UNIT_ASSERT_VALUES_EQUAL(2, p.GetPartitionStats()->GetEndOffset());
UNIT_ASSERT_VALUES_EQUAL(3, p.GetPartitionStats()->GetEndOffset());
auto& c = p.GetPartitionConsumerStats();
UNIT_ASSERT_VALUES_EQUAL(true, c.has_value());
UNIT_ASSERT_VALUES_EQUAL(1, c->GetCommittedOffset());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7), c->GetMaxWriteTimeLag());
//UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7), c->GetMaxWriteTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxReadTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(0), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(4), c->GetMaxCommittedTimeLag());
UNIT_ASSERT_TIME_EQUAL(TInstant::Now(), c->GetLastReadTime(), TDuration::Seconds(3));
UNIT_ASSERT_VALUES_EQUAL(2, c->GetLastReadOffset());
UNIT_ASSERT_VALUES_EQUAL(3, c->GetLastReadOffset());
}
}
}
Expand Down
Loading