Search in sources :

Example 1 with DefaultTranslogDeletionPolicy

use of org.opensearch.index.translog.DefaultTranslogDeletionPolicy in project OpenSearch by opensearch-project.

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 DefaultTranslogDeletionPolicy(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 : DefaultTranslogDeletionPolicy(org.opensearch.index.translog.DefaultTranslogDeletionPolicy) TranslogConfig(org.opensearch.index.translog.TranslogConfig) DefaultTranslogDeletionPolicy(org.opensearch.index.translog.DefaultTranslogDeletionPolicy) TranslogDeletionPolicy(org.opensearch.index.translog.TranslogDeletionPolicy) Translog(org.opensearch.index.translog.Translog)

Example 2 with DefaultTranslogDeletionPolicy

use of org.opensearch.index.translog.DefaultTranslogDeletionPolicy in project OpenSearch by opensearch-project.

the class NoOpEngine method trimUnreferencedTranslogFiles.

/**
 * This implementation will trim existing translog files using a {@link TranslogDeletionPolicy}
 * that retains nothing but the last translog generation from safe commit.
 */
@Override
public void trimUnreferencedTranslogFiles() {
    final Store store = this.engineConfig.getStore();
    store.incRef();
    try (ReleasableLock lock = readLock.acquire()) {
        ensureOpen();
        final List<IndexCommit> commits = DirectoryReader.listCommits(store.directory());
        if (commits.size() == 1 && translogStats.getTranslogSizeInBytes() > translogStats.getUncommittedSizeInBytes()) {
            final Map<String, String> commitUserData = getLastCommittedSegmentInfos().getUserData();
            final String translogUuid = commitUserData.get(Translog.TRANSLOG_UUID_KEY);
            if (translogUuid == null) {
                throw new IllegalStateException("commit doesn't contain translog unique id");
            }
            final TranslogConfig translogConfig = engineConfig.getTranslogConfig();
            final long localCheckpoint = Long.parseLong(commitUserData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY));
            final TranslogDeletionPolicy translogDeletionPolicy = new DefaultTranslogDeletionPolicy(-1, -1, 0);
            translogDeletionPolicy.setLocalCheckpointOfSafeCommit(localCheckpoint);
            try (Translog translog = new Translog(translogConfig, translogUuid, translogDeletionPolicy, engineConfig.getGlobalCheckpointSupplier(), engineConfig.getPrimaryTermSupplier(), seqNo -> {
            })) {
                translog.trimUnreferencedReaders();
                // refresh the translog stats
                this.translogStats = translog.stats();
                assert translog.currentFileGeneration() == translog.getMinFileGeneration() : "translog was not trimmed " + " current gen " + translog.currentFileGeneration() + " != min gen " + translog.getMinFileGeneration();
            }
        }
    } catch (final Exception e) {
        try {
            failEngine("translog trimming failed", e);
        } catch (Exception inner) {
            e.addSuppressed(inner);
        }
        throw new EngineException(shardId, "failed to trim translog", e);
    } finally {
        store.decRef();
    }
}
Also used : TranslogConfig(org.opensearch.index.translog.TranslogConfig) Store(org.opensearch.index.store.Store) ReleasableLock(org.opensearch.common.util.concurrent.ReleasableLock) IndexCommit(org.apache.lucene.index.IndexCommit) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Translog(org.opensearch.index.translog.Translog) DefaultTranslogDeletionPolicy(org.opensearch.index.translog.DefaultTranslogDeletionPolicy) TranslogDeletionPolicy(org.opensearch.index.translog.TranslogDeletionPolicy) DefaultTranslogDeletionPolicy(org.opensearch.index.translog.DefaultTranslogDeletionPolicy)

Example 3 with DefaultTranslogDeletionPolicy

use of org.opensearch.index.translog.DefaultTranslogDeletionPolicy in project OpenSearch by opensearch-project.

the class InternalEngineTests method testEngineCreationWithCustomTranslogDeletePolicy.

public void testEngineCreationWithCustomTranslogDeletePolicy() throws IOException {
    class CustomTranslogDeletionPolicy extends DefaultTranslogDeletionPolicy {

        public CustomTranslogDeletionPolicy(IndexSettings indexSettings, Supplier<RetentionLeases> retentionLeasesSupplier) {
            super(indexSettings.getTranslogRetentionSize().getBytes(), indexSettings.getTranslogRetentionAge().getMillis(), indexSettings.getTranslogRetentionTotalFiles());
        }
    }
    TranslogDeletionPolicyFactory translogDeletionPolicyFactory = CustomTranslogDeletionPolicy::new;
    EngineConfig config = engine.config();
    EngineConfig configWithCustomTranslogDeletionPolicyFactory = new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), translogDeletionPolicyFactory, config.getFlushMergesAfter(), config.getExternalRefreshListener(), config.getInternalRefreshListener(), config.getIndexSort(), config.getCircuitBreakerService(), config.getGlobalCheckpointSupplier(), config.retentionLeasesSupplier(), config.getPrimaryTermSupplier(), config.getTombstoneDocSupplier());
    engine.close();
    engine = createEngine(configWithCustomTranslogDeletionPolicyFactory);
    assertTrue(engine.getTranslog().getDeletionPolicy() instanceof CustomTranslogDeletionPolicy);
}
Also used : DefaultTranslogDeletionPolicy(org.opensearch.index.translog.DefaultTranslogDeletionPolicy) IndexSettings(org.opensearch.index.IndexSettings) CodecService(org.opensearch.index.codec.CodecService) Supplier(java.util.function.Supplier) IntSupplier(java.util.function.IntSupplier) LongSupplier(java.util.function.LongSupplier) TranslogDeletionPolicyFactory(org.opensearch.index.translog.TranslogDeletionPolicyFactory)

Aggregations

DefaultTranslogDeletionPolicy (org.opensearch.index.translog.DefaultTranslogDeletionPolicy)3 Translog (org.opensearch.index.translog.Translog)2 TranslogConfig (org.opensearch.index.translog.TranslogConfig)2 TranslogDeletionPolicy (org.opensearch.index.translog.TranslogDeletionPolicy)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 IntSupplier (java.util.function.IntSupplier)1 LongSupplier (java.util.function.LongSupplier)1 Supplier (java.util.function.Supplier)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 ReleasableLock (org.opensearch.common.util.concurrent.ReleasableLock)1 IndexSettings (org.opensearch.index.IndexSettings)1 CodecService (org.opensearch.index.codec.CodecService)1 Store (org.opensearch.index.store.Store)1 TranslogDeletionPolicyFactory (org.opensearch.index.translog.TranslogDeletionPolicyFactory)1