@ -119,7 +119,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
oldDatCompactRevision , err := fetchCompactRevisionFromDatFile ( oldDatFile )
oldDatCompactRevision , err := fetchCompactRevisionFromDatFile ( oldDatFile )
if err != nil {
if err != nil {
return
return fmt . Errorf ( "fetchCompactRevisionFromDatFile src %s failed: %v" , oldDatFile . Name ( ) , err )
}
}
if oldDatCompactRevision != v . lastCompactRevision {
if oldDatCompactRevision != v . lastCompactRevision {
return fmt . Errorf ( "current old dat file's compact revision %d is not the expected one %d" , oldDatCompactRevision , v . lastCompactRevision )
return fmt . Errorf ( "current old dat file's compact revision %d is not the expected one %d" , oldDatCompactRevision , v . lastCompactRevision )
@ -137,6 +137,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
return fmt . Errorf ( "readIndexEntry %s at offset %d failed: %v" , oldIdxFileName , idx_offset , err )
return fmt . Errorf ( "readIndexEntry %s at offset %d failed: %v" , oldIdxFileName , idx_offset , err )
}
}
key , offset , size := idxFileEntry ( IdxEntry )
key , offset , size := idxFileEntry ( IdxEntry )
glog . V ( 0 ) . Infof ( "key %d offset %d size %d" , key , offset , size )
if _ , found := incrementedHasUpdatedIndexEntry [ key ] ; ! found {
if _ , found := incrementedHasUpdatedIndexEntry [ key ] ; ! found {
incrementedHasUpdatedIndexEntry [ key ] = keyField {
incrementedHasUpdatedIndexEntry [ key ] = keyField {
offset : offset ,
offset : offset ,
@ -145,24 +146,29 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
}
}
}
}
if len ( incrementedHasUpdatedIndexEntry ) > 0 {
// no updates during commit step
if len ( incrementedHasUpdatedIndexEntry ) == 0 {
return nil
}
// deal with updates during commit step
var (
var (
dst , idx * os . File
dst , idx * os . File
)
)
if dst , err = os . OpenFile ( newDatFileName , os . O_RDWR , 0644 ) ; err != nil {
if dst , err = os . OpenFile ( newDatFileName , os . O_RDWR , 0644 ) ; err != nil {
return
return fmt . Errorf ( "open dat file %s failed: %v" , newDatFileName , err )
}
}
defer dst . Close ( )
defer dst . Close ( )
if idx , err = os . OpenFile ( newIdxFileName , os . O_RDWR , 0644 ) ; err != nil {
if idx , err = os . OpenFile ( newIdxFileName , os . O_RDWR , 0644 ) ; err != nil {
return
return fmt . Errorf ( "open idx file %s failed: %v" , newIdxFileName , err )
}
}
defer idx . Close ( )
defer idx . Close ( )
var newDatCompactRevision uint16
var newDatCompactRevision uint16
newDatCompactRevision , err = fetchCompactRevisionFromDatFile ( dst )
newDatCompactRevision , err = fetchCompactRevisionFromDatFile ( dst )
if err != nil {
if err != nil {
return
return fmt . Errorf ( "fetchCompactRevisionFromDatFile dst %s failed: %v" , dst . Name ( ) , err )
}
}
if oldDatCompactRevision + 1 != newDatCompactRevision {
if oldDatCompactRevision + 1 != newDatCompactRevision {
return fmt . Errorf ( "oldDatFile %s 's compact revision is %d while newDatFile %s 's compact revision is %d" , oldDatFileName , oldDatCompactRevision , newDatFileName , newDatCompactRevision )
return fmt . Errorf ( "oldDatFile %s 's compact revision is %d while newDatFile %s 's compact revision is %d" , oldDatFileName , oldDatCompactRevision , newDatFileName , newDatCompactRevision )
@ -189,12 +195,13 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
}
}
//updated needle
//updated needle
if incre_idx_entry . offset != 0 && incre_idx_entry . size != 0 {
if incre_idx_entry . offset != 0 && incre_idx_entry . size != 0 && incre_idx_entry . size != TombstoneFileSize {
//even the needle cache in memory is hit, the need_bytes is correct
//even the needle cache in memory is hit, the need_bytes is correct
glog . V ( 0 ) . Infof ( "file %d offset %d size %d" , key , int64 ( incre_idx_entry . offset ) * NeedlePaddingSize , incre_idx_entry . size )
var needle_bytes [ ] byte
var needle_bytes [ ] byte
needle_bytes , err = ReadNeedleBlob ( oldDatFile , int64 ( incre_idx_entry . offset ) * NeedlePaddingSize , incre_idx_entry . size )
needle_bytes , err = ReadNeedleBlob ( oldDatFile , int64 ( incre_idx_entry . offset ) * NeedlePaddingSize , incre_idx_entry . size )
if err != nil {
if err != nil {
return
return fmt . Errorf ( "ReadNeedleBlob %s key %d offset %d size %d failed: %v" , oldDatFile . Name ( ) , key , int64 ( incre_idx_entry . offset ) * NeedlePaddingSize , incre_idx_entry . size , err )
}
}
dst . Write ( needle_bytes )
dst . Write ( needle_bytes )
util . Uint32toBytes ( idx_entry_bytes [ 8 : 12 ] , uint32 ( offset / NeedlePaddingSize ) )
util . Uint32toBytes ( idx_entry_bytes [ 8 : 12 ] , uint32 ( offset / NeedlePaddingSize ) )
@ -205,7 +212,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
fakeDelNeedle . Cookie = 0x12345678
fakeDelNeedle . Cookie = 0x12345678
_ , _ , err = fakeDelNeedle . Append ( dst , v . Version ( ) )
_ , _ , err = fakeDelNeedle . Append ( dst , v . Version ( ) )
if err != nil {
if err != nil {
return
return fmt . Errorf ( "append deleted %d failed: %v" , key , err )
}
}
util . Uint32toBytes ( idx_entry_bytes [ 8 : 12 ] , uint32 ( 0 ) )
util . Uint32toBytes ( idx_entry_bytes [ 8 : 12 ] , uint32 ( 0 ) )
}
}
@ -216,7 +223,6 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
}
}
_ , err = idx . Write ( idx_entry_bytes )
_ , err = idx . Write ( idx_entry_bytes )
}
}
}
return nil
return nil
}
}