-
Notifications
You must be signed in to change notification settings - Fork 839
Reprioritize responses of GetReplicationMessagesResponse in frontend #6696
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
Changes from all commits
a221a40
5e39bb2
5e5bdb8
a6a29ee
89e1fab
bd0ea32
9bcfbe1
2d4cabc
a513e6a
9724782
88fd67d
4ed552b
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 |
---|---|---|
|
@@ -305,6 +305,35 @@ func (v *GetReplicationMessagesResponse) GetMessagesByShard() (o map[int32]*Repl | |
return | ||
} | ||
|
||
// GetEarliestCreationTime returns the earliest creation time of replication tasks if it exists, otherwise return nil | ||
func (v *GetReplicationMessagesResponse) GetEarliestCreationTime() *int64 { | ||
if v == nil { | ||
return nil | ||
} | ||
Comment on lines
+310
to
+312
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 is very unusual to check for reciver-ptr == nil. Is there an expected code-path which continues if * GetReplicationMessagesResponse is nil and operates with it? 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. All other methods of the structure do the same check. I assume that the structure can be nil in this case. 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. Got it. Makes total sense for consistency. |
||
|
||
var earliestTime *int64 | ||
for _, messages := range v.MessagesByShard { | ||
|
||
creationTime := messages.GetEarliestCreationTime() | ||
if creationTime == nil { | ||
continue | ||
} | ||
|
||
if earliestTime == nil || *creationTime < *earliestTime { | ||
earliestTime = creationTime | ||
} | ||
} | ||
|
||
if earliestTime == nil { | ||
return nil | ||
} | ||
|
||
// avoid returning a pointer to the internal value | ||
// for immutability | ||
result := *earliestTime | ||
return &result | ||
} | ||
|
||
// HistoryTaskV2Attributes is an internal type (TBD...) | ||
type HistoryTaskV2Attributes struct { | ||
DomainID string `json:"domainId,omitempty"` | ||
|
@@ -592,6 +621,34 @@ func (v *ReplicationMessages) GetSyncShardStatus() (o *SyncShardStatus) { | |
return | ||
} | ||
|
||
// GetEarliestCreationTime returns the earliest message time in the replication tasks if it exists | ||
// otherwise return nil | ||
func (v *ReplicationMessages) GetEarliestCreationTime() *int64 { | ||
if v == nil { | ||
return nil | ||
} | ||
|
||
var earliestTime *int64 | ||
for _, task := range v.GetReplicationTasks() { | ||
if task.CreationTime == nil { | ||
continue | ||
} | ||
|
||
if earliestTime == nil || *task.CreationTime < *earliestTime { | ||
earliestTime = task.CreationTime | ||
} | ||
} | ||
|
||
if earliestTime == nil { | ||
return nil | ||
} | ||
|
||
// avoid returning a pointer to the internal value | ||
// for immutability | ||
result := *earliestTime | ||
return &result | ||
} | ||
|
||
// ReplicationTask is an internal type (TBD...) | ||
type ReplicationTask struct { | ||
TaskType *ReplicationTaskType `json:"taskType,omitempty"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the case when earliestCreationTime is nil?
If we often have this case, then shouldn't we sort randomly instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! As I understand from the code,
CreationTime
is initially non-pointer, but internally it changed to pointer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, in general, we do not expect nil-s and its more like precaution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we don't expect nil-s there, but want to be sure that a NPE will never happen