@@ -215,7 +215,9 @@ func (t *freezerTable) repair() error {
215
215
if t .readonly {
216
216
return fmt .Errorf ("index file(path: %s, name: %s) size is not a multiple of %d" , t .path , t .name , indexEntrySize )
217
217
}
218
- truncateFreezerFile (t .index , stat .Size ()- overflow ) // New file can't trigger this path
218
+ if err := truncateFreezerFile (t .index , stat .Size ()- overflow ); err != nil {
219
+ return err
220
+ } // New file can't trigger this path
219
221
}
220
222
// Retrieve the file sizes and prepare for truncation
221
223
if stat , err = t .index .Stat (); err != nil {
@@ -260,8 +262,8 @@ func (t *freezerTable) repair() error {
260
262
// Print an error log if the index is corrupted due to an incorrect
261
263
// last index item. While it is theoretically possible to have a zero offset
262
264
// by storing all zero-size items, it is highly unlikely to occur in practice.
263
- if lastIndex .offset == 0 && offsetsSize % indexEntrySize > 1 {
264
- log .Error ("Corrupted index file detected" , "lastOffset" , lastIndex .offset , "items " , offsetsSize % indexEntrySize - 1 )
265
+ if lastIndex .offset == 0 && offsetsSize / indexEntrySize > 1 {
266
+ log .Error ("Corrupted index file detected" , "lastOffset" , lastIndex .offset , "indexes " , offsetsSize / indexEntrySize )
265
267
}
266
268
if t .readonly {
267
269
t .head , err = t .openFile (lastIndex .filenum , openFreezerFileForReadOnly )
@@ -416,6 +418,9 @@ func (t *freezerTable) truncateHead(items uint64) error {
416
418
if err := truncateFreezerFile (t .index , int64 (length + 1 )* indexEntrySize ); err != nil {
417
419
return err
418
420
}
421
+ if err := t .index .Sync (); err != nil {
422
+ return err
423
+ }
419
424
// Calculate the new expected size of the data file and truncate it
420
425
var expected indexEntry
421
426
if length == 0 {
@@ -438,13 +443,17 @@ func (t *freezerTable) truncateHead(items uint64) error {
438
443
// Release any files _after the current head -- both the previous head
439
444
// and any files which may have been opened for reading
440
445
t .releaseFilesAfter (expected .filenum , true )
446
+
441
447
// Set back the historic head
442
448
t .head = newHead
443
449
t .headId = expected .filenum
444
450
}
445
451
if err := truncateFreezerFile (t .head , int64 (expected .offset )); err != nil {
446
452
return err
447
453
}
454
+ if err := t .head .Sync (); err != nil {
455
+ return err
456
+ }
448
457
// All data files truncated, set internal counters and return
449
458
t .headBytes = int64 (expected .offset )
450
459
t .items .Store (items )
@@ -589,10 +598,12 @@ func (t *freezerTable) Close() error {
589
598
// error on Windows.
590
599
doClose (t .index , true , true )
591
600
doClose (t .meta , true , true )
601
+
592
602
// The preopened non-head data-files are all opened in readonly.
593
603
// The head is opened in rw-mode, so we sync it here - but since it's also
594
604
// part of t.files, it will be closed in the loop below.
595
605
doClose (t .head , true , false ) // sync but do not close
606
+
596
607
for _ , f := range t .files {
597
608
doClose (f , false , true ) // close but do not sync
598
609
}
0 commit comments