29
"github.com/cubefs/cubefs/proto"
30
"github.com/cubefs/cubefs/util/log"
31
"github.com/cubefs/cubefs/util/timeutil"
35
DeleteMarkFlag = 1 << 0
41
V2EnableColdInodeFlag uint64 = 0x02
42
V3EnableSnapInodeFlag uint64 = 0x04
65
type InodeMultiSnap struct {
67
multiVersions InodeBatch
87
Extents *SortedExtents
88
ObjExtents *SortedObjExtents
90
multiSnap *InodeMultiSnap
93
func (i *Inode) GetMultiVerString() string {
94
if i.multiSnap == nil {
98
return fmt.Sprintf("%v", i.multiSnap.multiVersions)
101
func (i *Inode) RangeMultiVer(visitor func(idx int, info *Inode) bool) {
102
if i.multiSnap == nil {
105
for k, v := range i.multiSnap.multiVersions {
112
func isInitSnapVer(seq uint64) bool {
113
return seq == math.MaxUint64
116
func NewMultiSnap(seq uint64) *InodeMultiSnap {
117
return &InodeMultiSnap{
122
func (i *Inode) verUpdate(seq uint64) {
123
if seq == 0 && i.multiSnap == nil {
126
if i.multiSnap == nil {
127
i.multiSnap = NewMultiSnap(seq)
129
i.multiSnap.verSeq = seq
133
func (i *Inode) setVerNoCheck(seq uint64) {
137
func (i *Inode) setVer(seq uint64) {
138
if i.getVer() > seq {
139
syslog.Println(fmt.Sprintf("inode[%v] old seq [%v] cann't use seq [%v]", i.getVer(), seq, string(debug.Stack())))
140
log.LogFatalf("inode[%v] old seq [%v] cann't use seq [%v] stack %v", i.Inode, i.getVer(), seq, string(debug.Stack()))
145
func (i *Inode) insertEkRefMap(mpId uint64, ek *proto.ExtentKey) {
146
if i.multiSnap == nil {
147
i.multiSnap = NewMultiSnap(i.getVer())
149
if i.multiSnap.ekRefMap == nil {
150
i.multiSnap.ekRefMap = new(sync.Map)
152
storeEkSplit(mpId, i.Inode, i.multiSnap.ekRefMap, ek)
155
func (i *Inode) isEkInRefMap(mpId uint64, ek *proto.ExtentKey) (ok bool) {
156
if i.multiSnap == nil {
159
if i.multiSnap.ekRefMap == nil {
160
log.LogErrorf("[storeEkSplit] mpId [%v] inodeID %v ekRef nil", mpId, i.Inode)
163
log.LogDebugf("[storeEkSplit] mpId [%v] inode[%v] mp[%v] extent id[%v] ek [%v]", mpId, i.Inode, ek.PartitionId, ek.ExtentId, ek)
164
id := ek.PartitionId<<32 | ek.ExtentId
165
_, ok = i.multiSnap.ekRefMap.Load(id)
169
func (i *Inode) getVer() uint64 {
170
if i.multiSnap == nil {
173
return i.multiSnap.verSeq
176
func (i *Inode) getLayerLen() int {
177
if i.multiSnap == nil {
180
return len(i.multiSnap.multiVersions)
183
func (i *Inode) getLayerVer(layer int) uint64 {
184
if i.multiSnap == nil {
185
log.LogErrorf("getLayerVer. inode[%v] multi snap nil", i.Inode)
189
if layer > i.getLayerLen()-1 {
190
log.LogErrorf("getLayerVer. inode[%v] layer %v not exist, len %v", i.Inode, layer, i.getLayerLen())
193
if i.multiSnap.multiVersions[layer] == nil {
194
log.LogErrorf("getLayerVer. inode[%v] layer %v nil", i.Inode, layer)
197
return i.multiSnap.multiVersions[layer].getVer()
200
func (i *Inode) isEmptyVerList() bool {
201
return i.getLayerLen() == 0
204
func (i *Inode) isTailIndexInList(id int) bool {
205
return id == i.getLayerLen()-1
208
func (i *Inode) getTailVerInList() (verSeq uint64, found bool) {
209
mLen := i.getLayerLen()
211
return i.getLayerVer(mLen - 1), true
217
func (inode *Inode) GetAllExtsOfflineInode(mpID uint64) (extInfo map[uint64][]*proto.ExtentKey) {
218
log.LogDebugf("deleteMarkedInodes. GetAllExtsOfflineInode.mp[%v] inode[%v] inode.Extents: %v, ino verList: %v",
219
mpID, inode.Inode, inode.Extents, inode.GetMultiVerString())
221
extInfo = make(map[uint64][]*proto.ExtentKey)
223
if inode.getLayerLen() > 0 {
224
log.LogWarnf("deleteMarkedInodes. GetAllExtsOfflineInode.mp[%v] inode[%v] verlist len %v should not drop",
225
mpID, inode.Inode, inode.getLayerLen())
228
for i := 0; i < inode.getLayerLen()+1; i++ {
231
dIno = inode.multiSnap.multiVersions[i-1]
233
log.LogDebugf("deleteMarkedInodes. GetAllExtsOfflineInode.mp[%v] inode[%v] dino[%v]", mpID, inode.Inode, dIno)
234
dIno.Extents.Range(func(_ int, ek proto.ExtentKey) bool {
240
log.LogDebugf("deleteMarkedInodes DecSplitEk mpID %v inode[%v]", mpID, inode.Inode)
241
if dOK, last = dIno.DecSplitEk(mpID, &ek); !dOK {
245
log.LogDebugf("deleteMarkedInodes. GetAllExtsOfflineInode.mp[%v] inode[%v] ek [%v] be removed", mpID, inode.Inode, ek)
249
log.LogDebugf("deleteMarkedInodes. GetAllExtsOfflineInode.mp[%v] inode[%v] ek [%v] be removed", mpID, inode.Inode, ek)
251
extInfo[ek.PartitionId] = append(extInfo[ek.PartitionId], &ek)
253
log.LogWritef("GetAllExtsOfflineInode. mp[%v] ino(%v) deleteExtent(%v)", mpID, inode.Inode, ek.String())
257
dIno.Extents = NewSortedExtents()
262
type InodeBatch []*Inode
266
TxInfo *proto.TransactionInfo
269
func NewTxInode(ino uint64, t uint32, txInfo *proto.TransactionInfo) *TxInode {
271
Inode: NewInode(ino, t),
277
func (ti *TxInode) Marshal() (result []byte, err error) {
278
buff := bytes.NewBuffer(make([]byte, 0))
280
bs, err := ti.Inode.Marshal()
284
if err = binary.Write(buff, binary.BigEndian, uint32(len(bs))); err != nil {
287
if _, err := buff.Write(bs); err != nil {
291
bs, err = ti.TxInfo.Marshal()
295
if err = binary.Write(buff, binary.BigEndian, uint32(len(bs))); err != nil {
298
if _, err := buff.Write(bs); err != nil {
301
result = buff.Bytes()
305
func (ti *TxInode) Unmarshal(raw []byte) (err error) {
306
buff := bytes.NewBuffer(raw)
309
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
312
data := make([]byte, int(dataLen))
313
if _, err = buff.Read(data); err != nil {
316
ino := NewInode(0, 0)
317
if err = ino.Unmarshal(data); err != nil {
322
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
325
data = make([]byte, int(dataLen))
326
if _, err = buff.Read(data); err != nil {
329
txInfo := proto.NewTransactionInfo(0, proto.TxTypeUndefined)
330
if err = txInfo.Unmarshal(data); err != nil {
337
func (i *InodeBatch) Clone() InodeBatch {
339
for _, inode := range []*Inode(*i) {
340
rB = append(rB, inode.Copy().(*Inode))
345
func (ino *Inode) getAllInodesInfo() (rsp []proto.InodeInfo) {
349
ino.RangeMultiVer(func(idx int, info *Inode) bool {
350
rspInodeInfo := &proto.InodeInfo{}
351
replyInfoNoCheck(rspInodeInfo, info)
352
rsp = append(rsp, *rspInodeInfo)
358
func (ino *Inode) getAllLayerEks() (rsp []proto.LayerInfo) {
361
rspInodeInfo := &proto.InodeInfo{}
362
replyInfoNoCheck(rspInodeInfo, ino)
364
layerInfo := proto.LayerInfo{
367
Eks: ino.Extents.eks,
369
rsp = append(rsp, layerInfo)
371
ino.RangeMultiVer(func(idx int, info *Inode) bool {
372
rspInodeInfo := &proto.InodeInfo{}
373
replyInfo(rspInodeInfo, info, nil)
374
layerInfo := proto.LayerInfo{
375
LayerIdx: uint32(idx + 1),
377
Eks: info.Extents.eks,
379
rsp = append(rsp, layerInfo)
387
func (i *Inode) String() string {
390
buff := bytes.NewBuffer(nil)
392
buff.WriteString("Inode{")
393
buff.WriteString(fmt.Sprintf("Inode[%d]", i.Inode))
394
buff.WriteString(fmt.Sprintf("Type[%d]", i.Type))
395
buff.WriteString(fmt.Sprintf("Uid[%d]", i.Uid))
396
buff.WriteString(fmt.Sprintf("Gid[%d]", i.Gid))
397
buff.WriteString(fmt.Sprintf("Size[%d]", i.Size))
398
buff.WriteString(fmt.Sprintf("Gen[%d]", i.Generation))
399
buff.WriteString(fmt.Sprintf("CT[%d]", i.CreateTime))
400
buff.WriteString(fmt.Sprintf("AT[%d]", i.AccessTime))
401
buff.WriteString(fmt.Sprintf("MT[%d]", i.ModifyTime))
402
buff.WriteString(fmt.Sprintf("LinkT[%s]", i.LinkTarget))
403
buff.WriteString(fmt.Sprintf("NLink[%d]", i.NLink))
404
buff.WriteString(fmt.Sprintf("Flag[%d]", i.Flag))
405
buff.WriteString(fmt.Sprintf("Reserved[%d]", i.Reserved))
406
buff.WriteString(fmt.Sprintf("Extents[%s]", i.Extents))
407
buff.WriteString(fmt.Sprintf("ObjExtents[%s]", i.ObjExtents))
408
buff.WriteString(fmt.Sprintf("verSeq[%v]", i.getVer()))
409
buff.WriteString(fmt.Sprintf("multiSnap.multiVersions.len[%v]", i.getLayerLen()))
410
buff.WriteString("}")
416
func NewInode(ino uint64, t uint32) *Inode {
417
ts := timeutil.GetCurrentTimeUnix()
426
Extents: NewSortedExtents(),
427
ObjExtents: NewSortedObjExtents(),
438
func (i *Inode) Less(than BtreeItem) bool {
439
ino, ok := than.(*Inode)
440
return ok && i.Inode < ino.Inode
444
func (i *Inode) Copy() BtreeItem {
445
newIno := NewInode(i.Inode, i.Type)
450
newIno.Generation = i.Generation
451
newIno.CreateTime = i.CreateTime
452
newIno.ModifyTime = i.ModifyTime
453
newIno.AccessTime = i.AccessTime
454
if size := len(i.LinkTarget); size > 0 {
455
newIno.LinkTarget = make([]byte, size)
456
copy(newIno.LinkTarget, i.LinkTarget)
458
newIno.NLink = i.NLink
460
newIno.Reserved = i.Reserved
461
newIno.Extents = i.Extents.Clone()
462
newIno.ObjExtents = i.ObjExtents.Clone()
463
if i.multiSnap != nil {
464
newIno.multiSnap = &InodeMultiSnap{
466
multiVersions: i.multiSnap.multiVersions.Clone(),
467
ekRefMap: i.multiSnap.ekRefMap,
474
func (i *Inode) CopyInodeOnly(cInode *Inode) *Inode {
475
tmpInode := cInode.CopyDirectly().(*Inode)
476
tmpInode.Extents = i.Extents
477
tmpInode.ObjExtents = i.ObjExtents
478
tmpInode.multiSnap = i.multiSnap
482
func (i *Inode) CopyDirectly() BtreeItem {
483
newIno := NewInode(i.Inode, i.Type)
488
newIno.Generation = i.Generation
489
newIno.CreateTime = i.CreateTime
490
newIno.ModifyTime = i.ModifyTime
491
newIno.AccessTime = i.AccessTime
492
if size := len(i.LinkTarget); size > 0 {
493
newIno.LinkTarget = make([]byte, size)
494
copy(newIno.LinkTarget, i.LinkTarget)
496
newIno.NLink = i.NLink
498
newIno.Reserved = i.Reserved
499
newIno.Extents = i.Extents.Clone()
500
newIno.ObjExtents = i.ObjExtents.Clone()
506
func (i *Inode) MarshalToJSON() ([]byte, error) {
509
return json.Marshal(i)
513
func (i *Inode) Marshal() (result []byte, err error) {
514
keyBytes := i.MarshalKey()
515
valBytes := i.MarshalValue()
516
keyLen := uint32(len(keyBytes))
517
valLen := uint32(len(valBytes))
518
buff := bytes.NewBuffer(make([]byte, 0, 128))
519
if err = binary.Write(buff, binary.BigEndian, keyLen); err != nil {
522
if _, err = buff.Write(keyBytes); err != nil {
525
if err = binary.Write(buff, binary.BigEndian, valLen); err != nil {
528
if _, err = buff.Write(valBytes); err != nil {
531
result = buff.Bytes()
536
func (i *Inode) Unmarshal(raw []byte) (err error) {
541
buff := bytes.NewBuffer(raw)
542
if err = binary.Read(buff, binary.BigEndian, &keyLen); err != nil {
545
keyBytes := make([]byte, keyLen)
546
if _, err = buff.Read(keyBytes); err != nil {
549
if err = i.UnmarshalKey(keyBytes); err != nil {
552
if err = binary.Read(buff, binary.BigEndian, &valLen); err != nil {
555
valBytes := make([]byte, valLen)
556
if _, err = buff.Read(valBytes); err != nil {
559
err = i.UnmarshalValue(valBytes)
564
func (i InodeBatch) Marshal() ([]byte, error) {
565
buff := bytes.NewBuffer(make([]byte, 0))
566
if err := binary.Write(buff, binary.BigEndian, uint32(len(i))); err != nil {
569
for _, inode := range i {
570
bs, err := inode.Marshal()
574
if err = binary.Write(buff, binary.BigEndian, uint32(len(bs))); err != nil {
577
if _, err := buff.Write(bs); err != nil {
581
return buff.Bytes(), nil
585
func InodeBatchUnmarshal(raw []byte) (InodeBatch, error) {
586
buff := bytes.NewBuffer(raw)
588
if err := binary.Read(buff, binary.BigEndian, &batchLen); err != nil {
592
result := make(InodeBatch, 0, int(batchLen))
595
for j := 0; j < int(batchLen); j++ {
596
if err := binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
599
data := make([]byte, int(dataLen))
600
if _, err := buff.Read(data); err != nil {
603
ino := NewInode(0, 0)
604
if err := ino.Unmarshal(data); err != nil {
607
result = append(result, ino)
614
func (i *Inode) MarshalKey() (k []byte) {
616
binary.BigEndian.PutUint64(k, i.Inode)
621
func (i *Inode) UnmarshalKey(k []byte) (err error) {
622
i.Inode = binary.BigEndian.Uint64(k)
627
func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
629
if err = binary.Write(buff, binary.BigEndian, &i.Type); err != nil {
632
if err = binary.Write(buff, binary.BigEndian, &i.Uid); err != nil {
635
if err = binary.Write(buff, binary.BigEndian, &i.Gid); err != nil {
638
if err = binary.Write(buff, binary.BigEndian, &i.Size); err != nil {
641
if err = binary.Write(buff, binary.BigEndian, &i.Generation); err != nil {
644
if err = binary.Write(buff, binary.BigEndian, &i.CreateTime); err != nil {
647
if err = binary.Write(buff, binary.BigEndian, &i.AccessTime); err != nil {
650
if err = binary.Write(buff, binary.BigEndian, &i.ModifyTime); err != nil {
654
symSize := uint32(len(i.LinkTarget))
655
if err = binary.Write(buff, binary.BigEndian, &symSize); err != nil {
658
if _, err = buff.Write(i.LinkTarget); err != nil {
662
if err = binary.Write(buff, binary.BigEndian, &i.NLink); err != nil {
665
if err = binary.Write(buff, binary.BigEndian, &i.Flag); err != nil {
668
if i.ObjExtents != nil && len(i.ObjExtents.eks) > 0 {
669
i.Reserved |= V2EnableColdInodeFlag
671
i.Reserved |= V3EnableSnapInodeFlag
674
if err = binary.Write(buff, binary.BigEndian, &i.Reserved); err != nil {
679
extData, err := i.Extents.MarshalBinary(true)
683
if err = binary.Write(buff, binary.BigEndian, uint32(len(extData))); err != nil {
686
if _, err = buff.Write(extData); err != nil {
690
if i.Reserved&V2EnableColdInodeFlag > 0 {
692
objExtData, err := i.ObjExtents.MarshalBinary()
696
if err = binary.Write(buff, binary.BigEndian, uint32(len(objExtData))); err != nil {
699
if _, err = buff.Write(objExtData); err != nil {
704
if err = binary.Write(buff, binary.BigEndian, i.getVer()); err != nil {
712
func (i *Inode) MarshalValue() (val []byte) {
714
buff := bytes.NewBuffer(make([]byte, 0, 128))
718
i.MarshalInodeValue(buff)
719
if i.getLayerLen() > 0 && i.getVer() == 0 {
720
log.LogFatalf("action[MarshalValue] inode[%v] current verseq [%v], hist len (%v) stack(%v)", i.Inode, i.getVer(), i.getLayerLen(), string(debug.Stack()))
722
if err = binary.Write(buff, binary.BigEndian, int32(i.getLayerLen())); err != nil {
727
if i.multiSnap != nil {
728
for _, ino := range i.multiSnap.multiVersions {
729
ino.MarshalInodeValue(buff)
739
func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
740
if err = binary.Read(buff, binary.BigEndian, &i.Type); err != nil {
743
if err = binary.Read(buff, binary.BigEndian, &i.Uid); err != nil {
746
if err = binary.Read(buff, binary.BigEndian, &i.Gid); err != nil {
749
if err = binary.Read(buff, binary.BigEndian, &i.Size); err != nil {
752
if err = binary.Read(buff, binary.BigEndian, &i.Generation); err != nil {
755
if err = binary.Read(buff, binary.BigEndian, &i.CreateTime); err != nil {
758
if err = binary.Read(buff, binary.BigEndian, &i.AccessTime); err != nil {
761
if err = binary.Read(buff, binary.BigEndian, &i.ModifyTime); err != nil {
766
if err = binary.Read(buff, binary.BigEndian, &symSize); err != nil {
770
i.LinkTarget = make([]byte, symSize)
771
if _, err = io.ReadFull(buff, i.LinkTarget); err != nil {
776
if err = binary.Read(buff, binary.BigEndian, &i.NLink); err != nil {
779
if err = binary.Read(buff, binary.BigEndian, &i.Flag); err != nil {
782
if err = binary.Read(buff, binary.BigEndian, &i.Reserved); err != nil {
787
if i.Extents == nil {
788
i.Extents = NewSortedExtents()
790
if i.ObjExtents == nil {
791
i.ObjExtents = NewSortedObjExtents()
794
v3 := i.Reserved&V3EnableSnapInodeFlag > 0
795
v2 := i.Reserved&V2EnableColdInodeFlag > 0
799
if err = binary.Read(buff, binary.BigEndian, &extSize); err != nil {
803
extBytes := make([]byte, extSize)
804
if _, err = io.ReadFull(buff, extBytes); err != nil {
808
if err, ekRef = i.Extents.UnmarshalBinary(extBytes, v3); err != nil {
813
if i.multiSnap == nil {
814
i.multiSnap = NewMultiSnap(0)
817
i.multiSnap.ekRefMap = ekRef
821
if err, _ = i.Extents.UnmarshalBinary(buff.Bytes(), false); err != nil {
829
ObjExtSize := uint32(0)
830
if err = binary.Read(buff, binary.BigEndian, &ObjExtSize); err != nil {
834
objExtBytes := make([]byte, ObjExtSize)
835
if _, err = io.ReadFull(buff, objExtBytes); err != nil {
838
if err = i.ObjExtents.UnmarshalBinary(objExtBytes); err != nil {
846
if err = binary.Read(buff, binary.BigEndian, &seq); err != nil {
857
func (i *Inode) GetSpaceSize() (extSize uint64) {
861
extSize += i.Extents.LayerSize()
866
func (i *Inode) UnmarshalValue(val []byte) (err error) {
867
buff := bytes.NewBuffer(val)
868
i.UnmarshalInodeValue(buff)
869
if i.Reserved&V3EnableSnapInodeFlag > 0 {
871
if err = binary.Read(buff, binary.BigEndian, &verCnt); err != nil {
872
log.LogInfof("action[UnmarshalValue] err get ver cnt inode[%v] new seq [%v]", i.Inode, i.getVer())
875
if verCnt > 0 && i.getVer() == 0 {
876
err = fmt.Errorf("inode[%v] verCnt %v root ver [%v]", i.Inode, verCnt, i.getVer())
877
log.LogFatalf("UnmarshalValue. %v", err)
880
for idx := int32(0); idx < verCnt; idx++ {
881
ino := &Inode{Inode: i.Inode}
882
ino.UnmarshalInodeValue(buff)
883
if ino.multiSnap != nil && ino.multiSnap.ekRefMap != nil {
884
if i.multiSnap.ekRefMap == nil {
885
i.multiSnap.ekRefMap = new(sync.Map)
888
proto.MergeSplitKey(i.Inode, i.multiSnap.ekRefMap, ino.multiSnap.ekRefMap)
890
if i.multiSnap == nil {
891
i.multiSnap = &InodeMultiSnap{}
894
i.multiSnap.multiVersions = append(i.multiSnap.multiVersions, ino)
901
func (i *Inode) AppendExtents(eks []proto.ExtentKey, ct int64, volType int) (delExtents []proto.ExtentKey) {
902
if proto.IsCold(volType) {
907
for _, ek := range eks {
908
delItems := i.Extents.Append(ek)
909
size := i.Extents.Size()
913
delExtents = append(delExtents, delItems...)
922
func (i *Inode) AppendObjExtents(eks []proto.ObjExtentKey, ct int64) (err error) {
926
for _, ek := range eks {
927
err = i.ObjExtents.Append(ek)
931
size := i.ObjExtents.Size()
941
func (i *Inode) PrintAllVersionInfo() {
942
if i.multiSnap == nil {
945
log.LogInfof("action[PrintAllVersionInfo] inode[%v] verSeq [%v] hist len [%v]", i.Inode, i.getVer(), i.getLayerLen())
946
for id, info := range i.multiSnap.multiVersions {
947
log.LogInfof("action[PrintAllVersionInfo] layer [%v] verSeq [%v] inode[%v]", id, info.getVer(), info)
952
func (i *Inode) MultiLayerClearExtByVer(layer int, dVerSeq uint64) (delExtents []proto.ExtentKey) {
957
ino = i.multiSnap.multiVersions[layer-1]
961
defer ino.Extents.Unlock()
963
for idx, ek := range ino.Extents.eks {
964
if ek.GetSeq() > dVerSeq {
965
delExtents = append(delExtents, ek)
966
ino.Extents.eks = append(ino.Extents.eks[idx:], ino.Extents.eks[:idx+1]...)
972
func (i *Inode) mergeExtentArr(mpId uint64, extentKeysLeft []proto.ExtentKey, extentKeysRight []proto.ExtentKey) []proto.ExtentKey {
973
lCnt := len(extentKeysLeft)
974
rCnt := len(extentKeysRight)
975
sortMergedExts := make([]proto.ExtentKey, 0, lCnt+rCnt)
978
doWork := func(keyArr *[]proto.ExtentKey, pos int) {
979
mLen := len(sortMergedExts)
980
if mLen > 0 && sortMergedExts[mLen-1].IsSequenceWithSameSeq(&(*keyArr)[pos]) {
981
sortMergedExts[mLen-1].Size += (*keyArr)[pos].Size
982
log.LogDebugf("[mergeExtentArr] mpId[%v]. ek left %v right %v", mpId, sortMergedExts[mLen-1], (*keyArr)[pos])
983
if !sortMergedExts[mLen-1].IsSplit() || !(*keyArr)[pos].IsSplit() {
984
log.LogErrorf("[mergeExtentArr] mpId[%v] ino[%v] ek merge left %v right %v not all split", mpId, i.Inode, sortMergedExts[mLen-1], (*keyArr)[pos])
986
i.DecSplitEk(mpId, &(*keyArr)[pos])
988
sortMergedExts = append(sortMergedExts, (*keyArr)[pos])
994
sortMergedExts = append(sortMergedExts, extentKeysRight[rPos:]...)
998
sortMergedExts = append(sortMergedExts, extentKeysLeft[lPos:]...)
1002
if extentKeysLeft[lPos].FileOffset < extentKeysRight[rPos].FileOffset {
1003
doWork(&extentKeysLeft, lPos)
1006
doWork(&extentKeysRight, rPos)
1011
return sortMergedExts
1017
func (i *Inode) RestoreExts2NextLayer(mpId uint64, delExtentsOrigin []proto.ExtentKey, curVer uint64, idx int) (delExtents []proto.ExtentKey, err error) {
1018
log.LogInfof("action[RestoreMultiSnapExts] mpId [%v] curVer [%v] delExtents size [%v] hist len [%v]", mpId, curVer, len(delExtentsOrigin), i.getLayerLen())
1020
if i.isEmptyVerList() {
1021
log.LogWarnf("action[RestoreMultiSnapExts] mpId [%v] inode[%v] restore have no old version left", mpId, i.Inode)
1022
return delExtentsOrigin, nil
1024
lastSeq := i.multiSnap.multiVersions[idx].getVer()
1025
specSnapExtent := make([]proto.ExtentKey, 0)
1027
for _, delExt := range delExtentsOrigin {
1030
log.LogDebugf("action[RestoreMultiSnapExts] mpId [%v] inode[%v] ext split [%v] with seq[%v] gSeq[%v] try to del.the last seq [%v], ek details[%v]",
1031
mpId, i.Inode, delExt.IsSplit(), delExt.GetSeq(), curVer, lastSeq, delExt)
1032
if delExt.GetSeq() > lastSeq {
1033
delExtents = append(delExtents, delExt)
1035
log.LogInfof("action[RestoreMultiSnapExts] mpId [%v] inode[%v] move to level 1 delExt [%v] specSnapExtent size [%v]", mpId, i.Inode, delExt, len(specSnapExtent))
1036
specSnapExtent = append(specSnapExtent, delExt)
1039
if len(specSnapExtent) == 0 {
1040
log.LogInfof("action[RestoreMultiSnapExts] mpId [%v] inode[%v] no need to move to level 1", mpId, i.Inode)
1043
if len(specSnapExtent) > 0 && i.isEmptyVerList() {
1044
err = fmt.Errorf("mpId [%v] inode[%v] error not found prev snapshot index", mpId, i.Inode)
1045
log.LogErrorf("action[RestoreMultiSnapExts] mpId [%v] inode[%v] %v", mpId, i.Inode, err)
1049
i.multiSnap.multiVersions[idx].Extents.Lock()
1050
i.multiSnap.multiVersions[idx].Extents.eks = i.mergeExtentArr(mpId, i.multiSnap.multiVersions[idx].Extents.eks, specSnapExtent)
1051
i.multiSnap.multiVersions[idx].Extents.Unlock()
1056
func (inode *Inode) unlinkTopLayer(mpId uint64, ino *Inode, mpVer uint64, verlist *proto.VolVersionInfoList) (ext2Del []proto.ExtentKey, doMore bool, status uint8) {
1059
log.LogDebugf("action[unlinkTopLayer] mpid [%v] mpver [%v] check if have snapshot depends on the deleitng ino[%v] (with no snapshot itself) found seq [%v], verlist %v",
1060
mpId, mpVer, ino, inode.getVer(), verlist)
1063
delFunc := func() (done bool) {
1064
if inode.NLink > 1 {
1065
log.LogDebugf("action[unlinkTopLayer] inode[%v] be unlinked, file link is %v", ino.Inode, inode.NLink)
1072
if ext2Del, err = inode.RestoreExts2NextLayer(mpId, inode.Extents.eks, mpVer, 0); err != nil {
1073
log.LogErrorf("action[getAndDelVerInList] ino[%v] RestoreMultiSnapExts split error %v", inode.Inode, err)
1074
status = proto.OpNotExistErr
1075
log.LogDebugf("action[unlinkTopLayer] mp[%v] iino[%v]", mpId, ino)
1078
inode.Extents.eks = inode.Extents.eks[:0]
1079
log.LogDebugf("action[getAndDelVerInList] mp[%v] ino[%v] verseq [%v] get del exts %v", mpId, inode.Inode, inode.getVer(), ext2Del)
1089
if mpVer == inode.getVer() {
1090
if inode.getLayerLen() == 0 {
1091
log.LogDebugf("action[unlinkTopLayer] no snapshot available depends on ino[%v] not found seq [%v] and return, verlist %v", ino, inode.getVer(), verlist)
1093
log.LogDebugf("action[unlinkTopLayer] inode[%v] be unlinked", ino.Inode)
1099
log.LogDebugf("action[unlinkTopLayer] need restore.ino[%v] withseq [%v] equal mp seq, verlist %v",
1100
ino, inode.getVer(), verlist)
1102
if !proto.IsDir(inode.Type) {
1106
log.LogDebugf("action[unlinkTopLayer] inode[%v] be unlinked, Dir", ino.Inode)
1112
log.LogDebugf("action[unlinkTopLayer] need create version.ino[%v] withseq [%v] not equal mp seq [%v], verlist %v", ino, inode.getVer(), mpVer, verlist)
1113
if proto.IsDir(inode.Type) {
1114
_, err := verlist.GetNextOlderVer(mpVer)
1116
log.LogDebugf("action[unlinkTopLayer] inode[%v] cann't get next older ver [%v] err %v", inode.Inode, mpVer, err)
1117
inode.CreateVer(mpVer)
1120
log.LogDebugf("action[unlinkTopLayer] inode[%v] be unlinked, Dir create ver 1st layer", ino.Inode)
1123
ver, err := verlist.GetNextOlderVer(mpVer)
1125
if err.Error() == "not found" {
1129
log.LogErrorf("action[unlinkTopLayer] inode[%v] cann't get next older ver [%v] err %v", inode.Inode, mpVer, err)
1132
inode.CreateVer(mpVer)
1133
if inode.NLink == 1 {
1134
inode.CreateUnlinkVer(mpVer, ver)
1137
log.LogDebugf("action[unlinkTopLayer] inode[%v] be unlinked, File create ver 1st layer", ino.Inode)
1142
func (inode *Inode) dirUnlinkVerInlist(ino *Inode, mpVer uint64, verlist *proto.VolVersionInfoList) (ext2Del []proto.ExtentKey, doMore bool, status uint8) {
1143
var idxWithTopLayer int
1146
if dIno, idxWithTopLayer = inode.getInoByVer(ino.getVer(), false); dIno == nil {
1147
log.LogDebugf("action[dirUnlinkVerInlist] ino[%v] not found", ino)
1151
if idxWithTopLayer == 0 {
1153
log.LogDebugf("action[dirUnlinkVerInlist] ino[%v] first layer do nothing", ino)
1157
if inode.multiSnap == nil {
1158
log.LogWarnf("action[dirUnlinkVerInlist] ino[%v] multiSnap should not be nil", inode)
1159
inode.multiSnap = &InodeMultiSnap{}
1162
mIdx := idxWithTopLayer - 1
1164
endSeq = inode.getVer()
1166
endSeq = inode.multiSnap.multiVersions[mIdx-1].getVer()
1169
log.LogDebugf("action[dirUnlinkVerInlist] inode[%v] try drop multiVersion idx %v effective seq scope [%v,%v) ",
1170
inode.Inode, mIdx, dIno.getVer(), endSeq)
1172
doWork := func() bool {
1173
verlist.RWLock.RLock()
1174
defer verlist.RWLock.RUnlock()
1176
for vidx, info := range verlist.VerList {
1177
if info.Ver >= dIno.getVer() && info.Ver < endSeq {
1178
log.LogDebugf("action[dirUnlinkVerInlist] inode[%v] dir layer idx %v still have effective snapshot seq [%v].so don't drop", inode.Inode, mIdx, info.Ver)
1181
if info.Ver >= endSeq || vidx == len(verlist.VerList)-1 {
1182
log.LogDebugf("action[dirUnlinkVerInlist] inode[%v] try drop multiVersion idx %v and return", inode.Inode, mIdx)
1185
inode.multiSnap.multiVersions = append(inode.multiSnap.multiVersions[:mIdx], inode.multiSnap.multiVersions[mIdx+1:]...)
1189
log.LogDebugf("action[dirUnlinkVerInlist] inode[%v] try drop scope [%v, %v), mp ver [%v] not suitable", inode.Inode, dIno.getVer(), endSeq, info.Ver)
1202
func (inode *Inode) unlinkVerInList(mpId uint64, ino *Inode, mpVer uint64, verlist *proto.VolVersionInfoList) (ext2Del []proto.ExtentKey, doMore bool, status uint8) {
1203
log.LogDebugf("action[unlinkVerInList] mpId [%v] ino[%v] try search seq [%v] isdir %v", mpId, ino, ino.getVer(), proto.IsDir(inode.Type))
1204
if proto.IsDir(inode.Type) {
1205
return inode.dirUnlinkVerInlist(ino, mpVer, verlist)
1211
if ino.getVer() == inode.getVer() || (isInitSnapVer(ino.getVer()) && inode.getVer() == 0) {
1212
if len(verlist.VerList) == 0 {
1213
status = proto.OpNotExistErr
1214
log.LogErrorf("action[unlinkVerInList] inode[%v] verlist should be larger than 0, return not found", inode.Inode)
1219
nVerSeq, found := inode.getLastestVer(inode.getVer(), verlist)
1221
status = proto.OpNotExistErr
1224
log.LogDebugf("action[unlinkVerInList] inode[%v] update current verseq [%v] to %v", inode.Inode, inode.getVer(), nVerSeq)
1225
inode.setVer(nVerSeq)
1229
if ext2Del, dIno = inode.getAndDelVerInList(mpId, ino.getVer(), mpVer, verlist); dIno == nil {
1230
status = proto.OpNotExistErr
1231
log.LogDebugf("action[unlinkVerInList] ino[%v]", ino)
1237
log.LogDebugf("action[unlinkVerInList] inode[%v] snapshot layer be unlinked", ino.Inode)
1242
func (i *Inode) ShouldDelVer(delVer uint64, mpVer uint64) (ok bool, err error) {
1243
if i.getVer() == 0 {
1245
if isInitSnapVer(delVer) {
1248
return false, fmt.Errorf("not found")
1257
if delVer > i.getVer() {
1258
return false, fmt.Errorf("not found")
1259
} else if delVer == i.getVer() {
1264
if isInitSnapVer(delVer) {
1265
tailVer, _ := i.getTailVerInList()
1269
return false, fmt.Errorf("not found")
1271
if i.multiSnap == nil {
1272
return false, fmt.Errorf("not found")
1274
for _, inoVer := range i.multiSnap.multiVersions {
1275
if inoVer.getVer() == delVer {
1278
if inoVer.getVer() < delVer {
1282
return false, fmt.Errorf("not found")
1288
func (ino *Inode) getInoByVer(verSeq uint64, equal bool) (i *Inode, idx int) {
1292
if verSeq == 0 || verSeq == ino.getVer() || (isInitSnapVer(verSeq) && ino.getVer() == 0) {
1295
if isInitSnapVer(verSeq) {
1296
listLen := ino.getLayerLen()
1298
log.LogDebugf("action[getInoByVer] ino[%v] no multiversion", ino.Inode)
1301
i = ino.multiSnap.multiVersions[listLen-1]
1302
if i.getVer() != 0 {
1303
log.LogDebugf("action[getInoByVer] ino[%v] lay seq [%v]", ino.Inode, i.getVer())
1308
if verSeq > 0 && ino.getVer() > verSeq {
1309
if ino.multiSnap != nil {
1310
for id, iTmp := range ino.multiSnap.multiVersions {
1311
if verSeq == iTmp.getVer() {
1312
log.LogDebugf("action[getInoByVer] ino[%v] get in multiversion id[%v]", ino.Inode, id)
1314
} else if verSeq > iTmp.getVer() {
1316
log.LogDebugf("action[getInoByVer] ino[%v] get in multiversion id[%v], %v, %v", ino.Inode, id, verSeq, iTmp.getVer())
1319
log.LogDebugf("action[getInoByVer] ino[%v] get in multiversion id[%v]", ino.Inode, id)
1326
log.LogDebugf("action[getInoByVer] ino[%v]", ino.Inode)
1337
func (i *Inode) getAndDelVerInList(mpId uint64, dVer uint64, mpVer uint64, verlist *proto.VolVersionInfoList) (delExtents []proto.ExtentKey, ino *Inode) {
1339
verlist.RWLock.RLock()
1340
defer verlist.RWLock.RUnlock()
1342
log.LogDebugf("action[getAndDelVerInList] ino[%v] verseq [%v] request del ver [%v] hist len %v isTmpFile %v",
1343
i.Inode, i.getVer(), dVer, i.getLayerLen(), i.IsTempFile())
1346
inoVerLen := i.getLayerLen()
1348
log.LogDebugf("action[getAndDelVerInList] ino[%v] RestoreMultiSnapExts no left", i.Inode)
1353
if isInitSnapVer(dVer) {
1356
lastVer := i.getVer()
1357
for id, mIno := range i.multiSnap.multiVersions {
1358
log.LogDebugf("action[getAndDelVerInList] ino[%v] multiSnap.multiVersions level %v verseq [%v]", i.Inode, id, mIno.getVer())
1359
if mIno.getVer() < dVer {
1360
log.LogDebugf("action[getAndDelVerInList] ino[%v] multiSnap.multiVersions level %v verseq [%v]", i.Inode, id, mIno.getVer())
1364
if mIno.getVer() == dVer {
1365
log.LogDebugf("action[getAndDelVerInList] ino[%v] ver [%v] step 3", i.Inode, mIno.getVer())
1369
if nVerSeq, err = verlist.GetNextNewerVer(dVer); err != nil {
1370
log.LogDebugf("action[getAndDelVerInList] get next version failed, err %v", err)
1373
if lastVer > nVerSeq {
1374
mIno.setVer(nVerSeq)
1377
if i.isTailIndexInList(id) {
1378
i.multiSnap.multiVersions = i.multiSnap.multiVersions[:inoVerLen-1]
1379
log.LogDebugf("action[getAndDelVerInList] ino[%v] idx %v be dropped", i.Inode, inoVerLen)
1380
return mIno.Extents.eks, mIno
1382
if nVerSeq, err = verlist.GetNextOlderVer(dVer); err != nil {
1383
log.LogDebugf("action[getAndDelVerInList] get next version failed, err %v", err)
1387
log.LogDebugf("action[getAndDelVerInList] ino[%v] ver [%v] nextVerseq [%v] step 3 ver ", i.Inode, mIno.getVer(), nVerSeq)
1391
if nVerSeq > i.multiSnap.multiVersions[id+1].getVer() {
1392
log.LogDebugf("action[getAndDelVerInList] ino[%v] get next version in verList update ver from %v to %v.And delete exts with ver [%v]",
1393
i.Inode, i.multiSnap.multiVersions[id].getVer(), nVerSeq, dVer)
1395
i.multiSnap.multiVersions[id].setVerNoCheck(nVerSeq)
1396
i.multiSnap.multiVersions[id] = i.CopyInodeOnly(i.multiSnap.multiVersions[id+1])
1398
delExtents = i.MultiLayerClearExtByVer(id+1, dVer)
1399
ino = i.multiSnap.multiVersions[id]
1400
if len(i.multiSnap.multiVersions[id].Extents.eks) != 0 {
1401
log.LogDebugf("action[getAndDelVerInList] ino[%v] after clear self still have ext and left", i.Inode)
1405
log.LogDebugf("action[getAndDelVerInList] ino[%v] ver [%v] nextver [%v] step 3 ver ", i.Inode, mIno.getVer(), nVerSeq)
1407
if delExtents, err = i.RestoreExts2NextLayer(mpId, mIno.Extents.eks, dVer, id+1); err != nil {
1408
log.LogDebugf("action[getAndDelVerInList] ino[%v] RestoreMultiSnapExts split error %v", i.Inode, err)
1413
i.multiSnap.multiVersions = append(i.multiSnap.multiVersions[:id], i.multiSnap.multiVersions[id+1:]...)
1415
log.LogDebugf("action[getAndDelVerInList] ino[%v] verseq [%v] get del exts %v", i.Inode, i.getVer(), delExtents)
1416
return delExtents, mIno
1418
lastVer = mIno.getVer()
1423
func (i *Inode) getLastestVer(reqVerSeq uint64, verlist *proto.VolVersionInfoList) (uint64, bool) {
1424
verlist.RWLock.RLock()
1425
defer verlist.RWLock.RUnlock()
1427
if len(verlist.VerList) == 0 {
1430
for _, info := range verlist.VerList {
1431
if info.Ver > reqVerSeq {
1432
return info.Ver, true
1436
log.LogDebugf("action[getLastestVer] inode[%v] reqVerseq [%v] not found, the largetst one %v",
1437
i.Inode, reqVerSeq, verlist.VerList[len(verlist.VerList)-1].Ver)
1441
func (i *Inode) CreateUnlinkVer(mpVer uint64, nVer uint64) {
1442
log.LogDebugf("action[CreateUnlinkVer] inode[%v] mpver [%v] nver [%v]", i.Inode, mpVer, nVer)
1444
ino := i.CopyDirectly().(*Inode)
1447
i.Extents = NewSortedExtents()
1448
i.ObjExtents = NewSortedObjExtents()
1451
log.LogDebugf("action[CreateUnlinkVer] inode[%v] create new version [%v] and store old one [%v], hist len [%v]",
1452
i.Inode, mpVer, i.getVer(), i.getLayerLen())
1455
if i.multiSnap == nil {
1456
i.multiSnap = &InodeMultiSnap{}
1458
if i.getLayerVer(0) == nVer {
1459
i.multiSnap.multiVersions[0] = ino
1461
i.multiSnap.multiVersions = append([]*Inode{ino}, i.multiSnap.multiVersions...)
1468
func (i *Inode) CreateVer(ver uint64) {
1470
ino := i.CopyDirectly().(*Inode)
1471
ino.Extents = NewSortedExtents()
1472
ino.ObjExtents = NewSortedObjExtents()
1473
ino.setVer(i.getVer())
1478
log.LogDebugf("action[CreateVer] inode[%v] create new version [%v] and store old one [%v], hist len [%v]",
1479
i.Inode, ver, i.getVer(), i.getLayerLen())
1481
if i.multiSnap == nil {
1482
i.multiSnap = &InodeMultiSnap{}
1484
i.multiSnap.multiVersions = append([]*Inode{ino}, i.multiSnap.multiVersions...)
1487
func (i *Inode) buildMultiSnap() {
1488
if i.multiSnap == nil {
1489
i.multiSnap = &InodeMultiSnap{}
1491
if i.multiSnap.ekRefMap == nil {
1492
i.multiSnap.ekRefMap = new(sync.Map)
1496
func (i *Inode) SplitExtentWithCheck(param *AppendExtParam) (delExtents []proto.ExtentKey, status uint8) {
1498
param.ek.SetSeq(param.mpVer)
1499
log.LogDebugf("action[SplitExtentWithCheck] mpId[%v].inode[%v],ek [%v],hist len %v", param.mpId, i.Inode, param.ek, i.getLayerLen())
1501
if param.mpVer != i.getVer() {
1502
log.LogDebugf("action[SplitExtentWithCheck] mpId[%v].CreateVer ver [%v]", param.mpId, param.mpVer)
1503
i.CreateVer(param.mpVer)
1509
delExtents, status = i.Extents.SplitWithCheck(param.mpId, i.Inode, param.ek, i.multiSnap.ekRefMap)
1510
if status != proto.OpOk {
1511
log.LogErrorf("action[SplitExtentWithCheck] mpId[%v].status [%v]", param.mpId, status)
1514
if len(delExtents) == 0 {
1518
if err = i.CreateLowerVersion(i.getVer(), param.multiVersionList); err != nil {
1522
if delExtents, err = i.RestoreExts2NextLayer(param.mpId, delExtents, param.mpVer, 0); err != nil {
1523
log.LogErrorf("action[fsmAppendExtentWithCheck] mpId[%v].ino[%v] RestoreMultiSnapExts split error %v", param.mpId, i.Inode, err)
1526
if proto.IsHot(param.volType) {
1528
i.ModifyTime = param.ct
1535
func (i *Inode) CreateLowerVersion(curVer uint64, verlist *proto.VolVersionInfoList) (err error) {
1536
verlist.RWLock.RLock()
1537
defer verlist.RWLock.RUnlock()
1539
log.LogDebugf("CreateLowerVersion inode[%v] curver [%v]", i.Inode, curVer)
1540
if len(verlist.VerList) <= 1 {
1543
if i.isEmptyVerList() {
1547
for _, info := range verlist.VerList {
1548
if info.Ver < curVer {
1551
if info.Ver >= curVer {
1555
if nextVer <= i.getLayerVer(0) {
1556
log.LogDebugf("CreateLowerVersion nextver [%v] layer 0 ver [%v]", nextVer, i.getLayerVer(0))
1560
ino := i.CopyDirectly().(*Inode)
1561
ino.Extents = NewSortedExtents()
1562
ino.ObjExtents = NewSortedObjExtents()
1565
log.LogDebugf("action[CreateLowerVersion] inode[%v] create new version [%v] and store old one [%v], hist len [%v]",
1566
i.Inode, ino, i.getVer(), i.getLayerLen())
1567
if i.multiSnap == nil {
1568
i.multiSnap = &InodeMultiSnap{}
1570
i.multiSnap.multiVersions = append([]*Inode{ino}, i.multiSnap.multiVersions...)
1575
type AppendExtParam struct {
1578
multiVersionList *proto.VolVersionInfoList
1581
discardExtents []proto.ExtentKey
1585
func (i *Inode) AppendExtentWithCheck(param *AppendExtParam) (delExtents []proto.ExtentKey, status uint8) {
1586
param.ek.SetSeq(param.mpVer)
1587
log.LogDebugf("action[AppendExtentWithCheck] mpId[%v].mpver [%v] inode[%v] and fsm ver [%v],ek [%v],hist len %v",
1588
param.mpId, param.mpVer, i.Inode, i.getVer(), param.ek, i.getLayerLen())
1590
if param.mpVer != i.getVer() {
1591
log.LogInfof("action[AppendExtentWithCheck] mpId[%v].inode ver [%v]", param.mpId, i.getVer())
1592
i.CreateVer(param.mpVer)
1598
refFunc := func(key *proto.ExtentKey) { i.insertEkRefMap(param.mpId, key) }
1599
delExtents, status = i.Extents.AppendWithCheck(i.Inode, param.ek, refFunc, param.discardExtents)
1600
if status != proto.OpOk {
1601
log.LogErrorf("action[AppendExtentWithCheck] mpId[%v].status [%v]", param.mpId, status)
1606
if i.getVer() > 0 && len(delExtents) > 0 {
1608
if err = i.CreateLowerVersion(i.getVer(), param.multiVersionList); err != nil {
1611
if delExtents, err = i.RestoreExts2NextLayer(param.mpId, delExtents, param.mpVer, 0); err != nil {
1612
log.LogErrorf("action[AppendExtentWithCheck] mpId[%v].RestoreMultiSnapExts err %v", param.mpId, err)
1613
return nil, proto.OpErr
1617
if proto.IsHot(param.volType) {
1618
size := i.Extents.Size()
1623
i.ModifyTime = param.ct
1628
func (i *Inode) ExtentsTruncate(length uint64, ct int64, doOnLastKey func(*proto.ExtentKey), insertRefMap func(ek *proto.ExtentKey)) (delExtents []proto.ExtentKey) {
1629
delExtents = i.Extents.Truncate(length, doOnLastKey, insertRefMap)
1637
func (i *Inode) IncNLink(verSeq uint64) {
1638
if i.getVer() < verSeq {
1647
func (i *Inode) DecNLink() {
1649
if proto.IsDir(i.Type) && i.NLink == 2 {
1659
func (i *Inode) DecNLinkByVer(verSeq uint64) {
1660
if i.getVer() < verSeq {
1666
func (i *Inode) DecSplitExts(mpId uint64, delExtents interface{}) {
1667
log.LogDebugf("[DecSplitExts] mpId [%v] inode[%v]", mpId, i.Inode)
1668
cnt := len(delExtents.([]proto.ExtentKey))
1669
for id := 0; id < cnt; id++ {
1670
ek := &delExtents.([]proto.ExtentKey)[id]
1672
log.LogDebugf("[DecSplitExts] mpId [%v] ek not split %v", mpId, ek)
1675
if i.multiSnap == nil || i.multiSnap.ekRefMap == nil {
1676
log.LogErrorf("[DecSplitExts] mpid [%v]. inode[%v] multiSnap.ekRefMap is nil", mpId, i.Inode)
1680
ok, last := i.DecSplitEk(mpId, ek)
1682
log.LogErrorf("[DecSplitExts] mpid [%v]. ek [%v] not found!", mpId, ek)
1686
log.LogDebugf("[DecSplitExts] mpid [%v] ek [%v] split flag be unset to remove all content", mpId, ek)
1692
func (i *Inode) DecSplitEk(mpId uint64, ext *proto.ExtentKey) (ok bool, last bool) {
1693
log.LogDebugf("[DecSplitEk] mpId[%v] inode[%v] dp [%v] extent id[%v].key %v ext %v", mpId, i.Inode, ext.PartitionId, ext.ExtentId,
1694
ext.PartitionId<<32|ext.ExtentId, ext)
1696
if i.multiSnap == nil || i.multiSnap.ekRefMap == nil {
1697
log.LogErrorf("DecSplitEk. multiSnap %v", i.multiSnap)
1700
if val, ok := i.multiSnap.ekRefMap.Load(ext.PartitionId<<32 | ext.ExtentId); !ok {
1701
log.LogErrorf("[DecSplitEk] mpId[%v]. dp [%v] inode[%v] ext not found", mpId, ext.PartitionId, i.Inode)
1704
if val.(uint32) == 0 {
1705
log.LogErrorf("[DecSplitEk] mpId[%v]. dp [%v] inode[%v] ek ref is zero!", mpId, ext.PartitionId, i.Inode)
1708
if val.(uint32) == 1 {
1709
log.LogDebugf("[DecSplitEk] mpId[%v] inode[%v] dp [%v] extent id[%v].key %v", mpId, i.Inode, ext.PartitionId, ext.ExtentId,
1710
ext.PartitionId<<32|ext.ExtentId)
1711
i.multiSnap.ekRefMap.Delete(ext.PartitionId<<32 | ext.ExtentId)
1714
i.multiSnap.ekRefMap.Store(ext.PartitionId<<32|ext.ExtentId, val.(uint32)-1)
1715
log.LogDebugf("[DecSplitEk] mpId[%v]. extend dp [%v] inode[%v] ek [%v] val %v", mpId, ext.PartitionId, i.Inode, ext, val.(uint32)-1)
1721
func (i *Inode) GetDecNLinkResult() (nLink uint32) {
1724
if proto.IsDir(i.Type) && nLink == 2 {
1735
func (i *Inode) GetNLink() uint32 {
1741
func (i *Inode) IsTempFile() bool {
1743
ok := i.NLink == 0 && !proto.IsDir(i.Type)
1748
func (i *Inode) IsEmptyDir() bool {
1750
ok := proto.IsDir(i.Type) && i.NLink <= 2
1755
func (i *Inode) IsEmptyDirAndNoSnapshot() bool {
1757
ok := proto.IsDir(i.Type) && i.NLink <= 2 && i.getLayerLen() == 0
1762
func (i *Inode) IsTopLayerEmptyDir() bool {
1764
ok := proto.IsDir(i.Type) && i.NLink <= 2
1770
func (i *Inode) SetDeleteMark() {
1772
i.Flag |= DeleteMarkFlag
1777
func (i *Inode) ShouldDelete() (ok bool) {
1779
ok = i.Flag&DeleteMarkFlag == DeleteMarkFlag
1788
func (i *Inode) ShouldDelayDelete() (ok bool) {
1790
ok = (i.Flag&DeleteMarkFlag != DeleteMarkFlag) &&
1792
time.Now().Unix()-i.AccessTime < InodeNLink0DelayDeleteSeconds
1798
func (i *Inode) SetAttr(req *SetattrRequest) {
1799
log.LogDebugf("action[SetAttr] inode[%v] req seq [%v] inode seq [%v]", i.Inode, req.VerSeq, i.getVer())
1801
if req.VerSeq != i.getVer() {
1802
i.CreateVer(req.VerSeq)
1805
log.LogDebugf("action[SetAttr] inode[%v] req seq [%v] inode seq [%v]", i.Inode, req.VerSeq, i.getVer())
1806
if req.Valid&proto.AttrMode != 0 {
1809
if req.Valid&proto.AttrUid != 0 {
1812
if req.Valid&proto.AttrGid != 0 {
1815
if req.Valid&proto.AttrAccessTime != 0 {
1816
i.AccessTime = req.AccessTime
1818
if req.Valid&proto.AttrModifyTime != 0 {
1819
i.ModifyTime = req.ModifyTime
1825
func (i *Inode) DoWriteFunc(fn func()) {
1832
func (i *Inode) DoReadFunc(fn func()) {
1839
func (i *Inode) SetMtime() {
1840
mtime := timeutil.GetCurrentTimeUnix()
1843
i.ModifyTime = mtime
1847
func (i *Inode) EmptyExtents(mtime int64) (delExtents []proto.ExtentKey) {
1851
delExtents = i.Extents.eks
1852
i.Extents = NewSortedExtents()
1858
func (i *Inode) CopyTinyExtents() (delExtents []proto.ExtentKey) {
1861
return i.Extents.CopyTinyExtents()