diff --git a/datanode/partition_raftfsm.go b/datanode/partition_raftfsm.go index 1d555f66a..1482b11fd 100644 --- a/datanode/partition_raftfsm.go +++ b/datanode/partition_raftfsm.go @@ -205,4 +205,5 @@ func (dp *DataPartition) Del(key interface{}) (interface{}, error) { func (dp *DataPartition) uploadApplyID(applyID uint64) { log.LogDebugf("[uploadApplyID] dp(%v) upload apply id(%v)", dp.partitionID, applyID) atomic.StoreUint64(&dp.appliedID, applyID) + atomic.StoreUint64(&dp.extentStore.ApplyId, applyID) } diff --git a/storage/extent.go b/storage/extent.go index 98f140a76..2a3b1e79e 100644 --- a/storage/extent.go +++ b/storage/extent.go @@ -72,6 +72,7 @@ type ExtentInfo struct { SnapshotDataOff uint64 `json:"snapSize"` SnapPreAllocDataOff uint64 `json:"snapPreAllocSize"` ApplyID uint64 `json:"applyID"` + ApplySize int64 `json:"ApplySize"` } func (ei *ExtentInfo) TotalSize() uint64 { @@ -577,12 +578,8 @@ func (e *Extent) GetCrc(blockNo int64) uint32 { return binary.BigEndian.Uint32(e.header[blockNo*util.PerBlockCrcSize : (blockNo+1)*util.PerBlockCrcSize]) } -func (e *Extent) autoComputeExtentCrc(crcFunc UpdateCrcFunc) (crc uint32, err error) { +func (e *Extent) autoComputeExtentCrc(extSize int64, crcFunc UpdateCrcFunc) (crc uint32, err error) { var blockCnt int - extSize := e.Size() - if e.snapshotDataOff > util.ExtentSize { - extSize = int64(e.snapshotDataOff) - } blockCnt = int(extSize / util.BlockSize) if extSize%util.BlockSize != 0 { blockCnt += 1 diff --git a/storage/extent_store.go b/storage/extent_store.go index 9d35c5d91..bb6524546 100644 --- a/storage/extent_store.go +++ b/storage/extent_store.go @@ -149,7 +149,6 @@ type ExtentStore struct { extentLock bool stopMutex sync.RWMutex stopC chan interface{} - ApplyIdMutex sync.RWMutex ApplyId uint64 } @@ -1541,9 +1540,7 @@ func (s *ExtentStore) autoComputeExtentCrc() { sort.Sort(ExtentInfoArr(extentInfos)) for _, ei := range extentInfos { - s.ApplyIdMutex.RLock() if ei == nil { - s.ApplyIdMutex.RUnlock() continue } @@ -1553,22 +1550,22 @@ func (s *ExtentStore) autoComputeExtentCrc() { e, err := s.extentWithHeader(ei) if err != nil { log.LogWarnf("[autoComputeExtentCrc] get extent error:%+v", err) - s.ApplyIdMutex.RUnlock() continue } - - extentCrc, err := e.autoComputeExtentCrc(s.PersistenceBlockCrc) + extSize := e.Size() + if e.snapshotDataOff > util.ExtentSize { + extSize = int64(e.snapshotDataOff) + } + extentCrc, err := e.autoComputeExtentCrc(extSize, s.PersistenceBlockCrc) if err != nil { log.LogError("[autoComputeExtentCrc] compute crc fail", err) - s.ApplyIdMutex.RUnlock() continue } - + ei.ApplySize = extSize ei.UpdateExtentInfo(e, extentCrc) - ei.ApplyID = s.ApplyId + atomic.StoreUint64(&ei.ApplyID, s.ApplyId) time.Sleep(time.Millisecond * 100) } - s.ApplyIdMutex.RUnlock() } time.Sleep(time.Second)