From 262082babc79c05ab2d769494a88e522015dda6d Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 7 Sep 2015 19:03:49 +0800 Subject: [PATCH] remove the dependence between tables and table As tables is the implement of table. So tables like the drivers, while table like database/sql. while drivers need to regiester in the init. --- infoschema/infoschema.go | 1 + infoschema/infoschema_test.go | 4 ---- table/tables/tables.go | 4 ++++ table/tables/tables_test.go | 3 --- tidb.go | 4 ---- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index 51c4c9ea4d..88bf480e49 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/table" + _ "github.com/pingcap/tidb/table/tables" ) // InfoSchema is the interface used to retrieve the schema information. diff --git a/infoschema/infoschema_test.go b/infoschema/infoschema_test.go index 0044755ad6..1a23e19dd3 100644 --- a/infoschema/infoschema_test.go +++ b/infoschema/infoschema_test.go @@ -22,8 +22,6 @@ import ( "github.com/pingcap/tidb/mysqldef" "github.com/pingcap/tidb/store/localstore" "github.com/pingcap/tidb/store/localstore/goleveldb" - "github.com/pingcap/tidb/table" - "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/util/types" ) @@ -37,8 +35,6 @@ type testSuite struct { } func (*testSuite) TestT(c *C) { - table.TableFromMeta = tables.TableFromMeta - driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}} store, err := driver.Open("memory") c.Assert(err, IsNil) diff --git a/table/tables/tables.go b/table/tables/tables.go index e8a3fc10df..4f668fc93f 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -570,3 +570,7 @@ func (t *Table) IterRecords(ctx context.Context, startKey string, cols []*column func (t *Table) AllocAutoID() (int64, error) { return t.alloc.Alloc(t.ID) } + +func init() { + table.TableFromMeta = TableFromMeta +} diff --git a/table/tables/tables_test.go b/table/tables/tables_test.go index 9c3e343640..26aabec211 100644 --- a/table/tables/tables_test.go +++ b/table/tables/tables_test.go @@ -25,8 +25,6 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/store/localstore" "github.com/pingcap/tidb/store/localstore/goleveldb" - "github.com/pingcap/tidb/table" - "github.com/pingcap/tidb/table/tables" ) func TestT(t *testing.T) { @@ -41,7 +39,6 @@ type testSuite struct { } func (ts *testSuite) SetUpSuite(c *C) { - table.TableFromMeta = tables.TableFromMeta driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}} store, err := driver.Open("memory") c.Check(err, IsNil) diff --git a/tidb.go b/tidb.go index fea0c5e67f..8b149af486 100644 --- a/tidb.go +++ b/tidb.go @@ -37,8 +37,6 @@ import ( "github.com/pingcap/tidb/store/localstore/boltdb" "github.com/pingcap/tidb/store/localstore/engine" "github.com/pingcap/tidb/store/localstore/goleveldb" - "github.com/pingcap/tidb/table" - "github.com/pingcap/tidb/table/tables" ) // Engine prefix name @@ -259,8 +257,6 @@ func init() { RegisterLocalStore("goleveldb", goleveldb.Driver{}) RegisterLocalStore("boltdb", boltdb.Driver{}) - table.TableFromMeta = tables.TableFromMeta - // start pprof handlers if Debug { go http.ListenAndServe(PprofAddr, nil)