From e8b62a723b19d3d1eea79bd188a25509ed02b8a2 Mon Sep 17 00:00:00 2001 From: Sandy Xu Date: Mon, 29 Aug 2022 17:35:14 +0800 Subject: [PATCH 1/2] meta: show detailed plock records for sessions --- pkg/meta/interface.go | 2 +- pkg/meta/redis.go | 2 +- pkg/meta/sql.go | 2 +- pkg/meta/tkv.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/meta/interface.go b/pkg/meta/interface.go index adb891d86c2c..d38ae6fc7e12 100644 --- a/pkg/meta/interface.go +++ b/pkg/meta/interface.go @@ -234,7 +234,7 @@ type Flock struct { type Plock struct { Inode Ino Owner uint64 - Records []byte // FIXME: loadLocks + Records []plockRecord } // Session contains detailed information of a client session diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index 8aa1640a3423..fcaa9057b4ee 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -400,7 +400,7 @@ func (m *redisMeta) getSession(sid string, detail bool) (*Session, error) { if isFlock { s.Flocks = append(s.Flocks, Flock{Ino(inode), owner, v}) } else { - s.Plocks = append(s.Plocks, Plock{Ino(inode), owner, []byte(v)}) + s.Plocks = append(s.Plocks, Plock{Ino(inode), owner, loadLocks([]byte(v))}) } } } diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index a41f28ae0f55..1553a0d153bd 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -448,7 +448,7 @@ func (m *dbMeta) getSession(row interface{}, detail bool) (*Session, error) { } s.Plocks = make([]Plock, 0, len(prows)) for _, prow := range prows { - s.Plocks = append(s.Plocks, Plock{prow.Inode, uint64(prow.Owner), prow.Records}) + s.Plocks = append(s.Plocks, Plock{prow.Inode, uint64(prow.Owner), loadLocks(prow.Records)}) } return nil }) diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index f3827cef89b9..906906bdeac0 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -555,7 +555,7 @@ func (m *kvMeta) getSession(sid uint64, detail bool) (*Session, error) { ls := unmarshalPlock(v) for o, l := range ls { if o.sid == sid { - s.Plocks = append(s.Plocks, Plock{inode, o.sid, l}) + s.Plocks = append(s.Plocks, Plock{inode, o.sid, loadLocks(l)}) } } } From 817f75881f48cb9c1704cd14c90532db45073c65 Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Tue, 30 Aug 2022 09:59:01 +0800 Subject: [PATCH 2/2] export fields of plock records --- pkg/meta/redis_lock.go | 12 ++++----- pkg/meta/sql_lock.go | 12 ++++----- pkg/meta/tkv_lock.go | 12 ++++----- pkg/meta/utils.go | 56 +++++++++++++++++++++--------------------- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/pkg/meta/redis_lock.go b/pkg/meta/redis_lock.go index 53d97ff69da5..bb294ee83941 100644 --- a/pkg/meta/redis_lock.go +++ b/pkg/meta/redis_lock.go @@ -110,13 +110,13 @@ func (r *redisMeta) Getlk(ctx Context, inode Ino, owner uint64, ltype *uint32, s ls := loadLocks([]byte(d)) for _, l := range ls { // find conflicted locks - if (*ltype == F_WRLCK || l.ltype == F_WRLCK) && *end >= l.start && *start <= l.end { - *ltype = l.ltype - *start = l.start - *end = l.end + if (*ltype == F_WRLCK || l.Type == F_WRLCK) && *end >= l.Start && *start <= l.End { + *ltype = l.Type + *start = l.Start + *end = l.End sid, _ := strconv.Atoi(strings.Split(k, "_")[0]) if uint64(sid) == r.sid { - *pid = l.pid + *pid = l.Pid } else { *pid = 0 } @@ -178,7 +178,7 @@ func (r *redisMeta) Setlk(ctx Context, inode Ino, owner uint64, block bool, ltyp ls := loadLocks([]byte(d)) for _, l := range ls { // find conflicted locks - if (ltype == F_WRLCK || l.ltype == F_WRLCK) && end >= l.start && start <= l.end { + if (ltype == F_WRLCK || l.Type == F_WRLCK) && end >= l.Start && start <= l.End { return syscall.EAGAIN } } diff --git a/pkg/meta/sql_lock.go b/pkg/meta/sql_lock.go index 581e5604b16e..d03f2b950dad 100644 --- a/pkg/meta/sql_lock.go +++ b/pkg/meta/sql_lock.go @@ -130,12 +130,12 @@ func (m *dbMeta) Getlk(ctx Context, inode Ino, owner_ uint64, ltype *uint32, sta ls := loadLocks(d) for _, l := range ls { // find conflicted locks - if (*ltype == F_WRLCK || l.ltype == F_WRLCK) && *end >= l.start && *start <= l.end { - *ltype = l.ltype - *start = l.start - *end = l.end + if (*ltype == F_WRLCK || l.Type == F_WRLCK) && *end >= l.Start && *start <= l.End { + *ltype = l.Type + *start = l.Start + *end = l.End if k.sid == m.sid { - *pid = l.pid + *pid = l.Pid } else { *pid = 0 } @@ -204,7 +204,7 @@ func (m *dbMeta) Setlk(ctx Context, inode Ino, owner_ uint64, block bool, ltype ls := loadLocks(d) for _, l := range ls { // find conflicted locks - if (ltype == F_WRLCK || l.ltype == F_WRLCK) && end >= l.start && start <= l.end { + if (ltype == F_WRLCK || l.Type == F_WRLCK) && end >= l.Start && start <= l.End { return syscall.EAGAIN } } diff --git a/pkg/meta/tkv_lock.go b/pkg/meta/tkv_lock.go index f6f1e8ac5ad4..90507878dc8b 100644 --- a/pkg/meta/tkv_lock.go +++ b/pkg/meta/tkv_lock.go @@ -144,12 +144,12 @@ func (m *kvMeta) Getlk(ctx Context, inode Ino, owner uint64, ltype *uint32, star ls := loadLocks(records) for _, l := range ls { // find conflicted locks - if (*ltype == F_WRLCK || l.ltype == F_WRLCK) && *end >= l.start && *start <= l.end { - *ltype = l.ltype - *start = l.start - *end = l.end + if (*ltype == F_WRLCK || l.Type == F_WRLCK) && *end >= l.Start && *start <= l.End { + *ltype = l.Type + *start = l.Start + *end = l.End if o.sid == m.sid { - *pid = l.pid + *pid = l.Pid } else { *pid = 0 } @@ -191,7 +191,7 @@ func (m *kvMeta) Setlk(ctx Context, inode Ino, owner uint64, block bool, ltype u ls := loadLocks(d) for _, l := range ls { // find conflicted locks - if (ltype == F_WRLCK || l.ltype == F_WRLCK) && end >= l.start && start <= l.end { + if (ltype == F_WRLCK || l.Type == F_WRLCK) && end >= l.Start && start <= l.End { return syscall.EAGAIN } } diff --git a/pkg/meta/utils.go b/pkg/meta/utils.go index 0994a358aa3d..c40b3638baa1 100644 --- a/pkg/meta/utils.go +++ b/pkg/meta/utils.go @@ -156,10 +156,10 @@ func lookupSubdir(m Meta, subdir string) (Ino, error) { } type plockRecord struct { - ltype uint32 - pid uint32 - start uint64 - end uint64 + Type uint32 + Pid uint32 + Start uint64 + End uint64 } func loadLocks(d []byte) []plockRecord { @@ -174,10 +174,10 @@ func loadLocks(d []byte) []plockRecord { func dumpLocks(ls []plockRecord) []byte { wb := utils.NewBuffer(uint32(len(ls)) * 24) for _, l := range ls { - wb.Put32(l.ltype) - wb.Put32(l.pid) - wb.Put64(l.start) - wb.Put64(l.end) + wb.Put32(l.Type) + wb.Put32(l.Pid) + wb.Put64(l.Start) + wb.Put64(l.End) } return wb.Bytes() } @@ -185,47 +185,47 @@ func dumpLocks(ls []plockRecord) []byte { func updateLocks(ls []plockRecord, nl plockRecord) []plockRecord { // ls is ordered by l.start without overlap size := len(ls) - for i := 0; i < size && nl.start <= nl.end; i++ { + for i := 0; i < size && nl.Start <= nl.End; i++ { l := ls[i] - if nl.start < l.start && nl.end >= l.start { + if nl.Start < l.Start && nl.End >= l.Start { // split nl ls = append(ls, nl) - ls[len(ls)-1].end = l.start - 1 - nl.start = l.start + ls[len(ls)-1].End = l.Start - 1 + nl.Start = l.Start } - if nl.start > l.start && nl.start <= l.end { + if nl.Start > l.Start && nl.Start <= l.End { // split l - l.end = nl.start - 1 + l.End = nl.Start - 1 ls = append(ls, l) - ls[i].start = nl.start + ls[i].Start = nl.Start l = ls[i] } - if nl.start == l.start { - ls[i].ltype = nl.ltype // update l - ls[i].pid = nl.pid - if l.end > nl.end { + if nl.Start == l.Start { + ls[i].Type = nl.Type // update l + ls[i].Pid = nl.Pid + if l.End > nl.End { // split l - ls[i].end = nl.end - l.start = nl.end + 1 + ls[i].End = nl.End + l.Start = nl.End + 1 ls = append(ls, l) } - nl.start = ls[i].end + 1 + nl.Start = ls[i].End + 1 } } - if nl.start <= nl.end { + if nl.Start <= nl.End { ls = append(ls, nl) } - sort.Slice(ls, func(i, j int) bool { return ls[i].start < ls[j].start }) + sort.Slice(ls, func(i, j int) bool { return ls[i].Start < ls[j].Start }) for i := 0; i < len(ls); { - if ls[i].ltype == F_UNLCK || ls[i].start > ls[i].end { + if ls[i].Type == F_UNLCK || ls[i].Start > ls[i].End { // remove empty one copy(ls[i:], ls[i+1:]) ls = ls[:len(ls)-1] } else { - if i+1 < len(ls) && ls[i].ltype == ls[i+1].ltype && ls[i].pid == ls[i+1].pid && ls[i].end+1 == ls[i+1].start { + if i+1 < len(ls) && ls[i].Type == ls[i+1].Type && ls[i].Pid == ls[i+1].Pid && ls[i].End+1 == ls[i+1].Start { // combine continuous range - ls[i].end = ls[i+1].end - ls[i+1].start = ls[i+1].end + 1 + ls[i].End = ls[i+1].End + ls[i+1].Start = ls[i+1].End + 1 } i++ }