Пример #1
0
func TestMVCCScanWithKeyPrefix(t *testing.T) {
	mvcc := createTestMVCC(t)
	// Let's say you have:
	// a
	// a<T=2>
	// a<T=1>
	// aa
	// aa<T=3>
	// aa<T=2>
	// b
	// b<T=5>
	// In this case, if we scan from "a"-"b", we wish to skip
	// a<T=2> and a<T=1> and find "aa'.
	err := mvcc.Put(Key(encoding.EncodeString([]byte{}, "/a")), makeTS(1, 0), value01, "")
	err = mvcc.Put(Key(encoding.EncodeString([]byte{}, "/a")), makeTS(2, 0), value02, "")
	err = mvcc.Put(Key(encoding.EncodeString([]byte{}, "/aa")), makeTS(2, 0), value02, "")
	err = mvcc.Put(Key(encoding.EncodeString([]byte{}, "/aa")), makeTS(3, 0), value03, "")
	err = mvcc.Put(Key(encoding.EncodeString([]byte{}, "/b")), makeTS(1, 0), value03, "")

	kvs, _, err := mvcc.Scan(Key(encoding.EncodeString([]byte{}, "/a")),
		Key(encoding.EncodeString([]byte{}, "/b")), 0, makeTS(2, 0), "")
	if err != nil {
		t.Fatal(err)
	}
	if len(kvs) != 2 ||
		!bytes.Equal(kvs[0].Key, Key(encoding.EncodeString([]byte{}, "/a"))) ||
		!bytes.Equal(kvs[1].Key, Key(encoding.EncodeString([]byte{}, "/aa"))) ||
		!bytes.Equal(kvs[0].Bytes, value02.Bytes) ||
		!bytes.Equal(kvs[1].Bytes, value02.Bytes) {
		t.Fatal("the value should not be empty")
	}
}
Пример #2
0
// Author: Jiang-Ming Yang ([email protected])

package engine

import (
	"bytes"
	"math"
	"testing"

	"github.com/cockroachdb/cockroach/encoding"
	"github.com/cockroachdb/cockroach/hlc"
)

// Constants for system-reserved keys in the KV map.
var (
	testKey01 = Key(encoding.EncodeString([]byte{}, "/db1"))
	testKey02 = Key(encoding.EncodeString([]byte{}, "/db2"))
	testKey03 = Key(encoding.EncodeString([]byte{}, "/db3"))
	testKey04 = Key(encoding.EncodeString([]byte{}, "/db4"))
	txn01     = "Txn01"
	txn02     = "Txn02"
	value01   = Value{Bytes: []byte("testValue01")}
	value02   = Value{Bytes: []byte("testValue02")}
	value03   = Value{Bytes: []byte("testValue03")}
	value04   = Value{Bytes: []byte("testValue04")}
)

// createTestMVCC creates a new MVCC instance with the given engine.
func createTestMVCC(t *testing.T) *MVCC {
	return &MVCC{
		engine: NewInMem(Attributes{}, 1<<20),