|
14 | 14 | import org.elasticsearch.action.delete.DeleteRequest;
|
15 | 15 | import org.elasticsearch.action.support.replication.TransportWriteAction;
|
16 | 16 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
| 17 | +import org.elasticsearch.cluster.node.DiscoveryNode; |
17 | 18 | import org.elasticsearch.cluster.routing.ShardRouting;
|
| 19 | +import org.elasticsearch.cluster.routing.ShardRoutingState; |
| 20 | +import org.elasticsearch.cluster.routing.TestShardRouting; |
18 | 21 | import org.elasticsearch.common.settings.Settings;
|
19 | 22 | import org.elasticsearch.common.unit.TimeValue;
|
20 | 23 | import org.elasticsearch.index.IndexSettings;
|
|
25 | 28 | import org.elasticsearch.index.shard.IndexShard;
|
26 | 29 | import org.elasticsearch.index.shard.ShardId;
|
27 | 30 | import org.elasticsearch.index.translog.Translog;
|
| 31 | +import org.elasticsearch.indices.recovery.RecoveryState; |
28 | 32 | import org.elasticsearch.threadpool.ThreadPool;
|
29 | 33 | import org.elasticsearch.xpack.ccr.CcrSettings;
|
30 | 34 | import org.elasticsearch.xpack.ccr.action.bulk.BulkShardOperationsRequest;
|
|
38 | 42 | import java.util.List;
|
39 | 43 | import java.util.Set;
|
40 | 44 | import java.util.concurrent.atomic.AtomicBoolean;
|
| 45 | +import java.util.concurrent.atomic.AtomicReference; |
41 | 46 | import java.util.function.BiConsumer;
|
42 | 47 | import java.util.function.Consumer;
|
43 | 48 | import java.util.function.LongConsumer;
|
44 | 49 |
|
| 50 | +import static java.util.Collections.emptyMap; |
| 51 | +import static java.util.Collections.emptySet; |
45 | 52 | import static org.hamcrest.Matchers.equalTo;
|
| 53 | +import static org.hamcrest.Matchers.is; |
46 | 54 | import static org.hamcrest.Matchers.nullValue;
|
47 | 55 |
|
48 | 56 | public class ShardFollowTaskReplicationTests extends ESIndexLevelReplicationTestCase {
|
@@ -129,6 +137,43 @@ public void testFailLeaderReplicaShard() throws Exception {
|
129 | 137 | }
|
130 | 138 | }
|
131 | 139 |
|
| 140 | + public void testChangeHistoryUUID() throws Exception { |
| 141 | + try (ReplicationGroup leaderGroup = createGroup(0); |
| 142 | + ReplicationGroup followerGroup = createFollowGroup(0)) { |
| 143 | + leaderGroup.startAll(); |
| 144 | + int docCount = leaderGroup.appendDocs(randomInt(64)); |
| 145 | + leaderGroup.assertAllEqual(docCount); |
| 146 | + followerGroup.startAll(); |
| 147 | + ShardFollowNodeTask shardFollowTask = createShardFollowTask(leaderGroup, followerGroup); |
| 148 | + final SeqNoStats leaderSeqNoStats = leaderGroup.getPrimary().seqNoStats(); |
| 149 | + final SeqNoStats followerSeqNoStats = followerGroup.getPrimary().seqNoStats(); |
| 150 | + shardFollowTask.start( |
| 151 | + leaderSeqNoStats.getGlobalCheckpoint(), |
| 152 | + leaderSeqNoStats.getMaxSeqNo(), |
| 153 | + followerSeqNoStats.getGlobalCheckpoint(), |
| 154 | + followerSeqNoStats.getMaxSeqNo()); |
| 155 | + leaderGroup.syncGlobalCheckpoint(); |
| 156 | + leaderGroup.assertAllEqual(docCount); |
| 157 | + Set<String> indexedDocIds = getShardDocUIDs(leaderGroup.getPrimary()); |
| 158 | + assertBusy(() -> { |
| 159 | + assertThat(followerGroup.getPrimary().getGlobalCheckpoint(), equalTo(leaderGroup.getPrimary().getGlobalCheckpoint())); |
| 160 | + followerGroup.assertAllEqual(indexedDocIds.size()); |
| 161 | + }); |
| 162 | + |
| 163 | + String oldHistoryUUID = leaderGroup.getPrimary().getHistoryUUID(); |
| 164 | + leaderGroup.reinitPrimaryShard(); |
| 165 | + leaderGroup.getPrimary().store().bootstrapNewHistory(); |
| 166 | + recoverShardFromStore(leaderGroup.getPrimary()); |
| 167 | + String newHistoryUUID = leaderGroup.getPrimary().getHistoryUUID(); |
| 168 | + |
| 169 | + assertBusy(() -> { |
| 170 | + assertThat(shardFollowTask.isStopped(), is(true)); |
| 171 | + assertThat(shardFollowTask.getFailure().getMessage(), equalTo("unexpected history uuid, expected [" + oldHistoryUUID + |
| 172 | + "], actual [" + newHistoryUUID + "]")); |
| 173 | + }); |
| 174 | + } |
| 175 | + } |
| 176 | + |
132 | 177 | @Override
|
133 | 178 | protected ReplicationGroup createGroup(int replicas, Settings settings) throws IOException {
|
134 | 179 | Settings newSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
@@ -167,14 +212,15 @@ private ShardFollowNodeTask createShardFollowTask(ReplicationGroup leaderGroup,
|
167 | 212 | between(1, 8),
|
168 | 213 | Long.MAX_VALUE,
|
169 | 214 | between(1, 4), 10240,
|
170 |
| - TimeValue.timeValueMillis(10), |
| 215 | + TimeValue.timeValueMillis(100), |
171 | 216 | TimeValue.timeValueMillis(10),
|
172 | 217 | leaderGroup.getPrimary().getHistoryUUID(),
|
173 | 218 | Collections.emptyMap()
|
174 | 219 | );
|
175 | 220 |
|
176 | 221 | BiConsumer<TimeValue, Runnable> scheduler = (delay, task) -> threadPool.schedule(delay, ThreadPool.Names.GENERIC, task);
|
177 | 222 | AtomicBoolean stopped = new AtomicBoolean(false);
|
| 223 | + AtomicReference<Exception> failureHolder = new AtomicReference<>(); |
178 | 224 | LongSet fetchOperations = new LongHashSet();
|
179 | 225 | return new ShardFollowNodeTask(
|
180 | 226 | 1L, "type", ShardFollowTask.NAME, "description", null, Collections.emptyMap(), params, scheduler, System::nanoTime) {
|
@@ -252,9 +298,14 @@ public void markAsCompleted() {
|
252 | 298 |
|
253 | 299 | @Override
|
254 | 300 | public void markAsFailed(Exception e) {
|
| 301 | + failureHolder.set(e); |
255 | 302 | stopped.set(true);
|
256 | 303 | }
|
257 | 304 |
|
| 305 | + @Override |
| 306 | + public Exception getFailure() { |
| 307 | + return failureHolder.get(); |
| 308 | + } |
258 | 309 | };
|
259 | 310 | }
|
260 | 311 |
|
|
0 commit comments