-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Add global checkpoint to translog checkpoints #21254
Merged
jasontedor
merged 9 commits into
elastic:feature/seq_no
from
jasontedor:global-checkpoint-in-translog
Nov 8, 2016
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8bea450
Add global checkpoint to translog checkpoints
jasontedor 37a50bb
Replace TODO with nocommit in Checkpoint
jasontedor 19d4db0
Add nocommit for loading global checkpoint
jasontedor 86ec4d0
Sync translog after global checkpoint sync
jasontedor 6cbed98
Pass global checkpoint supplier on open translog
jasontedor d742a68
Add missing checked exception to GCSA override
jasontedor 6c1338c
Add nocommit for wrapped exception in GCSA
jasontedor 37af724
Add test for persistence of global checkpoint
jasontedor 90f7b60
Simplify global checkpoint advance in test
jasontedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,6 @@ public class SequenceNumbersService extends AbstractIndexShardComponent { | |
|
||
final LocalCheckpointService localCheckpointService; | ||
final GlobalCheckpointService globalCheckpointService; | ||
private final Runnable onGlobalCheckpointUpdate; | ||
|
||
/** | ||
* Initialize the sequence number service. The {@code maxSeqNo} should be set to the last sequence number assigned by this shard, or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OMG what happened here :) |
||
|
@@ -51,19 +50,16 @@ public class SequenceNumbersService extends AbstractIndexShardComponent { | |
* @param maxSeqNo the last sequence number assigned by this shard, or {@link SequenceNumbersService#NO_OPS_PERFORMED} | ||
* @param localCheckpoint the last known local checkpoint for this shard, or {@link SequenceNumbersService#NO_OPS_PERFORMED} | ||
* @param globalCheckpoint the last known global checkpoint for this shard, or {@link SequenceNumbersService#UNASSIGNED_SEQ_NO} | ||
* @param onGlobalCheckpointUpdate invoked when the global checkpoint is updated | ||
*/ | ||
public SequenceNumbersService( | ||
final ShardId shardId, | ||
final IndexSettings indexSettings, | ||
final long maxSeqNo, | ||
final long localCheckpoint, | ||
final long globalCheckpoint, | ||
final Runnable onGlobalCheckpointUpdate) { | ||
final long globalCheckpoint) { | ||
super(shardId, indexSettings); | ||
localCheckpointService = new LocalCheckpointService(shardId, indexSettings, maxSeqNo, localCheckpoint); | ||
globalCheckpointService = new GlobalCheckpointService(shardId, indexSettings, globalCheckpoint); | ||
this.onGlobalCheckpointUpdate = onGlobalCheckpointUpdate; | ||
} | ||
|
||
/** | ||
|
@@ -123,12 +119,21 @@ public long getGlobalCheckpoint() { | |
return globalCheckpointService.getCheckpoint(); | ||
} | ||
|
||
/** | ||
* Scans through the currently known local checkpoint and updates the global checkpoint accordingly. | ||
* | ||
* @return true if the checkpoint has been updated or if it can not be updated since one of the local checkpoints | ||
* of one of the active allocations is not known. | ||
*/ | ||
public boolean updateGlobalCheckpointOnPrimary() { | ||
return globalCheckpointService.updateCheckpointOnPrimary(); | ||
} | ||
|
||
/** | ||
* updates the global checkpoint on a replica shard (after it has been updated by the primary). | ||
*/ | ||
public void updateGlobalCheckpointOnReplica(long checkpoint) { | ||
globalCheckpointService.updateCheckpointOnReplica(checkpoint); | ||
onGlobalCheckpointUpdate.run(); | ||
} | ||
|
||
/** | ||
|
@@ -142,17 +147,4 @@ public void updateAllocationIdsFromMaster(Set<String> activeAllocationIds, Set<S | |
globalCheckpointService.updateAllocationIdsFromMaster(activeAllocationIds, initializingAllocationIds); | ||
} | ||
|
||
/** | ||
* Scans through the currently known local checkpoint and updates the global checkpoint accordingly. | ||
* | ||
* @return true if the checkpoint has been updated or if it can not be updated since one of the local checkpoints | ||
* of one of the active allocations is not known. | ||
*/ | ||
public boolean updateGlobalCheckpointOnPrimary() { | ||
final boolean maybeUpdateGlobalCheckpoint = globalCheckpointService.updateCheckpointOnPrimary(); | ||
if (maybeUpdateGlobalCheckpoint) { | ||
onGlobalCheckpointUpdate.run(); | ||
} | ||
return maybeUpdateGlobalCheckpoint; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
core/src/test/java/org/elasticsearch/index/seqno/GlobalCheckpointSyncActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache license, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the license for the specific language governing permissions and | ||
* limitations under the license. | ||
*/ | ||
|
||
package org.elasticsearch.index.seqno; | ||
|
||
import org.apache.lucene.util.IOUtils; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.cluster.action.shard.ShardStateAction; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.index.shard.IndexShard; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.transport.CapturingTransport; | ||
import org.elasticsearch.threadpool.TestThreadPool; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.Transport; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
||
import static org.elasticsearch.mock.orig.Mockito.when; | ||
import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class GlobalCheckpointSyncActionTests extends ESTestCase { | ||
|
||
private ThreadPool threadPool; | ||
private Transport transport; | ||
private ClusterService clusterService; | ||
private TransportService transportService; | ||
private ShardStateAction shardStateAction; | ||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
threadPool = new TestThreadPool(getClass().getName()); | ||
transport = new CapturingTransport(); | ||
clusterService = createClusterService(threadPool); | ||
transportService = new TransportService(clusterService.getSettings(), transport, threadPool, | ||
TransportService.NOOP_TRANSPORT_INTERCEPTOR); | ||
transportService.start(); | ||
transportService.acceptIncomingRequests(); | ||
shardStateAction = new ShardStateAction(Settings.EMPTY, clusterService, transportService, null, null, threadPool); | ||
} | ||
|
||
public void tearDown() throws Exception { | ||
try { | ||
IOUtils.close(transportService, clusterService, transport); | ||
} finally { | ||
terminate(threadPool); | ||
} | ||
super.tearDown(); | ||
} | ||
|
||
public void testTranslogSyncAfterGlobalCheckpointSync() throws IOException { | ||
final IndicesService indicesService = mock(IndicesService.class); | ||
|
||
final Index index = new Index("index", "uuid"); | ||
final IndexService indexService = mock(IndexService.class); | ||
when(indicesService.indexServiceSafe(index)).thenReturn(indexService); | ||
|
||
final int id = randomIntBetween(0, 4); | ||
final IndexShard indexShard = mock(IndexShard.class); | ||
when(indexService.getShard(id)).thenReturn(indexShard); | ||
|
||
final Translog translog = mock(Translog.class); | ||
when(indexShard.getTranslog()).thenReturn(translog); | ||
|
||
final GlobalCheckpointSyncAction action = new GlobalCheckpointSyncAction( | ||
Settings.EMPTY, | ||
transportService, | ||
clusterService, | ||
indicesService, | ||
threadPool, | ||
shardStateAction, | ||
new ActionFilters(Collections.emptySet()), | ||
new IndexNameExpressionResolver(Settings.EMPTY)); | ||
final ShardId shardId = new ShardId(index, id); | ||
final GlobalCheckpointSyncAction.PrimaryRequest primaryRequest = new GlobalCheckpointSyncAction.PrimaryRequest(shardId); | ||
if (randomBoolean()) { | ||
action.shardOperationOnPrimary(primaryRequest); | ||
} else { | ||
action.shardOperationOnReplica(new GlobalCheckpointSyncAction.ReplicaRequest(primaryRequest, randomPositiveLong())); | ||
} | ||
|
||
verify(translog).sync(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need the conversion to an unchecked exceptions? shardOperationOnX Allows throwing them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bleskes This is correct for
shardOperationOnPrimary
(declares checkedException
) but notshardOperationOnReplica
(does not declare any checked exceptions). I did push d742a68 since this was missing from the signature forGlobalCheckpointSyncAction#shardOperationOnPrimary
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In master both
shardOperationOnPrimary
andshardOperationOnReplica
declare the top-level checked exception. We can pick this up and remove the wrapping after integrating master into feature/seq_no. I pushed 6c1338c.