Skip to content

Commit dd7ded8

Browse files
committed
PR feedback: pass copy blob name as request parameter.
1 parent d9db70d commit dd7ded8

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/analyze/BlobAnalyzeAction.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,16 @@ public StreamInput streamInput() throws IOException {
399399

400400
private void onLastReadForInitialWrite() {
401401
var readBlobName = request.blobName;
402-
if (request.doCopy && doEarlyCopy) {
402+
if (request.copyBlobName != null && doEarlyCopy) {
403403
try {
404-
final var copyName = request.blobName + "_copy";
405404
blobContainer.copyBlob(
406405
OperationPurpose.REPOSITORY_ANALYSIS,
407406
blobContainer,
408407
request.blobName,
409-
copyName,
408+
request.copyBlobName,
410409
request.targetLength
411410
);
412-
readBlobName = copyName;
411+
readBlobName = request.copyBlobName;
413412
} catch (UnsupportedOperationException uoe) {
414413
// not all repositories support copy
415414
} catch (NoSuchFileException | FileNotFoundException ignored) {
@@ -441,17 +440,16 @@ private void doReadAfterWrite() {
441440
logger.trace("sending read request to [{}] for [{}] after write complete", readNodes, request.getDescription());
442441
}
443442
var readBlobName = request.blobName;
444-
if (request.doCopy && (doEarlyCopy == false) && (request.getAbortWrite() == false)) {
443+
if (request.copyBlobName != null && doEarlyCopy == false && request.getAbortWrite() == false) {
445444
try {
446-
final var copyName = request.blobName + "_copy";
447445
blobContainer.copyBlob(
448446
OperationPurpose.REPOSITORY_ANALYSIS,
449447
blobContainer,
450448
request.blobName,
451-
copyName,
449+
request.copyBlobName,
452450
request.targetLength
453451
);
454-
readBlobName = copyName;
452+
readBlobName = request.copyBlobName;
455453
} catch (UnsupportedOperationException uoe) {
456454
// not all repositories support copy
457455
} catch (IOException e) {
@@ -734,7 +732,8 @@ static class Request extends ActionRequest {
734732
private final boolean readEarly;
735733
private final boolean writeAndOverwrite;
736734
private final boolean abortWrite;
737-
private final boolean doCopy;
735+
@Nullable
736+
private final String copyBlobName;
738737

739738
Request(
740739
String repositoryName,
@@ -748,7 +747,7 @@ static class Request extends ActionRequest {
748747
boolean readEarly,
749748
boolean writeAndOverwrite,
750749
boolean abortWrite,
751-
boolean doCopy
750+
@Nullable String copyBlobName
752751
) {
753752
assert 0 < targetLength;
754753
assert targetLength <= MAX_ATOMIC_WRITE_SIZE || (readEarly == false && writeAndOverwrite == false) : "oversized atomic write";
@@ -764,7 +763,7 @@ static class Request extends ActionRequest {
764763
this.readEarly = readEarly;
765764
this.writeAndOverwrite = writeAndOverwrite;
766765
this.abortWrite = abortWrite;
767-
this.doCopy = doCopy;
766+
this.copyBlobName = copyBlobName;
768767
}
769768

770769
Request(StreamInput in) throws IOException {
@@ -781,9 +780,9 @@ static class Request extends ActionRequest {
781780
writeAndOverwrite = in.readBoolean();
782781
abortWrite = in.readBoolean();
783782
if (in.getTransportVersion().onOrAfter(TransportVersions.REPO_ANALYSIS_COPY_BLOB)) {
784-
doCopy = in.readBoolean();
783+
copyBlobName = in.readOptionalString();
785784
} else {
786-
doCopy = false;
785+
copyBlobName = null;
787786
}
788787
}
789788

@@ -802,8 +801,8 @@ public void writeTo(StreamOutput out) throws IOException {
802801
out.writeBoolean(writeAndOverwrite);
803802
out.writeBoolean(abortWrite);
804803
if (out.getTransportVersion().onOrAfter(TransportVersions.REPO_ANALYSIS_COPY_BLOB)) {
805-
out.writeBoolean(doCopy);
806-
} else if (doCopy) {
804+
out.writeOptionalString(copyBlobName);
805+
} else if (copyBlobName != null) {
807806
assert false : out.getTransportVersion();
808807
throw new IllegalStateException(
809808
"cannot serialize " + this + "] using transport version [" + out.getTransportVersion() + "]"
@@ -834,8 +833,8 @@ public String getDescription() {
834833
+ writeAndOverwrite
835834
+ ", abortWrite="
836835
+ abortWrite
837-
+ ", doCopy="
838-
+ doCopy
836+
+ ", copyBlobName="
837+
+ copyBlobName
839838
+ "]";
840839
}
841840

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/analyze/RepositoryAnalyzeAction.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,22 +517,26 @@ public void run() {
517517
final List<Long> blobSizes = getBlobSizes(request);
518518
Collections.shuffle(blobSizes, random);
519519

520-
for (int i = 0; i < request.getBlobCount(); i++) {
520+
int blobCount = request.getBlobCount();
521+
for (int i = 0; i < blobCount; i++) {
521522
final long targetLength = blobSizes.get(i);
522523
final boolean smallBlob = targetLength <= MAX_ATOMIC_WRITE_SIZE; // avoid the atomic API for larger blobs
523524
final boolean abortWrite = smallBlob && request.isAbortWritePermitted() && rarely(random);
524525
final boolean doCopy = minClusterTransportVersion.onOrAfter(TransportVersions.REPO_ANALYSIS_COPY_BLOB)
525-
&& random.nextBoolean();
526+
&& rarely(random) && i > 0;
527+
final String blobName = "test-blob-" + i + "-" + UUIDs.randomBase64UUID(random);
528+
String copyBlobName = null;
526529
if (doCopy) {
527-
i++;
528-
if (i >= request.getBlobCount()) {
530+
copyBlobName = blobName + "-copy";
531+
blobCount--;
532+
if (i >= blobCount) {
529533
break;
530534
}
531535
}
532536
final BlobAnalyzeAction.Request blobAnalyzeRequest = new BlobAnalyzeAction.Request(
533537
request.getRepositoryName(),
534538
blobPath,
535-
"test-blob-" + i + "-" + UUIDs.randomBase64UUID(random),
539+
blobName,
536540
targetLength,
537541
random.nextLong(),
538542
nodes,
@@ -541,7 +545,7 @@ public void run() {
541545
smallBlob && rarely(random),
542546
repository.supportURLRepo() && repository.hasAtomicOverwrites() && smallBlob && rarely(random) && abortWrite == false,
543547
abortWrite,
544-
doCopy
548+
copyBlobName
545549
);
546550
final DiscoveryNode node = nodes.get(random.nextInt(nodes.size()));
547551
queue.add(ref -> runBlobAnalysis(ref, blobAnalyzeRequest, node));

0 commit comments

Comments
 (0)