-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Avoid background sync on relocated primary #40800
Changes from 1 commit
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 |
---|---|---|
|
@@ -30,20 +30,28 @@ | |
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.shard.DocsStats; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.search.sort.SortOrder; | ||
import org.elasticsearch.test.BackgroundIndexer; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.junit.annotations.TestLogging; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; | ||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; | ||
|
@@ -58,6 +66,23 @@ | |
public class RecoveryWhileUnderLoadIT extends ESIntegTestCase { | ||
private final Logger logger = LogManager.getLogger(RecoveryWhileUnderLoadIT.class); | ||
|
||
public static final class RetentionLeaseSyncIntervalSettingPlugin extends Plugin { | ||
|
||
@Override | ||
public List<Setting<?>> getSettings() { | ||
return Collections.singletonList(IndexService.RETENTION_LEASE_SYNC_INTERVAL_SETTING); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Stream.concat( | ||
super.nodePlugins().stream(), | ||
Stream.of(RetentionLeaseSyncIntervalSettingPlugin.class)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public void testRecoverWhileUnderLoadAllocateReplicasTest() throws Exception { | ||
logger.info("--> creating test index ..."); | ||
int numberOfShards = numberOfShards(); | ||
|
@@ -260,7 +285,8 @@ public void testRecoverWhileRelocating() throws Exception { | |
assertAcked(prepareCreate("test", 3, Settings.builder() | ||
.put(SETTING_NUMBER_OF_SHARDS, numShards) | ||
.put(SETTING_NUMBER_OF_REPLICAS, numReplicas) | ||
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC))); | ||
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC) | ||
.put(IndexService.RETENTION_LEASE_SYNC_INTERVAL_SETTING.getKey(), randomFrom("100ms")))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn’t any randomization here? Inadvertently left over from testing, you meant to also include the default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahahahaha. I wanted to run some extensive tests on the lowest value so I temporarily deleted the other ones :D fixed in ec75173 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s what I figured. 😄 |
||
|
||
final int numDocs = scaledRandomIntBetween(200, 9999); | ||
|
||
|
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.
I think this could potentially still fail if the shardRouting is updated between checking in line 821 and asserting inside
runUnderPrimaryPermit
. At least I cannot find the protection against that. If others agree, this could be something for a follow-up.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.
Once the shardRouting is an active primary, it will never be anything else. We never move a shard from primary to replica, and never move a shard from active to non-active. In each of these cases, the existing IndexShard instance will be remove and a new one created.