volume: atomic copying file, adds version and stopOffset

This commit is contained in:
Chris Lu
2019-04-19 12:29:49 -07:00
parent 730a032137
commit 3b3651dea3
9 changed files with 168 additions and 113 deletions

View File

@@ -125,7 +125,7 @@ func (s *Store) Status() []*VolumeInfo {
DeletedByteCount: v.nm.DeletedSize(),
ReadOnly: v.readOnly,
Ttl: v.Ttl,
CompactRevision: uint32(v.CompactRevision),
CompactRevision: uint32(v.CompactionRevision),
}
stats = append(stats, s)
}

View File

@@ -166,6 +166,6 @@ func (v *Volume) ToVolumeInformationMessage() *master_pb.VolumeInformationMessag
ReplicaPlacement: uint32(v.ReplicaPlacement.Byte()),
Version: uint32(v.Version()),
Ttl: v.Ttl.ToUint32(),
CompactRevision: uint32(v.SuperBlock.CompactRevision),
CompactRevision: uint32(v.SuperBlock.CompactionRevision),
}
}

View File

@@ -20,7 +20,7 @@ func (v *Volume) GetVolumeSyncStatus() *volume_server_pb.VolumeSyncStatusRespons
}
syncStatus.Collection = v.Collection
syncStatus.IdxFileSize = v.nm.IndexFileSize()
syncStatus.CompactRevision = uint32(v.SuperBlock.CompactRevision)
syncStatus.CompactRevision = uint32(v.SuperBlock.CompactionRevision)
syncStatus.Ttl = v.SuperBlock.Ttl.String()
syncStatus.Replication = v.SuperBlock.ReplicaPlacement.String()
return syncStatus

View File

@@ -24,12 +24,12 @@ const (
* Rest bytes: Reserved
*/
type SuperBlock struct {
version needle.Version
ReplicaPlacement *ReplicaPlacement
Ttl *needle.TTL
CompactRevision uint16
Extra *master_pb.SuperBlockExtra
extraSize uint16
version needle.Version
ReplicaPlacement *ReplicaPlacement
Ttl *needle.TTL
CompactionRevision uint16
Extra *master_pb.SuperBlockExtra
extraSize uint16
}
func (s *SuperBlock) BlockSize() int {
@@ -48,7 +48,7 @@ func (s *SuperBlock) Bytes() []byte {
header[0] = byte(s.version)
header[1] = s.ReplicaPlacement.Byte()
s.Ttl.ToBytes(header[2:4])
util.Uint16toBytes(header[4:6], s.CompactRevision)
util.Uint16toBytes(header[4:6], s.CompactionRevision)
if s.Extra != nil {
extraData, err := proto.Marshal(s.Extra)
@@ -112,7 +112,7 @@ func ReadSuperBlock(dataFile *os.File) (superBlock SuperBlock, err error) {
return
}
superBlock.Ttl = needle.LoadTTLFromBytes(header[2:4])
superBlock.CompactRevision = util.BytesToUint16(header[4:6])
superBlock.CompactionRevision = util.BytesToUint16(header[4:6])
superBlock.extraSize = util.BytesToUint16(header[6:8])
if superBlock.extraSize > 0 {

View File

@@ -27,7 +27,7 @@ func (v *Volume) Compact(preallocate int64) error {
filePath := v.FileName()
v.lastCompactIndexOffset = v.nm.IndexFileSize()
v.lastCompactRevision = v.SuperBlock.CompactRevision
v.lastCompactRevision = v.SuperBlock.CompactionRevision
glog.V(3).Infof("creating copies for volume %d ,last offset %d...", v.Id, v.lastCompactIndexOffset)
return v.copyDataAndGenerateIndexFile(filePath+".cpd", filePath+".cpx", preallocate)
}
@@ -105,7 +105,7 @@ func fetchCompactRevisionFromDatFile(file *os.File) (compactRevision uint16, err
if err != nil {
return 0, err
}
return superBlock.CompactRevision, nil
return superBlock.CompactionRevision, nil
}
func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldIdxFileName string) (err error) {
@@ -246,7 +246,7 @@ type VolumeFileScanner4Vacuum struct {
func (scanner *VolumeFileScanner4Vacuum) VisitSuperBlock(superBlock SuperBlock) error {
scanner.version = superBlock.Version()
superBlock.CompactRevision++
superBlock.CompactionRevision++
_, err := scanner.dst.Write(superBlock.Bytes())
scanner.newOffset = int64(superBlock.BlockSize())
return err
@@ -321,7 +321,7 @@ func (v *Volume) copyDataBasedOnIndexFile(dstName, idxName string) (err error) {
nm := NewBtreeNeedleMap(idx)
now := uint64(time.Now().Unix())
v.SuperBlock.CompactRevision++
v.SuperBlock.CompactionRevision++
dst.Write(v.SuperBlock.Bytes())
newOffset := int64(v.SuperBlock.BlockSize())