@@ -33,6 +33,7 @@ import (
3333 "github.com/pingcap/ticdc/pkg/common"
3434 appcontext "github.com/pingcap/ticdc/pkg/common/context"
3535 "github.com/pingcap/ticdc/pkg/config"
36+ "github.com/pingcap/ticdc/pkg/errors"
3637 "github.com/pingcap/ticdc/pkg/messaging"
3738 "github.com/pingcap/ticdc/pkg/metrics"
3839 "github.com/pingcap/ticdc/pkg/node"
@@ -76,7 +77,7 @@ type EventStore interface {
7677
7778 GetDispatcherDMLEventState (dispatcherID common.DispatcherID ) (bool , DMLEventState )
7879
79- // return an iterator which scan the data in ts range (dataRange.StartTs, dataRange.EndTs]
80+ // GetIterator return an iterator which scan the data in ts range (dataRange.StartTs, dataRange.EndTs]
8081 GetIterator (dispatcherID common.DispatcherID , dataRange common.DataRange ) (EventIterator , error )
8182}
8283
@@ -593,11 +594,12 @@ func (e *eventStore) GetIterator(dispatcherID common.DispatcherID, dataRange com
593594 return nil , nil
594595 }
595596 subscriptionStat := stat .subStat
596- if dataRange .StartTs < subscriptionStat .checkpointTs .Load () {
597- log .Panic ("dataRange startTs is larger than subscriptionStat checkpointTs, it should not happen" ,
597+ checkpoint := subscriptionStat .checkpointTs .Load ()
598+ if dataRange .StartTs < checkpoint {
599+ log .Panic ("dataRange startTs is smaller than subscriptionStat checkpointTs, it should not happen" ,
598600 zap .Stringer ("dispatcherID" , dispatcherID ),
599- zap .Uint64 ("checkpointTs " , subscriptionStat . checkpointTs . Load () ),
600- zap .Uint64 ("startTs " , dataRange . StartTs ))
601+ zap .Uint64 ("startTs " , dataRange . StartTs ),
602+ zap .Uint64 ("checkpointTs " , checkpoint ))
601603 }
602604 db := e .dbs [subscriptionStat .dbIndex ]
603605 e .dispatcherMeta .RUnlock ()
@@ -611,10 +613,11 @@ func (e *eventStore) GetIterator(dispatcherID common.DispatcherID, dataRange com
611613 UpperBound : end ,
612614 })
613615 if err != nil {
614- return nil , err
616+ return nil , errors . Trace ( err )
615617 }
616618 startTime := time .Now ()
617- iter .First ()
619+ // todo: what happens if iter.First() returns false?
620+ _ = iter .First ()
618621 metricEventStoreFirstReadDurationHistogram .Observe (time .Since (startTime ).Seconds ())
619622 metrics .EventStoreScanRequestsCount .Inc ()
620623
@@ -759,7 +762,6 @@ func (e *eventStore) writeEvents(db *pebble.DB, events []eventWithCallback) erro
759762 CounterKv .Add (float64 (kvCount ))
760763 metrics .EventStoreWriteBatchEventsCountHist .Observe (float64 (kvCount ))
761764 metrics .EventStoreWriteBatchSizeHist .Observe (float64 (batch .Len ()))
762- metrics .EventStoreWriteBytes .Add (float64 (batch .Len ()))
763765 start := time .Now ()
764766 err := batch .Commit (pebble .NoSync )
765767 metrics .EventStoreWriteDurationHistogram .Observe (float64 (time .Since (start ).Milliseconds ()) / 1000 )
@@ -790,10 +792,6 @@ type eventStoreIter struct {
790792}
791793
792794func (iter * eventStoreIter ) Next () (* common.RawKVEntry , bool , error ) {
793- if iter .innerIter == nil {
794- log .Panic ("iter is nil" )
795- }
796-
797795 rawKV := & common.RawKVEntry {}
798796 for {
799797 if ! iter .innerIter .Valid () {
@@ -805,20 +803,19 @@ func (iter *eventStoreIter) Next() (*common.RawKVEntry, bool, error) {
805803 log .Panic ("fail to decode raw kv entry" , zap .Error (err ))
806804 }
807805 metrics .EventStoreScanBytes .Add (float64 (len (value )))
808- if iter .needCheckSpan {
809- comparableKey := common .ToComparableKey (rawKV .Key )
810- if bytes .Compare (comparableKey , iter .tableSpan .StartKey ) >= 0 &&
811- bytes .Compare (comparableKey , iter .tableSpan .EndKey ) <= 0 {
812- break
813- }
814- log .Debug ("event store iter skip kv not in table span" ,
815- zap .String ("tableSpan" , common .FormatTableSpan (iter .tableSpan )),
816- zap .String ("key" , hex .EncodeToString (rawKV .Key )),
817- zap .Uint64 ("startTs" , rawKV .StartTs ),
818- zap .Uint64 ("commitTs" , rawKV .CRTs ))
819- } else {
806+ if ! iter .needCheckSpan {
807+ break
808+ }
809+ comparableKey := common .ToComparableKey (rawKV .Key )
810+ if bytes .Compare (comparableKey , iter .tableSpan .StartKey ) >= 0 &&
811+ bytes .Compare (comparableKey , iter .tableSpan .EndKey ) <= 0 {
820812 break
821813 }
814+ log .Debug ("event store iter skip kv not in table span" ,
815+ zap .String ("tableSpan" , common .FormatTableSpan (iter .tableSpan )),
816+ zap .String ("key" , hex .EncodeToString (rawKV .Key )),
817+ zap .Uint64 ("startTs" , rawKV .StartTs ),
818+ zap .Uint64 ("commitTs" , rawKV .CRTs ))
822819 iter .innerIter .Next ()
823820 }
824821 isNewTxn := false
@@ -830,7 +827,7 @@ func (iter *eventStoreIter) Next() (*common.RawKVEntry, bool, error) {
830827 iter .rowCount ++
831828 startTime := time .Now ()
832829 iter .innerIter .Next ()
833- metricEventStoreNextReadDurationHistogram .Observe (float64 ( time .Since (startTime ).Seconds () ))
830+ metricEventStoreNextReadDurationHistogram .Observe (time .Since (startTime ).Seconds ())
834831 return rawKV , isNewTxn , nil
835832}
836833
0 commit comments