2018-10-29 01:49:45 +03:00
|
|
|
package server
|
2016-03-05 02:08:16 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2018-10-11 00:25:40 +03:00
|
|
|
"github.com/mmcloughlin/geohash"
|
2021-01-26 00:34:40 +03:00
|
|
|
"github.com/tidwall/btree"
|
2018-10-11 00:25:40 +03:00
|
|
|
"github.com/tidwall/geojson"
|
|
|
|
"github.com/tidwall/geojson/geometry"
|
2016-03-28 18:57:41 +03:00
|
|
|
"github.com/tidwall/resp"
|
2021-02-08 03:54:56 +03:00
|
|
|
"github.com/tidwall/rtree"
|
2018-10-11 00:25:40 +03:00
|
|
|
"github.com/tidwall/tile38/internal/collection"
|
|
|
|
"github.com/tidwall/tile38/internal/glob"
|
2016-03-05 02:08:16 +03:00
|
|
|
)
|
|
|
|
|
2016-03-28 18:57:41 +03:00
|
|
|
type fvt struct {
|
|
|
|
field string
|
|
|
|
value float64
|
|
|
|
}
|
|
|
|
|
2020-03-04 00:39:43 +03:00
|
|
|
func orderFields(fmap map[string]int, farr []string, fields []float64) []fvt {
|
2016-03-28 18:57:41 +03:00
|
|
|
var fv fvt
|
2020-03-04 00:39:43 +03:00
|
|
|
var idx int
|
2016-03-28 18:57:41 +03:00
|
|
|
fvs := make([]fvt, 0, len(fmap))
|
2020-03-04 00:39:43 +03:00
|
|
|
for _, field := range farr {
|
|
|
|
idx = fmap[field]
|
2016-03-28 18:57:41 +03:00
|
|
|
if idx < len(fields) {
|
|
|
|
fv.field = field
|
|
|
|
fv.value = fields[idx]
|
2016-03-30 19:32:38 +03:00
|
|
|
if fv.value != 0 {
|
2016-03-28 18:57:41 +03:00
|
|
|
fvs = append(fvs, fv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fvs
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdBounds(msg *Message) (resp.Value, error) {
|
2016-08-19 18:33:58 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-08-19 18:33:58 +03:00
|
|
|
|
|
|
|
var ok bool
|
|
|
|
var key string
|
|
|
|
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-08-19 18:33:58 +03:00
|
|
|
if col == nil {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == RESP {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.NullValue(), nil
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errKeyNotFound
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
vals := make([]resp.Value, 0, 2)
|
|
|
|
var buf bytes.Buffer
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-08-19 18:33:58 +03:00
|
|
|
buf.WriteString(`{"ok":true`)
|
|
|
|
}
|
2017-08-11 03:32:40 +03:00
|
|
|
minX, minY, maxX, maxY := col.Bounds()
|
2016-10-03 21:37:16 +03:00
|
|
|
|
2018-10-11 00:25:40 +03:00
|
|
|
bbox := geojson.NewRect(geometry.Rect{
|
|
|
|
Min: geometry.Point{X: minX, Y: minY},
|
|
|
|
Max: geometry.Point{X: maxX, Y: maxY},
|
|
|
|
})
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-08-19 18:33:58 +03:00
|
|
|
buf.WriteString(`,"bounds":`)
|
2018-10-11 00:25:40 +03:00
|
|
|
buf.WriteString(string(bbox.AppendJSON(nil)))
|
2016-08-19 18:33:58 +03:00
|
|
|
} else {
|
|
|
|
vals = append(vals, resp.ArrayValue([]resp.Value{
|
|
|
|
resp.ArrayValue([]resp.Value{
|
2016-10-03 21:37:16 +03:00
|
|
|
resp.FloatValue(minX),
|
|
|
|
resp.FloatValue(minY),
|
2016-08-19 18:33:58 +03:00
|
|
|
}),
|
|
|
|
resp.ArrayValue([]resp.Value{
|
2016-10-03 21:37:16 +03:00
|
|
|
resp.FloatValue(maxX),
|
|
|
|
resp.FloatValue(maxY),
|
2016-08-19 18:33:58 +03:00
|
|
|
}),
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
buf.WriteString(`,"elapsed":"` + time.Since(start).String() + "\"}")
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.StringValue(buf.String()), nil
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return vals[0], nil
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, nil
|
2016-08-19 18:33:58 +03:00
|
|
|
}
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdType(msg *Message) (resp.Value, error) {
|
2016-08-26 23:42:52 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-08-26 23:42:52 +03:00
|
|
|
|
|
|
|
var ok bool
|
|
|
|
var key string
|
2021-03-31 18:13:44 +03:00
|
|
|
if _, key, ok = tokenval(vs); !ok || key == "" {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-08-26 23:42:52 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-08-26 23:42:52 +03:00
|
|
|
if col == nil {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == RESP {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.SimpleStringValue("none"), nil
|
2016-08-26 23:42:52 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errKeyNotFound
|
2016-08-26 23:42:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
typ := "hash"
|
|
|
|
|
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
return resp.StringValue(`{"ok":true,"type":` + string(typ) + `,"elapsed":"` + time.Since(start).String() + "\"}"), nil
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.SimpleStringValue(typ), nil
|
2016-08-26 23:42:52 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, nil
|
2016-08-26 23:42:52 +03:00
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdGet(msg *Message) (resp.Value, error) {
|
2016-03-05 02:08:16 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-03-28 18:57:41 +03:00
|
|
|
|
|
|
|
var ok bool
|
2016-03-05 02:08:16 +03:00
|
|
|
var key, id, typ, sprecision string
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, id, ok = tokenval(vs); !ok || id == "" {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-04-01 22:46:39 +03:00
|
|
|
|
|
|
|
withfields := false
|
|
|
|
if _, peek, ok := tokenval(vs); ok && strings.ToLower(peek) == "withfields" {
|
|
|
|
withfields = true
|
|
|
|
vs = vs[1:]
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-03-05 02:08:16 +03:00
|
|
|
if col == nil {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == RESP {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.NullValue(), nil
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errKeyNotFound
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
o, fields, _, ok := col.Get(id)
|
2016-03-05 02:08:16 +03:00
|
|
|
if !ok {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == RESP {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.NullValue(), nil
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errIDNotFound
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
|
|
|
|
vals := make([]resp.Value, 0, 2)
|
2016-03-05 02:08:16 +03:00
|
|
|
var buf bytes.Buffer
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-03-28 18:57:41 +03:00
|
|
|
buf.WriteString(`{"ok":true`)
|
|
|
|
}
|
2016-07-10 23:23:50 +03:00
|
|
|
vs, typ, ok = tokenval(vs)
|
|
|
|
typ = strings.ToLower(typ)
|
|
|
|
if !ok {
|
|
|
|
typ = "object"
|
|
|
|
}
|
|
|
|
switch typ {
|
|
|
|
default:
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidArgument(typ)
|
2016-07-10 23:23:50 +03:00
|
|
|
case "object":
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-03-28 18:57:41 +03:00
|
|
|
buf.WriteString(`,"object":`)
|
2018-10-11 00:25:40 +03:00
|
|
|
buf.WriteString(string(o.AppendJSON(nil)))
|
2016-03-28 18:57:41 +03:00
|
|
|
} else {
|
2016-07-10 05:44:28 +03:00
|
|
|
vals = append(vals, resp.StringValue(o.String()))
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2016-07-10 23:23:50 +03:00
|
|
|
case "point":
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-07-10 23:23:50 +03:00
|
|
|
buf.WriteString(`,"point":`)
|
2018-10-11 00:25:40 +03:00
|
|
|
buf.Write(appendJSONSimplePoint(nil, o))
|
2016-07-10 23:23:50 +03:00
|
|
|
} else {
|
2018-10-11 00:25:40 +03:00
|
|
|
point := o.Center()
|
2021-09-26 16:09:43 +03:00
|
|
|
z := extractZCoordinate(o)
|
2018-10-11 00:25:40 +03:00
|
|
|
if z != 0 {
|
2016-07-10 23:23:50 +03:00
|
|
|
vals = append(vals, resp.ArrayValue([]resp.Value{
|
|
|
|
resp.StringValue(strconv.FormatFloat(point.Y, 'f', -1, 64)),
|
|
|
|
resp.StringValue(strconv.FormatFloat(point.X, 'f', -1, 64)),
|
2018-10-11 00:25:40 +03:00
|
|
|
resp.StringValue(strconv.FormatFloat(z, 'f', -1, 64)),
|
2016-07-10 23:23:50 +03:00
|
|
|
}))
|
2016-03-28 18:57:41 +03:00
|
|
|
} else {
|
|
|
|
vals = append(vals, resp.ArrayValue([]resp.Value{
|
2016-07-10 23:23:50 +03:00
|
|
|
resp.StringValue(strconv.FormatFloat(point.Y, 'f', -1, 64)),
|
|
|
|
resp.StringValue(strconv.FormatFloat(point.X, 'f', -1, 64)),
|
2016-03-28 18:57:41 +03:00
|
|
|
}))
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-07-10 23:23:50 +03:00
|
|
|
case "hash":
|
|
|
|
if vs, sprecision, ok = tokenval(vs); !ok || sprecision == "" {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-07-10 23:23:50 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-07-10 23:23:50 +03:00
|
|
|
buf.WriteString(`,"hash":`)
|
|
|
|
}
|
|
|
|
precision, err := strconv.ParseInt(sprecision, 10, 64)
|
2020-08-12 01:11:06 +03:00
|
|
|
if err != nil || precision < 1 || precision > 12 {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidArgument(sprecision)
|
2016-07-10 23:23:50 +03:00
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
center := o.Center()
|
|
|
|
p := geohash.EncodeWithPrecision(center.Y, center.X, uint(precision))
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-07-10 23:23:50 +03:00
|
|
|
buf.WriteString(`"` + p + `"`)
|
|
|
|
} else {
|
|
|
|
vals = append(vals, resp.StringValue(p))
|
|
|
|
}
|
|
|
|
case "bounds":
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-07-10 23:23:50 +03:00
|
|
|
buf.WriteString(`,"bounds":`)
|
2018-10-11 00:25:40 +03:00
|
|
|
buf.Write(appendJSONSimpleBounds(nil, o))
|
2016-07-10 23:23:50 +03:00
|
|
|
} else {
|
2018-10-11 00:25:40 +03:00
|
|
|
bbox := o.Rect()
|
2016-07-10 23:23:50 +03:00
|
|
|
vals = append(vals, resp.ArrayValue([]resp.Value{
|
|
|
|
resp.ArrayValue([]resp.Value{
|
|
|
|
resp.FloatValue(bbox.Min.Y),
|
|
|
|
resp.FloatValue(bbox.Min.X),
|
|
|
|
}),
|
|
|
|
resp.ArrayValue([]resp.Value{
|
|
|
|
resp.FloatValue(bbox.Max.Y),
|
|
|
|
resp.FloatValue(bbox.Max.X),
|
|
|
|
}),
|
|
|
|
}))
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-07-10 23:23:50 +03:00
|
|
|
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) != 0 {
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, errInvalidNumberOfArguments
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-04-01 22:46:39 +03:00
|
|
|
if withfields {
|
2020-03-04 00:39:43 +03:00
|
|
|
fvs := orderFields(col.FieldMap(), col.FieldArr(), fields)
|
2016-04-01 22:46:39 +03:00
|
|
|
if len(fvs) > 0 {
|
|
|
|
fvals := make([]resp.Value, 0, len(fvs)*2)
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-04-01 22:46:39 +03:00
|
|
|
buf.WriteString(`,"fields":{`)
|
|
|
|
}
|
|
|
|
for i, fv := range fvs {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-04-01 22:46:39 +03:00
|
|
|
if i > 0 {
|
|
|
|
buf.WriteString(`,`)
|
|
|
|
}
|
|
|
|
buf.WriteString(jsonString(fv.field) + ":" + strconv.FormatFloat(fv.value, 'f', -1, 64))
|
|
|
|
} else {
|
|
|
|
fvals = append(fvals, resp.StringValue(fv.field), resp.StringValue(strconv.FormatFloat(fv.value, 'f', -1, 64)))
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-04-01 22:46:39 +03:00
|
|
|
i++
|
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == JSON {
|
2016-04-01 22:46:39 +03:00
|
|
|
buf.WriteString(`}`)
|
2016-03-28 18:57:41 +03:00
|
|
|
} else {
|
2016-04-01 22:46:39 +03:00
|
|
|
vals = append(vals, resp.ArrayValue(fvals))
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-01 22:46:39 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
buf.WriteString(`,"elapsed":"` + time.Since(start).String() + "\"}")
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.StringValue(buf.String()), nil
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2016-04-01 22:46:39 +03:00
|
|
|
var oval resp.Value
|
|
|
|
if withfields {
|
|
|
|
oval = resp.ArrayValue(vals)
|
|
|
|
} else {
|
|
|
|
oval = vals[0]
|
|
|
|
}
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return oval, nil
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
return NOMessage, nil
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdDel(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-03-28 18:57:41 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-03-28 18:57:41 +03:00
|
|
|
var ok bool
|
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, d.id, ok = tokenval(vs); !ok || d.id == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) != 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
found := false
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2016-03-05 02:08:16 +03:00
|
|
|
if col != nil {
|
2018-08-16 23:07:55 +03:00
|
|
|
d.obj, d.fields, ok = col.Delete(d.id)
|
2016-03-28 18:57:41 +03:00
|
|
|
if ok {
|
2016-07-13 07:59:36 +03:00
|
|
|
if col.Count() == 0 {
|
2021-12-09 19:24:26 +03:00
|
|
|
s.deleteCol(d.key)
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
|
|
|
found = true
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
s.groupDisconnectObject(d.key, d.id)
|
2016-03-05 02:08:16 +03:00
|
|
|
d.command = "del"
|
2016-03-28 18:57:41 +03:00
|
|
|
d.updated = found
|
2016-04-02 17:20:30 +03:00
|
|
|
d.timestamp = time.Now()
|
2016-03-28 18:57:41 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2016-03-28 18:57:41 +03:00
|
|
|
if d.updated {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(1)
|
2016-03-28 18:57:41 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(0)
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-12-29 17:53:01 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-12-29 17:53:01 +03:00
|
|
|
var ok bool
|
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, d.pattern, ok = tokenval(vs); !ok || d.pattern == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
now := time.Now()
|
|
|
|
iter := func(id string, o geojson.Object, fields []float64) bool {
|
|
|
|
if match, _ := glob.Match(d.pattern, id); match {
|
2018-11-24 01:53:33 +03:00
|
|
|
d.children = append(d.children, &commandDetails{
|
2016-12-29 17:53:01 +03:00
|
|
|
command: "del",
|
|
|
|
updated: true,
|
|
|
|
timestamp: now,
|
|
|
|
key: d.key,
|
|
|
|
id: id,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-03-29 22:50:04 +03:00
|
|
|
var expired int
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2016-12-29 17:53:01 +03:00
|
|
|
if col != nil {
|
|
|
|
g := glob.Parse(d.pattern, false)
|
|
|
|
if g.Limits[0] == "" && g.Limits[1] == "" {
|
2019-04-24 15:09:41 +03:00
|
|
|
col.Scan(false, nil, msg.Deadline, iter)
|
2016-12-29 17:53:01 +03:00
|
|
|
} else {
|
2019-04-24 15:09:41 +03:00
|
|
|
col.ScanRange(g.Limits[0], g.Limits[1], false, nil, msg.Deadline, iter)
|
2016-12-29 17:53:01 +03:00
|
|
|
}
|
|
|
|
var atLeastOneNotDeleted bool
|
|
|
|
for i, dc := range d.children {
|
2018-08-16 23:07:55 +03:00
|
|
|
dc.obj, dc.fields, ok = col.Delete(dc.id)
|
2016-12-29 17:53:01 +03:00
|
|
|
if !ok {
|
|
|
|
d.children[i].command = "?"
|
|
|
|
atLeastOneNotDeleted = true
|
|
|
|
} else {
|
|
|
|
d.children[i] = dc
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
s.groupDisconnectObject(dc.key, dc.id)
|
2016-12-29 17:53:01 +03:00
|
|
|
}
|
|
|
|
if atLeastOneNotDeleted {
|
2018-11-24 01:53:33 +03:00
|
|
|
var nchildren []*commandDetails
|
2016-12-29 17:53:01 +03:00
|
|
|
for _, dc := range d.children {
|
|
|
|
if dc.command == "del" {
|
|
|
|
nchildren = append(nchildren, dc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.children = nchildren
|
|
|
|
}
|
|
|
|
if col.Count() == 0 {
|
2021-12-09 19:24:26 +03:00
|
|
|
s.deleteCol(d.key)
|
2016-12-29 17:53:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
d.command = "pdel"
|
|
|
|
d.updated = len(d.children) > 0
|
|
|
|
d.timestamp = now
|
|
|
|
d.parent = true
|
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2017-03-29 22:50:04 +03:00
|
|
|
total := len(d.children) - expired
|
|
|
|
if total < 0 {
|
|
|
|
total = 0
|
|
|
|
}
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(total)
|
2016-12-29 17:53:01 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdDrop(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-03-28 18:57:41 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-03-28 18:57:41 +03:00
|
|
|
var ok bool
|
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) != 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2016-03-05 02:08:16 +03:00
|
|
|
if col != nil {
|
2021-12-09 19:24:26 +03:00
|
|
|
s.deleteCol(d.key)
|
2016-03-28 18:57:41 +03:00
|
|
|
d.updated = true
|
2016-03-05 02:08:16 +03:00
|
|
|
} else {
|
|
|
|
d.key = "" // ignore the details
|
2016-03-28 18:57:41 +03:00
|
|
|
d.updated = false
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
s.groupDisconnectCollection(d.key)
|
2016-03-05 02:08:16 +03:00
|
|
|
d.command = "drop"
|
2016-04-02 17:20:30 +03:00
|
|
|
d.timestamp = time.Now()
|
2016-03-28 18:57:41 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2016-03-28 18:57:41 +03:00
|
|
|
if d.updated {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(1)
|
2016-03-28 18:57:41 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(0)
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdRename(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2021-09-13 20:52:20 +03:00
|
|
|
nx := msg.Command() == "renamenx"
|
2018-12-28 04:15:53 +03:00
|
|
|
start := time.Now()
|
|
|
|
vs := msg.Args[1:]
|
|
|
|
var ok bool
|
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, d.newKey, ok = tokenval(vs); !ok || d.newKey == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2018-12-29 01:46:54 +03:00
|
|
|
if col == nil {
|
|
|
|
err = errKeyNotFound
|
|
|
|
return
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
s.hooks.Ascend(nil, func(v interface{}) bool {
|
2021-09-13 20:02:36 +03:00
|
|
|
h := v.(*Hook)
|
2018-12-28 04:15:53 +03:00
|
|
|
if h.Key == d.key || h.Key == d.newKey {
|
|
|
|
err = errKeyHasHooksSet
|
2021-09-13 20:02:36 +03:00
|
|
|
return false
|
2018-12-28 04:15:53 +03:00
|
|
|
}
|
2021-09-13 20:02:36 +03:00
|
|
|
return true
|
|
|
|
})
|
2018-12-28 04:15:53 +03:00
|
|
|
d.command = "rename"
|
2021-12-09 19:24:26 +03:00
|
|
|
newCol := s.getCol(d.newKey)
|
2018-12-29 01:46:54 +03:00
|
|
|
if newCol == nil {
|
|
|
|
d.updated = true
|
|
|
|
} else if nx {
|
|
|
|
d.updated = false
|
|
|
|
} else {
|
2021-12-09 19:24:26 +03:00
|
|
|
s.deleteCol(d.newKey)
|
2018-12-29 01:46:54 +03:00
|
|
|
d.updated = true
|
2018-12-28 04:15:53 +03:00
|
|
|
}
|
|
|
|
if d.updated {
|
2021-12-09 19:24:26 +03:00
|
|
|
s.deleteCol(d.key)
|
|
|
|
s.setCol(d.newKey, col)
|
2018-12-28 04:15:53 +03:00
|
|
|
}
|
|
|
|
d.timestamp = time.Now()
|
|
|
|
switch msg.OutputType {
|
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-12-28 04:15:53 +03:00
|
|
|
case RESP:
|
2018-12-29 01:46:54 +03:00
|
|
|
if !nx {
|
|
|
|
res = resp.SimpleStringValue("OK")
|
|
|
|
} else if d.updated {
|
2018-12-28 04:15:53 +03:00
|
|
|
res = resp.IntegerValue(1)
|
|
|
|
} else {
|
|
|
|
res = resp.IntegerValue(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdFlushDB(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-03-28 18:57:41 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) != 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2021-09-13 20:02:36 +03:00
|
|
|
|
|
|
|
// clear the entire database
|
2021-12-09 19:24:26 +03:00
|
|
|
s.cols = btree.NewNonConcurrent(byCollectionKey)
|
|
|
|
s.groupHooks = btree.NewNonConcurrent(byGroupHook)
|
|
|
|
s.groupObjects = btree.NewNonConcurrent(byGroupObject)
|
|
|
|
s.hookExpires = btree.NewNonConcurrent(byHookExpires)
|
|
|
|
s.hooks = btree.NewNonConcurrent(byHookName)
|
|
|
|
s.hooksOut = btree.NewNonConcurrent(byHookName)
|
|
|
|
s.hookTree = &rtree.RTree{}
|
|
|
|
s.hookCross = &rtree.RTree{}
|
2021-09-13 20:02:36 +03:00
|
|
|
|
2016-03-05 02:08:16 +03:00
|
|
|
d.command = "flushdb"
|
2016-03-28 18:57:41 +03:00
|
|
|
d.updated = true
|
2016-04-02 17:20:30 +03:00
|
|
|
d.timestamp = time.Now()
|
2016-03-28 18:57:41 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.SimpleStringValue("OK")
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) parseSetArgs(vs []string) (
|
2018-11-24 01:53:33 +03:00
|
|
|
d commandDetails, fields []string, values []float64,
|
2016-10-03 18:31:13 +03:00
|
|
|
xx, nx bool,
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
ex int64, etype []byte, evs []string, err error,
|
2016-07-15 22:22:48 +03:00
|
|
|
) {
|
2016-03-28 18:57:41 +03:00
|
|
|
var ok bool
|
2016-11-09 23:43:26 +03:00
|
|
|
var typ []byte
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, d.id, ok = tokenval(vs); !ok || d.id == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
var arg []byte
|
2018-10-29 01:49:45 +03:00
|
|
|
var nvs []string
|
2016-03-05 02:08:16 +03:00
|
|
|
for {
|
2016-11-09 23:43:26 +03:00
|
|
|
if nvs, arg, ok = tokenvalbytes(vs); !ok || len(arg) == 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
if lcb(arg, "field") {
|
2016-03-28 18:57:41 +03:00
|
|
|
vs = nvs
|
2016-03-05 02:08:16 +03:00
|
|
|
var name string
|
|
|
|
var svalue string
|
|
|
|
var value float64
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, name, ok = tokenval(vs); !ok || name == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if isReservedFieldName(name) {
|
|
|
|
err = errInvalidArgument(name)
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, svalue, ok = tokenval(vs); !ok || svalue == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
value, err = strconv.ParseFloat(svalue, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(svalue)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fields = append(fields, name)
|
|
|
|
values = append(values, value)
|
|
|
|
continue
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
if lcb(arg, "ex") {
|
2016-07-15 22:22:48 +03:00
|
|
|
vs = nvs
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
if ex != 0 {
|
2016-11-09 23:43:26 +03:00
|
|
|
err = errInvalidArgument(string(arg))
|
2016-07-15 22:22:48 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var s string
|
|
|
|
var v float64
|
|
|
|
if vs, s, ok = tokenval(vs); !ok || s == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, err = strconv.ParseFloat(s, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(s)
|
|
|
|
return
|
|
|
|
}
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
ex = time.Now().UnixNano() + int64(float64(time.Second)*v)
|
2016-07-15 22:22:48 +03:00
|
|
|
continue
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
if lcb(arg, "xx") {
|
2016-10-03 18:31:13 +03:00
|
|
|
vs = nvs
|
|
|
|
if nx {
|
2016-11-09 23:43:26 +03:00
|
|
|
err = errInvalidArgument(string(arg))
|
2016-10-03 18:31:13 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
xx = true
|
|
|
|
continue
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
if lcb(arg, "nx") {
|
2016-10-03 18:31:13 +03:00
|
|
|
vs = nvs
|
|
|
|
if xx {
|
2016-11-09 23:43:26 +03:00
|
|
|
err = errInvalidArgument(string(arg))
|
2016-10-03 18:31:13 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
nx = true
|
|
|
|
continue
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
break
|
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
if vs, typ, ok = tokenvalbytes(vs); !ok || len(typ) == 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) == 0 {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
etype = typ
|
2016-03-28 18:57:41 +03:00
|
|
|
evs = vs
|
2016-03-05 02:08:16 +03:00
|
|
|
switch {
|
|
|
|
default:
|
2016-11-09 23:43:26 +03:00
|
|
|
err = errInvalidArgument(string(typ))
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
2016-11-09 23:43:26 +03:00
|
|
|
case lcb(typ, "string"):
|
2016-07-10 05:44:28 +03:00
|
|
|
var str string
|
|
|
|
if vs, str, ok = tokenval(vs); !ok {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
d.obj = collection.String(str)
|
2016-11-09 23:43:26 +03:00
|
|
|
case lcb(typ, "point"):
|
2016-03-05 02:08:16 +03:00
|
|
|
var slat, slon, sz string
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, slat, ok = tokenval(vs); !ok || slat == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, slon, ok = tokenval(vs); !ok || slon == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
vs, sz, ok = tokenval(vs)
|
|
|
|
if !ok || sz == "" {
|
2018-10-11 00:25:40 +03:00
|
|
|
var x, y float64
|
|
|
|
y, err = strconv.ParseFloat(slat, 64)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(slat)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
x, err = strconv.ParseFloat(slon, 64)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(slon)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
d.obj = geojson.NewPoint(geometry.Point{X: x, Y: y})
|
2016-03-05 02:08:16 +03:00
|
|
|
} else {
|
2018-10-11 00:25:40 +03:00
|
|
|
var x, y, z float64
|
|
|
|
y, err = strconv.ParseFloat(slat, 64)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(slat)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
x, err = strconv.ParseFloat(slon, 64)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(slon)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
z, err = strconv.ParseFloat(sz, 64)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(sz)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
d.obj = geojson.NewPointZ(geometry.Point{X: x, Y: y}, z)
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-11-09 23:43:26 +03:00
|
|
|
case lcb(typ, "bounds"):
|
2016-03-05 02:08:16 +03:00
|
|
|
var sminlat, sminlon, smaxlat, smaxlon string
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, sminlat, ok = tokenval(vs); !ok || sminlat == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, sminlon, ok = tokenval(vs); !ok || sminlon == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, smaxlat, ok = tokenval(vs); !ok || smaxlat == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, smaxlon, ok = tokenval(vs); !ok || smaxlon == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var minlat, minlon, maxlat, maxlon float64
|
|
|
|
minlat, err = strconv.ParseFloat(sminlat, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(sminlat)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
minlon, err = strconv.ParseFloat(sminlon, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(sminlon)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
maxlat, err = strconv.ParseFloat(smaxlat, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(smaxlat)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
maxlon, err = strconv.ParseFloat(smaxlon, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(smaxlon)
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
d.obj = geojson.NewRect(geometry.Rect{
|
|
|
|
Min: geometry.Point{X: minlon, Y: minlat},
|
|
|
|
Max: geometry.Point{X: maxlon, Y: maxlat},
|
|
|
|
})
|
2016-11-09 23:43:26 +03:00
|
|
|
case lcb(typ, "hash"):
|
2016-03-05 02:08:16 +03:00
|
|
|
var shash string
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, shash, ok = tokenval(vs); !ok || shash == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2018-10-11 00:25:40 +03:00
|
|
|
lat, lon := geohash.Decode(shash)
|
|
|
|
d.obj = geojson.NewPoint(geometry.Point{X: lon, Y: lat})
|
2016-11-09 23:43:26 +03:00
|
|
|
case lcb(typ, "object"):
|
2016-03-28 18:57:41 +03:00
|
|
|
var object string
|
|
|
|
if vs, object, ok = tokenval(vs); !ok || object == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
d.obj, err = geojson.Parse(object, &s.geomParseOpts)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdSet(msg *Message) (res resp.Value, d commandDetails, err error) {
|
|
|
|
if s.config.maxMemory() > 0 && s.outOfMemory.on() {
|
2016-05-24 05:44:25 +03:00
|
|
|
err = errOOM
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-10-03 18:31:13 +03:00
|
|
|
var fmap map[string]int
|
2016-03-05 02:08:16 +03:00
|
|
|
var fields []string
|
|
|
|
var values []float64
|
2016-10-03 18:31:13 +03:00
|
|
|
var xx, nx bool
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
var ex int64
|
2021-12-09 19:24:26 +03:00
|
|
|
d, fields, values, xx, nx, ex, _, _, err = s.parseSetArgs(vs)
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2016-03-05 02:08:16 +03:00
|
|
|
if col == nil {
|
2016-10-03 18:31:13 +03:00
|
|
|
if xx {
|
|
|
|
goto notok
|
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
col = collection.New()
|
2021-12-09 19:24:26 +03:00
|
|
|
s.setCol(d.key, col)
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-10-31 20:17:30 +03:00
|
|
|
if xx || nx {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
_, _, _, ok := col.Get(d.id)
|
2016-10-31 20:17:30 +03:00
|
|
|
if (nx && ok) || (xx && !ok) {
|
2016-10-03 18:31:13 +03:00
|
|
|
goto notok
|
|
|
|
}
|
|
|
|
}
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
d.oldObj, d.oldFields, d.fields = col.Set(d.id, d.obj, fields, values, ex)
|
2016-03-05 02:08:16 +03:00
|
|
|
d.command = "set"
|
2016-03-28 18:57:41 +03:00
|
|
|
d.updated = true // perhaps we should do a diff on the previous object?
|
2016-04-02 17:20:30 +03:00
|
|
|
d.timestamp = time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.ConnType != Null || msg.OutputType != Null {
|
2016-12-06 02:24:26 +03:00
|
|
|
// likely loaded from aof at server startup, ignore field remapping.
|
|
|
|
fmap = col.FieldMap()
|
|
|
|
d.fmap = make(map[string]int)
|
|
|
|
for key, idx := range fmap {
|
|
|
|
d.fmap[key] = idx
|
|
|
|
}
|
|
|
|
}
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
// if ex != nil {
|
|
|
|
// server.expireAt(d.key, d.id, d.timestamp.Add(time.Duration(float64(time.Second)*(*ex))))
|
|
|
|
// }
|
2016-03-28 18:57:41 +03:00
|
|
|
switch msg.OutputType {
|
2016-11-09 23:43:26 +03:00
|
|
|
default:
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.SimpleStringValue("OK")
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
2016-10-03 18:31:13 +03:00
|
|
|
notok:
|
|
|
|
switch msg.OutputType {
|
2016-11-09 23:43:26 +03:00
|
|
|
default:
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2016-10-31 20:17:30 +03:00
|
|
|
if nx {
|
|
|
|
err = errIDAlreadyExists
|
|
|
|
} else {
|
|
|
|
err = errIDNotFound
|
|
|
|
}
|
|
|
|
return
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.NullValue()
|
2016-10-03 18:31:13 +03:00
|
|
|
}
|
|
|
|
return
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) parseFSetArgs(vs []string) (
|
2018-11-24 01:53:33 +03:00
|
|
|
d commandDetails, fields []string, values []float64, xx bool, err error,
|
2017-11-03 21:50:03 +03:00
|
|
|
) {
|
2016-03-28 18:57:41 +03:00
|
|
|
var ok bool
|
|
|
|
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
if vs, d.id, ok = tokenval(vs); !ok || d.id == "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2017-11-03 21:50:03 +03:00
|
|
|
for len(vs) > 0 {
|
|
|
|
var name string
|
|
|
|
if vs, name, ok = tokenval(vs); !ok || name == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if lc(name, "xx") {
|
|
|
|
xx = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if isReservedFieldName(name) {
|
|
|
|
err = errInvalidArgument(name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var svalue string
|
|
|
|
var value float64
|
|
|
|
if vs, svalue, ok = tokenval(vs); !ok || svalue == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
value, err = strconv.ParseFloat(svalue, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(svalue)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fields = append(fields, name)
|
|
|
|
values = append(values, value)
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdFset(msg *Message) (res resp.Value, d commandDetails, err error) {
|
|
|
|
if s.config.maxMemory() > 0 && s.outOfMemory.on() {
|
2018-01-24 02:54:10 +03:00
|
|
|
err = errOOM
|
|
|
|
return
|
|
|
|
}
|
2016-03-28 18:57:41 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2017-11-03 21:50:03 +03:00
|
|
|
var fields []string
|
|
|
|
var values []float64
|
|
|
|
var xx bool
|
2018-10-11 00:25:40 +03:00
|
|
|
var updateCount int
|
2021-12-09 19:24:26 +03:00
|
|
|
d, fields, values, xx, err = s.parseFSetArgs(vs)
|
2017-11-03 21:50:03 +03:00
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(d.key)
|
2016-03-05 02:08:16 +03:00
|
|
|
if col == nil {
|
|
|
|
err = errKeyNotFound
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var ok bool
|
2018-10-11 00:25:40 +03:00
|
|
|
d.obj, d.fields, updateCount, ok = col.SetFields(d.id, fields, values)
|
2017-11-03 21:50:03 +03:00
|
|
|
if !(ok || xx) {
|
2016-03-05 02:08:16 +03:00
|
|
|
err = errIDNotFound
|
|
|
|
return
|
|
|
|
}
|
2017-11-03 21:50:03 +03:00
|
|
|
if ok {
|
|
|
|
d.command = "fset"
|
|
|
|
d.timestamp = time.Now()
|
2018-10-11 00:25:40 +03:00
|
|
|
d.updated = updateCount > 0
|
2017-11-03 21:50:03 +03:00
|
|
|
fmap := col.FieldMap()
|
|
|
|
d.fmap = make(map[string]int)
|
|
|
|
for key, idx := range fmap {
|
|
|
|
d.fmap[key] = idx
|
|
|
|
}
|
2016-04-02 17:20:30 +03:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:57:41 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2018-10-11 00:25:40 +03:00
|
|
|
res = resp.IntegerValue(updateCount)
|
2016-03-28 18:57:41 +03:00
|
|
|
}
|
2016-03-05 02:08:16 +03:00
|
|
|
return
|
|
|
|
}
|
2016-07-15 22:22:48 +03:00
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdExpire(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-07-15 22:22:48 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-07-15 22:22:48 +03:00
|
|
|
var key, id, svalue string
|
|
|
|
var ok bool
|
|
|
|
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, id, ok = tokenval(vs); !ok || id == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, svalue, ok = tokenval(vs); !ok || svalue == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var value float64
|
|
|
|
value, err = strconv.ParseFloat(svalue, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = errInvalidArgument(svalue)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ok = false
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-07-15 22:22:48 +03:00
|
|
|
if col != nil {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
ex := time.Now().Add(time.Duration(float64(time.Second) * value)).UnixNano()
|
|
|
|
ok = col.SetExpires(id, ex)
|
2017-03-29 22:50:04 +03:00
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
d.updated = true
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2017-03-29 22:50:04 +03:00
|
|
|
if ok {
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.StringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2017-03-29 22:50:04 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.SimpleStringValue(""), d, errIDNotFound
|
2017-03-29 22:50:04 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2016-07-15 22:22:48 +03:00
|
|
|
if ok {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(1)
|
2016-07-15 22:22:48 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(0)
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdPersist(msg *Message) (res resp.Value, d commandDetails, err error) {
|
2016-07-15 22:22:48 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-07-15 22:22:48 +03:00
|
|
|
var key, id string
|
|
|
|
var ok bool
|
|
|
|
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, id, ok = tokenval(vs); !ok || id == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
2017-03-29 22:50:04 +03:00
|
|
|
var cleared bool
|
2016-07-15 22:22:48 +03:00
|
|
|
ok = false
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-07-15 22:22:48 +03:00
|
|
|
if col != nil {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
var ex int64
|
|
|
|
_, _, ex, ok = col.Get(id)
|
|
|
|
if ok && ex != 0 {
|
|
|
|
ok = col.SetExpires(id, 0)
|
|
|
|
if ok {
|
|
|
|
cleared = true
|
|
|
|
}
|
2017-03-29 22:50:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !ok {
|
2018-10-29 01:49:45 +03:00
|
|
|
if msg.OutputType == RESP {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.IntegerValue(0), d, nil
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.SimpleStringValue(""), d, errIDNotFound
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
2017-03-29 22:50:04 +03:00
|
|
|
d.command = "persist"
|
|
|
|
d.updated = cleared
|
|
|
|
d.timestamp = time.Now()
|
2016-07-15 22:22:48 +03:00
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2021-03-31 18:13:44 +03:00
|
|
|
res = resp.SimpleStringValue(`{"ok":true,"elapsed":"` + time.Since(start).String() + "\"}")
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2017-03-29 22:50:04 +03:00
|
|
|
if cleared {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(1)
|
2016-07-15 22:22:48 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(0)
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:24:26 +03:00
|
|
|
func (s *Server) cmdTTL(msg *Message) (res resp.Value, err error) {
|
2016-07-15 22:22:48 +03:00
|
|
|
start := time.Now()
|
2018-10-29 01:49:45 +03:00
|
|
|
vs := msg.Args[1:]
|
2016-07-15 22:22:48 +03:00
|
|
|
var key, id string
|
|
|
|
var ok bool
|
|
|
|
if vs, key, ok = tokenval(vs); !ok || key == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vs, id, ok = tokenval(vs); !ok || id == "" {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(vs) != 0 {
|
|
|
|
err = errInvalidNumberOfArguments
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var v float64
|
|
|
|
ok = false
|
|
|
|
var ok2 bool
|
2021-12-09 19:24:26 +03:00
|
|
|
col := s.getCol(key)
|
2016-07-15 22:22:48 +03:00
|
|
|
if col != nil {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
var ex int64
|
|
|
|
_, _, ex, ok = col.Get(id)
|
2016-07-15 22:22:48 +03:00
|
|
|
if ok {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
if ex != 0 {
|
|
|
|
now := start.UnixNano()
|
|
|
|
if now > ex {
|
2017-03-29 22:50:04 +03:00
|
|
|
ok2 = false
|
|
|
|
} else {
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
v = float64(ex-now) / float64(time.Second)
|
2017-03-29 22:50:04 +03:00
|
|
|
if v < 0 {
|
|
|
|
v = 0
|
|
|
|
}
|
Update expiration logic
This commit changes the logic for managing the expiration of
objects in the database.
Before: There was a server-wide hashmap that stored the
collection key, id, and expiration timestamp for all objects
that had a TTL. The hashmap was occasionally probed at 20
random positions, looking for objects that have expired. Those
expired objects were immediately deleted, and if there was 5
or more objects deleted, then the probe happened again, with
no delay. If the number of objects was less than 5 then the
there was a 1/10th of a second delay before the next probe.
Now: Rather than a server-wide hashmap, each collection has
its own ordered priority queue that stores objects with TTLs.
Rather than probing, there is a background routine that
executes every 1/10th of a second, which pops the expired
objects from the collection queues, and deletes them.
The collection/queue method is a more stable approach than
the hashmap/probing method. With probing, we can run into
major cache misses for some cases where there is wide
TTL duration, such as in the hours or days. This may cause
the system to occasionally fall behind, leaving should-be
expired objects in memory. Using a queue, there is no
cache misses, all objects that should be expired will be
right away, regardless of the TTL durations.
Fixes #616
2021-07-12 23:37:50 +03:00
|
|
|
ok2 = true
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch msg.OutputType {
|
2018-10-29 01:49:45 +03:00
|
|
|
case JSON:
|
2017-01-07 19:27:36 +03:00
|
|
|
if ok {
|
|
|
|
var ttl string
|
|
|
|
if ok2 {
|
|
|
|
ttl = strconv.FormatFloat(v, 'f', -1, 64)
|
|
|
|
} else {
|
|
|
|
ttl = "-1"
|
|
|
|
}
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.SimpleStringValue(
|
2021-03-31 18:13:44 +03:00
|
|
|
`{"ok":true,"ttl":` + ttl + `,"elapsed":"` + time.Since(start).String() + "\"}")
|
2017-01-07 19:27:36 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
return resp.SimpleStringValue(""), errIDNotFound
|
2017-01-07 19:27:36 +03:00
|
|
|
}
|
2018-10-29 01:49:45 +03:00
|
|
|
case RESP:
|
2016-07-15 22:22:48 +03:00
|
|
|
if ok {
|
|
|
|
if ok2 {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(int(v))
|
2016-07-15 22:22:48 +03:00
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(-1)
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
} else {
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
res = resp.IntegerValue(-2)
|
2016-07-15 22:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|