Skip to content

Commit 5047516

Browse files
authored
Add trace logs for debugging multipart download (#5434)
* testing without DelegatingBufferingSubscriber + added logs * more logs
1 parent a52e476 commit 5047516

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/async/FileAsyncResponseTransformer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,14 @@ public void onError(Throwable t) {
249249

250250
@Override
251251
public void onComplete() {
252+
log.trace(() -> "onComplete");
252253
// if write in progress, tell write to close on finish.
253254
synchronized (this) {
254255
if (writeInProgress) {
256+
log.trace(() -> "writeInProgress = true, not closing");
255257
closeOnLastWrite = true;
256258
} else {
259+
log.trace(() -> "writeInProgress = false, closing");
257260
close();
258261
}
259262
}
@@ -264,6 +267,7 @@ private void close() {
264267
if (fileChannel != null) {
265268
invokeSafely(fileChannel::close);
266269
}
270+
log.trace(() -> "Completing File async transformer future future");
267271
future.complete(null);
268272
} catch (RuntimeException exception) {
269273
future.completeExceptionally(exception);

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/async/SplittingTransformer.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ private SplittingTransformer(AsyncResponseTransformer<ResponseT, ResultT> upstre
123123
maximumBufferSizeInBytes, "maximumBufferSizeInBytes");
124124

125125
this.resultFuture.whenComplete((r, e) -> {
126+
log.trace(() -> "result future whenComplete");
126127
if (e == null) {
127128
return;
128129
}
129130
if (isCancelled.compareAndSet(false, true)) {
131+
log.trace(() -> "result future whenComplete with isCancelled=true");
130132
handleFutureCancel(e);
131133
}
132134
});
@@ -167,6 +169,7 @@ public void request(long n) {
167169

168170
@Override
169171
public void cancel() {
172+
log.trace(() -> String.format("received cancel signal. Current cancel state is 'isCancelled=%s'", isCancelled.get()));
170173
if (isCancelled.compareAndSet(false, true)) {
171174
log.trace(() -> "Cancelling splitting transformer");
172175
handleSubscriptionCancel();
@@ -207,26 +210,31 @@ private boolean doEmit() {
207210
/**
208211
* Handle the {@code .cancel()} signal received from the downstream subscription. Data that is being sent to the upstream
209212
* transformer need to finish processing before we complete. One typical use case for this is completing the multipart
210-
* download, the subscriber having reached the final part will signal that it doesn't need more parts by calling {@code
211-
* .cancel()} on the subscription.
213+
* download, the subscriber having reached the final part will signal that it doesn't need more parts by calling
214+
* {@code .cancel()} on the subscription.
212215
*/
213216
private void handleSubscriptionCancel() {
214217
synchronized (cancelLock) {
215218
if (downstreamSubscriber == null) {
219+
log.trace(() -> "downstreamSubscriber already null, skipping downstreamSubscriber.onComplete()");
216220
return;
217221
}
218222
if (!onStreamCalled.get()) {
219223
// we never subscribe publisherToUpstream to the upstream, it would not complete
224+
log.trace(() -> "publisherToUpstream never subscribed, skipping downstreamSubscriber.onComplete()");
220225
downstreamSubscriber = null;
221226
return;
222227
}
228+
log.trace(() -> "publisherToUpstream.complete()");
223229
publisherToUpstream.complete().whenComplete((v, t) -> {
224230
if (downstreamSubscriber == null) {
231+
log.trace(() -> "[in future] downstreamSubscriber already null, skipping downstreamSubscriber.onComplete()");
225232
return;
226233
}
227234
if (t != null) {
228235
downstreamSubscriber.onError(t);
229236
} else {
237+
log.trace(() -> "[in future] calling downstreamSubscriber.onComplete");
230238
downstreamSubscriber.onComplete();
231239
}
232240
downstreamSubscriber = null;
@@ -236,8 +244,8 @@ private void handleSubscriptionCancel() {
236244

237245
/**
238246
* Handle when the {@link SplittingTransformer#resultFuture} is cancelled or completed exceptionally from the outside. Data
239-
* need to stop being sent to the upstream transformer immediately. One typical use case for this is transfer manager
240-
* needing to pause download by calling {@code .cancel(true)} on the future.
247+
* need to stop being sent to the upstream transformer immediately. One typical use case for this is transfer manager needing
248+
* to pause download by calling {@code .cancel(true)} on the future.
241249
*
242250
* @param e The exception the future was complete exceptionally with.
243251
*/
@@ -281,6 +289,7 @@ public CompletableFuture<ResponseT> prepare() {
281289
});
282290
individualFuture.whenComplete((r, e) -> {
283291
if (isCancelled.get()) {
292+
log.trace(() -> "Individual future completed .");
284293
handleSubscriptionCancel();
285294
}
286295
});
@@ -308,8 +317,8 @@ public void onStream(SdkPublisher<ByteBuffer> publisher) {
308317
DelegatingBufferingSubscriber.builder()
309318
.maximumBufferInBytes(maximumBufferInBytes)
310319
.delegate(upstreamSubscriber)
311-
.build()
312-
));
320+
.build())
321+
);
313322
}
314323
}
315324
publisher.subscribe(new IndividualPartSubscriber<>(this.individualFuture, response));

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/GenericS3TransferManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ public final <ResultT> Download<ResultT> download(DownloadRequest<ResultT> downl
362362
r -> CompletedDownload.builder()
363363
.result(r)
364364
.build());
365+
future.whenComplete((r, e) -> {
366+
if (e != null) {
367+
log.error(() -> String.format("s3 client future completed exceptionally"), e);
368+
} else {
369+
log.trace(() -> String.format("s3 client future completed : %s", r));
370+
}
371+
});
365372
} catch (Throwable throwable) {
366373
returnFuture.completeExceptionally(throwable);
367374
}

services-custom/s3-transfer-manager/src/test/resources/log4j2.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %
2323
rootLogger.level = info
2424
rootLogger.appenderRef.stdout.ref = ConsoleAppender
2525

26+
logger.split.name = software.amazon.awssdk.core.internal.async
27+
logger.split.level = trace
28+
29+
logger.multi.name = software.amazon.awssdk.services.s3.internal.multipart
30+
logger.multi.level = trace
31+
2632
# Uncomment below to enable more specific logging
2733
#
2834
#logger.sdk.name = software.amazon.awssdk

0 commit comments

Comments
 (0)