-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Support "near" parameter in prepared query service block #2137
Changes from all commits
3797e65
865c264
100a467
4c1afb1
03fea4b
d567d6a
c457ee0
0c2ad07
104b234
62884a2
00819e8
7fd0c3c
01b28b9
46b6726
2b24644
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 |
---|---|---|
|
@@ -368,7 +368,25 @@ func (p *PreparedQuery) Execute(args *structs.PreparedQueryExecuteRequest, | |
// Shuffle the results in case coordinates are not available if they | ||
// requested an RTT sort. | ||
reply.Nodes.Shuffle() | ||
if err := p.srv.sortNodesByDistanceFrom(args.Source, reply.Nodes); err != nil { | ||
|
||
// Build the query source. This can be provided by the client, or by | ||
// the prepared query. Client-specified takes priority. | ||
qs := args.Source | ||
if qs.Datacenter == "" { | ||
qs.Datacenter = args.Agent.Datacenter | ||
} | ||
if query.Service.Near != "" && qs.Node == "" { | ||
qs.Node = query.Service.Near | ||
} | ||
|
||
// Respect the magic "_agent" flag. | ||
if qs.Node == "_agent" { | ||
qs.Node = args.Agent.Node | ||
} | ||
|
||
// Perform the distance sort | ||
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. Do we want to memoize this value for ~60s or whatever the interval is for the tomography calcs? I seem to recall someone saying this calc was "expensive," but if it's not, disregard. DNS can set a TTL, so maybe this isn't a huge issue, but that depends on the level of DNS caching at a given site. 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. It's not too bad - I'd probably leave as-is since this can be DNS TTL-ed and read-scaled with staleness across the servers. |
||
err = p.srv.sortNodesByDistanceFrom(qs, reply.Nodes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
|
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.
DC should always be supplied by
parseDC
but this is fine and defensive.