@@ -215,9 +215,7 @@ func (t *freezerTable) repair() error {
215215 if t .readonly {
216216 return fmt .Errorf ("index file(path: %s, name: %s) size is not a multiple of %d" , t .path , t .name , indexEntrySize )
217217 }
218- if err := truncateFreezerFile (t .index , stat .Size ()- overflow ); err != nil {
219- return err
220- } // New file can't trigger this path
218+ truncateFreezerFile (t .index , stat .Size ()- overflow ) // New file can't trigger this path
221219 }
222220 // Retrieve the file sizes and prepare for truncation
223221 if stat , err = t .index .Stat (); err != nil {
@@ -262,8 +260,8 @@ func (t *freezerTable) repair() error {
262260 // Print an error log if the index is corrupted due to an incorrect
263261 // last index item. While it is theoretically possible to have a zero offset
264262 // by storing all zero-size items, it is highly unlikely to occur in practice.
265- if lastIndex .offset == 0 && offsetsSize / indexEntrySize > 1 {
266- log .Error ("Corrupted index file detected" , "lastOffset" , lastIndex .offset , "indexes " , offsetsSize / indexEntrySize )
263+ if lastIndex .offset == 0 && offsetsSize % indexEntrySize > 1 {
264+ log .Error ("Corrupted index file detected" , "lastOffset" , lastIndex .offset , "items " , offsetsSize % indexEntrySize - 1 )
267265 }
268266 if t .readonly {
269267 t .head , err = t .openFile (lastIndex .filenum , openFreezerFileForReadOnly )
@@ -418,9 +416,6 @@ func (t *freezerTable) truncateHead(items uint64) error {
418416 if err := truncateFreezerFile (t .index , int64 (length + 1 )* indexEntrySize ); err != nil {
419417 return err
420418 }
421- if err := t .index .Sync (); err != nil {
422- return err
423- }
424419 // Calculate the new expected size of the data file and truncate it
425420 var expected indexEntry
426421 if length == 0 {
@@ -443,17 +438,13 @@ func (t *freezerTable) truncateHead(items uint64) error {
443438 // Release any files _after the current head -- both the previous head
444439 // and any files which may have been opened for reading
445440 t .releaseFilesAfter (expected .filenum , true )
446-
447441 // Set back the historic head
448442 t .head = newHead
449443 t .headId = expected .filenum
450444 }
451445 if err := truncateFreezerFile (t .head , int64 (expected .offset )); err != nil {
452446 return err
453447 }
454- if err := t .head .Sync (); err != nil {
455- return err
456- }
457448 // All data files truncated, set internal counters and return
458449 t .headBytes = int64 (expected .offset )
459450 t .items .Store (items )
@@ -598,12 +589,10 @@ func (t *freezerTable) Close() error {
598589 // error on Windows.
599590 doClose (t .index , true , true )
600591 doClose (t .meta , true , true )
601-
602592 // The preopened non-head data-files are all opened in readonly.
603593 // The head is opened in rw-mode, so we sync it here - but since it's also
604594 // part of t.files, it will be closed in the loop below.
605595 doClose (t .head , true , false ) // sync but do not close
606-
607596 for _ , f := range t .files {
608597 doClose (f , false , true ) // close but do not sync
609598 }
0 commit comments