-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1160 from chelma/MIGRATIONS-2128
Adding subshard work item on lease expiry
- Loading branch information
Showing
32 changed files
with
1,219 additions
and
383 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
190 changes: 175 additions & 15 deletions
190
...ntsFromSnapshotMigration/src/main/java/org/opensearch/migrations/RfsMigrateDocuments.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.