mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
CompleteMultipartUpload built the whole object as one byte array, so an object over Integer.MAX_VALUE bytes failed with an ArithmeticException, and anything smaller still needed the full object in the heap. In the persistent, hybrid and wal modes the parts are now copied file to file into one assembled file in the upload's directory, before the bucket lock is taken, and that file is renamed into place under the lock. A versioned bucket hard-links the current file to the versioned one rather than writing a second copy, which is safe because object files are only ever replaced by a rename, never modified in place. The full-object checksum is combined from each part's CRC and size, which is how S3 linearizes full-object checksums and why it offers them only for the CRC algorithms, so the object's bytes are never read for it and a mismatched expected checksum is rejected before assembly. Since the ETag and checksum now come from the part records, each UploadPart stores its bytes under its own storage ID kept on the record and drops the bytes it replaced only after publishing the new record. CompleteMultipartUpload reads each record once and assembles exactly the bytes those records name, so an UploadPart racing a Complete makes that Complete fail with InvalidPart instead of storing a checksum that describes different bytes. Memory mode still holds an object in one byte array, so an UploadPart that takes an upload past the largest array the JDK allocates, or a CompleteMultipartUpload over it, now fails with EntityTooLarge instead of exhausting the heap or overflowing the array size. Multipart uploads are tracked only in memory, so the part files under .multipart are removed at startup and on reset. Without that, a crash during assembly would leave a file as large as the object on disk for good. The S3 docs describe the memory-mode limit, the disk space a completion needs, and the operations that still read a whole object into memory.