remove no need codes.

This commit is contained in:
siddontang 2017-03-14 22:26:07 +08:00
parent b2e8658470
commit f79c9a1f09
10 changed files with 0 additions and 381 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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}
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -30,7 +30,6 @@ func TestStore(t *testing.T) {
testStore(db, t)
testClear(db, t)
testTx(db, t)
db.Close()
}

View File

@ -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()
}

View File

@ -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))
}
}