Skip to content

Commit 010bd4b

Browse files
committed
add missing KDocs and self review
1 parent a193a2f commit 010bd4b

File tree

3 files changed

+90
-25
lines changed

3 files changed

+90
-25
lines changed

hll/s3-transfer-manager/common/src/aws/sdk/kotlin/hll/s3transfermanager/S3TransferManager.kt

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,52 @@ import aws.sdk.kotlin.services.s3.withConfig
1919
*/
2020
public class S3TransferManager private constructor(s3Client: S3Client, builder: Builder) {
2121
public val client: S3Client = s3Client.withConfig { interceptors += S3TransferManagerBusinessMetricInterceptor }
22+
23+
/**
24+
* Preferred part size for multipart uploads.
25+
* If using this size would require more than 10,000 parts (the S3 limit),
26+
* the smallest possible part size that results in 10,000 parts is used instead.
27+
*
28+
* Default to 8,000,000 bytes.
29+
*/
2230
public val partSizeBytes: Long = builder.partSizeBytes
31+
32+
/**
33+
* Threshold size above which a file upload uses multipart upload
34+
* instead of a single put object request.
35+
*
36+
* Defaults to 16,000,000 bytes.
37+
*/
2338
public val multipartUploadThresholdBytes: Long = builder.multipartUploadThresholdBytes
39+
40+
/**
41+
* Strategy for multipart downloads, defined by [MultipartDownloadType].
42+
* Downloads can be performed either by specifying byte ranges or by requesting individual parts.
43+
*
44+
* Defaults to [Part].
45+
*/
2446
public val multipartDownloadType: MultipartDownloadType = builder.multipartDownloadType
47+
48+
/**
49+
* Mutable list of [TransferInterceptor]s, typically used to track transfers
50+
* or inspect/modify low-level S3 requests.
51+
*/
2552
public val interceptors: MutableList<TransferInterceptor> = builder.interceptors
53+
54+
/**
55+
* The maximum amount of parts to buffer in memory while waiting for uploads to complete.
56+
* The actual number of parts buffered at any given time may be less than or equal but never greater.
57+
*
58+
* Defaults to 5.
59+
*/
2660
public val maxInMemoryParts: Int = builder.maxInMemoryParts
61+
62+
/**
63+
* Maximum number of concurrent part uploads for a file.
64+
* The actual number of uploads at any given time may be less than or equal but never greater.
65+
*
66+
* Defaults to 5.
67+
*/
2768
public val maxConcurrentPartUploads: Int = builder.maxConcurrentPartUploads
2869

2970
public companion object {
@@ -32,29 +73,60 @@ public class S3TransferManager private constructor(s3Client: S3Client, builder:
3273
}
3374

3475
public class Builder {
35-
// TODO: K-docs for each one
76+
/**
77+
* Preferred part size for multipart uploads.
78+
* If using this size would require more than 10,000 parts (the S3 limit),
79+
* the smallest possible part size that results in 10,000 parts is used instead.
80+
*
81+
* Default to 8,000,000 bytes.
82+
*/
3683
public var partSizeBytes: Long = 8_000_000
84+
85+
/**
86+
* Threshold size above which a file upload uses multipart upload
87+
* instead of a single put object request.
88+
*
89+
* Defaults to 16,000,000 bytes.
90+
*/
3791
public var multipartUploadThresholdBytes: Long = 16_000_000L
92+
93+
/**
94+
* Strategy for multipart downloads, defined by [MultipartDownloadType].
95+
* Downloads can be performed either by specifying byte ranges or by requesting individual parts.
96+
*
97+
* Defaults to [Part].
98+
*/
3899
public var multipartDownloadType: MultipartDownloadType = Part
100+
101+
/**
102+
* Mutable list of [TransferInterceptor]s, typically used to track transfers
103+
* or inspect/modify low-level S3 requests.
104+
*/
39105
public var interceptors: MutableList<TransferInterceptor> = mutableListOf()
106+
107+
/**
108+
* The maximum amount of parts to buffer in memory while waiting for uploads to complete.
109+
* The actual number of parts buffered at any given time may be less than or equal but never greater.
110+
*
111+
* Defaults to 5.
112+
*/
40113
public var maxInMemoryParts: Int = 5
114+
115+
/**
116+
* Maximum number of concurrent part uploads for a file.
117+
* The actual number of uploads at any given time may be less than or equal but never greater.
118+
*
119+
* Defaults to 5.
120+
*/
41121
public var maxConcurrentPartUploads: Int = 5
42122

43123
internal fun build(client: S3Client): S3TransferManager =
44124
S3TransferManager(client, this)
45125
}
46126

47127
/**
48-
* Uploads a byte stream to Amazon S3, automatically using multipart uploads
49-
* for large objects as needed.
50-
*
51-
* This function handles the complexity of splitting the data into parts,
52-
* uploading each part, and completing the multipart upload. For object smaller than [multipartUploadThresholdBytes],
53-
* a standard single-part upload is performed automatically.
54-
*
55-
* If the specified [partSizeBytes] for multipart uploads is too small to allow
56-
* all parts to fit within S3's limit of 10,000 parts, the part size will be
57-
* automatically increased so that exactly 10,000 parts are uploaded.
128+
* Uploads a file to S3 via [aws.smithy.kotlin.runtime.content.ByteStream].
129+
* Uses multipart uploads with concurrent uploads if the object size is more than the configured [multipartUploadThresholdBytes].
58130
*/
59131
public suspend fun uploadFile(
60132
uploadFileRequest: UploadFileRequest,
@@ -70,16 +142,8 @@ public class S3TransferManager private constructor(s3Client: S3Client, builder:
70142
)
71143

72144
/**
73-
* Uploads a byte stream to Amazon S3, automatically using multipart uploads
74-
* for large objects as needed.
75-
*
76-
* This function handles the complexity of splitting the data into parts,
77-
* uploading each part, and completing the multipart upload. For object smaller than [multipartUploadThresholdBytes],
78-
* a standard single-part upload is performed automatically.
79-
*
80-
* If the specified [partSizeBytes] for multipart uploads is too small to allow
81-
* all parts to fit within S3's limit of 10,000 parts, the part size will be
82-
* automatically increased so that exactly 10,000 parts are uploaded.
145+
* Uploads a file to S3 via [aws.smithy.kotlin.runtime.content.ByteStream].
146+
* Uses multipart uploads with concurrent uploads if the object size is more than the configured [multipartUploadThresholdBytes].
83147
*/
84148
public suspend inline fun uploadFile(
85149
crossinline block: UploadFileRequest.Builder.() -> Unit,

hll/s3-transfer-manager/common/src/aws/sdk/kotlin/hll/s3transfermanager/operations/uploadfile/HelperFunctions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal fun resolvePartSize(contentLength: Long, targetPartSize: Long, logger:
4343
* [ByteStream.ChannelStream]
4444
* [ByteStream.SourceStream]
4545
*/
46-
internal fun resolvePartSource(body: ByteStream): Any =
46+
internal fun resolveSource(body: ByteStream): Any =
4747
when (body) {
4848
is ByteStream.Buffer -> body.bytes()
4949
is ByteStream.ChannelStream -> body.readFrom()

hll/s3-transfer-manager/common/src/aws/sdk/kotlin/hll/s3transfermanager/operations/uploadfile/hooks/TransferBytes.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import aws.sdk.kotlin.hll.s3transfermanager.operationHook
1414
import aws.sdk.kotlin.hll.s3transfermanager.operations.uploadfile.ceilDiv
1515
import aws.sdk.kotlin.hll.s3transfermanager.operations.uploadfile.nextPartBytes
1616
import aws.sdk.kotlin.hll.s3transfermanager.operations.uploadfile.resolvePartSize
17-
import aws.sdk.kotlin.hll.s3transfermanager.operations.uploadfile.resolvePartSource
17+
import aws.sdk.kotlin.hll.s3transfermanager.operations.uploadfile.resolveSource
1818
import aws.sdk.kotlin.hll.s3transfermanager.utils.S3TransferManagerException
1919
import aws.sdk.kotlin.services.s3.S3Client
2020
import aws.sdk.kotlin.services.s3.abortMultipartUpload
@@ -64,7 +64,7 @@ internal suspend fun transferBytes(
6464
try {
6565
val partSize = resolvePartSize(contentLength, partSizeBytes, logger)
6666
val numberOfParts = ceilDiv(contentLength, partSize).toInt()
67-
val partSource = resolvePartSource(uploadFileRequest.body!!)
67+
val partSource = resolveSource(uploadFileRequest.body!!)
6868

6969
val producer = produceParts(
7070
context.transferableBytes!!,
@@ -107,12 +107,13 @@ internal suspend fun transferBytes(
107107
}
108108
}
109109
} else {
110+
context.currentBytes = uploadFileRequest.body
111+
110112
operationHook(
111113
BytesTransferred,
112114
context,
113115
interceptors,
114116
) {
115-
context.currentBytes = uploadFileRequest.body // TODO: This will consume the bytes
116117
context.response = client.putObject(context.request as PutObjectRequest)
117118
context.transferredBytes = context.transferableBytes
118119
}

0 commit comments

Comments
 (0)