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

[index] Prevent duplicated writes to commit log #1375

Merged
merged 19 commits into from
Feb 27, 2019

Conversation

arnikola
Copy link
Collaborator

@arnikola arnikola commented Feb 13, 2019

Propagates a shouldWrite flag from the buffer if a point with the same value at the same time exists, which determines if the point should be added to the commit log or not.

@arnikola arnikola changed the title [wip] [index] Initial work to drop writing metrics to [wip] [index] Initial work to stop duplicating writes to commit log Feb 13, 2019
@arnikola arnikola added area:index All issues pertaining to m3ninx and m3db's index PR: Awaiting Review [db] labels Feb 19, 2019
@arnikola arnikola changed the title [wip] [index] Initial work to stop duplicating writes to commit log [index] Prevent duplicated writes to commit log Feb 19, 2019
@codecov
Copy link

codecov bot commented Feb 20, 2019

Codecov Report

Merging #1375 into master will increase coverage by 0.6%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1375      +/-   ##
=========================================
+ Coverage    70.7%   71.4%    +0.6%     
=========================================
  Files         827      48     -779     
  Lines       71229    4239   -66990     
=========================================
- Hits        50398    3027   -47371     
+ Misses      17534     999   -16535     
+ Partials     3297     213    -3084
Flag Coverage Δ
#aggregator 82.5% <ø> (+0.1%) ⬆️
#cluster ?
#collector ?
#dbnode 70% <ø> (-10.8%) ⬇️
#m3em ?
#m3ninx ?
#m3nsch ?
#metrics ?
#msg ?
#query ?
#x ?

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd3cc15...973599a. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 20, 2019

Codecov Report

Merging #1375 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1375   +/-   ##
======================================
  Coverage    70.8%   70.8%           
======================================
  Files         833     833           
  Lines       71487   71487           
======================================
  Hits        50642   50642           
  Misses      17533   17533           
  Partials     3312    3312
Flag Coverage Δ
#aggregator 82.3% <0%> (ø) ⬆️
#cluster 85.8% <0%> (ø) ⬆️
#collector 63.7% <0%> (ø) ⬆️
#dbnode 80.7% <0%> (ø) ⬆️
#m3em 73.2% <0%> (ø) ⬆️
#m3ninx 74.2% <0%> (ø) ⬆️
#m3nsch 51.1% <0%> (ø) ⬆️
#metrics 17.6% <0%> (ø) ⬆️
#msg 74.9% <0%> (ø) ⬆️
#query 65.6% <0%> (ø) ⬆️
#x 76% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8277c7a...a115ad0. Read the comment docs.

)
if writable {
// Perform write
err = entry.Series.Write(ctx, timestamp, value, unit, annotation)
shouldWrite, err = entry.Series.Write(ctx, timestamp, value, unit, annotation)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you moved the error handling code around? it looks like the old code only had to call DecrementReaderWriterCount once but this one has to do it multiple times

Copy link
Collaborator Author

@arnikola arnikola Feb 21, 2019

Choose a reason for hiding this comment

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

So this should still call DecrementReaderCount once, depending on which operations error; the previous code would still do these calls:

commitLogSeriesID = entry.Series.ID()
commitLogSeriesTags = entry.Series.Tags()
commitLogSeriesUniqueIndex = entry.Index

for no reason if .Write(..) errored. Happy to revert it though if this is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think i'd prefer not to change this for now as I think its a little more brittle now (cleanup code more spread out)

// whose lifecycle lives longer than the span of this request, making them
// safe for use by the async commitlog. Need to set the outcome in the
// error case so that the commitlog knows to skip this entry.
writes.SetOutcome(i, series, err)
Copy link
Contributor

@richardartoul richardartoul Feb 27, 2019

Choose a reason for hiding this comment

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

Not sure if I brought this up last time, but is there any reason we can't just SetOutcome in both cases? Feels a little safer to make sure everything gets updated anyways and I'm pretty sure its cheap since it literally just does this

func (b *writeBatch) SetOutcome(idx int, series Series, err error) {
	b.writes[idx].Write.Series = series
	b.writes[idx].Err = err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

So basically always SetOutcome

and then

if !wasWritten || err != nil {
    writes.SetSkipWrite(i)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Notice that I changed it to an OR because you always want to skip the write if it wasn't written or there was an error. I know the commitlog will skip it anyways if there was an error but this seems more semantically correct

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, sounds good to me; makes sense that the readability is worth more here

Copy link
Contributor

@richardartoul richardartoul left a comment

Choose a reason for hiding this comment

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

LGTM

@arnikola arnikola merged commit fdd8abd into master Feb 27, 2019
@arnikola arnikola deleted the arnikola/drop-duplicate-commit-logs branch February 27, 2019 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:index All issues pertaining to m3ninx and m3db's index
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants