Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed May 31, 2024
1 parent 29ccca3 commit 1354dbe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,7 @@ public long getMinFileGeneration() {
}
}

/**
* Returns the number of operations in the translog files
*/
public int totalOperations() {
return totalOperationsByMinGen(-1);
}

/**
* Returns the size in bytes of the v files
*/
public long sizeInBytes() {
return sizeInBytesByMinGen(-1);
}

long earliestLastModifiedAge() {
private long earliestLastModifiedAge() {
try (ReleasableLock ignored = readLock.acquire()) {
ensureOpen();
return findEarliestLastModifiedAge(System.currentTimeMillis(), readers, current);
Expand Down Expand Up @@ -890,8 +876,8 @@ public TranslogStats stats() {
try (ReleasableLock lock = readLock.acquire()) {
final long uncommittedGen = minGenerationForSeqNo(deletionPolicy.getLocalCheckpointOfSafeCommit() + 1, current, readers);
return new TranslogStats(
totalOperations(),
sizeInBytes(),
totalOperationsByMinGen(-1),
sizeInBytesByMinGen(-1),
totalOperationsByMinGen(uncommittedGen),
sizeInBytesByMinGen(uncommittedGen),
earliestLastModifiedAge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ public void testAsyncTranslogTrimActuallyWorks() throws Exception {
prepareIndex("test").setId("1").setSource("{\"foo\": \"bar\"}", XContentType.JSON).get();
indicesAdmin().prepareFlush("test").get();
IndexShard shard = indexService.getShard(0);
assertBusy(() -> assertThat(IndexShardTestCase.getTranslog(shard).totalOperations(), equalTo(0)));
assertBusy(() -> {
Translog translog = IndexShardTestCase.getTranslog(shard);
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
});
}

public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
Expand All @@ -393,7 +396,7 @@ public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
}
}
}
assertThat(translog.totalOperations(), equalTo(translogOps));
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(translogOps));
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(translogOps));
assertAcked(indicesAdmin().prepareClose("test"));

Expand All @@ -412,7 +415,7 @@ public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {

indexService = getInstanceFromNode(IndicesService.class).indexServiceSafe(indexService.index());
translog = IndexShardTestCase.getTranslog(indexService.getShard(0));
assertThat(translog.totalOperations(), equalTo(0));
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
assertThat(
getEngine(indexService.getShard(0)).getTranslogStats().getTranslogSizeInBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5790,7 +5790,8 @@ public void testCleanUpCommitsWhenGlobalCheckpointAdvanced() throws Exception {
globalCheckpoint.set(randomLongBetween(engine.getPersistedLocalCheckpoint(), Long.MAX_VALUE));
engine.syncTranslog();
assertThat(DirectoryReader.listCommits(store.directory()), contains(commits.get(commits.size() - 1)));
assertThat(engine.getTranslog().totalOperations(), equalTo(0));
Translog translog = engine.getTranslog();
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ public void testBasicCheckpoint() throws IOException {
lastSyncedGlobalCheckpoint = globalCheckpoint.get();
}
}
assertEquals(translogOperations, translog.totalOperations());
assertEquals(translogOperations, translog.stats().estimatedNumberOfOperations());
translog.add(indexOp("" + translogOperations, translogOperations, primaryTerm.get(), Integer.toString(translogOperations)));

final Checkpoint checkpoint = Checkpoint.read(translog.location().resolve(Translog.CHECKPOINT_FILE_NAME));
Expand All @@ -1311,7 +1311,7 @@ public void testBasicCheckpoint() throws IOException {
Translog.Operation next = snapshot.next();
assertNull(next);
}
assertEquals(translogOperations + 1, translog.totalOperations());
assertEquals(translogOperations + 1, translog.stats().estimatedNumberOfOperations());
assertThat(checkpoint.globalCheckpoint, equalTo(lastSyncedGlobalCheckpoint));
translog.close();
}
Expand Down Expand Up @@ -3477,7 +3477,7 @@ public void testRollGeneration() throws Exception {
}
assertThat(translog.currentFileGeneration(), equalTo(generation + i + 1));
assertThat(translog.getCurrent().getPrimaryTerm(), equalTo(primaryTerm.get()));
assertThat(translog.totalOperations(), equalTo(totalOperations));
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(totalOperations));
}
for (int i = 0; i <= rolls; i++) {
assertFileIsPresent(translog, generation + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void testTranslogHistoryTransferred() throws Exception {
shards.startAll();
final IndexShard replica = shards.getReplicas().get(0);
boolean softDeletesEnabled = replica.indexSettings().isSoftDeleteEnabled();
assertThat(getTranslog(replica).totalOperations(), equalTo(softDeletesEnabled ? 0 : docs + moreDocs));
Translog translog = getTranslog(replica);
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(softDeletesEnabled ? 0 : docs + moreDocs));
shards.assertAllEqual(docs + moreDocs);
}
}
Expand Down Expand Up @@ -115,7 +116,8 @@ public void testRetentionPolicyChangeDuringRecovery() throws Exception {
// rolling/flushing is async
assertBusy(() -> {
assertThat(replica.getLastSyncedGlobalCheckpoint(), equalTo(19L));
assertThat(getTranslog(replica).totalOperations(), equalTo(0));
Translog translog = getTranslog(replica);
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
});
}
}
Expand Down Expand Up @@ -264,7 +266,8 @@ public void testDifferentHistoryUUIDDisablesOPsRecovery() throws Exception {
// file based recovery should be made
assertThat(newReplica.recoveryState().getIndex().fileDetails(), not(empty()));
boolean softDeletesEnabled = replica.indexSettings().isSoftDeleteEnabled();
assertThat(getTranslog(newReplica).totalOperations(), equalTo(softDeletesEnabled ? 0 : numDocs));
Translog translog = getTranslog(newReplica);
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(softDeletesEnabled ? 0 : numDocs));

// history uuid was restored
assertThat(newReplica.getHistoryUUID(), equalTo(historyUUID));
Expand Down Expand Up @@ -401,7 +404,8 @@ public void testShouldFlushAfterPeerRecovery() throws Exception {
// Make sure the flushing will eventually be completed (eg. `shouldPeriodicallyFlush` is false)
assertBusy(() -> assertThat(getEngine(replica).shouldPeriodicallyFlush(), equalTo(false)));
boolean softDeletesEnabled = replica.indexSettings().isSoftDeleteEnabled();
assertThat(getTranslog(replica).totalOperations(), equalTo(softDeletesEnabled ? 0 : numDocs));
Translog translog = getTranslog(replica);
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(softDeletesEnabled ? 0 : numDocs));
shards.assertAllEqual(numDocs);
}
}
Expand Down

0 comments on commit 1354dbe

Please sign in to comment.