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 {
// 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

View File

@ -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

View File

@ -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

View File

@ -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{

View File

@ -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:]

View File

@ -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 {

View File

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

View File

@ -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:

View File

@ -38,26 +38,26 @@ import (
var errOOM = errors.New("OOM command not allowed when used memory > 'maxmemory'")
const goingLive = "going live"
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
const (
goingLive = "going live"
hookLogPrefix = "hook:log:"
)
// 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 []*commandDetailsT // for multi actions such as "PDEL"
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: