Repository: dgraph-io/badger
Pull request #1519 (2020-09-14 16:37:38)

pb: avoid protobuf warning due to common filename
If a Go program imports both badger (v1) and badger/v2, a warning will
be produced at init time:

	WARNING: proto: file "pb.proto" is already registered
	A future release will panic on registration conflicts. See:
	https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

The problem is the "pb.proto" filename; it's registered globally, which
makes it very likely to cause conflicts with other protobuf-generated
packages in a Go binary.

Coincidentally, this is a problem with badger's pb package in the v1 module,
since that too uses the name "pb.proto". Instead, call the file
"badgerpb2.proto", which should be unique enough, and it's also the name
we use for the Protobuf package.

Finally, update gen.sh to work out of the box via just "bash gen.sh"
without needing extra tweaks, thanks to the "paths=source_relative"
option. It forces output files to be produced next to the input files,
which is what we want.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dgraph-io/badger/1519)
<!-- Reviewable:end -->


mvdan: The alternative was to use subdirectories as part of the filename, like `pb/badger/v2.proto` or something like that. I personally find the method in this PR a little easier, since there are less directories to mess with.

Patch:
diff --git a/README.md b/README.md
index 5dd1b82..26c75a9 100644
--- a/README.md
+++ b/README.md
@@ -188,6 +188,7 @@ Below is a list of known projects that use Badger:
 * [Cete](https://github.com/mosuka/cete) - Simple and highly available distributed key-value store built on Badger. Makes it easy bringing up a cluster of Badger with Raft consensus algorithm by hashicorp/raft. 
 * [Volument](https://volument.com/) - A new take on website analytics backed by Badger.
 * [KVdb](https://kvdb.io/) - Hosted key-value store and serverless platform built on top of Badger.
+* [Terminotes] (https://gitlab.com/asad-awadia/terminotes) - Self hosted notes storage and search server - storage powered by BadgerDB
 
 If you are using Badger in a project please send a pull request to add it to the list.
 
diff --git a/badger/cmd/flatten.go b/badger/cmd/flatten.go
index 1882cb9..e1259f7 100644
--- a/badger/cmd/flatten.go
+++ b/badger/cmd/flatten.go
@@ -17,6 +17,9 @@
 package cmd
 
 import (
+	"fmt"
+	"math"
+
 	"github.com/dgraph-io/badger/v2"
 	"github.com/spf13/cobra"
 )
@@ -37,13 +40,23 @@ func init() {
 	flattenCmd.Flags().IntVarP(&numWorkers, "num-workers", "w", 1,
 		"Number of concurrent compactors to run. More compactors would use more"+
 			" server resources to potentially achieve faster compactions.")
+	flattenCmd.Flags().IntVarP(&numVersions, "num_versions", "", 1,
+		"Option to configure the maximum number of versions per key. "+
+			"Values <= 0 will be considered to have the max number of versions.")
 }
 
 func flatten(cmd *cobra.Command, args []string) error {
-	db, err := badger.Open(badger.DefaultOptions(sstDir).
+	if numVersions <= 0 {
+		// Keep all versions.
+		numVersions = math.MaxInt32
+	}
+	opt := badger.DefaultOptions(sstDir).
 		WithValueDir(vlogDir).
 		WithTruncate(truncate).
-		WithNumCompactors(0))
+		WithNumVersionsToKeep(numVersions).
+		WithNumCompactors(0)
+	fmt.Printf("Opening badger with options = %+v\n", opt)
+	db, err := badger.Open(opt)
 	if err != nil {
 		return err
 	}
diff --git a/db.go b/db.go
index 04c534b..53b39ae 100644
--- a/db.go
+++ b/db.go
@@ -193,43 +193,42 @@ func (db *DB) replayFunction() func(Entry, valuePointer) error {
 	}
 }
 
-// Open returns a new DB object.
-func Open(opt Options) (db *DB, err error) {
+func checkAndSetOptions(opt *Options) error {
 	// It's okay to have zero compactors which will disable all compactions but
 	// we cannot have just one compactor otherwise we will end up with all data
 	// on level 2.
 	if opt.NumCompactors == 1 {
-		return nil, errors.New("Cannot have 1 compactor. Need at least 2")
+		return errors.New("Cannot have 1 compactor. Need at least 2")
 	}
 	if opt.InMemory && (opt.Dir != "" || opt.ValueDir != "") {
-		return nil, errors.New("Cannot use badger in Disk-less mode with Dir or ValueDir set")
+		return errors.New("Cannot use badger in Disk-less mode with Dir or ValueDir set")
 	}
 	opt.maxBatchSize = (15 * opt.MaxTableSize) / 100
 	opt.maxBatchCount = opt.maxBatchSize / int64(skl.MaxNodeSize)
 
 	// We are limiting opt.ValueThreshold to maxValueThreshold for now.
 	if opt.ValueThreshold > maxValueThreshold {
-		return nil, errors.Errorf("Invalid ValueThreshold, must be less or equal to %d",
+		return errors.Errorf("Invalid ValueThreshold, must be less or equal to %d",
 			maxValueThreshold)
 	}
 
 	// If ValueThreshold is greater than opt.maxBatchSize, we won't be able to push any data using
 	// the transaction APIs. Transaction batches entries into batches of size opt.maxBatchSize.
 	if int64(opt.ValueThreshold) > opt.maxBatchSize {
-		return nil, errors.Errorf("Valuethreshold greater than max batch size of %d. Either "+
+		return errors.Errorf("Valuethreshold greater than max batch size of %d. Either "+
 			"reduce opt.ValueThreshold or increase opt.MaxTableSize.", opt.maxBatchSize)
 	}
 	if !(opt.ValueLogFileSize <= 2<<30 && opt.ValueLogFileSize >= 1<<20) {
-		return nil, ErrValueLogSize
+		return ErrValueLogSize
 	}
 	if !(opt.ValueLogLoadingMode == options.FileIO ||
 		opt.ValueLogLoadingMode == options.MemoryMap) {
-		return nil, ErrInvalidLoadingMode
+		return ErrInvalidLoadingMode
 	}
 
 	// Return error if badger is built without cgo and compression is set to ZSTD.
 	if opt.Compression == options.ZSTD && !y.CgoEnabled {
-		return nil, y.ErrZstdCgo
+		return y.ErrZstdCgo
 	}
 	// Keep L0 in memory if either KeepL0InMemory is set or if InMemory is set.
 	opt.KeepL0InMemory = opt.KeepL0InMemory || opt.InMemory
@@ -244,6 +243,20 @@ func Open(opt Options) (db *DB, err error) {
 		// Do not perform compaction in read only mode.
 		opt.CompactL0OnClose = false
 	}
+
+	needCache := (opt.Compression != options.None) || (len(opt.EncryptionKey) > 0)
+	if needCache && opt.BlockCacheSize == 0 {
+		opt.Warningf("BlockCacheSize should be set " +
+			"since compression/encryption are enabled")
+	}
+	return nil
+}
+
+// Open returns a new DB object.
+func Open(opt Options) (db *DB, err error) {
+	if err := checkAndSetOptions(&opt); err != nil {
+		return nil, err
+	}
 	var dirLockGuard, valueDirLockGuard *directoryLockGuard
 
 	// Create directories and acquire lock on it only if badger is not running in InMemory mode.
@@ -380,18 +393,8 @@ func Open(opt Options) (db *DB, err error) {
 			_ = db.flushMemtable(db.closers.memtable) // Need levels controller to be up.
 		}()
 	}
-
-	headKey := y.KeyWithTs(head, math.MaxUint64)
-	// Need to pass with timestamp, lsm get removes the last 8 bytes and compares key
-	vs, err := db.get(headKey)
-	if err != nil {
-		return db, errors.Wrap(err, "Retrieving head")
-	}
-	db.orc.nextTxnTs = vs.Version
-	var vptr valuePointer
-	if len(vs.Value) > 0 {
-		vptr.Decode(vs.Value)
-	}
+	vptr, version := db.getHead()
+	db.orc.nextTxnTs = version
 
 	replayCloser := z.NewCloser(1)
 	go db.doWrites(replayCloser)
@@ -427,6 +430,54 @@ func Open(opt Options) (db *DB, err error) {
 	return db, nil
 }
 
+// getHead prints all the head pointer in the DB and return the max value.
+func (db *DB) getHead() (valuePointer, uint64) {
+	// This is a hack. If we use newTransaction(..) we'll end up in deadlock
+	// since txnmark is not initialized when this function is called.
+	txn := Txn{
+		db:     db,
+		readTs: math.MaxUint64, // Show all versions.
+	}
+	var vptr valuePointer
+	iopt := DefaultIteratorOptions
+	iopt.AllVersions = true
+	iopt.InternalAccess = true
+	// Do not prefetch values. This could cause a race condition since
+	// prefetching is done via goroutines.
+	iopt.PrefetchValues = false
+	iopt.Reverse = true
+
+	it := txn.NewKeyIterator(head, iopt)
+	defer it.Close()
+
+	it.Rewind()
+	if !it.Valid() {
+		db.opt.Infof("No head keys found")
+		return vptr, 0
+	}
+
+	var maxVersion uint64
+	db.opt.Infof("Found the following head pointers")
+	for ; it.Valid(); it.Next() {
+		item := it.Item()
+		err := item.Value(func(val []byte) error {
+			vptr.Decode(val)
+			db.opt.Infof("Fid: %d Len: %d Offset: %d Version: %d\n",
+				vptr.Fid, vptr.Len, vptr.Offset, item.Version())
+			return nil
+		})
+		// This shouldn't happen.
+		y.Check(err)
+		// We're iterating in the reverse order so the last item would be the
+		// one with the biggest version.
+		maxVersion = item.Version()
+	}
+	// If we have reached here it means there were some head key and so the
+	// version should never be zero.
+	y.AssertTrue(maxVersion != 0)
+	return vptr, maxVersion
+}
+
 // cleanup stops all the goroutines started by badger. This is used in open to
 // cleanup goroutines in case of an error.
 func (db *DB) cleanup() {
@@ -1821,3 +1872,37 @@ func (db *DB) StreamDB(outOptions Options) error {
 	}
 	return nil
 }
+
+// Opts returns a copy of the DB options.
+func (db *DB) Opts() Options {
+	return db.opt
+}
+
+// MaxVersion returns the maximum commited version across all keys in the DB. It
+// uses the stream framework to find the maximum version.
+func (db *DB) MaxVersion() (uint64, error) {
+	maxVersion := uint64(0)
+	var mu sync.Mutex
+	var stream *Stream
+	if db.opt.managedTxns {
+		stream = db.NewStreamAt(math.MaxUint64)
+	} else {
+		stream = db.NewStream()
+	}
+
+	stream.ChooseKey = func(item *Item) bool {
+		mu.Lock()
+		if item.Version() > maxVersion {
+			maxVersion = item.Version()
+		}
+		mu.Unlock()
+		return false
+	}
+	stream.KeyToList = nil
+	stream.Send = nil
+	if err := stream.Orchestrate(context.Background()); err != nil {
+		return 0, err
+	}
+	return maxVersion, nil
+
+}
diff --git a/iterator.go b/iterator.go
index 11d0c27..2df066e 100644
--- a/iterator.go
+++ b/iterator.go
@@ -41,20 +41,21 @@ const (
 // Item is returned during iteration. Both the Key() and Value() output is only valid until
 // iterator.Next() is called.
 type Item struct {
-	status    prefetchStatus
-	err       error
-	wg        sync.WaitGroup
-	db        *DB
 	key       []byte
 	vptr      []byte
-	meta      byte // We need to store meta to know about bitValuePointer.
-	userMeta  byte
-	expiresAt uint64
 	val       []byte
-	slice     *y.Slice // Used only during prefetching.
-	next      *Item
 	version   uint64
-	txn       *Txn
+	expiresAt uint64
+
+	slice *y.Slice // Used only during prefetching.
+	next  *Item
+	txn   *Txn
+
+	err      error
+	wg       sync.WaitGroup
+	status   prefetchStatus
+	meta     byte // We need to store meta to know about bitValuePointer.
+	userMeta byte
 }
 
 // String returns a string representation of Item
@@ -167,10 +168,11 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
 
 		var vp valuePointer
 		vp.Decode(item.vptr)
-		result, cb, err := item.db.vlog.Read(vp, item.slice)
+		db := item.txn.db
+		result, cb, err := db.vlog.Read(vp, item.slice)
 		if err != ErrRetry {
 			if err != nil {
-				item.db.opt.Logger.Errorf(`Unable to read: Key: %v, Version : %v,
+				db.opt.Logger.Errorf(`Unable to read: Key: %v, Version : %v,
 				meta: %v, userMeta: %v`, key, item.version, item.meta, item.userMeta)
 			}
 			return result, cb, err
@@ -194,7 +196,7 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
 		// change the key user sees before and after this call. Also, this move
 		// logic is internal logic and should not impact the external behavior
 		// of the retrieval.
-		vs, err := item.db.get(key)
+		vs, err := item.txn.db.get(key)
 		if err != nil {
 			return nil, nil, err
 		}
@@ -226,7 +228,7 @@ func (item *Item) prefetchValue() {
 	if val == nil {
 		return
 	}
-	if item.db.opt.ValueLogLoadingMode == options.MemoryMap {
+	if item.txn.db.opt.ValueLogLoadingMode == options.MemoryMap {
 		buf := item.slice.Resize(len(val))
 		copy(buf, val)
 		item.val = buf
@@ -329,20 +331,21 @@ func (l *list) pop() *Item {
 // should work for most applications. Consider using that as a starting point
 // before customizing it for your own needs.
 type IteratorOptions struct {
-	// Indicates whether we should prefetch values during iteration and store them.
-	PrefetchValues bool
-	// How many KV pairs to prefetch while iterating. Valid only if PrefetchValues is true.
+	// PrefetchSize is the number of KV pairs to prefetch while iterating.
+	// Valid only if PrefetchValues is true.
 	PrefetchSize int
-	Reverse      bool // Direction of iteration. False is forward, true is backward.
-	AllVersions  bool // Fetch all valid versions of the same key.
+	// PrefetchValues Indicates whether we should prefetch values during
+	// iteration and store them.
+	PrefetchValues bool
+	Reverse        bool // Direction of iteration. False is forward, true is backward.
+	AllVersions    bool // Fetch all valid versions of the same key.
+	InternalAccess bool // Used to allow internal access to badger keys.
 
-	// The following option is used to narrow down the SSTables that iterator picks up. If
-	// Prefix is specified, only tables which could have this prefix are picked based on their range
-	// of keys.
-	Prefix      []byte // Only iterate over this given prefix.
+	// The following option is used to narrow down the SSTables that iterator
+	// picks up. If Prefix is specified, only tables which could have this
+	// prefix are picked based on their range of keys.
 	prefixIsKey bool   // If set, use the prefix for bloom filter lookup.
-
-	InternalAccess bool // Used to allow internal access to badger keys.
+	Prefix      []byte // Only iterate over this given prefix.
 }
 
 func (opt *IteratorOptions) compareToPrefix(key []byte) int {
@@ -505,7 +508,7 @@ func (txn *Txn) NewKeyIterator(key []byte, opt IteratorOptions) *Iterator {
 func (it *Iterator) newItem() *Item {
 	item := it.waste.pop()
 	if item == nil {
-		item = &Item{slice: new(y.Slice), db: it.txn.db, txn: it.txn}
+		item = &Item{slice: new(y.Slice), txn: it.txn}
 	}
 	return item
 }
diff --git a/pb/pb.pb.go b/pb/badgerpb2.pb.go
similarity index 81%
rename from pb/pb.pb.go
rename to pb/badgerpb2.pb.go
index 0d6fde3..edacec7 100644
--- a/pb/pb.pb.go
+++ b/pb/badgerpb2.pb.go
@@ -1,5 +1,5 @@
 // Code generated by protoc-gen-gogo. DO NOT EDIT.
-// source: pb.proto
+// source: badgerpb2.proto
 
 package pb
 
@@ -41,7 +41,7 @@ func (x EncryptionAlgo) String() string {
 }
 
 func (EncryptionAlgo) EnumDescriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{0}
+	return fileDescriptor_e63e84f9f0d3998c, []int{0}
 }
 
 type ManifestChange_Operation int32
@@ -66,7 +66,7 @@ func (x ManifestChange_Operation) String() string {
 }
 
 func (ManifestChange_Operation) EnumDescriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{3, 0}
+	return fileDescriptor_e63e84f9f0d3998c, []int{3, 0}
 }
 
 type Checksum_Algorithm int32
@@ -91,7 +91,7 @@ func (x Checksum_Algorithm) String() string {
 }
 
 func (Checksum_Algorithm) EnumDescriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{6, 0}
+	return fileDescriptor_e63e84f9f0d3998c, []int{6, 0}
 }
 
 type KV struct {
@@ -114,7 +114,7 @@ func (m *KV) Reset()         { *m = KV{} }
 func (m *KV) String() string { return proto.CompactTextString(m) }
 func (*KV) ProtoMessage()    {}
 func (*KV) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{0}
+	return fileDescriptor_e63e84f9f0d3998c, []int{0}
 }
 func (m *KV) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -210,7 +210,7 @@ func (m *KVList) Reset()         { *m = KVList{} }
 func (m *KVList) String() string { return proto.CompactTextString(m) }
 func (*KVList) ProtoMessage()    {}
 func (*KVList) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{1}
+	return fileDescriptor_e63e84f9f0d3998c, []int{1}
 }
 func (m *KVList) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -258,7 +258,7 @@ func (m *ManifestChangeSet) Reset()         { *m = ManifestChangeSet{} }
 func (m *ManifestChangeSet) String() string { return proto.CompactTextString(m) }
 func (*ManifestChangeSet) ProtoMessage()    {}
 func (*ManifestChangeSet) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{2}
+	return fileDescriptor_e63e84f9f0d3998c, []int{2}
 }
 func (m *ManifestChangeSet) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -310,7 +310,7 @@ func (m *ManifestChange) Reset()         { *m = ManifestChange{} }
 func (m *ManifestChange) String() string { return proto.CompactTextString(m) }
 func (*ManifestChange) ProtoMessage()    {}
 func (*ManifestChange) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{3}
+	return fileDescriptor_e63e84f9f0d3998c, []int{3}
 }
 func (m *ManifestChange) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -394,7 +394,7 @@ func (m *BlockOffset) Reset()         { *m = BlockOffset{} }
 func (m *BlockOffset) String() string { return proto.CompactTextString(m) }
 func (*BlockOffset) ProtoMessage()    {}
 func (*BlockOffset) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{4}
+	return fileDescriptor_e63e84f9f0d3998c, []int{4}
 }
 func (m *BlockOffset) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -457,7 +457,7 @@ func (m *TableIndex) Reset()         { *m = TableIndex{} }
 func (m *TableIndex) String() string { return proto.CompactTextString(m) }
 func (*TableIndex) ProtoMessage()    {}
 func (*TableIndex) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{5}
+	return fileDescriptor_e63e84f9f0d3998c, []int{5}
 }
 func (m *TableIndex) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -519,7 +519,7 @@ func (m *Checksum) Reset()         { *m = Checksum{} }
 func (m *Checksum) String() string { return proto.CompactTextString(m) }
 func (*Checksum) ProtoMessage()    {}
 func (*Checksum) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{6}
+	return fileDescriptor_e63e84f9f0d3998c, []int{6}
 }
 func (m *Checksum) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -576,7 +576,7 @@ func (m *DataKey) Reset()         { *m = DataKey{} }
 func (m *DataKey) String() string { return proto.CompactTextString(m) }
 func (*DataKey) ProtoMessage()    {}
 func (*DataKey) Descriptor() ([]byte, []int) {
-	return fileDescriptor_f80abaa17e25ccc8, []int{7}
+	return fileDescriptor_e63e84f9f0d3998c, []int{7}
 }
 func (m *DataKey) XXX_Unmarshal(b []byte) error {
 	return m.Unmarshal(b)
@@ -647,54 +647,54 @@ func init() {
 	proto.RegisterType((*DataKey)(nil), "badgerpb2.DataKey")
 }
 
-func init() { proto.RegisterFile("pb.proto", fileDescriptor_f80abaa17e25ccc8) }
-
-var fileDescriptor_f80abaa17e25ccc8 = []byte{
-	// 691 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x54, 0xdd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 0x5e, 0x0e, 0x7a, 0xdd, 0x41, 0x3d, 0x47,
-	0x0e, 0xa1, 0xf4, 0xf0, 0x70, 0xc5, 0xf8, 0xe2, 0xc3, 0xfb, 0xba, 0x62, 0x58, 0x50, 0xbc, 0x64,
-	0x82, 0x8d, 0x71, 0xbd, 0x33, 0x7a, 0x65, 0x77, 0xf4, 0x04, 0x34, 0x9b, 0x09, 0x96, 0x69, 0x93,
-	0x71, 0xb2, 0x80, 0x4e, 0x9c, 0x7d, 0xa7, 0xaa, 0x13, 0x27, 0xdf, 0xa1, 0x15, 0xa1, 0x94, 0xc8,
-	0x84, 0xdc, 0x9c, 0x3c, 0x2d, 0x67, 0x48, 0x5f, 0xbc, 0x3e, 0x86, 0xda, 0xfe, 0x6e, 0x90, 0x22,
-	0xe4, 0x19, 0xf2, 0x7a, 0xee, 0xa2, 0xf7, 0xed, 0xb9, 0xa1, 0x7c, 0x7f, 0x6e, 0x28, 0x3f, 0x9f,
-	0x1b, 0xca, 0xd7, 0x5f, 0x8d, 0xdc, 0xa7, 0xd3, 0xb9, 0x23, 0x16, 0x2b, 0xb3, 0x6d, 0x05, 0x5e,
-	0xc7, 0x9e, 0x47, 0x2c, 0x5c, 0xbc, 0x71, 0x82, 0x4e, 0xea, 0x41, 0x27, 0xee, 0x76, 0x42, 0xd3,
-	0x2c, 0xc8, 0xdf, 0x4d, 0xef, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3a, 0xcd, 0x7e, 0xad, 0x7a,
-	0x04, 0x00, 0x00,
+func init() { proto.RegisterFile("badgerpb2.proto", fileDescriptor_e63e84f9f0d3998c) }
+
+var fileDescriptor_e63e84f9f0d3998c = []byte{
+	// 689 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x54, 0xcd, 0x6e, 0xda, 0x40,
+	0x10, 0xc6, 0xc6, 0xe1, 0x67, 0x08, 0x84, 0xae, 0xda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x13, 0xf2, 0x17, 0x4c, 0xb0, 0x21,
+	0xae, 0xb6, 0x46, 0xaf, 0x6c, 0x8f, 0x9e, 0x80, 0x66, 0x31, 0xc1, 0x52, 0x6d, 0x32, 0x8e, 0x17,
+	0xd0, 0x8e, 0xd2, 0xef, 0x54, 0xb5, 0xa3, 0xf8, 0x3b, 0x34, 0x43, 0x94, 0x12, 0x99, 0x90, 0x9b,
+	0x93, 0xa5, 0xc5, 0x14, 0xe9, 0x8a, 0x37, 0x47, 0x50, 0xd9, 0xdd, 0x0d, 0x92, 0x87, 0x2c, 0x43,
+	0x5e, 0xcd, 0x9c, 0x77, 0xbe, 0x3f, 0xd5, 0x94, 0x1f, 0x4f, 0x35, 0xe5, 0xd7, 0x53, 0x4d, 0xf9,
+	0xf6, 0xbb, 0x96, 0xf9, 0x7c, 0x32, 0xb3, 0xc5, 0x7c, 0x39, 0x69, 0x9a, 0xbe, 0xdb, 0xb2, 0x66,
+	0x21, 0x0b, 0xe6, 0x6f, 0x6d, 0xbf, 0x95, 0x78, 0xd0, 0x8a, 0xda, 0xad, 0x60, 0x32, 0xc9, 0xc9,
+	0xdf, 0x4d, 0xe7, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x88, 0x22, 0x82, 0x98, 0x81, 0x04, 0x00,
+	0x00,
 }
 
 func (m *KV) Marshal() (dAtA []byte, err error) {
@@ -732,45 +732,45 @@ func (m *KV) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		dAtA[i] = 0x58
 	}
 	if m.StreamId != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.StreamId))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.StreamId))
 		i--
 		dAtA[i] = 0x50
 	}
 	if len(m.Meta) > 0 {
 		i -= len(m.Meta)
 		copy(dAtA[i:], m.Meta)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Meta)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Meta)))
 		i--
 		dAtA[i] = 0x32
 	}
 	if m.ExpiresAt != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.ExpiresAt))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.ExpiresAt))
 		i--
 		dAtA[i] = 0x28
 	}
 	if m.Version != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Version))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Version))
 		i--
 		dAtA[i] = 0x20
 	}
 	if len(m.UserMeta) > 0 {
 		i -= len(m.UserMeta)
 		copy(dAtA[i:], m.UserMeta)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.UserMeta)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.UserMeta)))
 		i--
 		dAtA[i] = 0x1a
 	}
 	if len(m.Value) > 0 {
 		i -= len(m.Value)
 		copy(dAtA[i:], m.Value)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Value)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Value)))
 		i--
 		dAtA[i] = 0x12
 	}
 	if len(m.Key) > 0 {
 		i -= len(m.Key)
 		copy(dAtA[i:], m.Key)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Key)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Key)))
 		i--
 		dAtA[i] = 0xa
 	}
@@ -809,7 +809,7 @@ func (m *KVList) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 					return 0, err
 				}
 				i -= size
-				i = encodeVarintPb(dAtA, i, uint64(size))
+				i = encodeVarintBadgerpb2(dAtA, i, uint64(size))
 			}
 			i--
 			dAtA[i] = 0xa
@@ -850,7 +850,7 @@ func (m *ManifestChangeSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 					return 0, err
 				}
 				i -= size
-				i = encodeVarintPb(dAtA, i, uint64(size))
+				i = encodeVarintBadgerpb2(dAtA, i, uint64(size))
 			}
 			i--
 			dAtA[i] = 0xa
@@ -884,32 +884,32 @@ func (m *ManifestChange) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		copy(dAtA[i:], m.XXX_unrecognized)
 	}
 	if m.Compression != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Compression))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Compression))
 		i--
 		dAtA[i] = 0x30
 	}
 	if m.EncryptionAlgo != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.EncryptionAlgo))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.EncryptionAlgo))
 		i--
 		dAtA[i] = 0x28
 	}
 	if m.KeyId != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.KeyId))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.KeyId))
 		i--
 		dAtA[i] = 0x20
 	}
 	if m.Level != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Level))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Level))
 		i--
 		dAtA[i] = 0x18
 	}
 	if m.Op != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Op))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Op))
 		i--
 		dAtA[i] = 0x10
 	}
 	if m.Id != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Id))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Id))
 		i--
 		dAtA[i] = 0x8
 	}
@@ -941,19 +941,19 @@ func (m *BlockOffset) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		copy(dAtA[i:], m.XXX_unrecognized)
 	}
 	if m.Len != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Len))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Len))
 		i--
 		dAtA[i] = 0x18
 	}
 	if m.Offset != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Offset))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Offset))
 		i--
 		dAtA[i] = 0x10
 	}
 	if len(m.Key) > 0 {
 		i -= len(m.Key)
 		copy(dAtA[i:], m.Key)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Key)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Key)))
 		i--
 		dAtA[i] = 0xa
 	}
@@ -985,14 +985,14 @@ func (m *TableIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		copy(dAtA[i:], m.XXX_unrecognized)
 	}
 	if m.EstimatedSize != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.EstimatedSize))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.EstimatedSize))
 		i--
 		dAtA[i] = 0x18
 	}
 	if len(m.BloomFilter) > 0 {
 		i -= len(m.BloomFilter)
 		copy(dAtA[i:], m.BloomFilter)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.BloomFilter)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.BloomFilter)))
 		i--
 		dAtA[i] = 0x12
 	}
@@ -1004,7 +1004,7 @@ func (m *TableIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 					return 0, err
 				}
 				i -= size
-				i = encodeVarintPb(dAtA, i, uint64(size))
+				i = encodeVarintBadgerpb2(dAtA, i, uint64(size))
 			}
 			i--
 			dAtA[i] = 0xa
@@ -1038,12 +1038,12 @@ func (m *Checksum) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		copy(dAtA[i:], m.XXX_unrecognized)
 	}
 	if m.Sum != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Sum))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Sum))
 		i--
 		dAtA[i] = 0x10
 	}
 	if m.Algo != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.Algo))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.Algo))
 		i--
 		dAtA[i] = 0x8
 	}
@@ -1075,34 +1075,34 @@ func (m *DataKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
 		copy(dAtA[i:], m.XXX_unrecognized)
 	}
 	if m.CreatedAt != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.CreatedAt))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.CreatedAt))
 		i--
 		dAtA[i] = 0x20
 	}
 	if len(m.Iv) > 0 {
 		i -= len(m.Iv)
 		copy(dAtA[i:], m.Iv)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Iv)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Iv)))
 		i--
 		dAtA[i] = 0x1a
 	}
 	if len(m.Data) > 0 {
 		i -= len(m.Data)
 		copy(dAtA[i:], m.Data)
-		i = encodeVarintPb(dAtA, i, uint64(len(m.Data)))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(len(m.Data)))
 		i--
 		dAtA[i] = 0x12
 	}
 	if m.KeyId != 0 {
-		i = encodeVarintPb(dAtA, i, uint64(m.KeyId))
+		i = encodeVarintBadgerpb2(dAtA, i, uint64(m.KeyId))
 		i--
 		dAtA[i] = 0x8
 	}
 	return len(dAtA) - i, nil
 }
 
-func encodeVarintPb(dAtA []byte, offset int, v uint64) int {
-	offset -= sovPb(v)
+func encodeVarintBadgerpb2(dAtA []byte, offset int, v uint64) int {
+	offset -= sovBadgerpb2(v)
 	base := offset
 	for v >= 1<<7 {
 		dAtA[offset] = uint8(v&0x7f | 0x80)
@@ -1120,28 +1120,28 @@ func (m *KV) Size() (n int) {
 	_ = l
 	l = len(m.Key)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	l = len(m.Value)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	l = len(m.UserMeta)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	if m.Version != 0 {
-		n += 1 + sovPb(uint64(m.Version))
+		n += 1 + sovBadgerpb2(uint64(m.Version))
 	}
 	if m.ExpiresAt != 0 {
-		n += 1 + sovPb(uint64(m.ExpiresAt))
+		n += 1 + sovBadgerpb2(uint64(m.ExpiresAt))
 	}
 	l = len(m.Meta)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	if m.StreamId != 0 {
-		n += 1 + sovPb(uint64(m.StreamId))
+		n += 1 + sovBadgerpb2(uint64(m.StreamId))
 	}
 	if m.StreamDone {
 		n += 2
@@ -1161,7 +1161,7 @@ func (m *KVList) Size() (n int) {
 	if len(m.Kv) > 0 {
 		for _, e := range m.Kv {
 			l = e.Size()
-			n += 1 + l + sovPb(uint64(l))
+			n += 1 + l + sovBadgerpb2(uint64(l))
 		}
 	}
 	if m.XXX_unrecognized != nil {
@@ -1179,7 +1179,7 @@ func (m *ManifestChangeSet) Size() (n int) {
 	if len(m.Changes) > 0 {
 		for _, e := range m.Changes {
 			l = e.Size()
-			n += 1 + l + sovPb(uint64(l))
+			n += 1 + l + sovBadgerpb2(uint64(l))
 		}
 	}
 	if m.XXX_unrecognized != nil {
@@ -1195,22 +1195,22 @@ func (m *ManifestChange) Size() (n int) {
 	var l int
 	_ = l
 	if m.Id != 0 {
-		n += 1 + sovPb(uint64(m.Id))
+		n += 1 + sovBadgerpb2(uint64(m.Id))
 	}
 	if m.Op != 0 {
-		n += 1 + sovPb(uint64(m.Op))
+		n += 1 + sovBadgerpb2(uint64(m.Op))
 	}
 	if m.Level != 0 {
-		n += 1 + sovPb(uint64(m.Level))
+		n += 1 + sovBadgerpb2(uint64(m.Level))
 	}
 	if m.KeyId != 0 {
-		n += 1 + sovPb(uint64(m.KeyId))
+		n += 1 + sovBadgerpb2(uint64(m.KeyId))
 	}
 	if m.EncryptionAlgo != 0 {
-		n += 1 + sovPb(uint64(m.EncryptionAlgo))
+		n += 1 + sovBadgerpb2(uint64(m.EncryptionAlgo))
 	}
 	if m.Compression != 0 {
-		n += 1 + sovPb(uint64(m.Compression))
+		n += 1 + sovBadgerpb2(uint64(m.Compression))
 	}
 	if m.XXX_unrecognized != nil {
 		n += len(m.XXX_unrecognized)
@@ -1226,13 +1226,13 @@ func (m *BlockOffset) Size() (n int) {
 	_ = l
 	l = len(m.Key)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	if m.Offset != 0 {
-		n += 1 + sovPb(uint64(m.Offset))
+		n += 1 + sovBadgerpb2(uint64(m.Offset))
 	}
 	if m.Len != 0 {
-		n += 1 + sovPb(uint64(m.Len))
+		n += 1 + sovBadgerpb2(uint64(m.Len))
 	}
 	if m.XXX_unrecognized != nil {
 		n += len(m.XXX_unrecognized)
@@ -1249,15 +1249,15 @@ func (m *TableIndex) Size() (n int) {
 	if len(m.Offsets) > 0 {
 		for _, e := range m.Offsets {
 			l = e.Size()
-			n += 1 + l + sovPb(uint64(l))
+			n += 1 + l + sovBadgerpb2(uint64(l))
 		}
 	}
 	l = len(m.BloomFilter)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	if m.EstimatedSize != 0 {
-		n += 1 + sovPb(uint64(m.EstimatedSize))
+		n += 1 + sovBadgerpb2(uint64(m.EstimatedSize))
 	}
 	if m.XXX_unrecognized != nil {
 		n += len(m.XXX_unrecognized)
@@ -1272,10 +1272,10 @@ func (m *Checksum) Size() (n int) {
 	var l int
 	_ = l
 	if m.Algo != 0 {
-		n += 1 + sovPb(uint64(m.Algo))
+		n += 1 + sovBadgerpb2(uint64(m.Algo))
 	}
 	if m.Sum != 0 {
-		n += 1 + sovPb(uint64(m.Sum))
+		n += 1 + sovBadgerpb2(uint64(m.Sum))
 	}
 	if m.XXX_unrecognized != nil {
 		n += len(m.XXX_unrecognized)
@@ -1290,18 +1290,18 @@ func (m *DataKey) Size() (n int) {
 	var l int
 	_ = l
 	if m.KeyId != 0 {
-		n += 1 + sovPb(uint64(m.KeyId))
+		n += 1 + sovBadgerpb2(uint64(m.KeyId))
 	}
 	l = len(m.Data)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	l = len(m.Iv)
 	if l > 0 {
-		n += 1 + l + sovPb(uint64(l))
+		n += 1 + l + sovBadgerpb2(uint64(l))
 	}
 	if m.CreatedAt != 0 {
-		n += 1 + sovPb(uint64(m.CreatedAt))
+		n += 1 + sovBadgerpb2(uint64(m.CreatedAt))
 	}
 	if m.XXX_unrecognized != nil {
 		n += len(m.XXX_unrecognized)
@@ -1309,11 +1309,11 @@ func (m *DataKey) Size() (n int) {
 	return n
 }
 
-func sovPb(x uint64) (n int) {
+func sovBadgerpb2(x uint64) (n int) {
 	return (math_bits.Len64(x|1) + 6) / 7
 }
-func sozPb(x uint64) (n int) {
-	return sovPb(uint64((x << 1) ^ uint64((int64(x) >> 63))))
+func sozBadgerpb2(x uint64) (n int) {
+	return sovBadgerpb2(uint64((x << 1) ^ uint64((int64(x) >> 63))))
 }
 func (m *KV) Unmarshal(dAtA []byte) error {
 	l := len(dAtA)
@@ -1323,7 +1323,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -1351,7 +1351,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1364,11 +1364,11 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1385,7 +1385,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1398,11 +1398,11 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1419,7 +1419,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1432,11 +1432,11 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1453,7 +1453,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			m.Version = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1472,7 +1472,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			m.ExpiresAt = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1491,7 +1491,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1504,11 +1504,11 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1525,7 +1525,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			m.StreamId = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1544,7 +1544,7 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			var v int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1559,15 +1559,15 @@ func (m *KV) Unmarshal(dAtA []byte) error {
 			m.StreamDone = bool(v != 0)
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -1590,7 +1590,7 @@ func (m *KVList) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -1618,7 +1618,7 @@ func (m *KVList) Unmarshal(dAtA []byte) error {
 			var msglen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1631,11 +1631,11 @@ func (m *KVList) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if msglen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + msglen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1647,15 +1647,15 @@ func (m *KVList) Unmarshal(dAtA []byte) error {
 			iNdEx = postIndex
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -1678,7 +1678,7 @@ func (m *ManifestChangeSet) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -1706,7 +1706,7 @@ func (m *ManifestChangeSet) Unmarshal(dAtA []byte) error {
 			var msglen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1719,11 +1719,11 @@ func (m *ManifestChangeSet) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if msglen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + msglen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1735,15 +1735,15 @@ func (m *ManifestChangeSet) Unmarshal(dAtA []byte) error {
 			iNdEx = postIndex
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -1766,7 +1766,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -1794,7 +1794,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.Id = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1813,7 +1813,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.Op = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1832,7 +1832,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.Level = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1851,7 +1851,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.KeyId = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1870,7 +1870,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.EncryptionAlgo = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1889,7 +1889,7 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			m.Compression = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1903,15 +1903,15 @@ func (m *ManifestChange) Unmarshal(dAtA []byte) error {
 			}
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -1934,7 +1934,7 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -1962,7 +1962,7 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -1975,11 +1975,11 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -1996,7 +1996,7 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 			m.Offset = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2015,7 +2015,7 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 			m.Len = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2029,15 +2029,15 @@ func (m *BlockOffset) Unmarshal(dAtA []byte) error {
 			}
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -2060,7 +2060,7 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -2088,7 +2088,7 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 			var msglen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2101,11 +2101,11 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if msglen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + msglen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -2122,7 +2122,7 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2135,11 +2135,11 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -2156,7 +2156,7 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 			m.EstimatedSize = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2170,15 +2170,15 @@ func (m *TableIndex) Unmarshal(dAtA []byte) error {
 			}
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -2201,7 +2201,7 @@ func (m *Checksum) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -2229,7 +2229,7 @@ func (m *Checksum) Unmarshal(dAtA []byte) error {
 			m.Algo = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2248,7 +2248,7 @@ func (m *Checksum) Unmarshal(dAtA []byte) error {
 			m.Sum = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2262,15 +2262,15 @@ func (m *Checksum) Unmarshal(dAtA []byte) error {
 			}
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -2293,7 +2293,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return ErrIntOverflowPb
+				return ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return io.ErrUnexpectedEOF
@@ -2321,7 +2321,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 			m.KeyId = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2340,7 +2340,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2353,11 +2353,11 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -2374,7 +2374,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2387,11 +2387,11 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 				}
 			}
 			if byteLen < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			postIndex := iNdEx + byteLen
 			if postIndex < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if postIndex > l {
 				return io.ErrUnexpectedEOF
@@ -2408,7 +2408,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 			m.CreatedAt = 0
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return ErrIntOverflowPb
+					return ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return io.ErrUnexpectedEOF
@@ -2422,15 +2422,15 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 			}
 		default:
 			iNdEx = preIndex
-			skippy, err := skipPb(dAtA[iNdEx:])
+			skippy, err := skipBadgerpb2(dAtA[iNdEx:])
 			if err != nil {
 				return err
 			}
 			if skippy < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) < 0 {
-				return ErrInvalidLengthPb
+				return ErrInvalidLengthBadgerpb2
 			}
 			if (iNdEx + skippy) > l {
 				return io.ErrUnexpectedEOF
@@ -2445,7 +2445,7 @@ func (m *DataKey) Unmarshal(dAtA []byte) error {
 	}
 	return nil
 }
-func skipPb(dAtA []byte) (n int, err error) {
+func skipBadgerpb2(dAtA []byte) (n int, err error) {
 	l := len(dAtA)
 	iNdEx := 0
 	depth := 0
@@ -2453,7 +2453,7 @@ func skipPb(dAtA []byte) (n int, err error) {
 		var wire uint64
 		for shift := uint(0); ; shift += 7 {
 			if shift >= 64 {
-				return 0, ErrIntOverflowPb
+				return 0, ErrIntOverflowBadgerpb2
 			}
 			if iNdEx >= l {
 				return 0, io.ErrUnexpectedEOF
@@ -2470,7 +2470,7 @@ func skipPb(dAtA []byte) (n int, err error) {
 		case 0:
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return 0, ErrIntOverflowPb
+					return 0, ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return 0, io.ErrUnexpectedEOF
@@ -2486,7 +2486,7 @@ func skipPb(dAtA []byte) (n int, err error) {
 			var length int
 			for shift := uint(0); ; shift += 7 {
 				if shift >= 64 {
-					return 0, ErrIntOverflowPb
+					return 0, ErrIntOverflowBadgerpb2
 				}
 				if iNdEx >= l {
 					return 0, io.ErrUnexpectedEOF
@@ -2499,14 +2499,14 @@ func skipPb(dAtA []byte) (n int, err error) {
 				}
 			}
 			if length < 0 {
-				return 0, ErrInvalidLengthPb
+				return 0, ErrInvalidLengthBadgerpb2
 			}
 			iNdEx += length
 		case 3:
 			depth++
 		case 4:
 			if depth == 0 {
-				return 0, ErrUnexpectedEndOfGroupPb
+				return 0, ErrUnexpectedEndOfGroupBadgerpb2
 			}
 			depth--
 		case 5:
@@ -2515,7 +2515,7 @@ func skipPb(dAtA []byte) (n int, err error) {
 			return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
 		}
 		if iNdEx < 0 {
-			return 0, ErrInvalidLengthPb
+			return 0, ErrInvalidLengthBadgerpb2
 		}
 		if depth == 0 {
 			return iNdEx, nil
@@ -2525,7 +2525,7 @@ func skipPb(dAtA []byte) (n int, err error) {
 }
 
 var (
-	ErrInvalidLengthPb        = fmt.Errorf("proto: negative length found during unmarshaling")
-	ErrIntOverflowPb          = fmt.Errorf("proto: integer overflow")
-	ErrUnexpectedEndOfGroupPb = fmt.Errorf("proto: unexpected end of group")
+	ErrInvalidLengthBadgerpb2        = fmt.Errorf("proto: negative length found during unmarshaling")
+	ErrIntOverflowBadgerpb2          = fmt.Errorf("proto: integer overflow")
+	ErrUnexpectedEndOfGroupBadgerpb2 = fmt.Errorf("proto: unexpected end of group")
 )
diff --git a/pb/pb.proto b/pb/badgerpb2.proto
similarity index 100%
rename from pb/pb.proto
rename to pb/badgerpb2.proto
diff --git a/pb/gen.sh b/pb/gen.sh
index 18e2d29..0b01769 100755
--- a/pb/gen.sh
+++ b/pb/gen.sh
@@ -1,11 +1,8 @@
 #!/bin/bash
 
-# You might need to go get -v github.com/gogo/protobuf/...
+# Run this script from its directory, so that badgerpb2.proto is where it's expected to
+# be.
 
-protos=${GOPATH-$HOME/go}/src/github.com/dgraph-io/badger/pb
-pushd $protos > /dev/null
-protoc --gofast_out=plugins=grpc:. -I=. pb.proto
+# You might need to go get -v github.com/gogo/protobuf/...
 
-# Move pb.pb.go file to the correct directory. This is necessary because protoc
-# would generate the pb.pb.go file inside a different directory.
-mv $protos/github.com/dgraph-io/badger/v2/pb/pb.pb.go ./
+protoc --gofast_out=plugins=grpc:. --gofast_opt=paths=source_relative -I=. badgerpb2.proto
diff --git a/structs.go b/structs.go
index 469cdc4..38355ba 100644
--- a/structs.go
+++ b/structs.go
@@ -140,13 +140,13 @@ func (h *header) DecodeFrom(reader *hashReader) (int, error) {
 type Entry struct {
 	Key       []byte
 	Value     []byte
-	UserMeta  byte
 	ExpiresAt uint64 // time.Unix
-	meta      byte
 	version   uint64
+	offset    uint32 // offset is an internal field.
+	UserMeta  byte
+	meta      byte
 
 	// Fields maintained internally.
-	offset   uint32
 	skipVlog bool
 	hlen     int // Length of the header.
 }
diff --git a/table/iterator.go b/table/iterator.go
index 8154499..f46ac74 100644
--- a/table/iterator.go
+++ b/table/iterator.go
@@ -174,7 +174,6 @@ type Iterator struct {
 func (t *Table) NewIterator(opt int) *Iterator {
 	t.IncrRef() // Important.
 	ti := &Iterator{t: t, opt: opt}
-	ti.next()
 	return ti
 }
 
diff --git a/table/table.go b/table/table.go
index 76125cc..0f2ee70 100644
--- a/table/table.go
+++ b/table/table.go
@@ -446,7 +446,13 @@ func (t *Table) initIndex() (*pb.BlockOffset, error) {
 		return nil, err
 	}
 
-	t.estimatedSize = index.EstimatedSize
+	if t.opt.Compression == options.None {
+		t.estimatedSize = index.EstimatedSize
+	} else {
+		// Due to compression the real size on disk is much
+		// smaller than what we estimate from index.EstimatedSize.
+		t.estimatedSize = uint64(t.tableSize)
+	}
 	t.hasBloomFilter = len(index.BloomFilter) > 0
 	t.noOfBlocks = len(index.Offsets)
 
diff --git a/txn.go b/txn.go
index 8ff06d2..21b0db5 100644
--- a/txn.go
+++ b/txn.go
@@ -249,9 +249,11 @@ func (o *oracle) doneCommit(cts uint64) {
 type Txn struct {
 	readTs   uint64
 	commitTs uint64
+	size     int64
+	count    int64
+	db       *DB
 
-	update bool     // update is used to conditionally keep track of reads.
-	reads  []uint64 // contains fingerprints of keys read.
+	reads []uint64 // contains fingerprints of keys read.
 	// contains fingerprints of keys written. This is used for conflict detection.
 	conflictKeys map[uint64]struct{}
 	readsLock    sync.Mutex // guards the reads slice. See addReadKey.
@@ -259,13 +261,10 @@ type Txn struct {
 	pendingWrites   map[string]*Entry // cache stores any writes done by txn.
 	duplicateWrites []*Entry          // Used in managed mode to store duplicate entries.
 
-	db        *DB
-	discarded bool
-	doneRead  bool
-
-	size         int64
-	count        int64
 	numIterators int32
+	discarded    bool
+	doneRead     bool
+	update       bool // update is used to conditionally keep track of reads.
 }
 
 type pendingWritesIterator struct {
@@ -483,7 +482,6 @@ func (txn *Txn) Get(key []byte) (item *Item, rerr error) {
 	item.version = vs.Version
 	item.meta = vs.Meta
 	item.userMeta = vs.UserMeta
-	item.db = txn.db
 	item.vptr = y.SafeCopy(item.vptr, vs.Value)
 	item.txn = txn
 	item.expiresAt = vs.ExpiresAt
diff --git a/y/iterator.go b/y/iterator.go
index 7c9b211..ef032ef 100644
--- a/y/iterator.go
+++ b/y/iterator.go
@@ -46,10 +46,6 @@ func sizeVarint(x uint64) (n int) {
 // EncodedSize is the size of the ValueStruct when encoded
 func (v *ValueStruct) EncodedSize() uint32 {
 	sz := len(v.Value) + 2 // meta, usermeta.
-	if v.ExpiresAt == 0 {
-		return uint32(sz + 1)
-	}
-
 	enc := sizeVarint(v.ExpiresAt)
 	return uint32(sz + enc)
 }


Test patch:
diff --git a/db2_test.go b/db2_test.go
index 2a19991..7b165e0 100644
--- a/db2_test.go
+++ b/db2_test.go
@@ -858,3 +858,72 @@ func TestIsClosed(t *testing.T) {
 	})
 
 }
+
+func TestMaxVersion(t *testing.T) {
+	N := uint64(10000)
+	key := func(i int) []byte {
+		return []byte(fmt.Sprintf("%d%10d", i, i))
+	}
+	t.Run("normal", func(t *testing.T) {
+		runBadgerTest(t, nil, func(t *testing.T, db *DB) {
+			// This will create commits from 1 to N.
+			for i := 0; i < int(N); i++ {
+				txnSet(t, db, key(i), nil, 0)
+			}
+			ver, err := db.MaxVersion()
+			require.NoError(t, err)
+			require.Equal(t, N, ver)
+		})
+	})
+	t.Run("multiple versions", func(t *testing.T) {
+		dir, err := ioutil.TempDir("", "badger-test")
+		require.NoError(t, err)
+		defer removeDir(dir)
+
+		opt := getTestOptions(dir)
+		opt.NumVersionsToKeep = 100
+		db, err := OpenManaged(opt)
+		require.NoError(t, err)
+
+		wb := db.NewManagedWriteBatch()
+		defer wb.Cancel()
+
+		k := make([]byte, 100)
+		rand.Read(k)
+		// Create multiple version of the same key.
+		for i := uint64(1); i <= N; i++ {
+			wb.SetEntryAt(&Entry{Key: k}, i)
+		}
+		require.NoError(t, wb.Flush())
+
+		ver, err := db.MaxVersion()
+		require.NoError(t, err)
+		require.Equal(t, N, ver)
+
+		require.NoError(t, db.Close())
+	})
+	t.Run("Managed mode", func(t *testing.T) {
+		dir, err := ioutil.TempDir("", "badger-test")
+		require.NoError(t, err)
+		defer removeDir(dir)
+
+		opt := getTestOptions(dir)
+		db, err := OpenManaged(opt)
+		require.NoError(t, err)
+
+		wb := db.NewManagedWriteBatch()
+		defer wb.Cancel()
+
+		// This will create commits from 1 to N.
+		for i := uint64(1); i <= N; i++ {
+			wb.SetEntryAt(&Entry{Key: []byte(fmt.Sprintf("%d", i))}, i)
+		}
+		require.NoError(t, wb.Flush())
+
+		ver, err := db.MaxVersion()
+		require.NoError(t, err)
+		require.Equal(t, N, ver)
+
+		require.NoError(t, db.Close())
+	})
+}
diff --git a/table/table_test.go b/table/table_test.go
index b9f6c98..88b7bd9 100644
--- a/table/table_test.go
+++ b/table/table_test.go
@@ -923,13 +923,30 @@ func TestMain(m *testing.M) {
 }
 
 func TestOpenKVSize(t *testing.T) {
-	opts := getTestTableOptions()
-	table, err := OpenTable(buildTestTable(t, "foo", 1, opts), opts)
-	require.NoError(t, err)
+	t.Run("compression", func(t *testing.T) {
+		// When compression is on
+		opts := getTestTableOptions()
+		opts.Compression = options.ZSTD
+		table, err := OpenTable(buildTestTable(t, "foo", 1000, opts), opts)
+		defer table.Close()
+		require.NoError(t, err)
+
+		// The estimated size is same as table size in case compression is enabled.
+		require.Equal(t, uint64(table.tableSize), table.EstimatedSize())
+	})
 
-	// The following values might change if the table/header structure is changed.
-	var entrySize uint64 = 15 /* DiffKey len */ + 4 /* Header Size */ + 4 /* Encoded vp */
-	require.Equal(t, entrySize, table.EstimatedSize())
+	t.Run("no compressin", func(t *testing.T) {
+		// When compression is off
+		opts := getTestTableOptions()
+		opts.Compression = options.None
+		table, err := OpenTable(buildTestTable(t, "foo", 1, opts), opts)
+		require.NoError(t, err)
+		defer table.Close()
+
+		stat, err := table.fd.Stat()
+		require.NoError(t, err)
+		require.Less(t, table.EstimatedSize(), uint64(stat.Size()))
+	})
 }
 
 // Run this test with command "go test -race -run TestDoesNotHaveRace"
diff --git a/y/y_test.go b/y/y_test.go
index d1b9631..151d711 100644
--- a/y/y_test.go
+++ b/y/y_test.go
@@ -2,6 +2,7 @@ package y
 
 import (
 	"bytes"
+	"encoding/binary"
 	"fmt"
 	"io"
 	"math/rand"
@@ -254,3 +255,24 @@ func TestPagebufferReader4(t *testing.T) {
 	require.Equal(t, err, io.EOF, "should return EOF")
 	require.Equal(t, n, 0)
 }
+
+func TestSizeVarintForZero(t *testing.T) {
+	siz := sizeVarint(0)
+	require.Equal(t, 1, siz)
+}
+
+func TestEncodedSize(t *testing.T) {
+	valBufSize := uint32(rand.Int31n(1e5))
+	expiry := rand.Uint64()
+	expiryVarintBuf := make([]byte, 64)
+	expVarintSize := uint32(binary.PutUvarint(expiryVarintBuf, expiry))
+	valBuf := make([]byte, valBufSize)
+	_, _ = rand.Read(valBuf)
+
+	valStruct := &ValueStruct{
+		Value:     valBuf,
+		ExpiresAt: expiry,
+	}
+
+	require.Equal(t, valBufSize+uint32(2)+expVarintSize, valStruct.EncodedSize())
+}