Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(233)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Issue 4388048: code review 4388048: net: sort records returned by LookupMX

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 9 months ago by cthom
Modified:
14 years, 9 months ago
Reviewers:
adg
CC:
rog, adg, rsc, golang-dev
Visibility:
Public.
net: sort records returned by LookupMX

Patch Set 1 #

Patch Set 2 : diff -r 4c6db3d9a715 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 4c6db3d9a715 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 4 : diff -r ffa7af487196 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r ffa7af487196 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r ffa7af487196 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 7 : diff -r ffa7af487196 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 8 : diff -r ffa7af487196 https://go.googlecode.com/hg/ #

Created: 14 years, 9 months ago
Download [raw] [tar.bz2]
Unified diffs Side-by-side diffs Delta from patch set Stats (+23 lines, -8 lines) Patch
M src/pkg/net/dnsclient.go View 1 2 3 4 5 6 7 2 chunks +23 lines, -8 lines 0 comments Download
Total messages: 13
|
cthom
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
14 years, 9 months ago (2011年04月11日 12:50:20 UTC) #1
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),
I'd like you to review this change to
https://go.googlecode.com/hg/ 
Sign in to reply to this message.
rog
http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go File src/pkg/net/dnsclient.go (right): http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go#newcode415 src/pkg/net/dnsclient.go:415: type mxslice []*MX YMMV, but if you wanted to ...
14 years, 9 months ago (2011年04月11日 13:33:57 UTC) #2
http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go
File src/pkg/net/dnsclient.go (right):
http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go#newc...
src/pkg/net/dnsclient.go:415: type mxslice []*MX
YMMV, but if you wanted to implement random ordering for objects with the same
preference, you do something like:
type mxrecords struct {
 mx []*MX
 perm []int
}
func (m *mxrecords) Less(i, j int) bool {
 if m.mx[i].Pref != m.mx[i].Pref {
 return m.mx[i].Pref < m.mx[j].Pref
 }
 return m.perm[i] < m.perm[j]
}
func (m *mxrecords) Swap(i, j int) {
 m.mx[i], m.mx[j] = m.mx[j], m.mx[i]
 m.perm[i], m.perm[j] = m.mx[j], m.mx[i]
}
func LookupMX(name string) (entries []*MX, err os.Error) {
 ...
 m := &mxrecords{entries, rand.Perm(len(entries))
 sort.Sort(m)
 return
}
this is a case where it would be nice to have rand.Shuffle - you could shuffle
consecutive sequences mx records with the same Pref, avoiding the need to
allocate a permutation array.
Sign in to reply to this message.
cthom
I was just reading the RFC, didn't realize the randomness was a MUST [sic], I ...
14 years, 9 months ago (2011年04月11日 13:52:10 UTC) #3
I was just reading the RFC, didn't realize the randomness was a MUST
[sic], I would've thought the "random" order the dns server sends them
would be sufficient. I'll adjust I suppose, but it does seem silly to
invest client-side code into load-balancing for the server.
On 11 April 2011 09:33, <rogpeppe@gmail.com> wrote:
>
> http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go
> File src/pkg/net/dnsclient.go (right):
>
>
http://codereview.appspot.com/4388048/diff/4001/src/pkg/net/dnsclient.go#newc...
> src/pkg/net/dnsclient.go:415: type mxslice []*MX
> YMMV, but if you wanted to implement random ordering for objects with
> the same preference, you do something like:
>
> type mxrecords struct {
> mx []*MX
> perm []int
> }
>
> func (m *mxrecords) Less(i, j int) bool {
>  if m.mx[i].Pref != m.mx[i].Pref {
>    return m.mx[i].Pref < m.mx[j].Pref
>  }
>  return m.perm[i] < m.perm[j]
> }
>
> func (m *mxrecords) Swap(i, j int) {
>  m.mx[i], m.mx[j] = m.mx[j], m.mx[i]
>  m.perm[i], m.perm[j] = m.mx[j], m.mx[i]
> }
>
> func LookupMX(name string) (entries []*MX, err os.Error) {
>  ...
>  m := &mxrecords{entries, rand.Perm(len(entries))
>  sort.Sort(m)
>  return
> }
>
> this is a case where it would be nice to have rand.Shuffle - you could
> shuffle consecutive sequences mx records with the same Pref, avoiding
> the need to allocate a permutation array.
>
> http://codereview.appspot.com/4388048/
>
Sign in to reply to this message.
cthom
Hello golang-dev@googlegroups.com, rog (cc: golang-dev@googlegroups.com), Please take another look.
14 years, 9 months ago (2011年04月11日 14:34:56 UTC) #4
Hello golang-dev@googlegroups.com, rog (cc: golang-dev@googlegroups.com),
Please take another look.
Sign in to reply to this message.
cthom
Hello golang-dev@googlegroups.com, rog (cc: golang-dev@googlegroups.com), Please take another look.
14 years, 9 months ago (2011年04月11日 14:36:04 UTC) #5
Hello golang-dev@googlegroups.com, rog (cc: golang-dev@googlegroups.com),
Please take another look.
Sign in to reply to this message.
adg
The code looks good, but I would like to see some simple test cases for ...
14 years, 9 months ago (2011年04月12日 01:09:09 UTC) #6
The code looks good, but I would like to see some simple test cases
for mxsorter.
Sign in to reply to this message.
rsc
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go File src/pkg/net/dnsclient.go (right): http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go#newcode414 src/pkg/net/dnsclient.go:414: // Implements sort.Interface This is working too hard. (I ...
14 years, 9 months ago (2011年04月12日 03:06:20 UTC) #7
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go
File src/pkg/net/dnsclient.go (right):
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go#newc...
src/pkg/net/dnsclient.go:414: // Implements sort.Interface
This is working too hard. (I know it's not your algorithm.)
type byPref []*MX
// usual methods, now 1/3 as long
func LookupMX(...) {
 ...
 // Shuffle.
 for i := range mx {
 j := rand.Intn(i+1)
 mx[i], mx[j] = mx[j], mx[i]
 }
 // Sort by preference.
 // Stays shuffled within equal preference.
 sort.Sort(byPref(mx))
}
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go#newc...
src/pkg/net/dnsclient.go:437: var records []dnsRR
While you're here,
s/records/rr/
s/entries/mx/
Sign in to reply to this message.
cthom
Changes made. Should I also include a test of byPref in this CL? i.e. func ...
14 years, 9 months ago (2011年04月12日 13:54:51 UTC) #8
Changes made.
Should I also include a test of byPref in this CL? i.e.
func TestMXPref(t *testing.T) {
	var mx1, mx2, mx3 []*MX
	mx1 = []*MX{
		&MX{"a", 5},
		&MX{"b", 5},
		&MX{"c", 5},
		&MX{"d", 5},
		&MX{"e", 5},
	}
	// Copied the shuffle here
	mx2 = append(mx2, mx1...)
	for i := range mx2 {
		j := rand.Intn(i+1)
		mx2[i], mx2[j] = mx2[j], mx2[i]
	}
	sort.Sort(byPref(mx2))
	// mx2 now holds a shuffled copy to check that shuffles are random
	mx3 = append(mx3, mx1...)
	for runs := 0; runs < 20; runs++ {
		for i := range mx3 {
			j := rand.Intn(i+1)
			mx3[i], mx3[j] = mx3[j], mx3[i]
		}
		sort.Sort(byPref(mx3))
		for i := range mx3 {
			if mx3[i] != mx2[i] && mx3[i] != mx1[i] {
				return
			}
		}
		copy(mx3, mx1)
	}
	t.Errorf("MX records don't get shuffled")
}
Or something, I don't have much experience writing test functions,
especially not for randomness, but honestly this seems more like a
test of rand and sort than anything, and it will fail something like 1
in every 19 sextillion builds.
On 11 April 2011 23:06, <rsc@golang.org> wrote:
>
> http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go
> File src/pkg/net/dnsclient.go (right):
>
>
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go#newc...
> src/pkg/net/dnsclient.go:414: // Implements sort.Interface
> This is working too hard. (I know it's not your algorithm.)
>
> type byPref []*MX
> // usual methods, now 1/3 as long
>
> func LookupMX(...) {
>  ...
>  // Shuffle.
>  for i := range mx {
>    j := rand.Intn(i+1)
>    mx[i], mx[j] = mx[j], mx[i]
>  }
>  // Sort by preference.
>  // Stays shuffled within equal preference.
>  sort.Sort(byPref(mx))
> }
>
>
http://codereview.appspot.com/4388048/diff/5002/src/pkg/net/dnsclient.go#newc...
> src/pkg/net/dnsclient.go:437: var records []dnsRR
> While you're here,
>
> s/records/rr/
> s/entries/mx/
>
> http://codereview.appspot.com/4388048/
>
Sign in to reply to this message.
rsc
Don't worry about a test. We don't have testing set up for any of the ...
14 years, 9 months ago (2011年04月12日 18:12:00 UTC) #9
Don't worry about a test. We don't have testing set up
for any of the DNS code, and it's going to get some
more work done on it soon anyway.
Russ
Sign in to reply to this message.
cthom
Hello rog, adg, rsc (cc: golang-dev@googlegroups.com), Please take another look.
14 years, 9 months ago (2011年04月12日 18:16:34 UTC) #10
Hello rog, adg, rsc (cc: golang-dev@googlegroups.com),
Please take another look.
Sign in to reply to this message.
adg
LGTM One last change. http://codereview.appspot.com/4388048/diff/6/src/pkg/net/dnsclient.go File src/pkg/net/dnsclient.go (right): http://codereview.appspot.com/4388048/diff/6/src/pkg/net/dnsclient.go#newcode414 src/pkg/net/dnsclient.go:414: // Implements sort.Interface by record ...
14 years, 9 months ago (2011年04月12日 23:41:10 UTC) #11
LGTM
One last change.
http://codereview.appspot.com/4388048/diff/6/src/pkg/net/dnsclient.go
File src/pkg/net/dnsclient.go (right):
http://codereview.appspot.com/4388048/diff/6/src/pkg/net/dnsclient.go#newcode414
src/pkg/net/dnsclient.go:414: // Implements sort.Interface by record preference
// byPref implements sort.Interface to sort MX records by preference
Sign in to reply to this message.
cthom
Hello rog, adg, rsc (cc: golang-dev@googlegroups.com), Please take another look.
14 years, 9 months ago (2011年04月13日 11:59:28 UTC) #12
Hello rog, adg, rsc (cc: golang-dev@googlegroups.com),
Please take another look.
Sign in to reply to this message.
adg
*** Submitted as http://code.google.com/p/go/source/detail?r=b353f61b9548 *** net: sort records returned by LookupMX R=rog, adg, rsc CC=golang-dev ...
14 years, 9 months ago (2011年04月14日 00:30:54 UTC) #13
*** Submitted as http://code.google.com/p/go/source/detail?r=b353f61b9548 ***
net: sort records returned by LookupMX
R=rog, adg, rsc
CC=golang-dev
http://codereview.appspot.com/4388048
Committer: Andrew Gerrand <adg@golang.org>
Sign in to reply to this message.
|
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /