Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to make all analysis take place in func() #1508

Merged
merged 3 commits into from
Dec 2, 2020

Conversation

mschoch
Copy link
Contributor

@mschoch mschoch commented Dec 1, 2020

by making analysis take place inside a func() a
closure can be used to encapsulate all the index
specific details. this allows the index API to not
know about scorch vs upsidedown analysis structures

by making analysis take place inside a func() a
closure can be used to encapsulate all the index
specific details.  this allows the index API to not
know about scorch vs upsidedown analysis structures
@mschoch
Copy link
Contributor Author

mschoch commented Dec 1, 2020

Currently this is stacked on top of the other change, as that the plugin interface moving is related (we can re-target it to fix-circular-deps if we merge make-plugin-interface-local first)

Expect this to fail, as it needs the zap changes to satisfy the new New(...) method signature.

@@ -335,16 +335,19 @@ func (s *Scorch) Batch(batch *index.Batch) (err error) {
go func() {
for _, doc := range batch.IndexOps {
if doc != nil {
aw := index.NewAnalysisWork(s, doc, resultChan)
doc := doc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure whether I followed this doc := doc logic ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is the classic Go range variable capture issue. The doc declared in the scope of the range statement is a single variable which changes each iteration of the loop. Because doc is type interface, it's essentially a pointer, then these are passed via channels, and accessed later, by which time the contents of the pointer has changed to some later iteration.

The doc := doc is declaring a new variable inside the loop iteration, which copies the doc from the range statement. This ensures the doc that is accessed later is a unique variable, not shared.

It is fundamentally the exact same as this line in upsidedown:

doc := batch.IndexOps[k]

@@ -41,7 +41,7 @@ type Plugin interface {
Version() uint32

// New takes a set of AnalysisResults and turns them into a new Segment
New(results []*index.AnalysisResult) (segment.Segment, uint64, error)
New(results []index.Document) (segment.Segment, uint64, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the above comment needs updates too?

also update comment, per review feedback
selects latest versions compatible with these changes
@mschoch mschoch merged commit c5e42bd into make-plugin-interface-local Dec 2, 2020
@mschoch mschoch deleted the simplify-analysis branch December 2, 2020 16:17
mschoch added a commit that referenced this pull request Dec 2, 2020
* move the plugin interface into scorch

* rename scorch Plugin to SegmentPlugin

and related functions

* update to make all analysis take place in func() (#1508)

* update to make all analysis take place in func()

by making analysis take place inside a func() a
closure can be used to encapsulate all the index
specific details.  this allows the index API to not
know about scorch vs upsidedown analysis structures

* rewrite variable declaration for clarity

also update comment, per review feedback

* update to latest versions

selects latest versions compatible with these changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants