mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-20 15:02:27 +00:00
c4f0b12a9a
* s3: stop warming every bucket's config at startup Listing all buckets in BucketRegistry.init() made S3 gateway startup O(buckets) and pinned every bucket's metadata and config resident, which does not scale past a few hundred thousand buckets. Both caches already have lazy miss paths, so load on first access instead and let the metadata subscription refresh only entries already resident; cold buckets cost one filer round-trip on their first request. * s3: bound the per-bucket caches with LRU eviction The bucket config cache, bucket registry, and their negative caches were plain maps that only ever grew: the config cache TTL made Get miss but never evicted the entry, and the not-found sets grew on every probe of a nonexistent bucket name. Cap all four at 65536 entries with LRU eviction so a gateway keeps its hot working set and evicted buckets reload from the filer on next access. * s3: cache parsed bucket config instead of the full filer entry Each cached BucketConfig retained the whole bucket entry (extended attribute map plus raw content bytes) alongside the fields parsed from it, roughly doubling per-bucket cache cost and keeping data the read path never looks at. Parse everything up front in newBucketConfigFromEntry - now also the creator identity, tags, encryption config, and stored lifecycle XML - and drop the entry. updateBucketConfig now reads the entry fresh from the filer and diffs the mapped extended attributes against it, so the patch is computed against current state instead of a cached copy; the config clone helpers that existed for that path go away. * s3: dedup cold bucket-registry loads per bucket The registry's notFound lock doubled as the load serializer, holding one global mutex across the filer round-trip so first-touch requests for different buckets queued behind each other; the cache fill also happened after the lock was released, so two concurrent misses for the same bucket could both reach the filer. Replace it with a singleflight per bucket that fills the cache inside the flight: different buckets load concurrently, the same bucket loads once.
82 lines
3.0 KiB
Go
82 lines
3.0 KiB
Go
package s3api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestVeeamObjectLockBugFix tests the fix for the bug where GetObjectLockConfigurationHandler
|
|
// would return NoSuchObjectLockConfiguration for buckets with no extended attributes,
|
|
// even when Object Lock was enabled. This caused Veeam to think Object Lock wasn't supported.
|
|
func TestVeeamObjectLockBugFix(t *testing.T) {
|
|
|
|
t.Run("Bug case: bucket with no extended attributes", func(t *testing.T) {
|
|
// This simulates the bug case where a bucket has no extended attributes at all
|
|
// The old code would immediately return NoSuchObjectLockConfiguration
|
|
// The new code correctly checks if Object Lock is enabled before returning an error
|
|
|
|
entry := &filer_pb.Entry{
|
|
Name: "test-bucket",
|
|
Extended: nil, // This is the key - no extended attributes
|
|
}
|
|
|
|
// Simulate the isObjectLockEnabledForBucket logic
|
|
enabled := false
|
|
if entry.Extended != nil {
|
|
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
|
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
|
}
|
|
}
|
|
|
|
// Should correctly return false (not enabled) - this would trigger 404 correctly
|
|
assert.False(t, enabled, "Object Lock should not be enabled when no extended attributes exist")
|
|
})
|
|
|
|
t.Run("Fix verification: bucket with Object Lock enabled via boolean flag", func(t *testing.T) {
|
|
// This verifies the fix works when Object Lock is enabled via boolean flag
|
|
|
|
entry := &filer_pb.Entry{
|
|
Name: "test-bucket",
|
|
Extended: map[string][]byte{
|
|
s3_constants.ExtObjectLockEnabledKey: []byte("true"),
|
|
},
|
|
}
|
|
|
|
// Simulate the isObjectLockEnabledForBucket logic
|
|
enabled := false
|
|
if entry.Extended != nil {
|
|
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
|
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
|
}
|
|
}
|
|
|
|
// Should correctly return true (enabled) - this would generate minimal XML response
|
|
assert.True(t, enabled, "Object Lock should be enabled when boolean flag is set")
|
|
})
|
|
|
|
t.Run("Fix verification: bucket with Object Lock enabled via Enabled constant", func(t *testing.T) {
|
|
// Test using the s3_constants.ObjectLockEnabled constant
|
|
|
|
entry := &filer_pb.Entry{
|
|
Name: "test-bucket",
|
|
Extended: map[string][]byte{
|
|
s3_constants.ExtObjectLockEnabledKey: []byte(s3_constants.ObjectLockEnabled),
|
|
},
|
|
}
|
|
|
|
// Simulate the isObjectLockEnabledForBucket logic
|
|
enabled := false
|
|
if entry.Extended != nil {
|
|
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
|
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
|
}
|
|
}
|
|
|
|
// Should correctly return true (enabled)
|
|
assert.True(t, enabled, "Object Lock should be enabled when constant is used")
|
|
})
|
|
}
|