3

I have a Spring Boot application which stores files on a MinIO server. My application receives groups of files and should save all files per each group or save nothing in a problem group. I use io.minio.MinioClient#putObject for each file in a group. Now my code looks like

fun saveFile(folderName: String, fileName: String, file: ByteArray) {
    file.inputStream().use {
        minioClient.putObject(folderName, fileName, it, PutObjectOptions(file.size.toLong(), -1))
    }
}

fun saveFiles(folderName: String, files: Map<String, ByteArray>) {
    try {
        files.forEach { (fileName, file) -> saveFile(folderName, fileName, file) }
    } catch (e: Exception) {
        files.forEach { (fileName, _) -> minioClient.removeObject(folderName, fileName) }
        throw e
    }
}

I wonder how I could refactor my saveFiles method to make it more transactional.

N.B. There are no rules about reading files by groups - each file could be read individually.

1 Answers1

0

You can try use this S3 feature, MinIO also support this feature.

Create .tar or .zip archive and send to S3 with metadata option snowball-auto-extract=true (header: X-Amz-Meta-Snowball-Auto-Extract), archive will be automatically extracted in S3.

This is not transaction but look very similar for me.

nikita.koshelev
  • 324
  • 1
  • 5