Skip to content
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

Flush inactive shards #31965

Closed
ywelsch opened this issue Jul 11, 2018 · 2 comments · Fixed by #49126
Closed

Flush inactive shards #31965

ywelsch opened this issue Jul 11, 2018 · 2 comments · Fixed by #49126
Assignees
Labels
>bug :Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. :Distributed Indexing/Recovery Anything around constructing a new shard, either from a local or a remote source.

Comments

@ywelsch
Copy link
Contributor

ywelsch commented Jul 11, 2018

We currently have a logic that triggers a sync flush when a primary shard becomes inactive (after 5 minutes of no write activity on the primary shard). The goal of this is to ensure that sync flush markers are in place after a period of inactivity, so that a full cluster / rolling restart of nodes results in quick peer recoveries when there is no write activity on the respective shard. With operation-based recoveries, we also provide fast recoveries when there is write activity during node restarts. Operation-based recovery can, however, more frequently trigger situations where a replica shard becomes inactive, yet not all its searchable segments are flushed to disk, as the flushing is only triggered when a primary becomes inactive, and is not triggered by subsequent recoveries of replicas. This results in unnecessary extra storage (more translog generations + more Lucene segments) and possibly slows down future store- and peer-based recoveries. /cc: @jpountz

The following test illustrates the issue:

package org.elasticsearch.indices.flush;

import org.elasticsearch.action.admin.indices.segments.IndexShardSegments;
import org.elasticsearch.action.admin.indices.segments.ShardSegments;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.IndexingMemoryController;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;

import java.util.List;

import static org.hamcrest.Matchers.equalTo;

@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
public class FlushOnInactivityIT extends ESIntegTestCase {

    public void testFlushOnInactivity() throws Exception {
        List<String> nodes = internalCluster().startNodes(2,
            Settings.builder().put(IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING.getKey(), "3s").build());

        client().admin().indices().prepareCreate("test").get();

        ensureGreen("test");

        index("test", "_doc", "1");
        refresh("test"); // create segment
        index("test", "_doc", "2");
        refresh("test"); // create segment

        internalCluster().restartNode(nodes.get(0), new InternalTestCluster.RestartCallback() {

            public Settings onNodeStopped(String nodeName) throws Exception {
                assertBusySegmentsFlushed(client(nodes.get(1)), "test");
                return super.onNodeStopped(nodeName);
            }

        });

        ensureGreen("test");

        assertBusySegmentsFlushed(client(), "test");
    }

    private void assertBusySegmentsFlushed(Client client, String index) throws Exception {
        assertBusy(() -> {
            for (IndexShardSegments indexShardSegments : client.admin().indices().prepareSegments(index).get().getIndices().get(index)
                .getShards().values()) {
                for (ShardSegments shardSegments : indexShardSegments) {
                    assertThat(shardSegments.getNumberOfCommitted(), equalTo(shardSegments.getNumberOfSearch()));
                }
            }
        });
    }

}
@ywelsch ywelsch added >bug :Distributed Indexing/Recovery Anything around constructing a new shard, either from a local or a remote source. :Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. team-discuss labels Jul 11, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@bleskes
Copy link
Contributor

bleskes commented Aug 1, 2018

We discussed it and decided that what we can do here depends on wether we can fully rely on ops based recovery to serve as a replacement for synced flush and fast full cluster restarts/node dropping off the cluster and joining back. Ops base recovery should do the job but since it's relatively new, we want to gather feedback on how well it performs. @zuketo has offered to collect to that 🙏

@dnhatn dnhatn self-assigned this Nov 13, 2019
dnhatn added a commit that referenced this issue Nov 22, 2019
With peer recovery retention leases and sequence-number based replica 
allocation, a regular flush can speed up recovery as a synced-flush.
With this change, we will flush instead of synced-flush when a shard
becomes inactive.

Closes #31965
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. :Distributed Indexing/Recovery Anything around constructing a new shard, either from a local or a remote source.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants