@@ -426,15 +426,6 @@ func (q *FileQueue) Dequeue() (int64, []byte, error) {
426426 return - 1 , nil , err
427427 }
428428 bb , err := q .peek (index )
429- sz := len (bb )
430- q .queueSize -= int64 (sz )
431- if q .queueSize < 0 {
432- q .queueSize = 0
433- }
434- b := new (bytes.Buffer )
435- binary .Write (b , binary .BigEndian , q .queueSize )
436- bbytes := b .Bytes ()
437- copy (q .metaFile .data [16 :24 ], bbytes [:])
438429 return index , bb , err
439430}
440431
@@ -520,24 +511,15 @@ func (q *FileQueue) Skip(count int64) error {
520511
521512 for i := 0 ; i < int (count ); i ++ {
522513 // check and update queue front index info
523- index , err := q .updateQueueFrontIndex ()
514+ _ , err := q .updateQueueFrontIndex ()
524515 if err != nil {
525516 return err
526517 }
527- bb , err := q .peek (index )
528- sz := len (bb )
529- q .queueSize -= int64 (sz )
530- if q .queueSize < 0 {
531- q .queueSize = 0
532- }
518+
533519 if q .IsEmpty () {
534- break
520+ return nil
535521 }
536522 }
537- b := new (bytes.Buffer )
538- binary .Write (b , binary .BigEndian , q .queueSize )
539- bbytes := b .Bytes ()
540- copy (q .metaFile .data [16 :24 ], bbytes [:])
541523 return nil
542524}
543525
@@ -617,6 +599,18 @@ func (q *FileQueue) updateQueueFrontIndex() (int64, error) {
617599
618600 }
619601
602+ // update total bytes in queue and write to meta file
603+ bb , _ = q .peek (queueFrontIndex )
604+ sz := len (bb )
605+ q .queueSize -= int64 (sz )
606+ if q .queueSize < 0 {
607+ q .queueSize = 0
608+ }
609+ b := new (bytes.Buffer )
610+ binary .Write (b , binary .BigEndian , q .queueSize )
611+ bbytes := b .Bytes ()
612+ copy (q .metaFile .data [16 :24 ], bbytes [:])
613+
620614 return queueFrontIndex , nil
621615}
622616
0 commit comments