Skip to content

Commit

Permalink
WIP: migrate github.com/spaolacci/murmur3 to github.com/twmb/murmur3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmains12 committed Aug 17, 2020
1 parent c762030 commit 0052f04
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ require (
github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25 // indirect
github.com/stretchr/testify v1.4.0
github.com/subosito/gotenv v1.2.1-0.20190917103637-de67a6614a4d // indirect
github.com/twmb/murmur3 v1.1.3
github.com/twotwotwo/sorts v0.0.0-20160814051341-bf5c1f2b8553
github.com/uber-go/atomic v0.0.0-00010101000000-000000000000 // indirect
github.com/uber-go/tally v3.3.13+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKw
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/twmb/murmur3 v1.1.3 h1:D83U0XYKcHRYwYIpBKf3Pks91Z0Byda/9SJ8B6EMRcA=
github.com/twmb/murmur3 v1.1.3/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/twotwotwo/sorts v0.0.0-20160814051341-bf5c1f2b8553 h1:DRC1ubdb3ZmyyIeCSTxjZIQAnpLPfKVgYrLETQuOPjo=
github.com/twotwotwo/sorts v0.0.0-20160814051341-bf5c1f2b8553/go.mod h1:Rj7Csq/tZ/egz+Ltc2IVpsA5309AmSMEswjkTZmq2Xc=
github.com/uber-go/tally v3.3.13+incompatible h1:5ic2UsDwjcWsw9jvEdWEE2XsmGCLMTt5Ukg4d74fed4=
Expand Down
2 changes: 1 addition & 1 deletion src/aggregator/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// were added.
package hash

import "github.com/spaolacci/murmur3"
import "github.com/twmb/murmur3"

// Hash128 is a 128-bit hash of an ID consisting of two unsigned 64-bit ints.
type Hash128 [2]uint64
Expand Down
2 changes: 1 addition & 1 deletion src/aggregator/sharding/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/m3db/m3/src/metrics/metric/id"

"github.com/spaolacci/murmur3"
"github.com/twmb/murmur3"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion src/dbnode/client/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/m3db/m3/src/dbnode/topology"
xclose "github.com/m3db/m3/src/x/close"

"github.com/spaolacci/murmur3"
"github.com/twmb/murmur3"
"github.com/uber/tchannel-go/thrift"
"go.uber.org/zap"
)
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions src/dbnode/sharding/murmur3test/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Package murmur3test contains some tests for converting github.com/spaolacci/murmur3 to
// github.com/twmb/murmur3.
package murmur3test
96 changes: 96 additions & 0 deletions src/dbnode/sharding/murmur3test/murmur3_lib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package murmur3test

import (
"testing"

"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
spaolaccimurmur3 "github.com/spaolacci/murmur3"
twmbmurmur3 "github.com/twmb/murmur3"
)

func TestMurmurSum32(t *testing.T) {
properties := gopter.NewProperties(newGopterTestParameters())
properties.Property("twmb matches spaolacci", prop.ForAll(
func(v []byte) bool {
return twmbmurmur3.Sum32(v) == spaolaccimurmur3.Sum32(v)
},
newByteGen(),
))

properties.TestingRun(t)
}

func TestMurmurSum128(t *testing.T) {
properties := gopter.NewProperties(newGopterTestParameters())
properties.Property("twmb matches spaolacci", prop.ForAll(
func(v []byte) bool {
twmbH1, twmbH2 := twmbmurmur3.Sum128(v)
spH1, spH2 := spaolaccimurmur3.Sum128(v)
return spH1 == twmbH1 && spH2 == twmbH2
},
newByteGen(),
))

properties.TestingRun(t)
}

func TestMurmurSeedSum32(t *testing.T) {
properties := gopter.NewProperties(newGopterTestParameters())
properties.Property("twmb matches spaolacci", prop.ForAll(
func(seed uint32, data []byte) bool {
return twmbmurmur3.SeedSum32(seed, data) == spaolaccimurmur3.Sum32WithSeed(data, seed)
},
gen.UInt32(),
newByteGen(),
))

properties.TestingRun(t)
}

func newGopterTestParameters() *gopter.TestParameters {
params := gopter.DefaultTestParameters()
params.MinSuccessfulTests = 100000

return params
}

// newByteGen returns a gopter generator for an []byte. All bytes (not just valid UTF-8) are generated.
func newByteGen() gopter.Gen {
// uint8 == byte; therefore, derive []byte generator from []uint8 generator.
return gopter.DeriveGen(func(v []uint8) []byte {
out := make([]byte, len(v))
for i, val := range v {
out[i] = val
}
return out
}, func(v []byte) []uint8 {
out := make([]byte, len(v))
for i, val := range v {
out[i] = val
}
return out
}, gen.SliceOf(gen.UInt8()))
}

5 changes: 2 additions & 3 deletions src/dbnode/sharding/shardset.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (

"github.com/m3db/m3/src/cluster/shard"
"github.com/m3db/m3/src/x/ident"

"github.com/spaolacci/murmur3"
twmbmurmur3 "github.com/twmb/murmur3"
)

var (
Expand Down Expand Up @@ -161,6 +160,6 @@ func NewHashGenWithSeed(seed uint32) HashGen {
// NewHashFn generates a HashFN based on murmur32 with a given seed
func NewHashFn(length int, seed uint32) HashFn {
return func(id ident.ID) uint32 {
return murmur3.Sum32WithSeed(id.Bytes(), seed) % uint32(length)
return twmbmurmur3.SeedSum32(seed, id.Bytes()) % uint32(length)
}
}
1 change: 0 additions & 1 deletion src/dbnode/sharding/shardset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/m3db/m3/src/cluster/shard"
"github.com/m3db/m3/src/x/ident"

"github.com/stretchr/testify/require"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
"github.com/spaolacci/murmur3"
"github.com/twmb/murmur3"
"github.com/stretchr/testify/require"
)

Expand Down

0 comments on commit 0052f04

Please sign in to comment.