-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add translog files age to Translog Stats (#28613) #28613
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
Changes from 2 commits
948614e
056710a
e3586d1
4066b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,8 @@ | |
| import static org.hamcrest.Matchers.hasToString; | ||
| import static org.hamcrest.Matchers.isIn; | ||
| import static org.hamcrest.Matchers.lessThanOrEqualTo; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.stub; | ||
|
|
||
| @LuceneTestCase.SuppressFileSystems("ExtrasFS") | ||
| public class TranslogTests extends ESTestCase { | ||
|
|
@@ -356,6 +358,25 @@ protected TranslogStats stats() throws IOException { | |
| return stats; | ||
| } | ||
|
|
||
| public void testFindEarliestLastModifiedAge() throws IOException { | ||
| long fixedTime = System.currentTimeMillis(); | ||
|
||
| long[] periods = new long[10]; | ||
|
||
| for (int i = 0; i < 9; i++) { | ||
| periods[i] = randomLongBetween(10000, 1000000); | ||
| } | ||
| List<TranslogReader> readers = new ArrayList<>(); | ||
| for (long l : periods) { | ||
| TranslogReader r = mock(TranslogReader.class); | ||
| stub(r.getLastModifiedTime()).toReturn(fixedTime - l); | ||
| readers.add(r); | ||
| } | ||
| long period = randomLongBetween(10000, 1000000); | ||
| periods[9] = period; | ||
| TranslogWriter w = mock(TranslogWriter.class); | ||
| stub(w.getLastModifiedTime()).toReturn(fixedTime - period); | ||
| assertThat(Translog.findEarliestLastModifiedAge(fixedTime, readers, w), equalTo(LongStream.of(periods).max().orElse(0L))); | ||
| } | ||
|
|
||
| public void testStats() throws IOException { | ||
| // self control cleaning for test | ||
| translog.getDeletionPolicy().setRetentionSizeInBytes(1024 * 1024); | ||
|
|
@@ -374,6 +395,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(97L)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(1)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(97L)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
|
|
||
| translog.add(new Translog.Delete("test", "2", 1, newUid("2"))); | ||
|
|
@@ -383,6 +405,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(146L)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(2)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(146L)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
|
|
||
| translog.add(new Translog.Delete("test", "3", 2, newUid("3"))); | ||
|
|
@@ -392,6 +415,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(195L)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(3)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(195L)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
|
|
||
| translog.add(new Translog.NoOp(3, 1, randomAlphaOfLength(16))); | ||
|
|
@@ -401,6 +425,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(237L)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(4)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(237L)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
|
|
||
| final long expectedSizeInBytes = 280L; | ||
|
|
@@ -411,6 +436,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(expectedSizeInBytes)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(4)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(expectedSizeInBytes)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
|
|
||
| { | ||
|
|
@@ -428,7 +454,8 @@ public void testStats() throws IOException { | |
| copy.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
| builder.endObject(); | ||
| assertThat(builder.string(), equalTo("{\"translog\":{\"operations\":4,\"size_in_bytes\":" + expectedSizeInBytes | ||
| + ",\"uncommitted_operations\":4,\"uncommitted_size_in_bytes\":" + expectedSizeInBytes + "}}")); | ||
| + ",\"uncommitted_operations\":4,\"uncommitted_size_in_bytes\":" + expectedSizeInBytes | ||
| + ",\"earliest_last_modified_age\":" + stats.getEarliestLastModifiedAge() + "}}")); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -439,6 +466,7 @@ public void testStats() throws IOException { | |
| assertThat(stats.getTranslogSizeInBytes(), equalTo(expectedSizeInBytes)); | ||
| assertThat(stats.getUncommittedOperations(), equalTo(0)); | ||
| assertThat(stats.getUncommittedSizeInBytes(), equalTo(firstOperationPosition)); | ||
| assertThat(stats.getEarliestLastModifiedAge(), greaterThan(1L)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -468,12 +496,12 @@ public void testUncommittedOperations() throws Exception { | |
| } | ||
|
|
||
| public void testTotalTests() { | ||
| final TranslogStats total = new TranslogStats(); | ||
| final TranslogStats total = new TranslogStats(0, 0, 0, 0, 1); | ||
| final int n = randomIntBetween(0, 16); | ||
| final List<TranslogStats> statsList = new ArrayList<>(n); | ||
| for (int i = 0; i < n; i++) { | ||
| final TranslogStats stats = new TranslogStats(randomIntBetween(1, 4096), randomIntBetween(1, 1 << 20), | ||
| randomIntBetween(1, 1 << 20), randomIntBetween(1, 4096)); | ||
| randomIntBetween(1, 1 << 20), randomIntBetween(1, 4096), randomIntBetween(1, 1 << 20)); | ||
| statsList.add(stats); | ||
| total.add(stats); | ||
| } | ||
|
|
@@ -490,22 +518,30 @@ public void testTotalTests() { | |
| assertThat( | ||
| total.getUncommittedSizeInBytes(), | ||
| equalTo(statsList.stream().mapToLong(TranslogStats::getUncommittedSizeInBytes).sum())); | ||
| assertThat( | ||
| total.getEarliestLastModifiedAge(), | ||
| equalTo(1L)); | ||
| } | ||
|
|
||
| public void testNegativeNumberOfOperations() { | ||
| IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(-1, 1, 1, 1)); | ||
| IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(-1, 1, 1, 1, 1)); | ||
| assertThat(e, hasToString(containsString("numberOfOperations must be >= 0"))); | ||
| e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, 1, -1, 1)); | ||
| e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, 1, -1, 1, 1)); | ||
| assertThat(e, hasToString(containsString("uncommittedOperations must be >= 0"))); | ||
| } | ||
|
|
||
| public void testNegativeSizeInBytes() { | ||
| IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, -1, 1, 1)); | ||
| IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, -1, 1, 1, 1)); | ||
| assertThat(e, hasToString(containsString("translogSizeInBytes must be >= 0"))); | ||
| e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, 1, 1, -1)); | ||
| e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, 1, 1, -1, 1)); | ||
| assertThat(e, hasToString(containsString("uncommittedSizeInBytes must be >= 0"))); | ||
| } | ||
|
|
||
| public void testOldestEntryInSeconds() { | ||
| IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new TranslogStats(1, 1, 1, 1, -1)); | ||
| assertThat(e, hasToString(containsString("earliestLastModifiedAge must be >= 0"))); | ||
| } | ||
|
|
||
| public void testSnapshot() throws IOException { | ||
| ArrayList<Translog.Operation> ops = new ArrayList<>(); | ||
| try (Translog.Snapshot snapshot = translog.newSnapshot()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a Math.max(0, currentTime - Math.min()) ? we rely on this being non negative, but time may go back and the FS may have other quirks.