* fix: achieve single-scan efficiency for S3 versioned object listing
When listing objects in a versioning-enabled bucket, the original code
triggered multiple getEntry calls per versioned object (up to 12 with
retries), causing excessive 'find' operations visible in Grafana and
leading to high memory usage.
This fix achieves single-scan efficiency by caching list metadata
(size, ETag, mtime, owner) directly in the .versions directory:
1. Add new Extended keys for caching list metadata in .versions dir
2. Update upload/copy/multipart paths to cache metadata when creating versions
3. Update getLatestVersionEntryFromDirectoryEntry to use cached metadata
(zero getEntry calls when cache is available)
4. Update updateLatestVersionAfterDeletion to maintain cache consistency
Performance improvement for N versioned objects:
- Before: N×1 to N×12 find operations per list request
- After: 0 extra find operations (all metadata from single scan)
This matches the efficiency of normal (non-versioned) object listing.
* Update s3api_object_versioning.go
* s3api: fix ETag handling for versioned objects and simplify delete marker creation
- Add Md5 attribute to synthetic logicalEntry for single-part uploads to ensure
filer.ETag() returns correct value in ListObjects response
- Simplify delete marker creation by initializing entry directly in mkFile callback
- Add bytes and encoding/hex imports for ETag parsing
* s3api: preserve default attributes in delete marker mkFile callback
Only modify Mtime field instead of replacing the entire Attributes struct,
preserving default values like Crtime, FileMode, Uid, and Gid that mkFile
initializes.
* s3api: fix ETag handling in newListEntry for multipart uploads
Prioritize ExtETagKey from Extended attributes before falling back to
filer.ETag(). This properly handles multipart upload ETags (format: md5-parts)
for versioned objects, where the synthetic entry has cached ETag metadata
but no chunks to calculate from.
* s3api: reduce code duplication in delete marker creation
Extract deleteMarkerExtended map to be reused in both mkFile callback
and deleteMarkerEntry construction.
* test: add multipart upload versioning tests for ETag verification
Add tests to verify that multipart uploaded objects in versioned buckets
have correct ETags when listed:
- TestMultipartUploadVersioningListETag: Basic multipart upload with 2 parts
- TestMultipartUploadMultipleVersionsListETag: Multiple multipart versions
- TestMixedSingleAndMultipartVersionsListETag: Mix of single-part and multipart
These tests cover a bug where synthetic entries for versioned objects
didn't include proper ETag handling for multipart uploads.
* test: add delete marker test for multipart uploaded versioned objects
TestMultipartUploadDeleteMarkerListBehavior verifies:
- Delete marker creation hides object from ListObjectsV2
- ListObjectVersions shows both version and delete marker
- Version ETag (multipart format) is preserved after delete marker
- Object can be accessed by version ID after delete marker
- Removing delete marker restores object visibility
* refactor: address code review feedback
- test: use assert.ElementsMatch for ETag verification (more idiomatic)
- s3api: optimize newListEntry ETag logic (check ExtETagKey first)
- s3api: fix edge case in ETag parsing (>= 2 instead of > 2)
* s3api: prevent stale cached metadata and preserve existing extended attrs
- setCachedListMetadata: clear old cached keys before setting new values
to prevent stale data when new version lacks certain fields (e.g., owner)
- createDeleteMarker: merge extended attributes instead of overwriting
to preserve any existing metadata on the entry
* s3api: extract clearCachedVersionMetadata to reduce code duplication
- clearCachedVersionMetadata: clears only metadata fields (size, mtime, etag, owner, deleteMarker)
- clearCachedListMetadata: now reuses clearCachedVersionMetadata + clears ID/filename
- setCachedListMetadata: uses clearCachedVersionMetadata (not clearCachedListMetadata
because caller has already set ID/filename)
* s3api: share timestamp between version entry and cache entry
Capture versionMtime once before mkFile and reuse for both:
- versionEntry.Attributes.Mtime in the mkFile callback
- versionEntryForCache.Attributes.Mtime for list caching
This keeps list vs. HEAD LastModified timestamps aligned.
* s3api: remove amzAccountId variable shadowing in multipart upload
Extract amzAccountId before mkFile callback and reuse in both places,
similar to how versionMtime is handled. Avoids confusion from
redeclaring the same variable.