Skip to content

Conversation

@dnhatn
Copy link
Member

@dnhatn dnhatn commented Apr 9, 2019

Today we always trim unsafe commits (whose max_seq_no >= global checkpoint) before starting a read-write or read-only engine. This is mandatory for read-write engines because they must start with the safe commit. This is also fine for read-only engines since most of the cases we should have exactly one commit after closing an index (trimming is a noop). However, this is not safe for following indices which might have more than one commits when they are being closed.

With this change, we won't trim anything if we are going to open a read-only engine.

I will work on a follow up to skip resync/rollback if an index is closed and another follow-up to enable the sanity check in ReadOnly for following indices.

Relates #33888

@dnhatn dnhatn added >enhancement :Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. v8.0.0 v7.2.0 v6.7.2 v7.0.1 labels Apr 9, 2019
@dnhatn dnhatn requested review from henningandersen and s1monw April 9, 2019 23:27
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@dnhatn dnhatn changed the title Do not trim unsafe commits when open read-ony engine Do not trim unsafe commits when open readonly engine Apr 9, 2019
+ "] from last commit does not match global checkpoint [" + globalCheckpoint + "]");
}
}
ensureMaxSeqNoEqualsToGlobalCheckpoint(seqNoStats);
Copy link
Member Author

Choose a reason for hiding this comment

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

I am working to make this check allow gaps in sequence numbers.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

left one comment

+ "] but got " + getRetentionLeases();
trimUnsafeCommits();
// don't trim anything if we are going to open a read only engine.
if (engineFactory.isReadOnlyEngineFactory() == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add an assertion below that ensures that if it's returning true that it's a subclass of ReadOnlyEngine.

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

Left one comment, I would prefer to keep the EngineFactory as is if possible.

I am not enough up to speed on the why closing a follower index is problematic wrt. read-only indices trimming indexes, will reach out to you about this.

trimUnsafeCommits();
// don't trim anything if we are going to open a read only engine.
if (engineFactory.isReadOnlyEngineFactory() == false) {
trimUnsafeCommits();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we not simply move trimUnsafeCommits() into InternalEngine constructor? As far as I can see, we always trim right before constructing engine.
It would move trim inside the mutex, but I think that is not a problem.

If we do that, we can avoid the new method on EngineFactory. I think the trimming logically belongs with the engine, not the factory.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 to move trimUnsafeCommits to the InternalEngine.

@dnhatn
Copy link
Member Author

dnhatn commented Apr 10, 2019

@s1monw and @henningandersen I've moved trimUnsafeCommits to InternalEngine. It's nicer I think. Can you please have another look? Thank you!

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks @dnhatn

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

looks much better! thanks

@dnhatn
Copy link
Member Author

dnhatn commented Apr 11, 2019

@s1monw @henningandersen thanks for reviewing.

@dnhatn dnhatn merged commit 3ec0cc5 into elastic:master Apr 11, 2019
@dnhatn dnhatn deleted the do_not_trim_commits branch April 11, 2019 19:15
dnhatn added a commit that referenced this pull request Apr 17, 2019
Today we always trim unsafe commits (whose max_seq_no >= global
checkpoint) before starting a read-write or read-only engine. This is
mandatory for read-write engines because they must start with the safe
commit. This is also fine for read-only engines since most of the cases
we should have exactly one commit after closing an index (trimming is a
noop). However, this is dangerous for following indices which might have
more than one commits when they are being closed.

With this change, we move the trimming logic to the ctor of InternalEngine
so we won't trim anything if we are going to open a read-only engine.
dnhatn added a commit that referenced this pull request Apr 17, 2019
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
Today we always trim unsafe commits (whose max_seq_no >= global
checkpoint) before starting a read-write or read-only engine. This is
mandatory for read-write engines because they must start with the safe
commit. This is also fine for read-only engines since most of the cases
we should have exactly one commit after closing an index (trimming is a
noop). However, this is dangerous for following indices which might have
more than one commits when they are being closed.

With this change, we move the trimming logic to the ctor of InternalEngine 
so we won't trim anything if we are going to open a read-only engine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >enhancement v7.2.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants