-
Notifications
You must be signed in to change notification settings - Fork 59
/
state_indexed.go
727 lines (624 loc) · 19 KB
/
state_indexed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
// Copyright 2015 Comcast Cable Communications Management, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// End Copyright
package core
// A location's state, which is basically a write-through cache in
// front of persistent storage. A location stores facts and rules.
// This code stores rules as facts ('{"rule":{"when":...}}'). Facts
// are indexed with a TermIndex. To find rules given an event, we use
// a PatternIndex to index rule 'when' clauses.
import (
"encoding/json"
"fmt"
"strings"
"sync"
"time"
// "code.google.com/p/rog-go/exp/deepcopy" // Broken
)
type IndexedState struct {
sync.RWMutex
// Name should probably the name of the location for this state.
Name string
// Loc points to the state's location in order to call back to
// the location for certain operations.
loc *Location
// FactIndex is the in-memory term index that allows us to
// search facts.
FactIndex *TermIndex
// RuleIndex is the in-memory pattern index that allows us to
// find rules for an incoming event.
RuleIndex *PatternIndex
// Map from IDs to facts.
IdToFact map[string]Map
// Store is how we persist and load data.
Store Storage
// Loaded indicates whether we have loaded data from Store.
Loaded bool
addHook AddHookFn
remHook RemHookFn
}
func (s *IndexedState) withPrivilege(ctx *Context) {
ctx.grantPrivilege("hook")
}
func (s *IndexedState) withoutPrivilege(ctx *Context) {
ctx.revokePrivilege()
}
func (s *IndexedState) slock(ctx *Context, read bool) {
Log(DEBUG, ctx, "IndexedState.slock", "read", read, "priv", ctx.isPrivileged("hook"))
if ctx != nil && ctx.isPrivileged("hook") {
return
}
if read {
s.RLock()
} else {
s.Lock()
}
}
func (s *IndexedState) sunlock(ctx *Context, read bool) {
Log(DEBUG, ctx, "IndexedState.sunlock", "read", read, "priv", ctx.isPrivileged("hook"))
if ctx != nil && ctx.isPrivileged("hook") {
return
}
if read {
s.RUnlock()
} else {
s.Unlock()
}
}
func (s *IndexedState) init(ctx *Context) error {
s.IdToFact = make(map[string]Map)
s.FactIndex = NewTermIndex()
s.RuleIndex = NewPatternIndex()
return nil
}
func NewIndexedState(ctx *Context, name string, store Storage) (*IndexedState, error) {
s := IndexedState{}
s.Name = name
if err := s.init(ctx); err != nil {
return nil, err
}
s.Store = store
return &s, nil
}
func (s *IndexedState) AddHook(hook AddHookFn) {
s.addHook = hook
}
func (s *IndexedState) RemHook(hook RemHookFn) {
s.remHook = hook
}
func (s *IndexedState) Count(ctx *Context) int {
s.slock(ctx, true)
n := len(s.IdToFact)
s.sunlock(ctx, true)
return n
}
func (s *IndexedState) IsLoaded(ctx *Context) bool {
s.slock(ctx, true)
loaded := s.Loaded
s.sunlock(ctx, true)
return loaded
}
func (s *IndexedState) Load(ctx *Context) error {
Log(INFO, ctx, "IndexedState.Load", "location", s.Name)
timer := NewTimer(ctx, "IndexedState.Load")
// ToDo: Combine defered code?
defer timer.Stop()
s.slock(ctx, false)
defer s.sunlock(ctx, false)
if s.Loaded {
Log(WARN, ctx, "IndexedState.Load", "location", s.Name, "loaded", "already")
return nil
}
pairs, err := s.Store.Load(ctx, s.Name)
if err != nil {
Log(ERROR, ctx, "IndexedState.Load", "location", s.Name, "error", err, "when", "Store.Load")
return err
}
for _, pair := range pairs {
id := string(pair.K)
bs := pair.V
var x Map
if err := json.Unmarshal(bs, &x); err != nil {
return err
}
_, err := s.add(ctx, id, x)
if err != nil {
_, is := err.(*ExpiredError)
if is {
// We have an expired fact in storage.
// Need to delete it and then skip it here.
// since no cache has been created, just remove it directly from the store
if _, err = s.Store.Remove(ctx, s.Name, []byte(id)); err != nil {
Log(ERROR, ctx, "IndexedState.Load", "location", s.Name, "error", err, "when", "rem", "id", id)
return err
}
} else {
Log(ERROR, ctx, "IndexedState.Load", "location", s.Name, "error", err, "when", "Store.Add", "pair", pair)
return err
}
}
}
s.Loaded = true
return nil
}
// ExtractTerms gets the terms from the given fact (or pattern).
// Since our TermIndex currently uses hash tables, it cannot do
// searches based on prefixes. Therefore, we extract all atomic terms
// without regard to structure.
//
// See the Elasticsearch FDS in another repo. That FDS uses Lucene's
// B*trees ordering to do prefix-based searches. If we are using such
// an FDS, we could extract terms with structure such as 'a.b.c' from
// {"a":{"b":"c"}}. We went to a fair amount of trouble to do that
// previously, and we might want to reimplement this FDS to provide
// support for searches based on term prefixes. Shouldn't be a huge
// deal.
//
// We might want to skip certain terms here that will have little
// value. Large numbers are candidates. Will a large number really
// help to find facts? We don't want an unbounded number of terms
// anyway, so numbers are suspect.
func ExtractTerms(ctx *Context, fact map[string]interface{}) []string {
terms := make(StringSet)
extractTermsAux(ctx, fact, terms, 0)
acc := terms.Array()
Log(DEBUG, ctx, "core.ExtractTerms", "fact", fact, "terms", acc)
return acc
}
func extractTermsAux(ctx *Context, x interface{}, terms StringSet, depth int) {
switch vv := x.(type) {
case string:
if !IsVariable(vv) {
if len(vv) < SystemParameters.StringLengthTermLimit {
terms.Add(vv)
}
}
case map[string]interface{}: // Fact
for k, v := range vv {
// Always index the property.
extractTermsAux(ctx, k, terms, depth+1)
switch k {
case "rule":
// Don't index the body of a rule.
continue
}
// Do not index the value of a property ending in '!'.
if strings.HasSuffix(k, "!") {
continue
}
extractTermsAux(ctx, v, terms, depth+1)
}
case []interface{}:
for _, y := range vv {
extractTermsAux(ctx, y, terms, depth+1)
}
case []string:
// ToDo: Contemplate use of ISlice.
for _, s := range vv {
extractTermsAux(ctx, s, terms, depth+1)
}
default:
// We don't index what we don't understand -- or what
// we otherwise choose to ignore. Numbers, for
// example.
}
Log(DEBUG, ctx, "core.extractTermsAux", "input", Gorep(x), "terms", terms)
}
func (s *IndexedState) Add(ctx *Context, id string, x Map) (string, error) {
Log(DEBUG, ctx, "IndexedState.Add", "state", s.Name, "factx", x, "id", id)
s.slock(ctx, false)
id, err := s.add(ctx, id, x)
s.sunlock(ctx, false)
if nil != err {
return "", err
}
js, err := json.Marshal(&x)
if err != nil {
return "", err
}
d := Pair{[]byte(id), js}
err = s.Store.Add(ctx, s.Name, &d)
if err != nil {
Log(WARN, ctx, "IndexedState.Add", "state", s.Name, "factjs", string(js), "id", id, "error", err)
return "", err
}
return id, err
}
func (s *IndexedState) add(ctx *Context, id string, x Map) (string, error) {
Log(DEBUG, ctx, "IndexedState.add", "state", s.Name, "factx", x, "id", id)
then := time.Now()
id, fact, err := PrepareFact(ctx, id, x)
if err != nil {
return id, err
}
rule, err := ExtractRule(ctx, fact, false)
if err != nil {
return id, err
}
if rule != nil {
// ToDo: Metric(ctx, "RuleUpdated", "location", s.Name, "ruleId", id)
Log(DEBUG, ctx, "IndexedState.add", "state", s.Name, "rule", rule, "ruleId", id)
if _, scheduled := rule["schedule"]; !scheduled {
if err = s.indexRule(ctx, id, rule); err != nil {
return "", err
}
}
}
// Try the hook first?
if s.addHook != nil {
s.withPrivilege(ctx)
defer s.withoutPrivilege(ctx)
err := s.addHook(ctx, s, id, fact, ctx.GetLoc().loading)
if err != nil {
Log(ERROR, ctx, "IndexedState.add", "state", s.Name, "error", err,
"when", "addHook")
return "", err
}
}
Log(DEBUG, ctx, "IndexedState.add", "state", s.Name, "fact", fact)
terms := ExtractTerms(ctx, fact)
for _, term := range terms {
s.FactIndex.Add(ctx, term, id)
}
s.IdToFact[id] = fact
elapsed := time.Now().Sub(then).Nanoseconds()
Log(DEBUG, ctx, "IndexedState.add", "state", s.Name, "id", id, "elapsed", elapsed)
return id, nil
}
// GetRulesPatterns extracts the rule's 'when' pattern.
func GetRulePatterns(ctx *Context, rule map[string]interface{}) []map[string]interface{} {
eventPattern, have := rule["when"]
if !have {
return nil
}
when := eventPattern.(map[string]interface{})
events := make([]map[string]interface{}, 0, 1)
p, fromQuery := when["pattern"]
// ToDo: Better type processing.
if fromQuery {
events = append(events, p.(map[string]interface{}))
} else {
events = append(events, when)
}
Log(DEBUG, ctx, "core.GetRulePatterns", "events", events)
return events
}
func (s *IndexedState) indexRule(ctx *Context, id string, rule map[string]interface{}) error {
Log(DEBUG, ctx, "IndexedState.indexRule", "state", s.Name, "rule", rule, "ruleId", id)
patterns := GetRulePatterns(ctx, rule)
if nil == patterns {
return NewSyntaxError("No 'when' in rule.")
}
_, have := s.IdToFact[id]
if have {
if err := s.unindexRule(ctx, id, rule); err != nil {
return err
}
}
for _, m := range patterns {
if err := s.RuleIndex.AddPatternMap(ctx, m, id); err != nil {
Log(ERROR, ctx, "IndexedState.indexRule", "id", id, "pattern", m, "error", err)
return err
}
}
return nil
}
func (s *IndexedState) unindexRule(ctx *Context, id string, rule map[string]interface{}) error {
Log(DEBUG, ctx, "IndexedState.unindexRule", "state", s.Name, "rule", rule, "ruleId", id)
patterns := GetRulePatterns(ctx, rule)
if patterns == nil {
return nil
}
for _, m := range patterns {
Log(DEBUG, ctx, "IndexedState.index", "id", id, "pattern", m)
if err := s.RuleIndex.RemPatternMap(ctx, m, id); err != nil {
Log(ERROR, ctx, "IndexedState.unindex", "id", id, "pattern", m, "error", err)
return err
}
}
return nil
}
func (s *IndexedState) Rem(ctx *Context, id string) (bool, error) {
Log(DEBUG, ctx, "IndexedState.Rem", "id", id)
timer := NewTimer(ctx, "IndexedState.Rem")
defer timer.Stop()
s.slock(ctx, false)
defer s.sunlock(ctx, false)
if s.remHook != nil {
// Consider the lock.
s.withPrivilege(ctx)
defer s.withoutPrivilege(ctx)
err := s.remHook(ctx, s, id)
if err != nil {
Log(ERROR, ctx, "IndexedState.Rem", "state", s.Name, "error", err,
"id", id, "when", "remHook")
// ToDo: Consider queuing, falling through, ...
return false, err
}
}
done, err := s.rem(ctx, id)
return done, err
}
func (s *IndexedState) rem(ctx *Context, id string) (bool, error) {
Log(DEBUG, ctx, "IndexedState.rem", "name", s.Name, "id", id)
// Currently we don't return an error if the fact isn't found.
// ToDo: Reconsider. For example, maybe have an additional
// argument that controls whether an error is return when the
// fact isn't found.
fact, have := s.IdToFact[id]
if have {
Log(DEBUG, ctx, "IndexedState.rem", "state", s.Name, "id", id, "fact", fact)
rule, err := ExtractRule(ctx, fact, false)
if err != nil {
return false, nil
}
if rule != nil {
if err := s.unindexRule(ctx, id, rule); err != nil {
return false, err
}
}
delete(s.IdToFact, id)
s.FactIndex.RemIdTerms(ctx, ExtractTerms(ctx, fact), id)
_, err = s.Store.Remove(ctx, s.Name, []byte(id))
if err != nil {
return true, err
}
} else {
Log(DEBUG, ctx, "IndexedState.rem", "state", s.Name, "id", id, "warning", "not found")
}
// ToDo: contemplate performance impact.
if err := s.deleteDependencies(ctx, id); nil != err {
// ToDo: Somebody handle err
Log(ERROR, ctx, "IndexedState.rem", "state", s.Name, "id", id, "error", err, "when", "deleteDependencies")
return have, err
}
return have, nil
}
func (s *IndexedState) deleteDependencies(ctx *Context, id string) error {
Log(DEBUG, ctx, "IndexedState.deleteDependencies", "location", s.Name, "id", id)
srs, err := s.search(ctx, Map{KW_DeleteWith: []string{id}})
if nil != err {
return err
}
Log(DEBUG, ctx, "IndexedState.deleteDependencies", "location", s.Name, "id", id, "found", len(srs.Found))
for _, sr := range srs.Found {
Log(DEBUG, ctx, "IndexedState.deleteDependencies",
"location", s.Name, "id", id, "target", sr.Id)
if _, err := s.rem(ctx, sr.Id); nil != err {
return err
}
}
return nil
}
func (s *IndexedState) remHooks(ctx *Context) error {
if s.remHook != nil {
// Try to run the remHook for every fact.
//
// Consider the lock.
s.withPrivilege(ctx)
defer s.withoutPrivilege(ctx)
for id := range s.IdToFact {
err := s.remHook(ctx, s, id)
if err != nil {
Log(ERROR, ctx, "IndexedState.Clear", "state", s.Name, "error", err,
"id", id, "when", "remHook")
return err
}
}
}
return nil
}
func (s *IndexedState) Clear(ctx *Context) error {
// We can easily get inconsistent here due to various failures.
// ToDo: Something better.
Log(INFO, ctx, "IndexedState.Clear", "name", s.Name)
s.slock(ctx, false)
defer s.sunlock(ctx, false)
if err := s.remHooks(ctx); err != nil {
return err
}
var err error
if _, err = s.Store.Clear(ctx, s.Name); err == nil {
err = s.init(ctx)
}
// ToDo: Something better
return err
}
func (s *IndexedState) Delete(ctx *Context) error {
Log(DEBUG, ctx, "IndexedState.Delete", "name", s.Name)
s.slock(ctx, false)
defer s.sunlock(ctx, false)
if err := s.remHooks(ctx); err != nil {
return err
}
var err error
if err = s.Store.Delete(ctx, s.Name); err == nil {
err = s.init(ctx)
}
// ToDo: Something better
return err
}
func (s *IndexedState) Get(ctx *Context, id string) (Map, error) {
fact, err := s.get(ctx, id, true)
return fact, err
}
func (s *IndexedState) get(ctx *Context, id string, getLock bool) (Map, error) {
// Assumes we have a read lock!
Log(DEBUG, ctx, "IndexedState.get", "name", s.Name, "id", id)
if getLock {
s.slock(ctx, true)
}
fact, found := s.IdToFact[id]
if getLock {
s.sunlock(ctx, true)
}
if !found {
return nil, NewNotFoundError("%s", id)
}
expired, err := s.expire(ctx, id, fact, 0)
if err != nil {
Log(ERROR, ctx, "IndexedState.Get", "error", err, "when", "expiring")
return nil, err
}
if expired {
Log(ERROR, ctx, "IndexedState.Get", "expired", expired, "id", id)
return nil, NewNotFoundError("%s", id)
}
maybeInjectId(ctx, id, fact, false)
return fact, nil
}
func (s *IndexedState) SearchForIDs(ctx *Context, pattern Map) ([]string, error) {
Log(DEBUG, ctx, "IndexedState.SearchForIDs", "location", s.Name, "pattern", pattern)
terms := ExtractTerms(ctx, pattern)
ids, err := s.FactIndex.Search(ctx, terms)
return ids, err
}
// expire checks for expiration and removes the fact if expired.
//
// This method is mostly generic and could be dissociated from
// IndexedState.
func (s *IndexedState) expire(ctx *Context, id string, fact map[string]interface{}, unixNow int64) (bool, error) {
Log(DEBUG, ctx, "IndexedState.expire", "id", id, "fact", fact)
// Same code for LinearState. ToDo: Generalize.
expired, err := checkExpiration(ctx, fact, unixNow)
if err != nil {
return false, err
}
if expired {
// Lots of things can go wrong and get us in an inconsistent state.
// ToDo: Be more careful.
Log(DEBUG, ctx, "IndexedState.expire", "fact", fact, "expired", expired, "now", unixNow)
if _, err := s.rem(ctx, id); err != nil {
Log(ERROR, ctx, "IndexedState.expire", "name", s.Name,
"when", "Rem", "error", err)
return true, err
}
}
return expired, nil
}
// Search queries the term index for the given pattern (represented as JSON).
// Obtains and releases the FDS mutex.
func (s *IndexedState) Search(ctx *Context, pattern Map) (*SearchResults, error) {
timer := NewTimer(ctx, "IndexedState.Search")
defer timer.Stop()
s.slock(ctx, true)
srs, err := s.search(ctx, pattern)
s.sunlock(ctx, true)
return srs, err
}
func (s *IndexedState) search(ctx *Context, pattern Map) (*SearchResults, error) {
Log(DEBUG, ctx, "IndexedState.search", "pattern", pattern)
then := Now()
ids, err := s.SearchForIDs(ctx, pattern)
if err != nil {
return nil, err
}
sra := make([]SearchResult, 0, len(ids)) // ToDo: More dynamic
expired := 0
now := NowSecs()
for _, id := range ids {
fact, ok := s.IdToFact[id]
if !ok {
Log(ERROR, ctx, "IndexedState.search", "warning", "missing JSON", "id", id)
continue
}
done, err := s.expire(ctx, id, fact, now)
if err != nil {
Log(ERROR, ctx, "IndexedState.search", "error", err, "when", "expiring")
}
if done {
Log(ERROR, ctx, "IndexedState.search", "expired", done, "id", id)
expired++
continue
}
bss, err := Matches(ctx, pattern, map[string]interface{}(fact))
if err != nil {
return nil, err
}
if 0 < len(bss) {
maybeInjectId(ctx, id, fact, false)
js, err := json.Marshal(&fact)
if err != nil {
Log(ERROR, ctx, "IndexedState.search", "error", err,
"when", "marshal", "fact", fact)
return nil, err
}
// ToDo: Eliminate JSON
sr := SearchResult{string(js), id, bss}
sra = append(sra, sr)
}
}
srs := SearchResults{sra, len(ids), Now() - then, expired}
Log(DEBUG, ctx, "IndexedState.search", "numIds", len(ids), "srs", sra)
if ctx != nil && ctx.GetLoc() != nil {
c := ctx.GetLoc().Control()
if c != nil {
limit := c.BindingsWarningLimit
if 0 < limit && limit < len(srs.Found) {
Log(WARN, ctx, "IndexedState.search", "name", s.Name,
"bindingsWarning", len(srs.Found),
"limit", limit)
}
}
}
return &srs, nil
}
func (s *IndexedState) FindRules(ctx *Context, event Map) (map[string]Map, error) {
Log(DEBUG, ctx, "IndexedState.FindRules", "name", s.Name, "event", event)
timer := NewTimer(ctx, "IndexedState.FindRules")
defer timer.Stop()
s.slock(ctx, true)
defer s.sunlock(ctx, true)
acc := make(map[string]Map)
ss, err := s.RuleIndex.SearchPatternsMap(ctx, map[string]interface{}(event))
if err != nil {
Log(ERROR, ctx, "IndexedState.FindRules", "error", err)
return nil, err
}
ids := ss.Array()
now := NowSecs()
for _, id := range ids {
rule, ok := s.IdToFact[id]
Log(DEBUG, ctx, "IndexedState.FindRules", "rule", rule, "ruleId", id)
expired, err := s.expire(ctx, id, rule, now)
if err != nil {
Log(ERROR, ctx, "IndexedState.FindRules", "error", err, "when", "expiring")
}
if expired {
Log(ERROR, ctx, "IndexedState.FindRules", "expired", expired, "ruleId", id, "rule", rule)
continue
}
if !ok {
err = fmt.Errorf("lost rule with id %s", id)
Log(ERROR, ctx, "IndexedState.FindRules", "error", err, "id", id)
// Should we totally fail?
return nil, err
}
body, err := ExtractRule(ctx, rule, true)
if err != nil {
Log(ERROR, ctx, "IndexedState.FindRules", "error", err)
// Should we totally fail?
return nil, err
}
// The following doesn't work, but it doesn't hurt.
// See comments near maybeInjectId().
// ToDo: Support read-time id injection?
//
// maybeInjectId(ctx, id, body, false)
acc[id] = body
}
Log(DEBUG, ctx, "IndexedState.FindRules", "rules", acc)
return acc, nil
}