When reading multiple ranges from the same key, it would be nice to know that the underlying data has changed if someone wrote in the meantime. This is what I'm referring to as "volatile". For Filesystems you can Lock, but for S3 there is no such thing. This is one potential solution:
fun rangedReadPinnedToSameObject(
s3: S3Client,
bucket: String,
key: String,
start: Long,
endInclusive: Long
): ByteArray {
val head = s3.headObject(
HeadObjectRequest.builder().bucket(bucket).key(key).build()
)
val etag = head.eTag()
val req = GetObjectRequest.builder()
.bucket(bucket)
.key(key)
.range("bytes=$start-$endInclusive")
.ifMatch(etag)
.build()
s3.getObject(req).use { input ->
return input.readBytes()
}
}
I believe this would fail if the eTag doesn't match, and throw an error which we could report.
This is untested though, needs more investigation
When reading multiple ranges from the same key, it would be nice to know that the underlying data has changed if someone wrote in the meantime. This is what I'm referring to as "volatile". For Filesystems you can Lock, but for S3 there is no such thing. This is one potential solution:
I believe this would fail if the
eTagdoesn't match, and throw an error which we could report.This is untested though, needs more investigation