From f79c9a1f09c7ca2fed14b62d99c16635dfc6c569 Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 14 Mar 2017 22:26:07 +0800 Subject: [PATCH] remove no need codes. --- server/client.go | 44 -------------- store/db.go | 11 ---- store/driver/batch.go | 70 --------------------- store/driver/driver.go | 22 ------- store/goleveldb/db.go | 4 -- store/leveldb/db.go | 4 -- store/rocksdb/db.go | 4 -- store/store_test.go | 1 - store/tx.go | 86 -------------------------- store/tx_test.go | 135 ----------------------------------------- 10 files changed, 381 deletions(-) delete mode 100644 store/driver/batch.go delete mode 100644 store/tx.go delete mode 100644 store/tx_test.go diff --git a/server/client.go b/server/client.go index 990f7fd..d5ab880 100644 --- a/server/client.go +++ b/server/client.go @@ -11,32 +11,6 @@ import ( "github.com/siddontang/ledisdb/ledis" ) -// var txUnsupportedCmds = map[string]struct{}{ -// "select": struct{}{}, -// "slaveof": struct{}{}, -// "fullsync": struct{}{}, -// "sync": struct{}{}, -// "begin": struct{}{}, -// "flushall": struct{}{}, -// "flushdb": struct{}{}, -// "eval": struct{}{}, -// "xmigrate": struct{}{}, -// "xmigratedb": struct{}{}, -// } - -// var scriptUnsupportedCmds = map[string]struct{}{ -// "slaveof": struct{}{}, -// "fullsync": struct{}{}, -// "sync": struct{}{}, -// "begin": struct{}{}, -// "commit": struct{}{}, -// "rollback": struct{}{}, -// "flushall": struct{}{}, -// "flushdb": struct{}{}, -// "xmigrate": struct{}{}, -// "xmigratedb": struct{}{}, -// } - type responseWriter interface { writeError(error) writeStatus(string) @@ -77,10 +51,6 @@ type client struct { buf bytes.Buffer - // tx *ledis.Tx - - // script *ledis.Multi - slaveListeningAddr string } @@ -117,20 +87,6 @@ func (c *client) perform() { } else if c.authEnabled() && !c.isAuthed && c.cmd != "auth" { err = ErrNotAuthenticated } else { - // if c.db.IsTransaction() { - // if _, ok := txUnsupportedCmds[c.cmd]; ok { - // err = fmt.Errorf("%s not supported in transaction", c.cmd) - // } - // } else if c.db.IsInMulti() { - // if _, ok := scriptUnsupportedCmds[c.cmd]; ok { - // err = fmt.Errorf("%s not supported in multi", c.cmd) - // } - // } - - // if err == nil { - // err = exeCmd(c) - // } - err = exeCmd(c) } diff --git a/store/db.go b/store/db.go index 5e09f26..bfc0418 100644 --- a/store/db.go +++ b/store/db.go @@ -124,17 +124,6 @@ func (db *DB) RevRangeLimitIterator(min []byte, max []byte, rangeType uint8, off return NewRevRangeLimitIterator(db.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count}) } -func (db *DB) Begin() (*Tx, error) { - tx, err := db.db.Begin() - if err != nil { - return nil, err - } - - db.st.TxNum.Add(1) - - return &Tx{tx, db.st}, nil -} - func (db *DB) Stat() *Stat { return db.st } diff --git a/store/driver/batch.go b/store/driver/batch.go deleted file mode 100644 index 1c1e899..0000000 --- a/store/driver/batch.go +++ /dev/null @@ -1,70 +0,0 @@ -package driver - -import ( - "github.com/syndtr/goleveldb/leveldb" -) - -type BatchPuter interface { - BatchPut([]Write) error - SyncBatchPut([]Write) error -} - -type Write struct { - Key []byte - Value []byte -} - -type WriteBatch struct { - d *leveldb.Batch - - wb []Write - w BatchPuter -} - -func (wb *WriteBatch) Close() { - wb.d.Reset() - wb.wb = wb.wb[0:0] -} - -func (wb *WriteBatch) Put(key, value []byte) { - if value == nil { - value = []byte{} - } - wb.wb = append(wb.wb, Write{key, value}) -} - -func (wb *WriteBatch) Delete(key []byte) { - wb.wb = append(wb.wb, Write{key, nil}) -} - -func (wb *WriteBatch) Commit() error { - return wb.w.BatchPut(wb.wb) -} - -func (wb *WriteBatch) SyncCommit() error { - return wb.w.SyncBatchPut(wb.wb) -} - -func (wb *WriteBatch) Rollback() error { - wb.wb = wb.wb[0:0] - return nil -} - -func (wb *WriteBatch) Data() []byte { - wb.d.Reset() - for _, w := range wb.wb { - if w.Value == nil { - wb.d.Delete(w.Key) - } else { - wb.d.Put(w.Key, w.Value) - } - } - return wb.d.Dump() -} - -func NewWriteBatch(puter BatchPuter) *WriteBatch { - return &WriteBatch{ - &leveldb.Batch{}, - []Write{}, - puter} -} diff --git a/store/driver/driver.go b/store/driver/driver.go index b571738..afa549c 100644 --- a/store/driver/driver.go +++ b/store/driver/driver.go @@ -1,13 +1,5 @@ package driver -import ( - "errors" -) - -var ( - ErrTxSupport = errors.New("transaction is not supported") -) - type IDB interface { Close() error @@ -25,8 +17,6 @@ type IDB interface { NewSnapshot() (ISnapshot, error) - Begin() (Tx, error) - Compact() error } @@ -62,18 +52,6 @@ type IWriteBatch interface { Close() } -type Tx interface { - Get(key []byte) ([]byte, error) - Put(key []byte, value []byte) error - Delete(key []byte) error - - NewIterator() IIterator - NewWriteBatch() IWriteBatch - - Commit() error - Rollback() error -} - type ISliceGeter interface { GetSlice(key []byte) (ISlice, error) } diff --git a/store/goleveldb/db.go b/store/goleveldb/db.go index 88d2516..1afc32f 100644 --- a/store/goleveldb/db.go +++ b/store/goleveldb/db.go @@ -180,10 +180,6 @@ func (db *DB) NewIterator() driver.IIterator { return it } -func (db *DB) Begin() (driver.Tx, error) { - return nil, driver.ErrTxSupport -} - func (db *DB) NewSnapshot() (driver.ISnapshot, error) { snapshot, err := db.db.GetSnapshot() if err != nil { diff --git a/store/leveldb/db.go b/store/leveldb/db.go index 2b6bf53..c9cf83f 100644 --- a/store/leveldb/db.go +++ b/store/leveldb/db.go @@ -298,10 +298,6 @@ func (db *DB) delete(wo *WriteOptions, key []byte) error { return nil } -func (db *DB) Begin() (driver.Tx, error) { - return nil, driver.ErrTxSupport -} - func (db *DB) Compact() error { C.leveldb_compact_range(db.db, nil, 0, nil, 0) return nil diff --git a/store/rocksdb/db.go b/store/rocksdb/db.go index a7ee720..5478831 100644 --- a/store/rocksdb/db.go +++ b/store/rocksdb/db.go @@ -327,10 +327,6 @@ func (db *DB) delete(wo *WriteOptions, key []byte) error { return nil } -func (db *DB) Begin() (driver.Tx, error) { - return nil, driver.ErrTxSupport -} - func (db *DB) Compact() error { C.rocksdb_compact_range(db.db, nil, 0, nil, 0) return nil diff --git a/store/store_test.go b/store/store_test.go index 3e33a7c..f5b9177 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -30,7 +30,6 @@ func TestStore(t *testing.T) { testStore(db, t) testClear(db, t) - testTx(db, t) db.Close() } diff --git a/store/tx.go b/store/tx.go deleted file mode 100644 index 4dbf311..0000000 --- a/store/tx.go +++ /dev/null @@ -1,86 +0,0 @@ -package store - -import ( - "github.com/siddontang/ledisdb/store/driver" -) - -type Tx struct { - tx driver.Tx - st *Stat -} - -func (tx *Tx) NewIterator() *Iterator { - it := new(Iterator) - it.it = tx.tx.NewIterator() - it.st = tx.st - - tx.st.IterNum.Add(1) - - return it -} - -func (tx *Tx) NewWriteBatch() *WriteBatch { - tx.st.BatchNum.Add(1) - - wb := new(WriteBatch) - wb.wb = tx.tx.NewWriteBatch() - wb.st = tx.st - return wb -} - -func (tx *Tx) RangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator { - return NewRangeLimitIterator(tx.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1}) -} - -func (tx *Tx) RevRangeIterator(min []byte, max []byte, rangeType uint8) *RangeLimitIterator { - return NewRevRangeLimitIterator(tx.NewIterator(), &Range{min, max, rangeType}, &Limit{0, -1}) -} - -//count < 0, unlimit. -// -//offset must >= 0, if < 0, will get nothing. -func (tx *Tx) RangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator { - return NewRangeLimitIterator(tx.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count}) -} - -//count < 0, unlimit. -// -//offset must >= 0, if < 0, will get nothing. -func (tx *Tx) RevRangeLimitIterator(min []byte, max []byte, rangeType uint8, offset int, count int) *RangeLimitIterator { - return NewRevRangeLimitIterator(tx.NewIterator(), &Range{min, max, rangeType}, &Limit{offset, count}) -} - -func (tx *Tx) Get(key []byte) ([]byte, error) { - v, err := tx.tx.Get(key) - tx.st.statGet(v, err) - return v, err -} - -func (tx *Tx) GetSlice(key []byte) (Slice, error) { - if v, err := tx.Get(key); err != nil { - return nil, err - } else if v == nil { - return nil, nil - } else { - return driver.GoSlice(v), nil - } -} - -func (tx *Tx) Put(key []byte, value []byte) error { - tx.st.PutNum.Add(1) - return tx.tx.Put(key, value) -} - -func (tx *Tx) Delete(key []byte) error { - tx.st.DeleteNum.Add(1) - return tx.tx.Delete(key) -} - -func (tx *Tx) Commit() error { - tx.st.TxCommitNum.Add(1) - return tx.tx.Commit() -} - -func (tx *Tx) Rollback() error { - return tx.tx.Rollback() -} diff --git a/store/tx_test.go b/store/tx_test.go deleted file mode 100644 index 7f982d0..0000000 --- a/store/tx_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package store - -import ( - "testing" - - "github.com/siddontang/ledisdb/store/driver" -) - -func TestTx(t *testing.T) { - -} - -func testTx(db *DB, t *testing.T) { - if tx, err := db.Begin(); err != nil { - if err == driver.ErrTxSupport { - return - } else { - t.Fatal(err) - } - } else { - tx.Rollback() - } - - key1 := []byte("1") - key2 := []byte("2") - key3 := []byte("3") - key4 := []byte("4") - - db.Put(key1, []byte("1")) - db.Put(key2, []byte("2")) - - tx, err := db.Begin() - if err != nil { - t.Fatal(err) - } - - if err := tx.Put(key1, []byte("a")); err != nil { - t.Fatal(err) - } - - if err := tx.Put(key2, []byte("b")); err != nil { - t.Fatal(err) - } - - if err := tx.Put(key3, []byte("c")); err != nil { - t.Fatal(err) - } - - if err := tx.Put(key4, []byte("d")); err != nil { - t.Fatal(err) - } - - it := tx.NewIterator() - - it.Seek(key1) - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "a" { - t.Fatal(string(it.Value())) - } - - it.SeekToFirst() - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "a" { - t.Fatal(string(it.Value())) - } - - it.Seek(key2) - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "b" { - t.Fatal(string(it.Value())) - } - - it.Next() - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "c" { - t.Fatal(string(it.Value())) - } - - it.SeekToLast() - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "d" { - t.Fatal(string(it.Value())) - } - - it.Close() - - tx.Rollback() - - if v, err := db.Get(key1); err != nil { - t.Fatal(err) - } else if string(v) != "1" { - t.Fatal(string(v)) - } - - tx, err = db.Begin() - if err != nil { - t.Fatal(err) - } - - if err := tx.Put(key1, []byte("a")); err != nil { - t.Fatal(err) - } - - it = tx.NewIterator() - - it.Seek(key2) - - if !it.Valid() { - t.Fatal("must valid") - } else if string(it.Value()) != "2" { - t.Fatal(string(it.Value())) - } - - it.Close() - - if err := tx.Commit(); err != nil { - t.Fatal(err) - } - - if v, err := db.Get(key1); err != nil { - t.Fatal(err) - } else if string(v) != "a" { - t.Fatal(string(v)) - } -}