Created
October 26, 2023 20:13
-
-
Save DiannaHohensee/2b26f08c74f94d1d9b904ab9aac488bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
public void testClusterStateCleanup() throws Exception { | |
final int NUM_NODES = 3; | |
// TODO: figure out how to manipulate the election settings so that elections occur and are quick -- took like 30 seconds?!?! And multiple elections occurred, races. | |
final Settings settings = Settings.builder().put(ELECTION_MAX_TIMEOUT_SETTING.getKey(), "500ms").build(); | |
// Start some master nodes | |
for (int i = 0; i < NUM_NODES; i++) { | |
// startMasterOnlyNode(settings); | |
startMasterOnlyNode(); | |
} | |
// Wait for an election. | |
ensureGreen(); | |
var nodeNames = internalCluster().getNodeNames(); | |
// Failover the master a few times, to generate new cluster state term directories in the blob store. | |
for (int i = 0; i < 3; i++) { | |
logger.info("~~~~stopping master node" + i); | |
internalCluster().restartNode(internalCluster().getMasterName(), InternalTestCluster.EMPTY_CALLBACK); | |
// internalCluster().stopCurrentMasterNode(); | |
// Wait for a new master to be elected. | |
logger.info("~~~~waiting for green..."); | |
ensureGreen(); | |
} | |
// TODO: check the blob store directories for 3 master directories | |
int numTerms = countTermDirectories(); | |
assert numTerms >= 2 : "expected to find at least three term directories, but only found: " + numTerms; | |
// The {@link co.elastic.elasticsearch.stateless.cluster.coordination.StatelessClusterStateCleanupService#CLUSTER_STATE_CLEANUP_DELAY_MINUTES} | |
// value defaults to 5 minutes. We will want this to happen more quickly for testing purposes, but enough time to check first that the expected term directories are present | |
for (int i = 0; i < internalCluster().size(); ++i) { | |
// Set 1-millisecond delay before cleaning up old cluster state. | |
internalCluster().getInstance(StatelessClusterStateCleanupService.class, nodeNames[i]).setClusterStateCleanupDelayMinutesForTest(new TimeValue(1, TimeUnit.SECONDS)); | |
} | |
assertBusy(() -> { | |
int terms = countTermDirectories(); | |
assert terms == 1 : "found more than one term directory: " + terms; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment