MCPcopy Create free account
hub / github.com/RTradeLtd/Lens / New

Function New

engine/engine.go:46–93  ·  view source on GitHub ↗

New instantiates a new Engine

(l *zap.SugaredLogger, opts Opts)

Source from the content-addressed store, hash-verified

44
45// New instantiates a new Engine
46func New(l *zap.SugaredLogger, opts Opts) (*Engine, error) {
47 index, err := bleve.New(opts.StorePath, newLensIndex())
48 if err != nil {
49 if err == bleve.ErrorIndexPathExists {
50 l.Infow("opening existing index",
51 "path", opts.StorePath)
52 index, err = bleve.Open(opts.StorePath)
53 if err != nil {
54 return nil, fmt.Errorf("failed to open existing index at %s: %s",
55 opts.StorePath, err.Error())
56 }
57 } else {
58 return nil, fmt.Errorf("failed to instantiate index: %s", err.Error())
59 }
60 } else {
61 l.Infow("successfully created new bleve index",
62 "path", opts.StorePath)
63 }
64
65 var queueLogger = l.Named("queue")
66 return &Engine{
67 l: l,
68
69 index: index,
70
71 q: queue.New(queueLogger,
72 func(items []*queue.Item) error {
73 var b = index.NewBatch()
74 for _, item := range items {
75 if item != nil {
76 if item.Val != nil {
77 if err := b.Index(item.Key, item.Val); err != nil {
78 queueLogger.Errorw("failed to add document to batch",
79 "error", err, "key", item.Key)
80 }
81 } else {
82 b.Delete(item.Key)
83 }
84 }
85 }
86 return index.Batch(b)
87 },
88 index.Close,
89 opts.Queue),
90
91 stop: make(chan bool, 1),
92 }, nil
93}
94
95// ClusterOpts denotes Lens database clustering options
96type ClusterOpts struct {

Callers 4

NewV2Function · 0.92
TestEngine_parallelFunction · 0.70
TestEngine_IndexFunction · 0.70
TestEngine_SearchFunction · 0.70

Calls 3

NewFunction · 0.92
newLensIndexFunction · 0.85
IndexMethod · 0.65

Tested by 3

TestEngine_parallelFunction · 0.56
TestEngine_IndexFunction · 0.56
TestEngine_SearchFunction · 0.56