forked from mirror/ledisdb
Merge branch 'develop'
This commit is contained in:
commit
5487f68bfa
|
@ -11,8 +11,8 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/boltdb/bolt",
|
"ImportPath": "github.com/boltdb/bolt",
|
||||||
"Comment": "data/v1-256-ge65c902",
|
"Comment": "v1.0-5-g33e7a07",
|
||||||
"Rev": "e65c9027c35b7ef1014db9e02686889e51aadb2e"
|
"Rev": "33e7a074e2c470b6d0b7ee23322a1c4cc759044b"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/cupcake/rdb",
|
"ImportPath": "github.com/cupcake/rdb",
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/syndtr/goleveldb/leveldb",
|
"ImportPath": "github.com/syndtr/goleveldb/leveldb",
|
||||||
"Rev": "c9e0ae706141dc099005d6d247e4880c7feda2e1"
|
"Rev": "63c9e642efad852f49e20a6f90194cae112fd2ac"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/syndtr/gosnappy/snappy",
|
"ImportPath": "github.com/syndtr/gosnappy/snappy",
|
||||||
|
|
|
@ -21,7 +21,7 @@ var dbName = flag.String("db_name", "", "select a db to use, it will overwrite t
|
||||||
var usePprof = flag.Bool("pprof", false, "enable pprof")
|
var usePprof = flag.Bool("pprof", false, "enable pprof")
|
||||||
var pprofPort = flag.Int("pprof_port", 6060, "pprof http port")
|
var pprofPort = flag.Int("pprof_port", 6060, "pprof http port")
|
||||||
var slaveof = flag.String("slaveof", "", "make the server a slave of another instance")
|
var slaveof = flag.String("slaveof", "", "make the server a slave of another instance")
|
||||||
var readonly = flag.Bool("readonly", false, "set readonly mode, salve server is always readonly")
|
var readonly = flag.Bool("readonly", false, "set readonly mode, slave server is always readonly")
|
||||||
var rpl = flag.Bool("rpl", false, "enable replication or not, slave server is always enabled")
|
var rpl = flag.Bool("rpl", false, "enable replication or not, slave server is always enabled")
|
||||||
var rplSync = flag.Bool("rpl_sync", false, "enable sync replication or not")
|
var rplSync = flag.Bool("rpl_sync", false, "enable sync replication or not")
|
||||||
var ttlCheck = flag.Int("ttl_check", 0, "TTL check interval")
|
var ttlCheck = flag.Int("ttl_check", 0, "TTL check interval")
|
||||||
|
|
|
@ -139,7 +139,7 @@ func (c *ttlChecker) setNextCheckTime(when int64, force bool) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
if force {
|
if force {
|
||||||
c.nc = when
|
c.nc = when
|
||||||
} else if !force && c.nc > when {
|
} else if c.nc > when {
|
||||||
c.nc = when
|
c.nc = when
|
||||||
}
|
}
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
|
|
|
@ -34,6 +34,7 @@ func startTestApp() {
|
||||||
os.RemoveAll(cfg.DataDir)
|
os.RemoveAll(cfg.DataDir)
|
||||||
|
|
||||||
cfg.Addr = "127.0.0.1:16380"
|
cfg.Addr = "127.0.0.1:16380"
|
||||||
|
cfg.HttpAddr = "127.0.0.1:21181"
|
||||||
|
|
||||||
os.RemoveAll("/tmp/testdb")
|
os.RemoveAll("/tmp/testdb")
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,14 @@ func newClientHTTP(app *App, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
c := new(httpClient)
|
c := new(httpClient)
|
||||||
|
c.client = newClient(app)
|
||||||
|
|
||||||
err = c.makeRequest(app, r, w)
|
err = c.makeRequest(app, r, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.client.close()
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.client = newClient(app)
|
|
||||||
c.perform()
|
c.perform()
|
||||||
c.client.close()
|
c.client.close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHttp(t *testing.T) {
|
||||||
|
startTestApp()
|
||||||
|
|
||||||
|
r, err := http.Get(fmt.Sprintf("http://%s/SET/http_hello/world", testApp.cfg.HttpAddr))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ioutil.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
|
|
||||||
|
r, err = http.Get(fmt.Sprintf("http://%s/GET/http_hello?type=json", testApp.cfg.HttpAddr))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := ioutil.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
|
|
||||||
|
var v struct {
|
||||||
|
Data string `json:"GET"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = json.Unmarshal(b, &v); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if v.Data != "world" {
|
||||||
|
t.Fatal("not equal")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -113,7 +113,7 @@ func newOptions(cfg *config.LevelDBConfig) *opt.Options {
|
||||||
opts := &opt.Options{}
|
opts := &opt.Options{}
|
||||||
opts.ErrorIfMissing = false
|
opts.ErrorIfMissing = false
|
||||||
|
|
||||||
opts.BlockCache = cache.NewLRUCache(cfg.CacheSize)
|
opts.BlockCacheCapacity = cfg.CacheSize
|
||||||
|
|
||||||
//we must use bloomfilter
|
//we must use bloomfilter
|
||||||
opts.Filter = filter.NewBloomFilter(defaultFilterBits)
|
opts.Filter = filter.NewBloomFilter(defaultFilterBits)
|
||||||
|
@ -126,7 +126,7 @@ func newOptions(cfg *config.LevelDBConfig) *opt.Options {
|
||||||
|
|
||||||
opts.BlockSize = cfg.BlockSize
|
opts.BlockSize = cfg.BlockSize
|
||||||
opts.WriteBuffer = cfg.WriteBufferSize
|
opts.WriteBuffer = cfg.WriteBufferSize
|
||||||
opts.CachedOpenFiles = cfg.MaxOpenFiles
|
opts.OpenFilesCacheCapacity = cfg.MaxOpenFiles
|
||||||
|
|
||||||
//here we use default value, later add config support
|
//here we use default value, later add config support
|
||||||
opts.CompactionTableSize = 32 * 1024 * 1024
|
opts.CompactionTableSize = 32 * 1024 * 1024
|
||||||
|
|
Loading…
Reference in New Issue