fix data race on call map in single = logic

This moves the code which modifies the PQL call object if a Row query
on an int field uses a single = instead of ==. Instead of processing
this at the shard level, we'll process it during the initial
translation step so that it isn't operated on concurrently.
This commit is contained in:
Matt Jaffee 2020-10-14 16:10:20 -05:00
parent a293f864f2
commit 937bc271de
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -2503,24 +2503,6 @@ func (e *executor) executeRowShard(ctx context.Context, index string, c *pql.Cal
}
}
timeNotSet := fromTime.IsZero() && toTime.IsZero()
// This is workaround to support pql.ASSIGN ('=') as condition ('==') for int and decimal fields
if c.Name == "Row" && timeNotSet &&
(f.Type() == FieldTypeInt || f.Type() == FieldTypeDecimal) {
// re-write args as conditions for fieldName
for k, v := range c.Args {
if _, ok := v.(*pql.Condition); k == fieldName && !ok {
c.Args[k] = &pql.Condition{
Op: pql.EQ,
Value: v,
}
return e.executeRowBSIGroupShard(ctx, index, c, shard)
}
}
}
rowID, rowOK, rowErr := c.UintArg(fieldName)
if rowErr != nil {
return nil, fmt.Errorf("Row() error with arg for row: %v", rowErr)
@ -2529,6 +2511,7 @@ func (e *executor) executeRowShard(ctx context.Context, index string, c *pql.Cal
}
// Simply return row if times are not set.
timeNotSet := fromTime.IsZero() && toTime.IsZero()
if c.Name == "Row" && timeNotSet {
frag := e.Holder.fragment(index, fieldName, viewStandard, shard)
if frag == nil {
@ -4073,8 +4056,9 @@ func (e *executor) translateCall(ctx context.Context, indexName string, c *pql.C
}
// Translate row key, if field is specified & key exists.
var field *Field
if fieldName != "" {
field := idx.Field(fieldName)
field = idx.Field(fieldName)
if field == nil {
// Instead of returning ErrFieldNotFound here,
// we just return, and don't attempt the translation.
@ -4212,6 +4196,21 @@ func (e *executor) translateCall(ctx context.Context, indexName string, c *pql.C
}
}
// This is workaround to support pql.ASSIGN ('=') as condition ('==') for int and decimal fields
if c.Name == "Row" && field != nil &&
(field.Type() == FieldTypeInt || field.Type() == FieldTypeDecimal) {
// re-write args as conditions for fieldName
for k, v := range c.Args {
if _, ok := v.(*pql.Condition); k == fieldName && !ok {
c.Args[k] = &pql.Condition{
Op: pql.EQ,
Value: v,
}
break
}
}
}
return nil
}