-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…119559) When synthetic sources are used in peer recoveries, the translog operations via peer recoveries may differ from those created through replication. This change relaxes the translog operation assertion to account for synthetic source, allowing these operations to be considered equivalent. Closes #119191
- Loading branch information
Showing
14 changed files
with
428 additions
and
114 deletions.
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
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
90 changes: 90 additions & 0 deletions
90
server/src/main/java/org/elasticsearch/index/engine/TranslogOperationAsserter.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,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.engine; | ||
|
||
import org.apache.lucene.search.similarities.BM25Similarity; | ||
import org.apache.lucene.store.ByteBuffersDirectory; | ||
import org.elasticsearch.index.cache.query.TrivialQueryCachingPolicy; | ||
import org.elasticsearch.index.mapper.DocumentParser; | ||
import org.elasticsearch.index.mapper.MappingLookup; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.Translog; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* | ||
* A utility class to assert that translog operations with the same sequence number | ||
* in the same generation are either identical or equivalent when synthetic sources are used. | ||
*/ | ||
public abstract class TranslogOperationAsserter { | ||
public static final TranslogOperationAsserter DEFAULT = new TranslogOperationAsserter() { | ||
}; | ||
|
||
private TranslogOperationAsserter() { | ||
|
||
} | ||
|
||
public static TranslogOperationAsserter withEngineConfig(EngineConfig engineConfig) { | ||
return new TranslogOperationAsserter() { | ||
@Override | ||
public boolean assertSameIndexOperation(Translog.Index o1, Translog.Index o2) throws IOException { | ||
if (super.assertSameIndexOperation(o1, o2)) { | ||
return true; | ||
} | ||
if (engineConfig.getIndexSettings().isRecoverySourceSyntheticEnabled()) { | ||
return super.assertSameIndexOperation(synthesizeSource(engineConfig, o1), o2) | ||
|| super.assertSameIndexOperation(o1, synthesizeSource(engineConfig, o2)); | ||
} | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
static Translog.Index synthesizeSource(EngineConfig engineConfig, Translog.Index op) throws IOException { | ||
final ShardId shardId = engineConfig.getShardId(); | ||
final MappingLookup mappingLookup = engineConfig.getMapperService().mappingLookup(); | ||
final DocumentParser documentParser = engineConfig.getMapperService().documentParser(); | ||
try ( | ||
var directory = new ByteBuffersDirectory(); | ||
var reader = TranslogDirectoryReader.createInMemoryReader(shardId, engineConfig, directory, documentParser, mappingLookup, op) | ||
) { | ||
final Engine.Searcher searcher = new Engine.Searcher( | ||
"assert_translog", | ||
reader, | ||
new BM25Similarity(), | ||
null, | ||
TrivialQueryCachingPolicy.NEVER, | ||
() -> {} | ||
); | ||
try ( | ||
LuceneSyntheticSourceChangesSnapshot snapshot = new LuceneSyntheticSourceChangesSnapshot( | ||
mappingLookup, | ||
searcher, | ||
LuceneSyntheticSourceChangesSnapshot.DEFAULT_BATCH_SIZE, | ||
Integer.MAX_VALUE, | ||
op.seqNo(), | ||
op.seqNo(), | ||
true, | ||
false, | ||
engineConfig.getIndexSettings().getIndexVersionCreated() | ||
) | ||
) { | ||
final Translog.Operation normalized = snapshot.next(); | ||
assert normalized != null : "expected one operation; got zero"; | ||
return (Translog.Index) normalized; | ||
} | ||
} | ||
} | ||
|
||
public boolean assertSameIndexOperation(Translog.Index o1, Translog.Index o2) throws IOException { | ||
return Translog.Index.equalsWithoutAutoGeneratedTimestamp(o1, o2); | ||
} | ||
} |
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
Oops, something went wrong.