mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-30 08:50:48 +01:00
s3: lazy, bounded, entry-free per-bucket caches (#10213)
* 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.
This commit is contained in:
1 parent
3089480c30
commit
c4f0b12a9a
19 files changed
+328
-623
No files matched your search
@@ -18,18 +18,15 @@ func TestVeeamObjectLockBugFix(t *testing.T) {
|
||||
// The old code would immediately return NoSuchObjectLockConfiguration
|
||||
// The new code correctly checks if Object Lock is enabled before returning an error
|
||||
|
||||
bucketConfig := &BucketConfig{
|
||||
Name: "test-bucket",
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Extended: nil, // This is the key - no extended attributes
|
||||
},
|
||||
entry := &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Extended: nil, // This is the key - no extended attributes
|
||||
}
|
||||
|
||||
// Simulate the isObjectLockEnabledForBucket logic
|
||||
enabled := false
|
||||
if bucketConfig.Entry.Extended != nil {
|
||||
if enabledBytes, exists := bucketConfig.Entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
if entry.Extended != nil {
|
||||
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
||||
}
|
||||
}
|
||||
@@ -41,20 +38,17 @@ func TestVeeamObjectLockBugFix(t *testing.T) {
|
||||
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
|
||||
|
||||
bucketConfig := &BucketConfig{
|
||||
entry := &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtObjectLockEnabledKey: []byte("true"),
|
||||
},
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtObjectLockEnabledKey: []byte("true"),
|
||||
},
|
||||
}
|
||||
|
||||
// Simulate the isObjectLockEnabledForBucket logic
|
||||
enabled := false
|
||||
if bucketConfig.Entry.Extended != nil {
|
||||
if enabledBytes, exists := bucketConfig.Entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
if entry.Extended != nil {
|
||||
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
||||
}
|
||||
}
|
||||
@@ -66,20 +60,17 @@ func TestVeeamObjectLockBugFix(t *testing.T) {
|
||||
t.Run("Fix verification: bucket with Object Lock enabled via Enabled constant", func(t *testing.T) {
|
||||
// Test using the s3_constants.ObjectLockEnabled constant
|
||||
|
||||
bucketConfig := &BucketConfig{
|
||||
entry := &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: "test-bucket",
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtObjectLockEnabledKey: []byte(s3_constants.ObjectLockEnabled),
|
||||
},
|
||||
Extended: map[string][]byte{
|
||||
s3_constants.ExtObjectLockEnabledKey: []byte(s3_constants.ObjectLockEnabled),
|
||||
},
|
||||
}
|
||||
|
||||
// Simulate the isObjectLockEnabledForBucket logic
|
||||
enabled := false
|
||||
if bucketConfig.Entry.Extended != nil {
|
||||
if enabledBytes, exists := bucketConfig.Entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
if entry.Extended != nil {
|
||||
if enabledBytes, exists := entry.Extended[s3_constants.ExtObjectLockEnabledKey]; exists {
|
||||
enabled = string(enabledBytes) == s3_constants.ObjectLockEnabled || string(enabledBytes) == "true"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user