Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion db/column/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/ByteStorage/FlyDB/config"
"github.com/ByteStorage/FlyDB/lib/wal"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -75,6 +76,15 @@ func TestColumn_ListColumnFamilies(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, column)

dirs, err := ioutil.ReadDir(option.DbMemoryOptions.Option.DirPath)
assert.Nil(t, err)
dirCount := 0
for _, dir := range dirs {
if dir.IsDir() {
dirCount++
}
}

err = column.CreateColumnFamily("test")
assert.Nil(t, err)

Expand All @@ -89,7 +99,7 @@ func TestColumn_ListColumnFamilies(t *testing.T) {

list, err := column.ListColumnFamilies()
assert.Nil(t, err)
assert.Equal(t, 4, len(list))
assert.Equal(t, dirCount+3, len(list))

err = column.DropColumnFamily("test")
assert.Nil(t, err)
Expand Down
22 changes: 13 additions & 9 deletions db/engine/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ package engine

import (
"fmt"
"github.com/ByteStorage/FlyDB/config"
data2 "github.com/ByteStorage/FlyDB/db/data"
"github.com/ByteStorage/FlyDB/db/index"
"github.com/ByteStorage/FlyDB/lib/backup"
"github.com/ByteStorage/FlyDB/lib/const"
"go.uber.org/zap"
"io"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"

"go.uber.org/zap"

"github.com/ByteStorage/FlyDB/config"
data2 "github.com/ByteStorage/FlyDB/db/data"
"github.com/ByteStorage/FlyDB/db/index"
"github.com/ByteStorage/FlyDB/lib/backup"
"github.com/ByteStorage/FlyDB/lib/const"
_ "github.com/ByteStorage/FlyDB/lib/logger"
)

// DB represents a FlyDB database instance,
Expand Down Expand Up @@ -147,7 +150,6 @@ func (db *DB) Sync() error {

// Put write a key-value pair to db, and the key must be not empty
func (db *DB) Put(key []byte, value []byte) error {
zap.L().Info("put", zap.ByteString("key", key), zap.ByteString("value", value))
// check key
if len(key) == 0 {
return _const.ErrKeyIsEmpty
Expand All @@ -163,6 +165,7 @@ func (db *DB) Put(key []byte, value []byte) error {
// append log record
pos, err := db.appendLogRecordWithLock(logRecord)
if err != nil {
zap.L().Error("put error", zap.Error(err), zap.Any("operation", NewPutOperation(key, value)))
return err
}

Expand All @@ -171,6 +174,7 @@ func (db *DB) Put(key []byte, value []byte) error {
return _const.ErrIndexUpdateFailed
}

zap.L().Info("put success", zap.Any("operation", NewPutOperation(key, value)))
return nil
}

Expand Down Expand Up @@ -348,8 +352,6 @@ func (db *DB) getValueByPosition(logRecordPst *data2.LogRecordPst) ([]byte, erro

// Delete data according to the key
func (db *DB) Delete(key []byte) error {
zap.L().Info("delete", zap.ByteString("key", key))

// Determine the validity of the key
if len(key) == 0 {
return _const.ErrKeyIsEmpty
Expand All @@ -369,6 +371,7 @@ func (db *DB) Delete(key []byte) error {
// Write to the data file
_, err := db.appendLogRecordWithLock(logRecord)
if err != nil {
zap.L().Error("delete error", zap.Error(err), zap.Any("operation", NewDeleteOperation(key)))
return err
}

Expand All @@ -377,6 +380,7 @@ func (db *DB) Delete(key []byte) error {
if !ok {
return _const.ErrIndexUpdateFailed
}
zap.L().Info("delete success", zap.Any("operation", NewDeleteOperation(key)))
return nil
}

Expand Down
Loading