From f2c217c216cad2b0fec0236faabe91fb110d5f05 Mon Sep 17 00:00:00 2001 From: tidwall Date: Fri, 23 Nov 2018 15:53:33 -0700 Subject: [PATCH] Refactor and comment command details --- internal/server/aof.go | 4 ++-- internal/server/crud.go | 24 +++++++++++----------- internal/server/dev.go | 2 +- internal/server/fence.go | 4 ++-- internal/server/hooks.go | 6 +++--- internal/server/json.go | 4 ++-- internal/server/live.go | 2 +- internal/server/scripts.go | 2 +- internal/server/server.go | 42 +++++++++++++++++++------------------- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/internal/server/aof.go b/internal/server/aof.go index 50263345..c8e8382d 100644 --- a/internal/server/aof.go +++ b/internal/server/aof.go @@ -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 { // just ignore writes if the command did not update @@ -189,7 +189,7 @@ func (server *Server) writeAOF(args []string, d *commandDetailsT) error { return nil } -func (server *Server) queueHooks(d *commandDetailsT) error { +func (server *Server) queueHooks(d *commandDetails) error { // big list of all of the messages var hmsgs []string var hooks []*Hook diff --git a/internal/server/crud.go b/internal/server/crud.go index 089a25d3..e2a17933 100644 --- a/internal/server/crud.go +++ b/internal/server/crud.go @@ -293,7 +293,7 @@ func (server *Server) cmdGet(msg *Message) (resp.Value, error) { 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() vs := msg.Args[1:] var ok bool @@ -337,7 +337,7 @@ func (server *Server) cmdDel(msg *Message) (res resp.Value, d commandDetailsT, e 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() vs := msg.Args[1:] var ok bool @@ -356,7 +356,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT, now := time.Now() iter := func(id string, o geojson.Object, fields []float64) bool { if match, _ := glob.Match(d.pattern, id); match { - d.children = append(d.children, &commandDetailsT{ + d.children = append(d.children, &commandDetails{ command: "del", updated: true, timestamp: now, @@ -388,7 +388,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT, server.clearIDExpires(d.key, dc.id) } if atLeastOneNotDeleted { - var nchildren []*commandDetailsT + var nchildren []*commandDetails for _, dc := range d.children { if dc.command == "del" { nchildren = append(nchildren, dc) @@ -417,7 +417,7 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT, 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() vs := msg.Args[1:] var ok bool @@ -453,7 +453,7 @@ func (server *Server) cmdDrop(msg *Message) (res resp.Value, d commandDetailsT, 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() vs := msg.Args[1:] 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) ( - d commandDetailsT, fields []string, values []float64, + d commandDetails, fields []string, values []float64, xx, nx bool, expires *float64, etype []byte, evs []string, err error, ) { @@ -699,7 +699,7 @@ func (server *Server) parseSetArgs(vs []string) ( 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() { err = errOOM return @@ -770,7 +770,7 @@ notok: } 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 if vs, d.key, ok = tokenval(vs); !ok || d.key == "" { @@ -812,7 +812,7 @@ func (server *Server) parseFSetArgs(vs []string) ( 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() { err = errOOM return @@ -856,7 +856,7 @@ func (server *Server) cmdFset(msg *Message) (res resp.Value, d commandDetailsT, 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() vs := msg.Args[1:] var key, id, svalue string @@ -910,7 +910,7 @@ func (server *Server) cmdExpire(msg *Message) (res resp.Value, d commandDetailsT 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() vs := msg.Args[1:] var key, id string diff --git a/internal/server/dev.go b/internal/server/dev.go index 7609ea1d..de071895 100644 --- a/internal/server/dev.go +++ b/internal/server/dev.go @@ -80,7 +80,7 @@ func (c *Server) cmdMassInsert(msg *Message) (res resp.Value, err error) { nmsg := &Message{} *nmsg = *msg nmsg.Args = args - var d commandDetailsT + var d commandDetails _, d, err = c.command(nmsg, nil) if err != nil { return err diff --git a/internal/server/fence.go b/internal/server/fence.go index 4fe67b19..93545e01 100644 --- a/internal/server/fence.go +++ b/internal/server/fence.go @@ -12,7 +12,7 @@ import ( ) // 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) if len(fence.accept) == 0 { return msgs @@ -55,7 +55,7 @@ func hookJSONString(hookName string, metas []FenceMeta) string { } func fenceMatch( hookName string, sw *scanWriter, fence *liveFenceSwitches, - metas []FenceMeta, details *commandDetailsT, + metas []FenceMeta, details *commandDetails, ) []string { if details.command == "drop" { return []string{ diff --git a/internal/server/hooks.go b/internal/server/hooks.go index d155532a..29ac5a7b 100644 --- a/internal/server/hooks.go +++ b/internal/server/hooks.go @@ -36,7 +36,7 @@ func (a hooksByName) Swap(i, j int) { } 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() vs := msg.Args[1:] @@ -204,7 +204,7 @@ func (c *Server) cmdSetHook(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() vs := msg.Args[1:] @@ -240,7 +240,7 @@ func (c *Server) cmdDelHook(msg *Message, chanCmd 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() vs := msg.Args[1:] diff --git a/internal/server/json.go b/internal/server/json.go index fb8b0cb7..8706dbb8 100644 --- a/internal/server/json.go +++ b/internal/server/json.go @@ -156,7 +156,7 @@ func (c *Server) cmdJget(msg *Message) (resp.Value, error) { 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] start := time.Now() @@ -248,7 +248,7 @@ func (c *Server) cmdJset(msg *Message) (res resp.Value, d commandDetailsT, err e 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() if len(msg.Args) != 4 { diff --git a/internal/server/live.go b/internal/server/live.go index 042e071e..7ba0c7d1 100644 --- a/internal/server/live.go +++ b/internal/server/live.go @@ -15,7 +15,7 @@ type liveBuffer struct { key string glob string fence *liveFenceSwitches - details []*commandDetailsT + details []*commandDetails cond *sync.Cond } diff --git a/internal/server/scripts.go b/internal/server/scripts.go index f5473a93..13832fbd 100644 --- a/internal/server/scripts.go +++ b/internal/server/scripts.go @@ -558,7 +558,7 @@ func (c *Server) cmdScriptFlush(msg *Message) (resp.Value, error) { } func (c *Server) commandInScript(msg *Message) ( - res resp.Value, d commandDetailsT, err error, + res resp.Value, d commandDetails, err error, ) { switch msg.Command() { default: diff --git a/internal/server/server.go b/internal/server/server.go index 9e208794..6707e03f 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -38,26 +38,26 @@ import ( 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:" - -type commandDetailsT struct { - command string - key, id string - field string - value float64 - obj geojson.Object - fields []float64 - fmap map[string]int - oldObj geojson.Object - oldFields []float64 - updated bool - timestamp time.Time - - parent bool // when true, only children are forwarded - pattern string // PDEL key pattern - children []*commandDetailsT // for multi actions such as "PDEL" +// commandDetails is detailed information about a mutable command. It's used +// for geofence formulas. +type commandDetails struct { + command string // client command, like "SET" or "DEL" + key, id string // collection key and object id of object + fmap map[string]int // map of field names to value indexes + obj geojson.Object // new object + fields []float64 // array of field values + oldObj geojson.Object // previous object, if any + oldFields []float64 // previous object field values + updated bool // object was updated + timestamp time.Time // timestamp when the update occured + parent bool // when true, only children are forwarded + pattern string // PDEL key pattern + children []*commandDetails // for multi actions such as "PDEL" } // Server is a tile38 controller @@ -101,7 +101,7 @@ type Server struct { follows map[*bytes.Buffer]bool fcond *sync.Cond - lstack []*commandDetailsT + lstack []*commandDetails lives map[*liveBuffer]bool lcond *sync.Cond fcup bool // follow caught up @@ -1053,7 +1053,7 @@ func (server *Server) reset() { } 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() { default: