forked from mirror/ledisdb
Merge branch 'develop'
This commit is contained in:
commit
b9d10ace23
|
@ -102,7 +102,7 @@ type Config struct {
|
|||
|
||||
DataDir string `toml:"data_dir"`
|
||||
|
||||
Databases uint8 `toml:"databases"`
|
||||
Databases int `toml:"databases"`
|
||||
|
||||
DBName string `toml:"db_name"`
|
||||
DBPath string `toml:"db_path"`
|
||||
|
@ -214,6 +214,10 @@ func (cfg *Config) adjust() {
|
|||
cfg.ConnReadBufferSize = getDefault(4*KB, cfg.ConnReadBufferSize)
|
||||
cfg.ConnWriteBufferSize = getDefault(4*KB, cfg.ConnWriteBufferSize)
|
||||
cfg.TTLCheckInterval = getDefault(1, cfg.TTLCheckInterval)
|
||||
cfg.Databases = getDefault(0, cfg.Databases)
|
||||
if cfg.Databases > 256 {
|
||||
cfg.Databases = 256
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *LevelDBConfig) adjust() {
|
||||
|
|
|
@ -12,7 +12,7 @@ data_dir = "/tmp/ledis_server"
|
|||
# Set the number of databases. You can use `select dbindex` to choose a db.
|
||||
# dbindex must be in [0, databases - 1].
|
||||
# Maximum databases is 256.
|
||||
databases = 16
|
||||
databases = 256
|
||||
|
||||
# Log server command, set empty to disable
|
||||
access_log = ""
|
||||
|
|
|
@ -45,6 +45,8 @@ func Open(cfg *config.Config) (*Ledis, error) {
|
|||
|
||||
if cfg.Databases == 0 {
|
||||
cfg.Databases = 16
|
||||
} else if cfg.Databases > 256 {
|
||||
cfg.Databases = 256
|
||||
}
|
||||
|
||||
os.MkdirAll(cfg.DataDir, 0755)
|
||||
|
@ -83,8 +85,8 @@ func Open(cfg *config.Config) (*Ledis, error) {
|
|||
}
|
||||
|
||||
l.dbs = make([]*DB, cfg.Databases)
|
||||
for i := uint8(0); i < cfg.Databases; i++ {
|
||||
l.dbs[i] = l.newDB(i)
|
||||
for i := 0; i < cfg.Databases; i++ {
|
||||
l.dbs[i] = l.newDB(uint8(i))
|
||||
}
|
||||
|
||||
l.checkTTL()
|
||||
|
@ -111,7 +113,7 @@ func (l *Ledis) Close() {
|
|||
|
||||
func (l *Ledis) Select(index int) (*DB, error) {
|
||||
if index < 0 || index >= len(l.dbs) {
|
||||
return nil, fmt.Errorf("invalid db index %d", index)
|
||||
return nil, fmt.Errorf("invalid db index %d, must in [0, %d]", index, len(l.dbs)-1)
|
||||
}
|
||||
|
||||
return l.dbs[index], nil
|
||||
|
|
|
@ -121,7 +121,7 @@ func configGetCommand(c *client) error {
|
|||
key := hack.String(args[1])
|
||||
switch key {
|
||||
case "databases":
|
||||
ay = append(ay, []byte("databases"), num.FormatUint8ToSlice(c.app.cfg.Databases))
|
||||
ay = append(ay, []byte("databases"), num.FormatIntToSlice(c.app.cfg.Databases))
|
||||
}
|
||||
|
||||
c.resp.writeSliceArray(ay)
|
||||
|
|
|
@ -45,18 +45,18 @@ func main() {
|
|||
|
||||
wb := db.NewWriteBatch()
|
||||
|
||||
for i := uint8(0); i < cfg.Databases; i++ {
|
||||
minK, maxK := oldKeyPair(i)
|
||||
for i := 0; i < cfg.Databases; i++ {
|
||||
minK, maxK := oldKeyPair(uint8(i))
|
||||
|
||||
it := db.RangeIterator(minK, maxK, store.RangeROpen)
|
||||
num := 0
|
||||
for ; it.Valid(); it.Next() {
|
||||
dt, k, t, err := decodeOldKey(i, it.RawKey())
|
||||
dt, k, t, err := decodeOldKey(uint8(i), it.RawKey())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
newKey := encodeNewKey(i, dt, k, t)
|
||||
newKey := encodeNewKey(uint8(i), dt, k, t)
|
||||
|
||||
wb.Put(newKey, it.RawValue())
|
||||
wb.Delete(it.RawKey())
|
||||
|
|
Loading…
Reference in New Issue