Skip to content

Compactor optimization - PR FOR FEEDBACK ONLY - #754

Closed
davisp wants to merge 4 commits into
masterfrom
compactor-rewrite
Closed

Compactor optimization - PR FOR FEEDBACK ONLY#754
davisp wants to merge 4 commits into
masterfrom
compactor-rewrite

Conversation

@davisp

@davisp davisp commented Aug 16, 2017

Copy link
Copy Markdown
Member

It occurred to me the other day that we already have the docid tree stored in the original database so the first pass at compaction is wasting a lot of time and IO writing out the emsort structure. This optimizes the compactor to avoid that first use of emsort and instead reads document IDs from the original db's id_tree.

There are zero tests for correct compactor behavior right now (outside of the PSE branch) so I'm going to start writing a bunch of tests that will do mean things to the compactor to make sure that this doesn't have any issues around breaking things. However, given the change I figured I'd at least open a feedback PR while I write the test suite for the compactor behavior.

Strictly copy/paste moving of code to make a more logical ordering of
start to finish reading top down.
Comment thread src/couch/src/couch_db_updater.erl Outdated
};
_ when DataHdrIsDbHdr ->
% We tried to swap out the compaction but there were
% writes to the database during compction. Start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

compaction typo

% This is a bit worrisome. init_db/4 will monitor the data fd
% but it doesn't know about the meta fd. For now I'll maintain
% that the data fd is the old normal fd and meta fd is special
% and hope everything works out for the best.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the concern over the lack of a monitor on the meta file descriptor still valid? Or is it moot with the couch_file:close(MetaFd) call now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, it got moved to clean up start_compact. That comment is way old me. I know how couch_file works better now so the comment can go as its misleading.

Comment thread src/couch/src/couch_db_updater.erl Outdated
{total_changes, TotalChanges}
],
case (Retry /= nil) and couch_task_status:is_task_added() of
case (Retry) and couch_task_status:is_task_added() of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unnecessary parens

Comment thread src/couch/src/couch_db_updater.erl Outdated
% first pass. This means we may have docs that already exist
% in the seq_tree in the .data file. Here we lookup any old
% update_seqs so that they can be removed.
OldDocIdTree =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a little rusty but this looks like a refactoring mistake ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Totes was. Got mixed in when separating commits.

This change adds a new `#comp_st{}` record that is used to pass
compaction state through the various compaction steps. There are zero
changes to the existing compaction logic. This merely sets the stage for
adding our docid copy optimization.
@davisp
davisp force-pushed the compactor-rewrite branch from 0f899b7 to fb67c8b Compare August 16, 2017 19:56
davisp added 2 commits August 16, 2017 16:15
This optimizes the first pass of compaction to avoid writing data to the
emsort structure stored in the .compact.meta file. Instead of writing
data there we instead just re-read the docid tree from the original
database.
@davisp
davisp force-pushed the compactor-rewrite branch from fb67c8b to c802565 Compare August 16, 2017 21:15
@davisp davisp mentioned this pull request Aug 25, 2017
2 tasks
@davisp

davisp commented Aug 25, 2017

Copy link
Copy Markdown
Member Author

Closing in favor of #778

@davisp davisp closed this Aug 25, 2017
@davisp
davisp deleted the compactor-rewrite branch April 1, 2020 17:19
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.

3 participants