forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Adding subshard work items on lease expiry" (opensear…
…ch-project#1183)" This reverts commit b055711 Signed-off-by: Andre Kurait <[email protected]>
- Loading branch information
1 parent
8c95468
commit a7c48e2
Showing
28 changed files
with
608 additions
and
310 deletions.
There are no files selected for viewing
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
115 changes: 115 additions & 0 deletions
115
...romSnapshotMigration/src/test/java/org/opensearch/migrations/RfsMigrateDocumentsTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.opensearch.migrations; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
import org.opensearch.migrations.bulkload.workcoordination.WorkItemTimeProvider; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
class RfsMigrateDocumentsTest { | ||
|
||
|
||
private static class TestClass extends RfsMigrateDocuments { | ||
public static int getSuccessorNextAcquisitionLeaseExponent(WorkItemTimeProvider workItemTimeProvider, Duration initialLeaseDuration, | ||
Instant leaseExpirationTime) { | ||
return RfsMigrateDocuments.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetSuccessorNextAcquisitionLeaseExponent_LessThanLowerThreshold() { | ||
WorkItemTimeProvider workItemTimeProvider = new WorkItemTimeProvider(); | ||
|
||
// Lease at 40 minutes, shard prep 59 seconds, successor lease should be decreased since shard prep is < 2.5% | ||
// and exponent is > 0 | ||
var existingLeaseExponent = 2; | ||
var shardPrepTime = Duration.ofSeconds(59); | ||
Duration initialLeaseDuration = Duration.ofMinutes(10); | ||
var initialLeaseMultiple = (int) Math.pow(2, existingLeaseExponent); | ||
|
||
workItemTimeProvider.getLeaseAcquisitionTimeRef().set(Instant.EPOCH); | ||
workItemTimeProvider.getDocumentMigraionStartTimeRef().set(Instant.EPOCH.plus(shardPrepTime)); | ||
Instant leaseExpirationTime = Instant.EPOCH.plus(initialLeaseDuration.multipliedBy(initialLeaseMultiple)); | ||
|
||
int successorNextAcquisitionLeaseExponent = TestClass.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
|
||
Assertions.assertEquals(existingLeaseExponent - 1, successorNextAcquisitionLeaseExponent, "Should decrease successorExponent"); | ||
} | ||
|
||
|
||
@Test | ||
public void testGetSuccessorNextAcquisitionLeaseExponent_LessThanLowerThresholdWith0Exponent() { | ||
WorkItemTimeProvider workItemTimeProvider = new WorkItemTimeProvider(); | ||
|
||
var shardPrepTime = Duration.ofSeconds(1); | ||
var existingLeaseExponent = 0; | ||
var initialLeaseMultiple = (int) Math.pow(2, existingLeaseExponent); | ||
|
||
workItemTimeProvider.getLeaseAcquisitionTimeRef().set(Instant.EPOCH); | ||
workItemTimeProvider.getDocumentMigraionStartTimeRef().set(Instant.EPOCH.plus(shardPrepTime)); | ||
Duration initialLeaseDuration = Duration.ofMinutes(10); | ||
Instant leaseExpirationTime = Instant.EPOCH.plus(initialLeaseDuration.multipliedBy(initialLeaseMultiple)); | ||
|
||
int successorNextAcquisitionLeaseExponent = TestClass.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
|
||
Assertions.assertEquals(0, successorNextAcquisitionLeaseExponent, "Should return 0 for successorExponent"); | ||
} | ||
|
||
|
||
@Test | ||
public void testGetSuccessorNextAcquisitionLeaseExponent_LessThanUpperThreshold() { | ||
WorkItemTimeProvider workItemTimeProvider = new WorkItemTimeProvider(); | ||
|
||
var shardPrepTime = Duration.ofSeconds(59); | ||
var existingLeaseExponent = 0; | ||
var initialLeaseMultiple = (int) Math.pow(2, existingLeaseExponent); | ||
|
||
workItemTimeProvider.getLeaseAcquisitionTimeRef().set(Instant.EPOCH); | ||
workItemTimeProvider.getDocumentMigraionStartTimeRef().set(Instant.EPOCH.plus(shardPrepTime)); | ||
Duration initialLeaseDuration = Duration.ofMinutes(10); | ||
Instant leaseExpirationTime = Instant.EPOCH.plus(initialLeaseDuration.multipliedBy(initialLeaseMultiple)); | ||
|
||
int successorNextAcquisitionLeaseExponent = TestClass.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
|
||
Assertions.assertEquals(existingLeaseExponent, successorNextAcquisitionLeaseExponent, "Should return existingLeaseExponent + 1 when shard prep time is less than 10% of lease duration"); | ||
} | ||
|
||
@Test | ||
public void testGetSuccessorNextAcquisitionLeaseExponent_EqualToUpperThreshold() { | ||
WorkItemTimeProvider workItemTimeProvider = new WorkItemTimeProvider(); | ||
|
||
var shardPrepTime = Duration.ofSeconds(60); | ||
var existingLeaseExponent = 0; | ||
var initialLeaseMultiple = (int) Math.pow(2, existingLeaseExponent); | ||
|
||
workItemTimeProvider.getLeaseAcquisitionTimeRef().set(Instant.EPOCH); | ||
workItemTimeProvider.getDocumentMigraionStartTimeRef().set(Instant.EPOCH.plus(shardPrepTime)); | ||
Duration initialLeaseDuration = Duration.ofMinutes(10); | ||
Instant leaseExpirationTime = Instant.EPOCH.plus(initialLeaseDuration.multipliedBy(initialLeaseMultiple)); | ||
|
||
int successorNextAcquisitionLeaseExponent = TestClass.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
|
||
Assertions.assertEquals(existingLeaseExponent, successorNextAcquisitionLeaseExponent, "Should return existingLeaseExponent when shard prep time is equal to 10% of lease duration"); | ||
} | ||
|
||
@Test | ||
public void testGetSuccessorNextAcquisitionLeaseExponent_ExceedsUpperThreshold() { | ||
WorkItemTimeProvider workItemTimeProvider = new WorkItemTimeProvider(); | ||
|
||
var shardPrepTime = Duration.ofSeconds(61); | ||
var existingLeaseExponent = 0; | ||
var initialLeaseMultiple = (int) Math.pow(2, existingLeaseExponent); | ||
|
||
workItemTimeProvider.getLeaseAcquisitionTimeRef().set(Instant.EPOCH); | ||
workItemTimeProvider.getDocumentMigraionStartTimeRef().set(Instant.EPOCH.plus(shardPrepTime)); | ||
Duration initialLeaseDuration = Duration.ofMinutes(10); | ||
Instant leaseExpirationTime = Instant.EPOCH.plus(initialLeaseDuration.multipliedBy(initialLeaseMultiple)); | ||
|
||
int successorNextAcquisitionLeaseExponent = TestClass.getSuccessorNextAcquisitionLeaseExponent(workItemTimeProvider, initialLeaseDuration, leaseExpirationTime); | ||
|
||
Assertions.assertEquals(existingLeaseExponent + 1, successorNextAcquisitionLeaseExponent, "Should return existingLeaseExponent + 1 when shard prep time is greater than to 10% of lease duration"); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.