diff --git a/store/hbase/kv.go b/store/hbase/kv.go index f2f8395ce9..4ceb22bca4 100644 --- a/store/hbase/kv.go +++ b/store/hbase/kv.go @@ -30,8 +30,6 @@ const ( hbaseQualifier = "q" // hbaseFmlAndQual is a shortcut. hbaseFmlAndQual = hbaseColFamily + ":" + hbaseQualifier - // hbaseTableName is the table name in hbase which is invisible to SQL layer. - hbaseTableName = "tidb" ) var ( @@ -112,18 +110,25 @@ func (d Driver) Open(zkInfo string) (kv.Storage, error) { if len(zkInfo) == 0 { return nil, errors.Trace(ErrZkInvalid) } + pos := strings.LastIndex(zkInfo, "/") + if pos == -1 { + return nil, errors.Trace(ErrZkInvalid) + } + tableName := zkInfo[pos+1:] + zks := strings.Split(zkInfo[:pos], ",") + if store, ok := mc.cache[zkInfo]; ok { // TODO: check the cache store has the same engine with this Driver. return store, nil } - zks := strings.Split(zkInfo, ",") + c, err := hbase.NewClient(zks, "/hbase") if err != nil { return nil, errors.Trace(err) } - if !c.TableExists(hbaseTableName) { + if !c.TableExists(tableName) { // Create new hbase table for store. - t := hbase.NewTableDesciptor(hbase.NewTableNameWithDefaultNS(hbaseTableName)) + t := hbase.NewTableDesciptor(hbase.NewTableNameWithDefaultNS(tableName)) cf := hbase.NewColumnFamilyDescriptor(hbaseColFamily) cf.AddStrAddr("THEMIS_ENABLE", "true") t.AddColumnDesc(cf) @@ -134,7 +139,7 @@ func (d Driver) Open(zkInfo string) (kv.Storage, error) { } s := &hbaseStore{ zkInfo: zkInfo, - storeName: hbaseTableName, + storeName: tableName, cli: c, } mc.cache[zkInfo] = s diff --git a/store/localstore/mvcc_test.go b/store/localstore/mvcc_test.go index 0afd3b6954..56f4be4ce6 100644 --- a/store/localstore/mvcc_test.go +++ b/store/localstore/mvcc_test.go @@ -301,3 +301,13 @@ func (t *testMvccSuite) TestBufferedIterator(c *C) { c.Assert(it.Value(), DeepEquals, []byte("2")) tx.Commit() } + +func encodeInt(n int) []byte { + return []byte(fmt.Sprintf("%010d", n)) +} + +func decodeInt(s []byte) int { + var n int + fmt.Sscanf(string(s), "%010d", &n) + return n +} diff --git a/store/localstore/kv_test.go b/store/store_test.go similarity index 95% rename from store/localstore/kv_test.go rename to store/store_test.go index fea59447d5..32dcc92a36 100644 --- a/store/localstore/kv_test.go +++ b/store/store_test.go @@ -11,9 +11,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package localstore +package store import ( + "flag" "fmt" "os" "strconv" @@ -22,11 +23,18 @@ import ( "testing" . "github.com/pingcap/check" + "github.com/pingcap/tidb" "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/store/localstore" "github.com/pingcap/tidb/store/localstore/boltdb" "github.com/pingcap/tidb/store/localstore/goleveldb" ) +var ( + testStore = flag.String("teststore", "memory", "test store name, [memory, goleveldb, boltdb]") + testStorePath = flag.String("testpath", "testkv", "test storage path") +) + const ( startIndex = 0 testCount = 2 @@ -44,16 +52,11 @@ type testKVSuite struct { } func (s *testKVSuite) SetUpSuite(c *C) { - path := "memory:" - d := Driver{ - goleveldb.MemoryDriver{}, - } - store, err := d.Open(path) + store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath)) c.Assert(err, IsNil) s.s = store - // must in cache - cacheS, _ := d.Open(path) + cacheS, _ := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath)) c.Assert(cacheS, Equals, store) } @@ -513,8 +516,8 @@ func (s *testKVSuite) TestConditionUpdate(c *C) { func (s *testKVSuite) TestDBClose(c *C) { path := "memory:test" - d := Driver{ - goleveldb.MemoryDriver{}, + d := localstore.Driver{ + Driver: goleveldb.MemoryDriver{}, } store, err := d.Open(path) c.Assert(err, IsNil) @@ -560,8 +563,8 @@ func (s *testKVSuite) TestDBClose(c *C) { } func (s *testKVSuite) TestBoltDBDeadlock(c *C) { - d := Driver{ - boltdb.Driver{}, + d := localstore.Driver{ + Driver: boltdb.Driver{}, } path := "boltdb_test" defer os.Remove(path)