Skip to content

Conversation

rychipman
Copy link
Collaborator

No description provided.

Connection() (Connection, error)
}

const UnsetRTT = -1 * time.Millisecond
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a time when the delay will be 0 nanoseconds? Can we just let 0 mean unset? That way we don't have to remember to set it to UnsetRTT everywhere?

Also, does this need to be exported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I had originally started with (because in real life there would be no way that should happen), but the rtt tests actually require the 0 is treated as a valid delay value distinct from 'NULL', which is why I made this change.

As far as exporting, I just exported because the AverageRTT() getter was exported, figuring that the two sort of go together.


desc = buildServerDesc(m.connectionOpts.Endpoint, isMasterResult, buildInfoResult)
desc.averageRTT = delay // TODO: actually calculate this properly
desc.updateAverageRTT(delay)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc here is brand new, so it's RTT will always be unset. You need to get this value from somewhere else... perhaps store it in the ServerMonitor itself. I don't think you'll need a lock for it since this method will never happen concurrently.

@rychipman
Copy link
Collaborator Author

Updated the patch to persist the averageRTT value in the ServerMonitor

Copy link
Collaborator

@craiggwilson craiggwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in addition to the inline comments, I think ServerDesc should be changed as follows such that we don't have to remember to set averageRTT all the time. First, add a field (averageRTTSet bool).
Second, have the AverageRTT() function return UnsetRTT when averageRTTSet is false, and return averageRTT otherwise. That way our zero value is still correct.


desc = buildServerDesc(m.connectionOpts.Endpoint, isMasterResult, buildInfoResult)
desc.updateAverageRTT(delay)
desc.updateAverageRTT(m.averageRTT, delay)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can read it here, just set it back here, where it gets calculated... no need to set it in a different place.

core/server.go Outdated
// given its most recent RTT value
func (d *ServerDesc) updateAverageRTT(delay time.Duration) {
if d.averageRTT == UnsetRTT {
func (d *ServerDesc) updateAverageRTT(averageRTT, delay time.Duration) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps pull this function out and put it somewhere else. At this point, there isn't any reason for it to be hanging off ServerDesc.

averageRTT: startingAverageRTT,
}
desc.updateAverageRTT(newRTT)
desc := ServerDesc{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the tests need to care about ServerDesc at all. How ServerDesc carries around the RTT value I think is of little concern to getting this calculation correct.


// updateAverageRTT calcuates the averageRTT of the server
// given its most recent RTT value
func (m *ServerMonitor) updateAverageRTT(delay time.Duration) time.Duration {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to make this a method on ServerMonitor, since that is where we are actually persisting the RTT

return d.version
}

func (d *ServerDesc) setAverageRTT(rtt time.Duration) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a helper here so we don't have to manually set averageRTTSet = true

@rychipman
Copy link
Collaborator Author

I went with your suggestion of a flag so that the zero values of all fields represent the unset state. Also moved the updateAverageRTT function to the monitor, because it seemed more appropriate there.

@rychipman rychipman closed this Feb 9, 2017
edaniels referenced this pull request in edaniels/mongo-go-driver Feb 10, 2020
joyjwang added a commit to joyjwang/mongo-go-driver that referenced this pull request Oct 2, 2024
# This is the 1st commit message:

test

# This is the commit message mongodb#2:

test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants