Search in sources :

Example 6 with TranslogDeletionPolicy

use of org.elasticsearch.index.translog.TranslogDeletionPolicy in project crate by crate.

the class ReadOnlyEngine method translogStats.

private static TranslogStats translogStats(final EngineConfig config, final SegmentInfos infos) throws IOException {
    final String translogUuid = infos.getUserData().get(Translog.TRANSLOG_UUID_KEY);
    if (translogUuid == null) {
        throw new IllegalStateException("commit doesn't contain translog unique id");
    }
    final TranslogConfig translogConfig = config.getTranslogConfig();
    final TranslogDeletionPolicy translogDeletionPolicy = new TranslogDeletionPolicy(config.getIndexSettings().getTranslogRetentionSize().getBytes(), config.getIndexSettings().getTranslogRetentionAge().getMillis(), config.getIndexSettings().getTranslogRetentionTotalFiles());
    final long localCheckpoint = Long.parseLong(infos.getUserData().get(SequenceNumbers.LOCAL_CHECKPOINT_KEY));
    translogDeletionPolicy.setLocalCheckpointOfSafeCommit(localCheckpoint);
    try (Translog translog = new Translog(translogConfig, translogUuid, translogDeletionPolicy, config.getGlobalCheckpointSupplier(), config.getPrimaryTermSupplier(), seqNo -> {
    })) {
        return translog.stats();
    }
}
Also used : TranslogConfig(org.elasticsearch.index.translog.TranslogConfig) TranslogDeletionPolicy(org.elasticsearch.index.translog.TranslogDeletionPolicy) Translog(org.elasticsearch.index.translog.Translog)

Example 7 with TranslogDeletionPolicy

use of org.elasticsearch.index.translog.TranslogDeletionPolicy in project crate by crate.

the class CombinedDeletionPolicyTests method testDeleteInvalidCommits.

public void testDeleteInvalidCommits() throws Exception {
    final AtomicLong globalCheckpoint = new AtomicLong(randomNonNegativeLong());
    final SoftDeletesPolicy softDeletesPolicy = new SoftDeletesPolicy(globalCheckpoint::get, -1, 0, () -> RetentionLeases.EMPTY);
    TranslogDeletionPolicy translogPolicy = createTranslogDeletionPolicy();
    CombinedDeletionPolicy indexPolicy = newCombinedDeletionPolicy(translogPolicy, softDeletesPolicy, globalCheckpoint);
    final int invalidCommits = between(1, 10);
    final List<IndexCommit> commitList = new ArrayList<>();
    for (int i = 0; i < invalidCommits; i++) {
        long maxSeqNo = randomNonNegativeLong();
        commitList.add(mockIndexCommit(randomLongBetween(-1, maxSeqNo), maxSeqNo, UUID.randomUUID()));
    }
    final UUID expectedTranslogUUID = UUID.randomUUID();
    final int validCommits = between(1, 10);
    long lastMaxSeqNo = between(1, 1000);
    long lastCheckpoint = randomLongBetween(-1, lastMaxSeqNo);
    for (int i = 0; i < validCommits; i++) {
        lastMaxSeqNo += between(1, 1000);
        lastCheckpoint = randomLongBetween(lastCheckpoint, lastMaxSeqNo);
        commitList.add(mockIndexCommit(lastCheckpoint, lastMaxSeqNo, expectedTranslogUUID));
    }
    // We should never keep invalid commits regardless of the value of the global checkpoint.
    indexPolicy.onCommit(commitList);
    for (int i = 0; i < invalidCommits - 1; i++) {
        verify(commitList.get(i), times(1)).delete();
    }
    assertThat(softDeletesPolicy.getMinRetainedSeqNo(), equalTo(getLocalCheckpoint(CombinedDeletionPolicy.findSafeCommitPoint(commitList, globalCheckpoint.get())) + 1));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongArrayList(com.carrotsearch.hppc.LongArrayList) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TranslogDeletionPolicy(org.elasticsearch.index.translog.TranslogDeletionPolicy) TranslogDeletionPolicies.createTranslogDeletionPolicy(org.elasticsearch.index.translog.TranslogDeletionPolicies.createTranslogDeletionPolicy) IndexCommit(org.apache.lucene.index.IndexCommit)

Aggregations

TranslogDeletionPolicy (org.elasticsearch.index.translog.TranslogDeletionPolicy)7 IndexCommit (org.apache.lucene.index.IndexCommit)5 LongArrayList (com.carrotsearch.hppc.LongArrayList)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 TranslogDeletionPolicies.createTranslogDeletionPolicy (org.elasticsearch.index.translog.TranslogDeletionPolicies.createTranslogDeletionPolicy)4 Translog (org.elasticsearch.index.translog.Translog)2 TranslogConfig (org.elasticsearch.index.translog.TranslogConfig)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ReleasableLock (org.elasticsearch.common.util.concurrent.ReleasableLock)1 Store (org.elasticsearch.index.store.Store)1