mirror of
https://github.com/luxfi/zapdb.git
synced 2026-10-30 15:12:20 +00:00
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 #1208.
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
/*
|
|
* Copyright (C) 2017 Dgraph Labs, Inc. and Contributors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package y
|
|
|
|
import "expvar"
|
|
|
|
var (
|
|
// LSMSize has size of the LSM in bytes
|
|
LSMSize *expvar.Map
|
|
// VlogSize has size of the value log in bytes
|
|
VlogSize *expvar.Map
|
|
// PendingWrites tracks the number of pending writes.
|
|
PendingWrites *expvar.Map
|
|
|
|
// These are cumulative
|
|
|
|
// NumReads has cumulative number of reads
|
|
NumReads *expvar.Int
|
|
// NumWrites has cumulative number of writes
|
|
NumWrites *expvar.Int
|
|
// NumBytesRead has cumulative number of bytes read
|
|
NumBytesRead *expvar.Int
|
|
// NumBytesWritten has cumulative number of bytes written
|
|
NumBytesWritten *expvar.Int
|
|
// NumLSMGets is number of LMS gets
|
|
NumLSMGets *expvar.Map
|
|
// NumLSMBloomHits is number of LMS bloom hits
|
|
NumLSMBloomHits *expvar.Map
|
|
// NumGets is number of gets
|
|
NumGets *expvar.Int
|
|
// NumPuts is number of puts
|
|
NumPuts *expvar.Int
|
|
// NumBlockedPuts is number of blocked puts
|
|
NumBlockedPuts *expvar.Int
|
|
// NumMemtableGets is number of memtable gets
|
|
NumMemtableGets *expvar.Int
|
|
)
|
|
|
|
// These variables are global and have cumulative values for all kv stores.
|
|
func init() {
|
|
NumReads = expvar.NewInt("badger_v2_disk_reads_total")
|
|
NumWrites = expvar.NewInt("badger_v2_disk_writes_total")
|
|
NumBytesRead = expvar.NewInt("badger_v2_read_bytes")
|
|
NumBytesWritten = expvar.NewInt("badger_v2_written_bytes")
|
|
NumLSMGets = expvar.NewMap("badger_v2_lsm_level_gets_total")
|
|
NumLSMBloomHits = expvar.NewMap("badger_v2_lsm_bloom_hits_total")
|
|
NumGets = expvar.NewInt("badger_v2_gets_total")
|
|
NumPuts = expvar.NewInt("badger_v2_puts_total")
|
|
NumBlockedPuts = expvar.NewInt("badger_v2_blocked_puts_total")
|
|
NumMemtableGets = expvar.NewInt("badger_v2_memtable_gets_total")
|
|
LSMSize = expvar.NewMap("badger_v2_lsm_size_bytes")
|
|
VlogSize = expvar.NewMap("badger_v2_vlog_size_bytes")
|
|
PendingWrites = expvar.NewMap("badger_v2_pending_writes_total")
|
|
}
|