Skip to content

Bug fix S3fifo race condition #22156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4034f7e
update deleted
cpegeric May 16, 2025
f224924
Merge branch 'main' into s3fifo-race-main
mergify[bot] May 16, 2025
dd044ff
cleanup
cpegeric May 16, 2025
dcd5490
Merge branch 's3fifo-race-main' of github.com:cpegeric/matrixone into…
cpegeric May 16, 2025
9e97aee
update
cpegeric May 16, 2025
15dbb34
update
cpegeric May 16, 2025
12ced87
add tests
cpegeric May 16, 2025
0331f9c
fix sca
cpegeric May 16, 2025
cbf8647
check double free
cpegeric May 16, 2025
9ae40fe
postfn protected by shardmap
cpegeric May 19, 2025
3f30dd3
update
cpegeric May 19, 2025
8ab612d
isDeleted protected by shardmap mutex
cpegeric May 19, 2025
c6338e7
use mutex instead
cpegeric May 19, 2025
d2fcc57
update
cpegeric May 19, 2025
ac7f439
use RLock
cpegeric May 19, 2025
a7ebf4b
protect Slice()
cpegeric May 19, 2025
b7847b6
check buffer deallocated
cpegeric May 20, 2025
a420ff5
add tests and comments
cpegeric May 20, 2025
dbc16ff
comments
cpegeric May 20, 2025
43ec47b
fix sca
cpegeric May 20, 2025
ee52cc7
panic
cpegeric May 20, 2025
f1de9d7
fix sca
cpegeric May 20, 2025
60f0513
DeletePaths add setDeleted to avoid multiple postEvict
cpegeric May 20, 2025
e9262aa
merge
cpegeric May 21, 2025
80f132a
merge fix
cpegeric May 21, 2025
72f6421
add test for double free and bug fix looping
cpegeric May 21, 2025
98b2724
merge fix
cpegeric Jul 10, 2025
663cf96
retain/release inside cache
cpegeric Jul 10, 2025
eda779e
update
cpegeric Jul 10, 2025
745f6c3
Merge branch 'main' into s3fifo-reborn-refcnt
mergify[bot] Jul 10, 2025
f9217dd
delete paths
cpegeric Jul 10, 2025
3e24a6b
Merge branch 's3fifo-reborn-refcnt' of github.com:cpegeric/matrixone …
cpegeric Jul 10, 2025
66eb809
item mutex protect everything
cpegeric Jul 11, 2025
1011890
update comment
cpegeric Jul 11, 2025
7ef725c
remove ghost
cpegeric Jul 11, 2025
c8b0520
Merge branch 'main' into s3fifo-reborn-noghost
mergify[bot] Jul 11, 2025
7f131f6
remove unused code
cpegeric Jul 11, 2025
83a4bd9
Merge branch 's3fifo-reborn-noghost' of github.com:cpegeric/matrixone…
cpegeric Jul 11, 2025
86431b9
retain also call postfn
cpegeric Jul 11, 2025
f881a5f
bug fix check deleted first
cpegeric Jul 14, 2025
fec1fdb
bug fix
cpegeric Jul 14, 2025
e55d7f8
cleanup
cpegeric Jul 14, 2025
44cfcb7
comments
cpegeric Jul 14, 2025
f96cf77
bytes remove refs pointer
cpegeric Jul 15, 2025
f6514ef
Merge branch 'main' into s3fifo-reborn-noghost
cpegeric Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions pkg/fileservice/fifocache/data_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ func shardCacheKey(key fscache.CacheKey) uint64 {
var hasher maphash.Hash
hasher.SetSeed(seed)
hasher.Write(util.UnsafeToBytes(&key.Offset))
hasher.Write(util.UnsafeToBytes(&key.Sz))
hasher.WriteString(key.Path)
return hasher.Sum64()
}

var _ fscache.DataCache = new(DataCache)

func (d *DataCache) Available() int64 {
d.fifo.queueLock.RLock()
defer d.fifo.queueLock.RUnlock()
ret := d.fifo.capacity() - d.fifo.used1 - d.fifo.used2
ret := d.fifo.capacity() - d.fifo.Used()
if ret < 0 {
ret = 0
}
Expand All @@ -66,24 +65,20 @@ func (d *DataCache) Capacity() int64 {
}

func (d *DataCache) DeletePaths(ctx context.Context, paths []string) {
deletes := make([]*_CacheItem[fscache.CacheKey, fscache.Data], 0, 10)
for _, path := range paths {
for i := 0; i < len(d.fifo.shards); i++ {
d.deletePath(ctx, i, path)
}

key := fscache.CacheKey{Path: path}
d.fifo.htab.CompareAndDelete(key, func(key1, key2 fscache.CacheKey) bool {
return key1.Path == key2.Path
}, func(value *_CacheItem[fscache.CacheKey, fscache.Data]) {
deletes = append(deletes, value)
})
}
}

func (d *DataCache) deletePath(ctx context.Context, shardIndex int, path string) {
shard := &d.fifo.shards[shardIndex]
shard.Lock()
defer shard.Unlock()
for key, item := range shard.values {
if key.Path == path {
delete(shard.values, key)
if d.fifo.postEvict != nil {
d.fifo.postEvict(ctx, item.key, item.value, item.size)
}
}
// FSCACHEDATA RELEASE
for _, item := range deletes {
item.MarkAsDeleted(ctx, d.fifo.postEvict)
}
}

Expand All @@ -109,7 +104,5 @@ func (d *DataCache) Set(ctx context.Context, key query.CacheKey, value fscache.D
}

func (d *DataCache) Used() int64 {
d.fifo.queueLock.RLock()
defer d.fifo.queueLock.RUnlock()
return d.fifo.used1 + d.fifo.used2
return d.fifo.Used()
}
2 changes: 1 addition & 1 deletion pkg/fileservice/fifocache/data_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestShardCacheKeyAllocs(t *testing.T) {
Offset: 3,
Path: strings.Repeat("abc", 42),
}
if n := testing.AllocsPerRun(64, func() {
if n := testing.AllocsPerRun(64000, func() {
shardCacheKey(key)
}); n != 0 {
t.Fatalf("should not allocate")
Expand Down
Loading
Loading