From f2cc5f5fd9c45835301874506a53fcf36f999bd5 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 12 Dec 2014 20:56:17 +0800 Subject: [PATCH 1/4] use newest goleveldb you must update goleveldb by yourself --- Godeps/Godeps.json | 6 +++--- store/goleveldb/db.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 5aae124..cd2c5bf 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -11,8 +11,8 @@ }, { "ImportPath": "github.com/boltdb/bolt", - "Comment": "data/v1-256-ge65c902", - "Rev": "e65c9027c35b7ef1014db9e02686889e51aadb2e" + "Comment": "v1.0-5-g33e7a07", + "Rev": "33e7a074e2c470b6d0b7ee23322a1c4cc759044b" }, { "ImportPath": "github.com/cupcake/rdb", @@ -60,7 +60,7 @@ }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", - "Rev": "c9e0ae706141dc099005d6d247e4880c7feda2e1" + "Rev": "63c9e642efad852f49e20a6f90194cae112fd2ac" }, { "ImportPath": "github.com/syndtr/gosnappy/snappy", diff --git a/store/goleveldb/db.go b/store/goleveldb/db.go index af8633b..88d2516 100644 --- a/store/goleveldb/db.go +++ b/store/goleveldb/db.go @@ -113,7 +113,7 @@ func newOptions(cfg *config.LevelDBConfig) *opt.Options { opts := &opt.Options{} opts.ErrorIfMissing = false - opts.BlockCache = cache.NewLRUCache(cfg.CacheSize) + opts.BlockCacheCapacity = cfg.CacheSize //we must use bloomfilter opts.Filter = filter.NewBloomFilter(defaultFilterBits) @@ -126,7 +126,7 @@ func newOptions(cfg *config.LevelDBConfig) *opt.Options { opts.BlockSize = cfg.BlockSize opts.WriteBuffer = cfg.WriteBufferSize - opts.CachedOpenFiles = cfg.MaxOpenFiles + opts.OpenFilesCacheCapacity = cfg.MaxOpenFiles //here we use default value, later add config support opts.CompactionTableSize = 32 * 1024 * 1024 From bb01d4c246db3281af3b02a337059e34fb4f7069 Mon Sep 17 00:00:00 2001 From: siddontang Date: Mon, 15 Dec 2014 09:59:20 +0800 Subject: [PATCH 2/4] Merge branch 'pr/122' into develop --- ledis/t_ttl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledis/t_ttl.go b/ledis/t_ttl.go index f16a735..2fd2e3f 100644 --- a/ledis/t_ttl.go +++ b/ledis/t_ttl.go @@ -139,7 +139,7 @@ func (c *ttlChecker) setNextCheckTime(when int64, force bool) { c.Lock() if force { c.nc = when - } else if !force && c.nc > when { + } else if c.nc > when { c.nc = when } c.Unlock() From 8d94615ee4a0cbfacb9cc60e759fcd231343f70f Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 23 Dec 2014 08:47:28 +0800 Subject: [PATCH 3/4] fix typo, #115 --- cmd/ledis-server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ledis-server/main.go b/cmd/ledis-server/main.go index f1c695b..e2f246a 100644 --- a/cmd/ledis-server/main.go +++ b/cmd/ledis-server/main.go @@ -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 pprofPort = flag.Int("pprof_port", 6060, "pprof http port") 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 rplSync = flag.Bool("rpl_sync", false, "enable sync replication or not") var ttlCheck = flag.Int("ttl_check", 0, "TTL check interval") From 8c75a693f440d1c08c0ac2fbe79f458842c6aef9 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 26 Dec 2014 10:08:37 +0800 Subject: [PATCH 4/4] fix http panic error --- server/app_test.go | 1 + server/client_http.go | 3 ++- server/client_http_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 server/client_http_test.go diff --git a/server/app_test.go b/server/app_test.go index 17e2989..781d6fb 100644 --- a/server/app_test.go +++ b/server/app_test.go @@ -34,6 +34,7 @@ func startTestApp() { os.RemoveAll(cfg.DataDir) cfg.Addr = "127.0.0.1:16380" + cfg.HttpAddr = "127.0.0.1:21181" os.RemoveAll("/tmp/testdb") diff --git a/server/client_http.go b/server/client_http.go index 4383673..db44c21 100644 --- a/server/client_http.go +++ b/server/client_http.go @@ -45,13 +45,14 @@ func newClientHTTP(app *App, w http.ResponseWriter, r *http.Request) { var err error c := new(httpClient) + c.client = newClient(app) err = c.makeRequest(app, r, w) if err != nil { + c.client.close() w.Write([]byte(err.Error())) return } - c.client = newClient(app) c.perform() c.client.close() } diff --git a/server/client_http_test.go b/server/client_http_test.go new file mode 100644 index 0000000..418a7c0 --- /dev/null +++ b/server/client_http_test.go @@ -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") + } + +}