From c0110b8af9a0b6a03463cb04c3f1a543630a011f Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 16 Nov 2017 17:16:54 +0000 Subject: [PATCH] Implement updated rixxdb api interface --- kvs/err.go | 2 +- kvs/kv.go | 2 +- kvs/rixxdb/main.go | 2 +- kvs/rixxdb/tx.go | 70 +++++++++++++++++++++++++++++++++------------- kvs/tx.go | 11 ++++++-- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/kvs/err.go b/kvs/err.go index 0c04d976..637bb79d 100644 --- a/kvs/err.go +++ b/kvs/err.go @@ -24,7 +24,7 @@ type DBError struct { // Error returns the string representation of the error. func (e *DBError) Error() string { - return fmt.Sprintf("There was a problem writing to the database") + return fmt.Sprintf("Unable to write to the database") } // KVError is an error which occurs when there is a diff --git a/kvs/kv.go b/kvs/kv.go index cf5eae0d..15a55ef8 100644 --- a/kvs/kv.go +++ b/kvs/kv.go @@ -19,5 +19,5 @@ type KV interface { Exi() bool Key() []byte Val() []byte - Ver() int64 + Ver() uint64 } diff --git a/kvs/rixxdb/main.go b/kvs/rixxdb/main.go index c7b2b08d..278711a0 100644 --- a/kvs/rixxdb/main.go +++ b/kvs/rixxdb/main.go @@ -28,7 +28,7 @@ func init() { var pntr *rixxdb.DB - path := strings.TrimLeft(opts.DB.Path, "rixxdb://") + path := strings.TrimPrefix(opts.DB.Path, "rixxdb://") pntr, err = rixxdb.Open(path, &rixxdb.Config{ SyncPolicy: opts.DB.Time, diff --git a/kvs/rixxdb/tx.go b/kvs/rixxdb/tx.go index ec929a1f..c047d951 100644 --- a/kvs/rixxdb/tx.go +++ b/kvs/rixxdb/tx.go @@ -65,13 +65,45 @@ func (tx *TX) Commit() error { return tx.pntr.Commit() } -func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { - all, err := tx.pntr.Get(ver, key) +func (tx *TX) Clr(key []byte) (kvs.KV, error) { + all, err := tx.pntr.Clr(key) return one(all, err) } -func (tx *TX) GetL(ver int64, key []byte) ([]kvs.KV, error) { - all, err := tx.pntr.GetL(ver, key) +func (tx *TX) ClrL(key []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.ClrL(key, max) + out := make([]kvs.KV, len(all)) + for i, v := range all { + out[i] = v + } + return many(out, err) +} + +func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.ClrP(key, max) + out := make([]kvs.KV, len(all)) + for i, v := range all { + out[i] = v + } + return many(out, err) +} + +func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.ClrR(beg, end, max) + out := make([]kvs.KV, len(all)) + for i, v := range all { + out[i] = v + } + return many(out, err) +} + +func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { + all, err := tx.pntr.Get(uint64(ver), key) + return one(all, err) +} + +func (tx *TX) GetL(ver int64, key []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.GetL(uint64(ver), key, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -80,7 +112,7 @@ func (tx *TX) GetL(ver int64, key []byte) ([]kvs.KV, error) { } func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.GetP(ver, key, max) + all, err := tx.pntr.GetP(uint64(ver), key, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -89,7 +121,7 @@ func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { } func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.GetR(ver, beg, end, max) + all, err := tx.pntr.GetR(uint64(ver), beg, end, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -98,16 +130,16 @@ func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err } func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { - all, err := tx.pntr.Del(ver, key) + all, err := tx.pntr.Del(uint64(ver), key) return one(all, err) } func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { - return tx.pntr.DelC(ver, key, exp) + return tx.pntr.DelC(uint64(ver), key, exp) } -func (tx *TX) DelL(ver int64, key []byte) ([]kvs.KV, error) { - all, err := tx.pntr.DelL(ver, key) +func (tx *TX) DelL(ver int64, key []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.DelL(uint64(ver), key, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -116,7 +148,7 @@ func (tx *TX) DelL(ver int64, key []byte) ([]kvs.KV, error) { } func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.DelP(ver, key, max) + all, err := tx.pntr.DelP(uint64(ver), key, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -125,7 +157,7 @@ func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { } func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.DelR(ver, beg, end, max) + all, err := tx.pntr.DelR(uint64(ver), beg, end, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -134,17 +166,17 @@ func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err } func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { - all, err := tx.pntr.Put(ver, key, val) + all, err := tx.pntr.Put(uint64(ver), key, val) return one(all, err) } func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { - all, err := tx.pntr.PutC(ver, key, val, exp) + all, err := tx.pntr.PutC(uint64(ver), key, val, exp) return one(all, err) } -func (tx *TX) PutL(ver int64, key []byte, val []byte) ([]kvs.KV, error) { - all, err := tx.pntr.PutL(ver, key, val) +func (tx *TX) PutL(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.PutL(uint64(ver), key, val, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -153,7 +185,7 @@ func (tx *TX) PutL(ver int64, key []byte, val []byte) ([]kvs.KV, error) { } func (tx *TX) PutP(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.PutP(ver, key, val, max) + all, err := tx.pntr.PutP(uint64(ver), key, val, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v @@ -161,8 +193,8 @@ func (tx *TX) PutP(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, err return many(out, err) } -func (tx *TX) PutR(ver int64, key []byte, val []byte, exp []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.PutR(ver, key, val, exp, max) +func (tx *TX) PutR(ver int64, beg []byte, end []byte, val []byte, max uint64) ([]kvs.KV, error) { + all, err := tx.pntr.PutR(uint64(ver), beg, end, val, max) out := make([]kvs.KV, len(all)) for i, v := range all { out[i] = v diff --git a/kvs/tx.go b/kvs/tx.go index 154ac74b..a839b284 100644 --- a/kvs/tx.go +++ b/kvs/tx.go @@ -20,20 +20,25 @@ type TX interface { Cancel() error Commit() error + Clr([]byte) (KV, error) + ClrL([]byte, uint64) ([]KV, error) + ClrP([]byte, uint64) ([]KV, error) + ClrR([]byte, []byte, uint64) ([]KV, error) + Get(int64, []byte) (KV, error) - GetL(int64, []byte) ([]KV, error) + GetL(int64, []byte, uint64) ([]KV, error) GetP(int64, []byte, uint64) ([]KV, error) GetR(int64, []byte, []byte, uint64) ([]KV, error) Del(int64, []byte) (KV, error) DelC(int64, []byte, []byte) (KV, error) - DelL(int64, []byte) ([]KV, error) + DelL(int64, []byte, uint64) ([]KV, error) DelP(int64, []byte, uint64) ([]KV, error) DelR(int64, []byte, []byte, uint64) ([]KV, error) Put(int64, []byte, []byte) (KV, error) PutC(int64, []byte, []byte, []byte) (KV, error) - PutL(int64, []byte, []byte) ([]KV, error) + PutL(int64, []byte, []byte, uint64) ([]KV, error) PutP(int64, []byte, []byte, uint64) ([]KV, error) PutR(int64, []byte, []byte, []byte, uint64) ([]KV, error) }