Skip to content

Fix TranslogTests#testStats #85828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,23 @@ public void testFindEarliestLastModifiedAge() throws IOException {
assertThat(Translog.findEarliestLastModifiedAge(fixedTime, readers, w), equalTo(LongStream.of(periods).max().orElse(0L)));
}

public void testStats() throws IOException {
private void waitForPositiveAge() throws Exception {
final var lastModifiedTime = translog.getCurrent().getLastModifiedTime();
assertBusy(() -> assertThat(System.currentTimeMillis(), greaterThan(lastModifiedTime)));
}

public void testStats() throws Exception {
// self control cleaning for test
final long firstOperationPosition = translog.getFirstOperationPosition();
{
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(0));
}
assertThat((int) firstOperationPosition, greaterThan(CodecUtil.headerLength(TranslogHeader.TRANSLOG_CODEC)));
translog.add(new Translog.Index("1", 0, primaryTerm.get(), new byte[] { 1 }));

translog.add(new Translog.Index("1", 0, primaryTerm.get(), new byte[] { 1 }));
{
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(1));
assertThat(stats.getTranslogSizeInBytes(), equalTo(157L));
Expand All @@ -467,6 +473,7 @@ public void testStats() throws IOException {

translog.add(new Translog.Delete("2", 1, primaryTerm.get()));
{
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(2));
assertThat(stats.getTranslogSizeInBytes(), equalTo(193L));
Expand All @@ -477,6 +484,7 @@ public void testStats() throws IOException {

translog.add(new Translog.Delete("3", 2, primaryTerm.get()));
{
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(3));
assertThat(stats.getTranslogSizeInBytes(), equalTo(229L));
Expand All @@ -487,6 +495,7 @@ public void testStats() throws IOException {

translog.add(new Translog.NoOp(3, 1, randomAlphaOfLength(16)));
{
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(4));
assertThat(stats.getTranslogSizeInBytes(), equalTo(271L));
Expand All @@ -497,6 +506,7 @@ public void testStats() throws IOException {

translog.rollGeneration();
{
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(4));
assertThat(stats.getTranslogSizeInBytes(), equalTo(326L));
Expand Down Expand Up @@ -532,13 +542,13 @@ public void testStats() throws IOException {
translog.getDeletionPolicy().setLocalCheckpointOfSafeCommit(randomLongBetween(3, Long.MAX_VALUE));
translog.trimUnreferencedReaders();
{
long lastModifiedAge = System.currentTimeMillis() - translog.getCurrent().getLastModifiedTime();
waitForPositiveAge();
final TranslogStats stats = stats();
assertThat(stats.estimatedNumberOfOperations(), equalTo(0));
assertThat(stats.getTranslogSizeInBytes(), equalTo(firstOperationPosition));
assertThat(stats.getUncommittedOperations(), equalTo(0));
assertThat(stats.getUncommittedSizeInBytes(), equalTo(firstOperationPosition));
assertThat(stats.getEarliestLastModifiedAge(), greaterThanOrEqualTo(lastModifiedAge));
assertThat(stats.getEarliestLastModifiedAge(), greaterThan(0L));
}
}

Expand Down