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

Ref count write operations on IndexShard #10610

Closed
wants to merge 22 commits into from

Conversation

brwe
Copy link
Contributor

@brwe brwe commented Apr 15, 2015

This commit adds a counter for IndexShard that keeps track of how many write operations
are currently in flight on a shard. The counter is incremented whenever a write request is submitted in TransportShardReplicationOperationAction and decremented when it is finished. On a primary it stays incremented while replicas are being processed. The counter is an instance of AbstractRefCounted. Once this counter reaches 0 each write operation will be rejected with an IndexShardClosedException.

As a follow up we could use this counter to block closing of a shard until all pending write operations have been processed. Currently we only decrement the counter once on IndexShard.close() but do not wait for the counter to reach 0.

@@ -130,10 +130,9 @@ protected ShardIterator shards(ClusterState clusterState, InternalRequest reques
}

@Override
protected Tuple<BulkShardResponse, BulkShardRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) {
protected Tuple<BulkShardResponse, BulkShardRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest, IndexShard indexShard) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should also pass the IndexService since we already have it in the base class. Saves on the lookup.

@brwe brwe force-pushed the feature/index-shard-refcounting branch from e169733 to ed4e2bc Compare April 16, 2015 14:32
@brwe
Copy link
Contributor Author

brwe commented Apr 16, 2015

Addressed all comments. Want to take another look?
I am unsure about the Integration test I added: SimpleIndexShardCounterIntegrationTests. It tests if replicas are failed in case the counter cannot be increased anymore. We should never get in this state so I do not know if we actually need to test this. If not I can also remove this check I guess: https://github.com/elastic/elasticsearch/pull/10610/files#diff-9669e07f0556311d187e534e321a0393R728

@@ -721,6 +725,9 @@ public void recover(Engine.RecoveryHandler recoveryHandler) throws EngineExcepti
}

public void failShard(String reason, Throwable e) {
if (engineClosed()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to check this here I think we should never check this and just call fail on it?

Copy link
Contributor

Choose a reason for hiding this comment

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

or if use engineUnsafe() and check for null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed it for an Integration test I wrote, not sure if it makes sense though. See my comment above #10610 (comment)

@s1monw
Copy link
Contributor

s1monw commented Apr 16, 2015

I did another review of this

@s1monw s1monw self-assigned this Apr 16, 2015
* Wipes any data that a test can leave behind: indices, templates and repositories
*/
public void wipe() {
assertShardIndexCounter();
Copy link
Contributor

Choose a reason for hiding this comment

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

unneeded here?

@s1monw
Copy link
Contributor

s1monw commented Apr 16, 2015

I did another review...

am unsure about the Integration test I added: SimpleIndexShardCounterIntegrationTests. It tests if

I think we don't need any integration test here really, we have enough integration tests that test this and your assertions are good too?

@brwe
Copy link
Contributor Author

brwe commented Apr 27, 2015

I rebased on master now that #10749 has been pushed and replaced all integration tests by unit tests similar to the ones in #10749. I like the new test much more than the old ones but I had some trouble simulating an IndexShard and am unsure if the way I do it is a little too hacky. Please have another look!

@brwe
Copy link
Contributor Author

brwe commented May 4, 2015

Chatted with @s1monw and implemented all changes now. Want to have another look?

IndexService indexService = indicesService.indexServiceSafe(shardId.index().getName());
IndexShard indexShard = indexService.shardSafe(shardId.id());
return new IndexShardReference(indexShard);

Copy link
Contributor

Choose a reason for hiding this comment

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

extra newline

@brwe brwe force-pushed the feature/index-shard-refcounting branch from 1eed609 to 352476b Compare May 4, 2015 11:33
@brwe brwe force-pushed the feature/index-shard-refcounting branch from 352476b to e47e1ef Compare May 4, 2015 11:37
@brwe
Copy link
Contributor Author

brwe commented May 4, 2015

pushed another commit

@s1monw
Copy link
Contributor

s1monw commented May 4, 2015

LGTM

@brwe brwe added v2.0.0-beta1 :Core/Infra/Core Core issues without another label v1.6.0 and removed in progress labels May 4, 2015
@brwe brwe closed this in 7bf83ff May 4, 2015
@brwe
Copy link
Contributor Author

brwe commented May 4, 2015

still have to backport to 1.x...

@brwe brwe reopened this May 4, 2015
brwe added a commit to brwe/elasticsearch that referenced this pull request May 4, 2015
This commit adds a counter for IndexShard that keeps track of how many write operations
are currently in flight on a shard. The counter is incremented whenever a write request is
submitted in TransportShardReplicationOperationAction and decremented when it is finished.
On a primary it stays incremented while replicas are being processed.
The counter is an instance of AbstractRefCounted. Once this counter reaches 0
each write operation will be rejected with an IndexClosedException.

closes elastic#10610
brwe added a commit that referenced this pull request May 5, 2015
This commit adds a counter for IndexShard that keeps track of how many write operations
are currently in flight on a shard. The counter is incremented whenever a write request is
submitted in TransportShardReplicationOperationAction and decremented when it is finished.
On a primary it stays incremented while replicas are being processed.
The counter is an instance of AbstractRefCounted. Once this counter reaches 0
each write operation will be rejected with an IndexShardClosedException.

closes #10610
@brwe
Copy link
Contributor Author

brwe commented May 5, 2015

pushed to 1.x

@brwe brwe closed this May 5, 2015
@bleskes bleskes mentioned this pull request May 5, 2015
@clintongormley clintongormley changed the title ref count write operations on IndexShard Ref count write operations on IndexShard May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants