Skip to content

Commit 2348e3a

Browse files
committed
Induce artificial latency and fail 30% of uploads
Signed-off-by: Ashish Singh <ssashish@amazon.com>
1 parent 7caf213 commit 2348e3a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

server/src/main/java/org/opensearch/index/shard/RemoteStoreRefreshListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Map;
3939
import java.util.Optional;
40+
import java.util.Random;
4041
import java.util.Set;
4142
import java.util.concurrent.atomic.AtomicBoolean;
4243
import java.util.concurrent.atomic.AtomicLong;
@@ -72,6 +73,8 @@ public final class RemoteStoreRefreshListener implements ReferenceManager.Refres
7273
private final AtomicLong refreshSeqNo = new AtomicLong();
7374
private final Map<String, Long> fileSizeMap = new HashMap<>();
7475

76+
private final Random random = new Random();
77+
7578
public RemoteStoreRefreshListener(IndexShard indexShard) {
7679
this.indexShard = indexShard;
7780
this.storeDirectory = indexShard.store().directory();
@@ -153,6 +156,15 @@ public void afterRefresh(boolean didRefresh) {
153156
// Start tracking total uploads started
154157
statsTracker.incrementTotalUploadsStarted();
155158

159+
// For test purpose
160+
// Step 1 - Injection artificial delay of 1s to 100s
161+
Thread.sleep(random.nextInt(100) + 1);
162+
163+
// Step 2 - Fail 30% of requests by throwing exception
164+
if (random.nextInt(100) < 30) {
165+
throw new RuntimeException("Failing upload for test purpose");
166+
}
167+
156168
// Start the segments upload
157169
segmentsUploadStatus = UploadStatus.STARTED;
158170
segmentsUploadStatus = uploadNewSegments(localSegmentsPostRefresh, statsTracker, sizeMap);

0 commit comments

Comments
 (0)