Skip to content

Commit 3ed4ce6

Browse files
committed
fix: Fix race conditions
1 parent 9444168 commit 3ed4ce6

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

core/dir.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,10 +1864,12 @@ func (parent *Inode) insertSubTree(path string, obj *BlobItemOutput, dirs map[*I
18641864
inode.SetFromBlobItem(obj)
18651865
sealPastDirs(dirs, inode)
18661866
} else {
1867+
inode.mu.Lock()
18671868
now := time.Now()
18681869
if inode.AttrTime.Before(now) {
18691870
inode.SetAttrTime(now)
18701871
}
1872+
inode.mu.Unlock()
18711873
}
18721874

18731875
// mark this dir but don't seal anything else
@@ -1905,9 +1907,29 @@ func (parent *Inode) LookUpCached(name string) (inode *Inode, err error) {
19051907
parent.mu.Lock()
19061908
ok := false
19071909
inode = parent.findChildUnlocked(name)
1910+
if inode == nil {
1911+
ok = false
1912+
if parent.dir.DeletedChildren != nil {
1913+
if _, ok := parent.dir.DeletedChildren[name]; ok {
1914+
// File is deleted locally
1915+
parent.mu.Unlock()
1916+
return nil, syscall.ENOENT
1917+
}
1918+
}
1919+
if !expired(parent.dir.DirTime, parent.fs.flags.StatCacheTTL) {
1920+
// Don't recheck from the server if directory cache is actual
1921+
parent.mu.Unlock()
1922+
return nil, syscall.ENOENT
1923+
}
1924+
}
1925+
1926+
ttl := parent.fs.flags.StatCacheTTL
1927+
parent.mu.Unlock()
1928+
19081929
if inode != nil {
1930+
inode.mu.Lock()
19091931
ok = true
1910-
if expired(inode.AttrTime, parent.fs.flags.StatCacheTTL) {
1932+
if expired(inode.AttrTime, ttl) {
19111933
ok = false
19121934
if atomic.LoadInt32(&inode.CacheState) != ST_CACHED ||
19131935
inode.isDir() && atomic.LoadInt64(&inode.dir.ModifiedChildren) > 0 {
@@ -1921,22 +1943,9 @@ func (parent *Inode) LookUpCached(name string) (inode *Inode, err error) {
19211943
inode.logFuse("lookup expired")
19221944
}
19231945
}
1924-
} else {
1925-
ok = false
1926-
if parent.dir.DeletedChildren != nil {
1927-
if _, ok := parent.dir.DeletedChildren[name]; ok {
1928-
// File is deleted locally
1929-
parent.mu.Unlock()
1930-
return nil, syscall.ENOENT
1931-
}
1932-
}
1933-
if !expired(parent.dir.DirTime, parent.fs.flags.StatCacheTTL) {
1934-
// Don't recheck from the server if directory cache is actual
1935-
parent.mu.Unlock()
1936-
return nil, syscall.ENOENT
1937-
}
1946+
inode.mu.Unlock()
19381947
}
1939-
parent.mu.Unlock()
1948+
19401949
if !ok {
19411950
inode, err = parent.recheckInode(inode, name)
19421951
err = mapAwsError(err)
@@ -1947,6 +1956,7 @@ func (parent *Inode) LookUpCached(name string) (inode *Inode, err error) {
19471956
return nil, syscall.ENOENT
19481957
}
19491958
}
1959+
19501960
return inode, nil
19511961
}
19521962

core/tigris_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ import (
2929
"github.com/tigrisdata/tigrisfs/core/cfg"
3030
)
3131

32+
var (
33+
triedDetect bool
34+
detected bool
35+
localTigris bool
36+
)
37+
3238
func tigrisDetected(flags *cfg.FlagStorage) (bool, bool) {
39+
if triedDetect {
40+
return detected, localTigris
41+
}
42+
3343
endpoint := flags.Endpoint
3444
if endpoint == "" {
3545
endpoint = os.Getenv("AWS_ENDPOINT_URL")
@@ -42,7 +52,11 @@ func tigrisDetected(flags *cfg.FlagStorage) (bool, bool) {
4252
return false, local
4353
}
4454

45-
return strings.Contains(r.Header.Get("Server"), "Tigris"), local
55+
triedDetect = true
56+
localTigris = local
57+
detected = r.StatusCode == http.StatusOK && strings.Contains(r.Header.Get("Server"), "Tigris")
58+
59+
return detected, local
4660
}
4761

4862
func LocalTigrisDetected(flags *cfg.FlagStorage) bool {

test/cluster/test_random.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ _cluster_setup() {
3232
touch "$TEST_ARTIFACTS/test_random/log1" "$TEST_ARTIFACTS/test_random/log2" "$TEST_ARTIFACTS/test_random/log3"
3333

3434
#opts="--debug_fuse --debug_grpc --log-format console --log-level debug --no-log-color"
35-
opts="--log-format console --no-log-color"
35+
opts="--log-format console --log-level info --no-log-color"
3636
nodes="--cluster-peer=1:localhost:1337 --cluster-peer=2:localhost:1338 --cluster-peer=3:localhost:1339"
3737

3838
MNT1=$(mktemp --suffix .node1 -d)
39-
_mount "$MNT1" $opts -f --log-file="$TEST_ARTIFACTS/test_random/log1" --pprof=6060 --cluster-me=1:localhost:1337 $nodes #--debug_fuse --debug_grpc
39+
_mount "$MNT1" $opts -f --log-file="$TEST_ARTIFACTS/test_random/log1" --pprof=6060 --cluster-me=1:localhost:1337 $nodes
4040

4141
MNT2=$(mktemp --suffix .node2 -d)
4242
_mount "$MNT2" $opts -f --log-file="$TEST_ARTIFACTS/test_random/log2" --pprof=6070 --cluster-me=2:localhost:1338 $nodes

test/run-proxy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [ $CLOUD == "s3" ]; then
3333
echo jclouds.provider=filesystem >>test/s3proxy_test.properties
3434
echo jclouds.filesystem.basedir=/tmp/s3proxy >>test/s3proxy_test.properties
3535
fi
36-
PROXY_BIN="java -Xms512m -Xmx8g --add-opens java.base/java.lang=ALL-UNNAMED -jar s3proxy.jar --properties test/s3proxy_test.properties"
36+
PROXY_BIN="java --add-opens java.base/java.lang=ALL-UNNAMED -jar s3proxy.jar --properties test/s3proxy_test.properties"
3737
export AWS_ACCESS_KEY_ID=foo
3838
export AWS_SECRET_ACCESS_KEY=bar
3939
export ENDPOINT=http://localhost:$PROXY_PORT

0 commit comments

Comments
 (0)