未验证 提交 c1a1c095 编写于 作者: D Davies Liu 提交者: GitHub

meta/sql: Fix returned inode from Rename and locks (#543)

* fix returned inode in Rename()

* fix locks with mysql
上级 21040863
......@@ -1611,6 +1611,9 @@ func (r *redisMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
sattr.Nlink--
dattr.Nlink++
}
if inode != nil {
*inode = ino
}
if attr != nil {
*attr = iattr
}
......
......@@ -281,14 +281,14 @@ func testMetaClient(t *testing.T, m Meta) {
if st := GetSummary(m, ctx, 1, &summary); st != 0 {
t.Fatalf("summary: %s", st)
}
expected := Summary{Length: 202, Size: 20480, Files: 3, Dirs: 2}
expected := Summary{Length: 402, Size: 20480, Files: 3, Dirs: 2}
if summary != expected {
t.Fatalf("summary %+v not equal to expected: %+v", summary, expected)
}
if st := GetSummary(m, ctx, inode, &summary); st != 0 {
t.Fatalf("summary: %s", st)
}
expected = Summary{Length: 402, Size: 24576, Files: 4, Dirs: 2}
expected = Summary{Length: 602, Size: 24576, Files: 4, Dirs: 2}
if summary != expected {
t.Fatalf("summary %+v not equal to expected: %+v", summary, expected)
}
......@@ -472,10 +472,10 @@ func testLocks(t *testing.T, m Meta) {
time.Sleep(time.Millisecond)
count--
if count > 0 {
logger.Errorf("count should be be zero but got %d", count)
logger.Fatalf("count should be be zero but got %d", count)
}
if st := m.Setlk(ctx, inode, uint64(i), false, syscall.F_UNLCK, 0, 0xFFFF, uint32(i)); st != 0 {
logger.Errorf("plock unlock: %s", st)
logger.Fatalf("plock unlock: %s", st)
err = st
}
}(i)
......@@ -759,7 +759,7 @@ func testTruncateAndDelete(t *testing.T, m Meta) {
var ss []Slice
m.ListSlices(ctx, &ss, false)
if len(ss) != 1 {
t.Fatalf("number of chunks: %d != 3, %+v", len(ss), ss)
t.Fatalf("number of chunks: %d != 1, %+v", len(ss), ss)
}
m.Close(ctx, inode)
if st := m.Unlink(ctx, 1, "f"); st != 0 {
......
......@@ -1385,6 +1385,9 @@ func (m *dbMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst In
spn.Nlink--
dpn.Nlink++
}
if inode != nil {
*inode = sn.Inode
}
m.parseAttr(&sn, attr)
if n, err := s.Delete(&edge{Parent: parentSrc, Name: se.Name}); err != nil {
......
......@@ -60,7 +60,18 @@ func TestMySQLClient(t *testing.T) {
m.engine.DropTables(&sustained{})
m.engine.DropTables(&xattr{})
m.engine.DropTables(&delfile{})
m.engine.DropTables(&flock{})
m.engine.DropTables(&plock{})
testTruncateAndDelete(t, m)
testMetaClient(t, m)
testStickyBit(t, m)
testLocks(t, m)
testConcurrentWrite(t, m)
testCompaction(t, m)
testCopyFileRange(t, m)
m.conf.CaseInsensi = true
testCaseIncensi(t, m)
}
func TestStickyBitSQL(t *testing.T) {
......
......@@ -35,6 +35,12 @@ func (m *dbMeta) Flock(ctx Context, inode Ino, owner uint64, ltype uint32, block
var err syscall.Errno
for {
err = errno(m.txn(func(s *xorm.Session) error {
if exists, err := s.Get(&node{Inode: inode}); err != nil || !exists {
if err == nil && !exists {
err = syscall.ENOENT
}
return err
}
rows, err := s.Rows(&flock{Inode: inode})
if err != nil {
return err
......@@ -143,6 +149,12 @@ func (m *dbMeta) Setlk(ctx Context, inode Ino, owner uint64, block bool, ltype u
lock := plockRecord{ltype, pid, start, end}
for {
err = errno(m.txn(func(s *xorm.Session) error {
if exists, err := s.Get(&node{Inode: inode}); err != nil || !exists {
if err == nil && !exists {
err = syscall.ENOENT
}
return err
}
if ltype == syscall.F_UNLCK {
var l = plock{Inode: inode, Owner: owner, Sid: m.sid}
ok, err := m.engine.Get(&l)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册