Refactor and comment command details

This commit is contained in:
tidwall 2018-11-23 15:53:33 -07:00
parent 1197cca40c
commit f2c217c216
9 changed files with 45 additions and 45 deletions

View File

@ -122,7 +122,7 @@ func (server *Server) flushAOF() {
} }
} }
func (server *Server) writeAOF(args []string, d *commandDetailsT) error { func (server *Server) writeAOF(args []string, d *commandDetails) error {
if d != nil && !d.updated { if d != nil && !d.updated {
// just ignore writes if the command did not update // just ignore writes if the command did not update
@ -189,7 +189,7 @@ func (server *Server) writeAOF(args []string, d *commandDetailsT) error {
return nil return nil
} }
func (server *Server) queueHooks(d *commandDetailsT) error { func (server *Server) queueHooks(d *commandDetails) error {
// big list of all of the messages // big list of all of the messages
var hmsgs []string var hmsgs []string
var hooks []*Hook var hooks []*Hook

View File

@ -293,7 +293,7 @@ func (server *Server) cmdGet(msg *Message) (resp.Value, error) {
return NOMessage, nil return NOMessage, nil
} }
func (server *Server) cmdDel(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdDel(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
var ok bool var ok bool
@ -337,7 +337,7 @@ func (server *Server) cmdDel(msg *Message) (res resp.Value, d commandDetailsT, e
return return
} }
func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
var ok bool var ok bool
@ -356,7 +356,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT,
now := time.Now() now := time.Now()
iter := func(id string, o geojson.Object, fields []float64) bool { iter := func(id string, o geojson.Object, fields []float64) bool {
if match, _ := glob.Match(d.pattern, id); match { if match, _ := glob.Match(d.pattern, id); match {
d.children = append(d.children, &commandDetailsT{ d.children = append(d.children, &commandDetails{
command: "del", command: "del",
updated: true, updated: true,
timestamp: now, timestamp: now,
@ -388,7 +388,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT,
server.clearIDExpires(d.key, dc.id) server.clearIDExpires(d.key, dc.id)
} }
if atLeastOneNotDeleted { if atLeastOneNotDeleted {
var nchildren []*commandDetailsT var nchildren []*commandDetails
for _, dc := range d.children { for _, dc := range d.children {
if dc.command == "del" { if dc.command == "del" {
nchildren = append(nchildren, dc) nchildren = append(nchildren, dc)
@ -417,7 +417,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT,
return return
} }
func (server *Server) cmdDrop(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdDrop(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
var ok bool var ok bool
@ -453,7 +453,7 @@ func (server *Server) cmdDrop(msg *Message) (res resp.Value, d commandDetailsT,
return return
} }
func (server *Server) cmdFlushDB(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdFlushDB(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
if len(vs) != 0 { if len(vs) != 0 {
@ -480,7 +480,7 @@ func (server *Server) cmdFlushDB(msg *Message) (res resp.Value, d commandDetails
} }
func (server *Server) parseSetArgs(vs []string) ( func (server *Server) parseSetArgs(vs []string) (
d commandDetailsT, fields []string, values []float64, d commandDetails, fields []string, values []float64,
xx, nx bool, xx, nx bool,
expires *float64, etype []byte, evs []string, err error, expires *float64, etype []byte, evs []string, err error,
) { ) {
@ -699,7 +699,7 @@ func (server *Server) parseSetArgs(vs []string) (
return return
} }
func (server *Server) cmdSet(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdSet(msg *Message) (res resp.Value, d commandDetails, err error) {
if server.config.maxMemory() > 0 && server.outOfMemory.on() { if server.config.maxMemory() > 0 && server.outOfMemory.on() {
err = errOOM err = errOOM
return return
@ -770,7 +770,7 @@ notok:
} }
func (server *Server) parseFSetArgs(vs []string) ( func (server *Server) parseFSetArgs(vs []string) (
d commandDetailsT, fields []string, values []float64, xx bool, err error, d commandDetails, fields []string, values []float64, xx bool, err error,
) { ) {
var ok bool var ok bool
if vs, d.key, ok = tokenval(vs); !ok || d.key == "" { if vs, d.key, ok = tokenval(vs); !ok || d.key == "" {
@ -812,7 +812,7 @@ func (server *Server) parseFSetArgs(vs []string) (
return return
} }
func (server *Server) cmdFset(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdFset(msg *Message) (res resp.Value, d commandDetails, err error) {
if server.config.maxMemory() > 0 && server.outOfMemory.on() { if server.config.maxMemory() > 0 && server.outOfMemory.on() {
err = errOOM err = errOOM
return return
@ -856,7 +856,7 @@ func (server *Server) cmdFset(msg *Message) (res resp.Value, d commandDetailsT,
return return
} }
func (server *Server) cmdExpire(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdExpire(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
var key, id, svalue string var key, id, svalue string
@ -910,7 +910,7 @@ func (server *Server) cmdExpire(msg *Message) (res resp.Value, d commandDetailsT
return return
} }
func (server *Server) cmdPersist(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (server *Server) cmdPersist(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
var key, id string var key, id string

View File

@ -80,7 +80,7 @@ func (c *Server) cmdMassInsert(msg *Message) (res resp.Value, err error) {
nmsg := &Message{} nmsg := &Message{}
*nmsg = *msg *nmsg = *msg
nmsg.Args = args nmsg.Args = args
var d commandDetailsT var d commandDetails
_, d, err = c.command(nmsg, nil) _, d, err = c.command(nmsg, nil)
if err != nil { if err != nil {
return err return err

View File

@ -12,7 +12,7 @@ import (
) )
// FenceMatch executes a fence match returns back json messages for fence detection. // FenceMatch executes a fence match returns back json messages for fence detection.
func FenceMatch(hookName string, sw *scanWriter, fence *liveFenceSwitches, metas []FenceMeta, details *commandDetailsT) []string { func FenceMatch(hookName string, sw *scanWriter, fence *liveFenceSwitches, metas []FenceMeta, details *commandDetails) []string {
msgs := fenceMatch(hookName, sw, fence, metas, details) msgs := fenceMatch(hookName, sw, fence, metas, details)
if len(fence.accept) == 0 { if len(fence.accept) == 0 {
return msgs return msgs
@ -55,7 +55,7 @@ func hookJSONString(hookName string, metas []FenceMeta) string {
} }
func fenceMatch( func fenceMatch(
hookName string, sw *scanWriter, fence *liveFenceSwitches, hookName string, sw *scanWriter, fence *liveFenceSwitches,
metas []FenceMeta, details *commandDetailsT, metas []FenceMeta, details *commandDetails,
) []string { ) []string {
if details.command == "drop" { if details.command == "drop" {
return []string{ return []string{

View File

@ -36,7 +36,7 @@ func (a hooksByName) Swap(i, j int) {
} }
func (c *Server) cmdSetHook(msg *Message, chanCmd bool) ( func (c *Server) cmdSetHook(msg *Message, chanCmd bool) (
res resp.Value, d commandDetailsT, err error, res resp.Value, d commandDetails, err error,
) { ) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
@ -204,7 +204,7 @@ func (c *Server) cmdSetHook(msg *Message, chanCmd bool) (
} }
func (c *Server) cmdDelHook(msg *Message, chanCmd bool) ( func (c *Server) cmdDelHook(msg *Message, chanCmd bool) (
res resp.Value, d commandDetailsT, err error, res resp.Value, d commandDetails, err error,
) { ) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]
@ -240,7 +240,7 @@ func (c *Server) cmdDelHook(msg *Message, chanCmd bool) (
} }
func (c *Server) cmdPDelHook(msg *Message, channel bool) ( func (c *Server) cmdPDelHook(msg *Message, channel bool) (
res resp.Value, d commandDetailsT, err error, res resp.Value, d commandDetails, err error,
) { ) {
start := time.Now() start := time.Now()
vs := msg.Args[1:] vs := msg.Args[1:]

View File

@ -156,7 +156,7 @@ func (c *Server) cmdJget(msg *Message) (resp.Value, error) {
return NOMessage, nil return NOMessage, nil
} }
func (c *Server) cmdJset(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (c *Server) cmdJset(msg *Message) (res resp.Value, d commandDetails, err error) {
// JSET key path value [RAW] // JSET key path value [RAW]
start := time.Now() start := time.Now()
@ -248,7 +248,7 @@ func (c *Server) cmdJset(msg *Message) (res resp.Value, d commandDetailsT, err e
return NOMessage, d, nil return NOMessage, d, nil
} }
func (c *Server) cmdJdel(msg *Message) (res resp.Value, d commandDetailsT, err error) { func (c *Server) cmdJdel(msg *Message) (res resp.Value, d commandDetails, err error) {
start := time.Now() start := time.Now()
if len(msg.Args) != 4 { if len(msg.Args) != 4 {

View File

@ -15,7 +15,7 @@ type liveBuffer struct {
key string key string
glob string glob string
fence *liveFenceSwitches fence *liveFenceSwitches
details []*commandDetailsT details []*commandDetails
cond *sync.Cond cond *sync.Cond
} }

View File

@ -558,7 +558,7 @@ func (c *Server) cmdScriptFlush(msg *Message) (resp.Value, error) {
} }
func (c *Server) commandInScript(msg *Message) ( func (c *Server) commandInScript(msg *Message) (
res resp.Value, d commandDetailsT, err error, res resp.Value, d commandDetails, err error,
) { ) {
switch msg.Command() { switch msg.Command() {
default: default:

View File

@ -38,26 +38,26 @@ import (
var errOOM = errors.New("OOM command not allowed when used memory > 'maxmemory'") var errOOM = errors.New("OOM command not allowed when used memory > 'maxmemory'")
const goingLive = "going live" const (
goingLive = "going live"
hookLogPrefix = "hook:log:"
)
const hookLogPrefix = "hook:log:" // commandDetails is detailed information about a mutable command. It's used
// for geofence formulas.
type commandDetailsT struct { type commandDetails struct {
command string command string // client command, like "SET" or "DEL"
key, id string key, id string // collection key and object id of object
field string fmap map[string]int // map of field names to value indexes
value float64 obj geojson.Object // new object
obj geojson.Object fields []float64 // array of field values
fields []float64 oldObj geojson.Object // previous object, if any
fmap map[string]int oldFields []float64 // previous object field values
oldObj geojson.Object updated bool // object was updated
oldFields []float64 timestamp time.Time // timestamp when the update occured
updated bool parent bool // when true, only children are forwarded
timestamp time.Time pattern string // PDEL key pattern
children []*commandDetails // for multi actions such as "PDEL"
parent bool // when true, only children are forwarded
pattern string // PDEL key pattern
children []*commandDetailsT // for multi actions such as "PDEL"
} }
// Server is a tile38 controller // Server is a tile38 controller
@ -101,7 +101,7 @@ type Server struct {
follows map[*bytes.Buffer]bool follows map[*bytes.Buffer]bool
fcond *sync.Cond fcond *sync.Cond
lstack []*commandDetailsT lstack []*commandDetails
lives map[*liveBuffer]bool lives map[*liveBuffer]bool
lcond *sync.Cond lcond *sync.Cond
fcup bool // follow caught up fcup bool // follow caught up
@ -1053,7 +1053,7 @@ func (server *Server) reset() {
} }
func (server *Server) command(msg *Message, client *Client) ( func (server *Server) command(msg *Message, client *Client) (
res resp.Value, d commandDetailsT, err error, res resp.Value, d commandDetails, err error,
) { ) {
switch msg.Command() { switch msg.Command() {
default: default: