Skip to content

Commit 3a00ed8

Browse files
committed
Merge branch 'ccr' into ccr_expand_stats_api_response
* ccr: Fix ShardFollowNodeTask.Status equals and hash code (elastic#33189) Make soft-deletes settings final (elastic#33172) Only fetch mapping updates when necessary (elastic#33182)
2 parents b49f1ef + 5954354 commit 3a00ed8

File tree

11 files changed

+115
-90
lines changed

11 files changed

+115
-90
lines changed

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public final class IndexSettings {
242242
* Specifies if the index should use soft-delete instead of hard-delete for update/delete operations.
243243
*/
244244
public static final Setting<Boolean> INDEX_SOFT_DELETES_SETTING =
245-
Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope);
245+
Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope, Property.Final);
246246

247247
/**
248248
* Controls how many soft-deleted documents will be kept around before being merged away. Keeping more deleted

server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,12 @@ public void testQueryDefaultField() {
553553
);
554554
assertThat(index.getDefaultFields(), equalTo(Arrays.asList("body", "title")));
555555
}
556+
557+
public void testUpdateSoftDeletesFails() {
558+
IndexScopedSettings settings = new IndexScopedSettings(Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
559+
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () ->
560+
settings.updateSettings(Settings.builder().put("index.soft_deletes.enabled", randomBoolean()).build(),
561+
Settings.builder(), Settings.builder(), "index"));
562+
assertThat(error.getMessage(), equalTo("final index setting [index.soft_deletes.enabled], not updateable"));
563+
}
556564
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ public String toString() {
161161

162162
public static final class Response extends ActionResponse {
163163

164-
private long indexMetadataVersion;
164+
private long mappingVersion;
165165

166-
public long getIndexMetadataVersion() {
167-
return indexMetadataVersion;
166+
public long getMappingVersion() {
167+
return mappingVersion;
168168
}
169169

170170
private long globalCheckpoint;
@@ -188,8 +188,8 @@ public Translog.Operation[] getOperations() {
188188
Response() {
189189
}
190190

191-
Response(final long indexMetadataVersion, final long globalCheckpoint, final long maxSeqNo, final Translog.Operation[] operations) {
192-
this.indexMetadataVersion = indexMetadataVersion;
191+
Response(final long mappingVersion, final long globalCheckpoint, final long maxSeqNo, final Translog.Operation[] operations) {
192+
this.mappingVersion = mappingVersion;
193193
this.globalCheckpoint = globalCheckpoint;
194194
this.maxSeqNo = maxSeqNo;
195195
this.operations = operations;
@@ -198,7 +198,7 @@ public Translog.Operation[] getOperations() {
198198
@Override
199199
public void readFrom(final StreamInput in) throws IOException {
200200
super.readFrom(in);
201-
indexMetadataVersion = in.readVLong();
201+
mappingVersion = in.readVLong();
202202
globalCheckpoint = in.readZLong();
203203
maxSeqNo = in.readZLong();
204204
operations = in.readArray(Translog.Operation::readOperation, Translog.Operation[]::new);
@@ -207,7 +207,7 @@ public void readFrom(final StreamInput in) throws IOException {
207207
@Override
208208
public void writeTo(final StreamOutput out) throws IOException {
209209
super.writeTo(out);
210-
out.writeVLong(indexMetadataVersion);
210+
out.writeVLong(mappingVersion);
211211
out.writeZLong(globalCheckpoint);
212212
out.writeZLong(maxSeqNo);
213213
out.writeArray(Translog.Operation::writeOperation, operations);
@@ -218,15 +218,15 @@ public boolean equals(final Object o) {
218218
if (this == o) return true;
219219
if (o == null || getClass() != o.getClass()) return false;
220220
final Response that = (Response) o;
221-
return indexMetadataVersion == that.indexMetadataVersion &&
221+
return mappingVersion == that.mappingVersion &&
222222
globalCheckpoint == that.globalCheckpoint &&
223223
maxSeqNo == that.maxSeqNo &&
224224
Arrays.equals(operations, that.operations);
225225
}
226226

227227
@Override
228228
public int hashCode() {
229-
return Objects.hash(indexMetadataVersion, globalCheckpoint, maxSeqNo, Arrays.hashCode(operations));
229+
return Objects.hash(mappingVersion, globalCheckpoint, maxSeqNo, Arrays.hashCode(operations));
230230
}
231231
}
232232

@@ -252,15 +252,15 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
252252
IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex());
253253
IndexShard indexShard = indexService.getShard(request.getShard().id());
254254
final SeqNoStats seqNoStats = indexShard.seqNoStats();
255-
final long indexMetaDataVersion = clusterService.state().metaData().index(shardId.getIndex()).getVersion();
255+
final long mappingVersion = clusterService.state().metaData().index(shardId.getIndex()).getMappingVersion();
256256

257257
final Translog.Operation[] operations = getOperations(
258258
indexShard,
259259
seqNoStats.getGlobalCheckpoint(),
260260
request.fromSeqNo,
261261
request.maxOperationCount,
262262
request.maxOperationSizeInBytes);
263-
return new Response(indexMetaDataVersion, seqNoStats.getGlobalCheckpoint(), seqNoStats.getMaxSeqNo(), operations);
263+
return new Response(mappingVersion, seqNoStats.getGlobalCheckpoint(), seqNoStats.getMaxSeqNo(), operations);
264264
}
265265

266266
@Override

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowNodeTask.java

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public abstract class ShardFollowNodeTask extends AllocatedPersistentTask {
8181
private long followerMaxSeqNo = 0;
8282
private int numConcurrentReads = 0;
8383
private int numConcurrentWrites = 0;
84-
private long currentIndexMetadataVersion = 0;
84+
private long currentMappingVersion = 0;
8585
private long totalFetchTimeMillis = 0;
8686
private long numberOfSuccessfulFetches = 0;
8787
private long numberOfFailedFetches = 0;
@@ -139,14 +139,13 @@ void start(
139139
this.lastRequestedSeqNo = followerGlobalCheckpoint;
140140
}
141141

142-
// Forcefully updates follower mapping, this gets us the leader imd version and
143-
// makes sure that leader and follower mapping are identical.
144-
updateMapping(imdVersion -> {
142+
// updates follower mapping, this gets us the leader mapping version and makes sure that leader and follower mapping are identical
143+
updateMapping(mappingVersion -> {
145144
synchronized (ShardFollowNodeTask.this) {
146-
currentIndexMetadataVersion = imdVersion;
145+
currentMappingVersion = mappingVersion;
147146
}
148-
LOGGER.info("{} Started to follow leader shard {}, followGlobalCheckPoint={}, indexMetaDataVersion={}",
149-
params.getFollowShardId(), params.getLeaderShardId(), followerGlobalCheckpoint, imdVersion);
147+
LOGGER.info("{} Started to follow leader shard {}, followGlobalCheckPoint={}, mappingVersion={}",
148+
params.getFollowShardId(), params.getLeaderShardId(), followerGlobalCheckpoint, mappingVersion);
150149
coordinateReads();
151150
});
152151
}
@@ -269,7 +268,7 @@ private void sendShardChangesRequest(long from, int maxOperationCount, long maxR
269268
}
270269

271270
void handleReadResponse(long from, long maxRequiredSeqNo, ShardChangesAction.Response response) {
272-
maybeUpdateMapping(response.getIndexMetadataVersion(), () -> innerHandleReadResponse(from, maxRequiredSeqNo, response));
271+
maybeUpdateMapping(response.getMappingVersion(), () -> innerHandleReadResponse(from, maxRequiredSeqNo, response));
273272
}
274273

275274
/** Called when some operations are fetched from the leading */
@@ -355,16 +354,16 @@ private synchronized void handleWriteResponse(final BulkShardOperationsResponse
355354
coordinateReads();
356355
}
357356

358-
private synchronized void maybeUpdateMapping(Long minimumRequiredIndexMetadataVersion, Runnable task) {
359-
if (currentIndexMetadataVersion >= minimumRequiredIndexMetadataVersion) {
360-
LOGGER.trace("{} index metadata version [{}] is higher or equal than minimum required index metadata version [{}]",
361-
params.getFollowShardId(), currentIndexMetadataVersion, minimumRequiredIndexMetadataVersion);
357+
private synchronized void maybeUpdateMapping(Long minimumRequiredMappingVersion, Runnable task) {
358+
if (currentMappingVersion >= minimumRequiredMappingVersion) {
359+
LOGGER.trace("{} mapping version [{}] is higher or equal than minimum required mapping version [{}]",
360+
params.getFollowShardId(), currentMappingVersion, minimumRequiredMappingVersion);
362361
task.run();
363362
} else {
364-
LOGGER.trace("{} updating mapping, index metadata version [{}] is lower than minimum required index metadata version [{}]",
365-
params.getFollowShardId(), currentIndexMetadataVersion, minimumRequiredIndexMetadataVersion);
366-
updateMapping(imdVersion -> {
367-
currentIndexMetadataVersion = imdVersion;
363+
LOGGER.trace("{} updating mapping, mapping version [{}] is lower than minimum required mapping version [{}]",
364+
params.getFollowShardId(), currentMappingVersion, minimumRequiredMappingVersion);
365+
updateMapping(mappingVersion -> {
366+
currentMappingVersion = mappingVersion;
368367
task.run();
369368
});
370369
}
@@ -441,7 +440,7 @@ public synchronized Status getStatus() {
441440
numConcurrentReads,
442441
numConcurrentWrites,
443442
buffer.size(),
444-
currentIndexMetadataVersion,
443+
currentMappingVersion,
445444
totalFetchTimeMillis,
446445
numberOfSuccessfulFetches,
447446
numberOfFailedFetches,
@@ -469,7 +468,7 @@ public static class Status implements Task.Status {
469468
static final ParseField NUMBER_OF_CONCURRENT_READS_FIELD = new ParseField("number_of_concurrent_reads");
470469
static final ParseField NUMBER_OF_CONCURRENT_WRITES_FIELD = new ParseField("number_of_concurrent_writes");
471470
static final ParseField NUMBER_OF_QUEUED_WRITES_FIELD = new ParseField("number_of_queued_writes");
472-
static final ParseField INDEX_METADATA_VERSION_FIELD = new ParseField("index_metadata_version");
471+
static final ParseField MAPPING_VERSION_FIELD = new ParseField("mapping_version");
473472
static final ParseField TOTAL_FETCH_TIME_MILLIS_FIELD = new ParseField("total_fetch_time_millis");
474473
static final ParseField NUMBER_OF_SUCCESSFUL_FETCHES_FIELD = new ParseField("number_of_successful_fetches");
475474
static final ParseField NUMBER_OF_FAILED_FETCHES_FIELD = new ParseField("number_of_failed_fetches");
@@ -529,7 +528,7 @@ public static class Status implements Task.Status {
529528
STATUS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), NUMBER_OF_CONCURRENT_READS_FIELD);
530529
STATUS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), NUMBER_OF_CONCURRENT_WRITES_FIELD);
531530
STATUS_PARSER.declareInt(ConstructingObjectParser.constructorArg(), NUMBER_OF_QUEUED_WRITES_FIELD);
532-
STATUS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), INDEX_METADATA_VERSION_FIELD);
531+
STATUS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), MAPPING_VERSION_FIELD);
533532
STATUS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), TOTAL_FETCH_TIME_MILLIS_FIELD);
534533
STATUS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_SUCCESSFUL_FETCHES_FIELD);
535534
STATUS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_FETCHES_FIELD);
@@ -614,10 +613,10 @@ public int numberOfQueuedWrites() {
614613
return numberOfQueuedWrites;
615614
}
616615

617-
private final long indexMetadataVersion;
616+
private final long mappingVersion;
618617

619-
public long indexMetadataVersion() {
620-
return indexMetadataVersion;
618+
public long mappingVersion() {
619+
return mappingVersion;
621620
}
622621

623622
private final long totalFetchTimeMillis;
@@ -697,7 +696,7 @@ public long timeSinceLastFetchMillis() {
697696
final int numberOfConcurrentReads,
698697
final int numberOfConcurrentWrites,
699698
final int numberOfQueuedWrites,
700-
final long indexMetadataVersion,
699+
final long mappingVersion,
701700
final long totalFetchTimeMillis,
702701
final long numberOfSuccessfulFetches,
703702
final long numberOfFailedFetches,
@@ -719,7 +718,7 @@ public long timeSinceLastFetchMillis() {
719718
this.numberOfConcurrentReads = numberOfConcurrentReads;
720719
this.numberOfConcurrentWrites = numberOfConcurrentWrites;
721720
this.numberOfQueuedWrites = numberOfQueuedWrites;
722-
this.indexMetadataVersion = indexMetadataVersion;
721+
this.mappingVersion = mappingVersion;
723722
this.totalFetchTimeMillis = totalFetchTimeMillis;
724723
this.numberOfSuccessfulFetches = numberOfSuccessfulFetches;
725724
this.numberOfFailedFetches = numberOfFailedFetches;
@@ -729,7 +728,7 @@ public long timeSinceLastFetchMillis() {
729728
this.numberOfSuccessfulBulkOperations = numberOfSuccessfulBulkOperations;
730729
this.numberOfFailedBulkOperations = numberOfFailedBulkOperations;
731730
this.numberOfOperationsIndexed = numberOfOperationsIndexed;
732-
this.fetchExceptions = fetchExceptions;
731+
this.fetchExceptions = Objects.requireNonNull(fetchExceptions);
733732
this.timeSinceLastFetchMillis = timeSinceLastFetchMillis;
734733
}
735734

@@ -744,7 +743,7 @@ public Status(final StreamInput in) throws IOException {
744743
this.numberOfConcurrentReads = in.readVInt();
745744
this.numberOfConcurrentWrites = in.readVInt();
746745
this.numberOfQueuedWrites = in.readVInt();
747-
this.indexMetadataVersion = in.readVLong();
746+
this.mappingVersion = in.readVLong();
748747
this.totalFetchTimeMillis = in.readVLong();
749748
this.numberOfSuccessfulFetches = in.readVLong();
750749
this.numberOfFailedFetches = in.readVLong();
@@ -775,7 +774,7 @@ public void writeTo(final StreamOutput out) throws IOException {
775774
out.writeVInt(numberOfConcurrentReads);
776775
out.writeVInt(numberOfConcurrentWrites);
777776
out.writeVInt(numberOfQueuedWrites);
778-
out.writeVLong(indexMetadataVersion);
777+
out.writeVLong(mappingVersion);
779778
out.writeVLong(totalFetchTimeMillis);
780779
out.writeVLong(numberOfSuccessfulFetches);
781780
out.writeVLong(numberOfFailedFetches);
@@ -803,7 +802,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
803802
builder.field(NUMBER_OF_CONCURRENT_READS_FIELD.getPreferredName(), numberOfConcurrentReads);
804803
builder.field(NUMBER_OF_CONCURRENT_WRITES_FIELD.getPreferredName(), numberOfConcurrentWrites);
805804
builder.field(NUMBER_OF_QUEUED_WRITES_FIELD.getPreferredName(), numberOfQueuedWrites);
806-
builder.field(INDEX_METADATA_VERSION_FIELD.getPreferredName(), indexMetadataVersion);
805+
builder.field(MAPPING_VERSION_FIELD.getPreferredName(), mappingVersion);
807806
builder.humanReadableField(
808807
TOTAL_FETCH_TIME_MILLIS_FIELD.getPreferredName(),
809808
"total_fetch_time",
@@ -867,14 +866,22 @@ public boolean equals(final Object o) {
867866
numberOfConcurrentReads == that.numberOfConcurrentReads &&
868867
numberOfConcurrentWrites == that.numberOfConcurrentWrites &&
869868
numberOfQueuedWrites == that.numberOfQueuedWrites &&
870-
indexMetadataVersion == that.indexMetadataVersion &&
869+
mappingVersion == that.mappingVersion &&
871870
totalFetchTimeMillis == that.totalFetchTimeMillis &&
872871
numberOfSuccessfulFetches == that.numberOfSuccessfulFetches &&
873872
numberOfFailedFetches == that.numberOfFailedFetches &&
874873
operationsReceived == that.operationsReceived &&
875874
totalTransferredBytes == that.totalTransferredBytes &&
876875
numberOfSuccessfulBulkOperations == that.numberOfSuccessfulBulkOperations &&
877876
numberOfFailedBulkOperations == that.numberOfFailedBulkOperations &&
877+
numberOfOperationsIndexed == that.numberOfOperationsIndexed &&
878+
/*
879+
* ElasticsearchException does not implement equals so we will assume the fetch exceptions are equal if they are equal
880+
* up to the key set and their messages. Note that we are relying on the fact that the fetch exceptions are ordered by
881+
* keys.
882+
*/
883+
fetchExceptions.keySet().equals(that.fetchExceptions.keySet()) &&
884+
getFetchExceptionMessages(this).equals(getFetchExceptionMessages(that)) &&
878885
timeSinceLastFetchMillis == that.timeSinceLastFetchMillis;
879886
}
880887

@@ -891,16 +898,26 @@ public int hashCode() {
891898
numberOfConcurrentReads,
892899
numberOfConcurrentWrites,
893900
numberOfQueuedWrites,
894-
indexMetadataVersion,
901+
mappingVersion,
895902
totalFetchTimeMillis,
896903
numberOfSuccessfulFetches,
897904
numberOfFailedFetches,
898905
operationsReceived,
899906
totalTransferredBytes,
900907
numberOfSuccessfulBulkOperations,
901908
numberOfFailedBulkOperations,
909+
numberOfOperationsIndexed,
910+
/*
911+
* ElasticsearchException does not implement hash code so we will compute the hash code based on the key set and the
912+
* messages. Note that we are relying on the fact that the fetch exceptions are ordered by keys.
913+
*/
914+
fetchExceptions.keySet(),
915+
getFetchExceptionMessages(this),
902916
timeSinceLastFetchMillis);
917+
}
903918

919+
private static List<String> getFetchExceptionMessages(final Status status) {
920+
return status.fetchExceptions().values().stream().map(ElasticsearchException::getMessage).collect(Collectors.toList());
904921
}
905922

906923
public String toString() {

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected void innerUpdateMapping(LongConsumer handler, Consumer<Exception> erro
115115
putMappingRequest.type(mappingMetaData.type());
116116
putMappingRequest.source(mappingMetaData.source().string(), XContentType.JSON);
117117
followerClient.admin().indices().putMapping(putMappingRequest, ActionListener.wrap(
118-
putMappingResponse -> handler.accept(indexMetaData.getVersion()),
118+
putMappingResponse -> handler.accept(indexMetaData.getMappingVersion()),
119119
errorHandler));
120120
}, errorHandler));
121121
}

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesResponseTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class ShardChangesResponseTests extends AbstractStreamableTestCase<ShardC
1212

1313
@Override
1414
protected ShardChangesAction.Response createTestInstance() {
15-
final long indexMetadataVersion = randomNonNegativeLong();
15+
final long mappingVersion = randomNonNegativeLong();
1616
final long leaderGlobalCheckpoint = randomNonNegativeLong();
1717
final long leaderMaxSeqNo = randomLongBetween(leaderGlobalCheckpoint, Long.MAX_VALUE);
1818
final int numOps = randomInt(8);
1919
final Translog.Operation[] operations = new Translog.Operation[numOps];
2020
for (int i = 0; i < numOps; i++) {
2121
operations[i] = new Translog.NoOp(i, 0, "test");
2222
}
23-
return new ShardChangesAction.Response(indexMetadataVersion, leaderGlobalCheckpoint, leaderMaxSeqNo, operations);
23+
return new ShardChangesAction.Response(mappingVersion, leaderGlobalCheckpoint, leaderMaxSeqNo, operations);
2424
}
2525

2626
@Override

0 commit comments

Comments
 (0)