Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Apr 7, 2022
1 parent f01e4ae commit 2d67d57
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 968 deletions.
7 changes: 1 addition & 6 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func TestOpen(t *testing.T) {

var count int
want := []string{
`{"name":"__genji_epoch_seq", "owner":{"table_name":"__genji_catalog"}, "sql":"CREATE SEQUENCE __genji_epoch_seq CACHE 0", "type":"sequence"}`,
`{"name":"__genji_sequence", "sql":"CREATE TABLE __genji_sequence (name TEXT, seq INTEGER, PRIMARY KEY (name))", "namespace":2, "type":"table"}`,
`{"name":"__genji_store_seq", "owner":{"table_name":"__genji_catalog"}, "sql":"CREATE SEQUENCE __genji_store_seq MAXVALUE 4294967295 START WITH 101 CACHE 0", "type":"sequence"}`,
`{"name":"seqD", "sql":"CREATE SEQUENCE seqD INCREMENT BY 10 MINVALUE 100 START WITH 500 CYCLE", "type":"sequence"}`,
Expand Down Expand Up @@ -137,13 +136,9 @@ func TestOpen(t *testing.T) {

d, err = db.QueryDocument("SELECT * FROM __genji_sequence")
assert.NoError(t, err)
testutil.RequireDocJSONEq(t, d, `{"name":"__genji_epoch_seq"}`)

d, err = db.QueryDocument("SELECT * FROM __genji_sequence OFFSET 1")
assert.NoError(t, err)
testutil.RequireDocJSONEq(t, d, `{"name":"__genji_store_seq", "seq":105}`)

d, err = db.QueryDocument("SELECT * FROM __genji_sequence OFFSET 2")
d, err = db.QueryDocument("SELECT * FROM __genji_sequence OFFSET 1")
assert.NoError(t, err)
testutil.RequireDocJSONEq(t, d, `{"name": "seqD", "seq": 500}`)
}
Expand Down
17 changes: 1 addition & 16 deletions internal/database/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const (
// System sequences
const (
StoreSequence = InternalPrefix + "store_seq"
EpochSequence = InternalPrefix + "epoch_seq"
)

// Catalog manages all database objects such as tables, indexes and sequences.
Expand All @@ -51,7 +50,7 @@ func NewCatalog() *Catalog {

func (c *Catalog) Init(tx *Transaction) error {
// ensure the store sequence exists
err := c.ensureSequenceExists(tx, &SequenceInfo{
return c.ensureSequenceExists(tx, &SequenceInfo{
Name: StoreSequence,
IncrementBy: 1,
Min: 1, Max: math.MaxUint32,
Expand All @@ -60,20 +59,6 @@ func (c *Catalog) Init(tx *Transaction) error {
TableName: CatalogTableName,
},
})
if err != nil {
return err
}

// ensure the transaction epoch sequence exists
return c.ensureSequenceExists(tx, &SequenceInfo{
Name: EpochSequence,
IncrementBy: 1,
Min: 1, Max: math.MaxInt64,
Start: 1,
Owner: Owner{
TableName: CatalogTableName,
},
})
}

func (c *Catalog) ensureSequenceExists(tx *Transaction, seq *SequenceInfo) error {
Expand Down
12 changes: 5 additions & 7 deletions internal/database/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,16 @@ func TestReadOnlyTables(t *testing.T) {
err = res.Iterate(func(d types.Document) error {
switch i {
case 0:
testutil.RequireDocJSONEq(t, d, `{"name":"__genji_epoch_seq", "owner":{"table_name":"__genji_catalog"}, "sql":"CREATE SEQUENCE __genji_epoch_seq CACHE 0", "type":"sequence"}`)
case 1:
testutil.RequireDocJSONEq(t, d, `{"name":"__genji_sequence", "sql":"CREATE TABLE __genji_sequence (name TEXT, seq INTEGER, PRIMARY KEY (name))", "namespace":2, "type":"table"}`)
case 2:
case 1:
testutil.RequireDocJSONEq(t, d, `{"name":"__genji_store_seq", "owner":{"table_name":"__genji_catalog"}, "sql":"CREATE SEQUENCE __genji_store_seq MAXVALUE 4294967295 START WITH 101 CACHE 0", "type":"sequence"}`)
case 3:
case 2:
testutil.RequireDocJSONEq(t, d, `{"name":"foo", "docid_sequence_name":"foo_seq", "sql":"CREATE TABLE foo (a INTEGER, b[3].c DOUBLE, UNIQUE (b[3].c))", "namespace":101, "type":"table"}`)
case 4:
case 3:
testutil.RequireDocJSONEq(t, d, `{"name":"foo_b[3].c_idx", "owner":{"table_name":"foo", "paths":["b[3].c"]}, "sql":"CREATE UNIQUE INDEX `+"`foo_b[3].c_idx`"+` ON foo (b[3].c)", "namespace":102, "table_name":"foo", "type":"index"}`)
case 5:
case 4:
testutil.RequireDocJSONEq(t, d, `{"name":"foo_seq", "owner":{"table_name":"foo"}, "sql":"CREATE SEQUENCE foo_seq CACHE 64", "type":"sequence"}`)
case 6:
case 5:
testutil.RequireDocJSONEq(t, d, `{"name":"idx_foo_a", "sql":"CREATE INDEX idx_foo_a ON foo (a)", "namespace":103, "table_name":"foo", "type":"index"}`)
default:
t.Fatalf("count should be 5, got %d", i)
Expand Down
6 changes: 0 additions & 6 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package database
import (
"context"
"sync"
"sync/atomic"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble"
Expand Down Expand Up @@ -32,10 +31,6 @@ type Database struct {
// Pool of reusable transient engines to use for temporary indices.
TransientStorePool *TransientStorePool

// Pool of transaction ids.
// TODO(asdine): add epochs to avoid overflows
txIDPool uint32

closeOnce sync.Once
}

Expand Down Expand Up @@ -194,7 +189,6 @@ func (db *Database) beginTx(ctx context.Context, opts *TxOptions) (*Transaction,

tx := Transaction{
Session: kv.NewSession(st, opts.ReadOnly),
Id: atomic.AddUint32(&db.txIDPool, 1),
Writable: !opts.ReadOnly,
DBMu: db.txmu,
}
Expand Down
148 changes: 0 additions & 148 deletions internal/lock/lock.go

This file was deleted.

Loading

0 comments on commit 2d67d57

Please sign in to comment.