Commit 8097259
authored
Proto: make badger/v2 compatible with v1 (dgraph-io#1293)
There were two instances of init-time work being incompatible with v1.
That is, if one imported both v1 and v2 as part of a Go build, the
resulting binary would end up panicking before main could run. The
examples below are done with the latest versions of v1 and v2, and a
main.go as follows:
package main
import (
_ "github.com/dgraph-io/badger"
_ "github.com/dgraph-io/badger/v2"
)
func main() {}
First, the protobuf package used "pb" as its proto package name. This is
a problem, because types are registered globally with their fully
qualified names, like "pb.Foo". Since both badger/pb and badger/v2/pb
tried to globally register types with the same qualified names, we'd get
a panic:
$ go run .
panic: proto: duplicate enum registered: pb.ManifestChange_Operation
goroutine 1 [running]:
github.com/golang/protobuf/proto.RegisterEnum(...)
.../go/pkg/mod/github.com/golang/[email protected]/proto/properties.go:459
github.com/dgraph-io/badger/v2/pb.init.0()
.../badger/pb/pb.pb.go:638 +0x459
To fix this, make v2's proto package fully qualified. Since the
namespace is global, just "v2.pb" wouldn't suffice; it's not unique
enough. "dgraph.badger.v2.pb" seems good, since it follows the Go module
path pretty closely.
The second issue was with expvar, which too uses globally registered
names:
$ go run .
2020/04/08 22:59:20 Reuse of exported var name: badger_disk_reads_total
panic: Reuse of exported var name: badger_disk_reads_total
goroutine 1 [running]:
log.Panicln(0xc00010de48, 0x2, 0x2)
.../src/log/log.go:365 +0xac
expvar.Publish(0x906fcc, 0x17, 0x9946a0, 0xc0000b0318)
.../src/expvar/expvar.go:278 +0x267
expvar.NewInt(...)
.../src/expvar/expvar.go:298
github.com/dgraph-io/badger/v2/y.init.1()
.../badger/y/metrics.go:55 +0x65
exit status 2
This time, replacing the "badger_" var prefix with "badger_v2_" seems
like it's simple enough as a fix.
Fixes dgraph-io#1208.1 parent 2e708d9 commit 8097259
3 files changed
+74
-70
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
0 commit comments