-
Notifications
You must be signed in to change notification settings - Fork 138
feat: Enable Stats on Resumed Sync #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from 14 commits
cdb961b
776fade
6398bf9
b79f70e
3b50a5d
335571a
bf1ac3a
7961d2b
3332a36
f3e044a
948b1fe
c9f54db
0315a45
628f7b3
c7952c2
ff82c4a
e7aa390
ebdb1ae
a27fdfd
e7a2dbc
724d045
3c225f4
d89c722
e74771b
bb814a6
521caa2
99699b5
68c35fa
ba93364
87751c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,9 @@ const ( | |
| MixedType StateType = "MIXED" | ||
| // constant key for chunks | ||
| ChunksKey = "chunks" | ||
| // constant keys for stats | ||
| TotalRecordCountKey = "total_record_count" | ||
| SyncedRecordCountKey = "synced_record_count" | ||
| ) | ||
|
|
||
| type GlobalState struct { | ||
|
|
@@ -254,6 +257,90 @@ func (s *State) RemoveChunk(stream *ConfiguredStream, chunk Chunk) int { | |
| return -1 | ||
| } | ||
|
|
||
| // GetTotalRecordCount retrieves the total record count for a stream from state | ||
| func (s *State) GetTotalRecordCount(stream *ConfiguredStream) int64 { | ||
| s.RLock() | ||
| defer s.RUnlock() | ||
|
|
||
| index, contains := utils.ArrayContains(s.Streams, func(elem *StreamState) bool { | ||
| return elem.Namespace == stream.Namespace() && elem.Stream == stream.Name() | ||
| }) | ||
| if contains { | ||
| if count, loaded := s.Streams[index].State.Load(TotalRecordCountKey); loaded { | ||
| if countInt64, ok := count.(int64); ok { | ||
| return countInt64 | ||
| } | ||
| // Handle case where count might be stored as float64 (from JSON unmarshalling) | ||
| if countFloat64, ok := count.(float64); ok { | ||
| return int64(countFloat64) | ||
| } | ||
Itz-Agasta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one took me a while to figure out. I added more logging and noticed something weird - even though the state file had I traced through the code and found the issue in if count, loaded := s.Streams[index].State.Load(RemainingRecordCountKey); loaded {
if countInt64, ok := count.(int64); ok {
return countInt64 // This was failing!
}
}
return 0Ig Go's JSON unmarshaling converts ALL numbers to |
||
| } | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| // SetTotalRecordCount stores the total record count for a stream in state | ||
| func (s *State) SetTotalRecordCount(stream *ConfiguredStream, count int64) { | ||
| s.Lock() | ||
| defer s.Unlock() | ||
|
|
||
| index, contains := utils.ArrayContains(s.Streams, func(elem *StreamState) bool { | ||
| return elem.Namespace == stream.Namespace() && elem.Stream == stream.Name() | ||
| }) | ||
| if contains { | ||
| s.Streams[index].State.Store(TotalRecordCountKey, count) | ||
| s.Streams[index].HoldsValue.Store(true) | ||
| } else { | ||
| newStream := s.initStreamState(stream) | ||
| newStream.State.Store(TotalRecordCountKey, count) | ||
| newStream.HoldsValue.Store(true) | ||
| s.Streams = append(s.Streams, newStream) | ||
| } | ||
| s.LogState() | ||
| } | ||
|
|
||
| // GetSyncedRecordCount retrieves the synced record count for a stream from state | ||
| func (s *State) GetSyncedRecordCount(stream *ConfiguredStream) int64 { | ||
| s.RLock() | ||
| defer s.RUnlock() | ||
|
|
||
| index, contains := utils.ArrayContains(s.Streams, func(elem *StreamState) bool { | ||
| return elem.Namespace == stream.Namespace() && elem.Stream == stream.Name() | ||
| }) | ||
| if contains { | ||
| if count, loaded := s.Streams[index].State.Load(SyncedRecordCountKey); loaded { | ||
| if countInt64, ok := count.(int64); ok { | ||
| return countInt64 | ||
| } | ||
| // Handle case where count might be stored as float64 (from JSON unmarshalling) | ||
| if countFloat64, ok := count.(float64); ok { | ||
| return int64(countFloat64) | ||
| } | ||
Itz-Agasta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| // SetSyncedRecordCount stores the synced record count for a stream in state | ||
| func (s *State) SetSyncedRecordCount(stream *ConfiguredStream, count int64) { | ||
| s.Lock() | ||
| defer s.Unlock() | ||
|
|
||
| index, contains := utils.ArrayContains(s.Streams, func(elem *StreamState) bool { | ||
| return elem.Namespace == stream.Namespace() && elem.Stream == stream.Name() | ||
| }) | ||
| if contains { | ||
| s.Streams[index].State.Store(SyncedRecordCountKey, count) | ||
| s.Streams[index].HoldsValue.Store(true) | ||
| } else { | ||
| newStream := s.initStreamState(stream) | ||
| newStream.State.Store(SyncedRecordCountKey, count) | ||
| newStream.HoldsValue.Store(true) | ||
| s.Streams = append(s.Streams, newStream) | ||
| } | ||
| s.LogState() | ||
| } | ||
|
|
||
| func (s *State) MarshalJSON() ([]byte, error) { | ||
| type Alias State | ||
| p := Alias(*s) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.