Skip to content

Commit

Permalink
core: BID bitwise structure and flags (object metadata)
Browse files Browse the repository at this point in the history
* part one

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jun 18, 2024
1 parent abc0300 commit 054fecd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
9 changes: 7 additions & 2 deletions core/lif.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ var _ lifUnlocker = (*LIF)(nil)
func (lom *LOM) LIF() (lif LIF) {
debug.Assert(lom.md.uname != nil)
debug.Assert(lom.Bprops() != nil && lom.Bprops().BID != 0)
bid := lom.bid()
if bid == 0 {
bid = lom.Bprops().BID
}
debug.Assert(bid == lom.Bprops().BID, bid, " vs ", lom.Bprops().BID) // TODO -- FIXME: 52 bits
return LIF{
uname: *lom.md.uname,
bid: lom.Bprops().BID,
bid: bid,
digest: lom.digest,
}
}
Expand All @@ -48,7 +53,7 @@ func (lif *LIF) LOM() (lom *LOM, err error) {
if bprops := lom.Bprops(); bprops == nil {
err = cmn.NewErrObjDefunct(lom.String(), 0, lif.bid)
FreeLOM(lom)
} else if bprops.BID != lif.bid {
} else if bprops.BID != lif.bid { // TODO -- FIXME: 52 bits
err = cmn.NewErrObjDefunct(lom.String(), bprops.BID, lif.bid)
FreeLOM(lom)
}
Expand Down
42 changes: 15 additions & 27 deletions core/lom.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ func (lom *LOM) Atime() time.Time { return time.Unix(0, lom.md.Atime) }
func (lom *LOM) AtimeUnix() int64 { return lom.md.Atime }
func (lom *LOM) SetAtimeUnix(tu int64) { lom.md.Atime = tu }

func (lom *LOM) bid() uint64 { return lom.md.bckID }
func (lom *LOM) setbid(bpropsBID uint64) { lom.md.bckID = bpropsBID } // TODO -- FIXME: 52 bits

// custom metadata
func (lom *LOM) GetCustomMD() cos.StrKVs { return lom.md.GetCustomMD() }
func (lom *LOM) SetCustomMD(md cos.StrKVs) { lom.md.SetCustomMD(md) }
Expand Down Expand Up @@ -394,12 +397,7 @@ func (lom *LOM) Load(cacheit, locked bool) error {
if err := lom.FromFS(); err != nil {
return err
}
bid := lom.Bprops().BID
debug.Assert(bid != 0, lom.Cname())
if bid == 0 {
return nil
}
lom.md.bckID = bid
lom.setbid(lom.Bprops().BID) // TODO -- FIXME: remove
if err := lom._checkBucket(bmd); err != nil {
return err
}
Expand All @@ -411,20 +409,18 @@ func (lom *LOM) Load(cacheit, locked bool) error {
}

func (lom *LOM) _checkBucket(bmd *meta.BMD) (err error) {
bck, bckID := &lom.bck, lom.md.bckID
debug.Assert(bckID != 0)
bck := &lom.bck
bprops, present := bmd.Get(bck)
if !present {
if bck.IsRemote() {
return cmn.NewErrRemoteBckNotFound(bck.Bucket())
}
return cmn.NewErrBckNotFound(bck.Bucket())
}
if bckID == bprops.BID {
return nil // ok
if lom.bid() != bprops.BID { // TODO -- FIXME: 52 bits
err = cmn.NewErrObjDefunct(lom.String(), lom.bid(), bprops.BID)
}
err = cmn.NewErrObjDefunct(lom.String(), lom.md.bckID, lom.bck.Props.BID)
return
return err
}

// usage: fast (and unsafe) loading object metadata except atime - no locks
Expand All @@ -437,22 +433,15 @@ func (lom *LOM) LoadUnsafe() (err error) {
// fast path
if lmd != nil {
lom.md = *lmd
err = lom._checkBucket(bmd)
return
return lom._checkBucket(bmd)
}

// read and decode xattr; NOTE: fs.GetXattr* vs fs.SetXattr race possible and must be
// either a) handled or b) benign from the caller's perspective
if _, err = lom.lmfs(true); err != nil {
return
}
// check bucket
bid := lom.Bprops().BID
debug.Assert(bid != 0, lom.Cname())
if bid == 0 {
return
if _, err = lom.lmfs(true); err == nil {
err = lom._checkBucket(bmd)
}
lom.md.bckID = bid
return lom._checkBucket(bmd)
return err
}

//
Expand All @@ -462,10 +451,9 @@ func (lom *LOM) LoadUnsafe() (err error) {
// store new or refresh existing
func (lom *LOM) Recache() {
debug.Assert(!lom.IsCopy())
lom.setbid(lom.Bprops().BID) // TODO -- FIXME: 52 bits

md := lom.md
bid := lom.Bprops().BID
debug.Assert(bid != 0)
md.bckID, lom.md.bckID = bid, bid

lcache := lom.lcache()
val, ok := lcache.Swap(lom.digest, &md)
Expand Down
4 changes: 2 additions & 2 deletions core/lom_xattr.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (lom *LOM) Persist() (err error) {
if !lom.IsCopy() {
lom.Recache()
}
lom.md.bckID = lom.Bprops().BID
lom.setbid(lom.Bprops().BID)
}
return
}
Expand All @@ -203,7 +203,7 @@ func (lom *LOM) Persist() (err error) {
if !lom.IsCopy() {
lom.Recache()
}
lom.md.bckID = lom.Bprops().BID
lom.setbid(lom.Bprops().BID)
}
}
g.smm.Free(buf)
Expand Down

0 comments on commit 054fecd

Please sign in to comment.