Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kkewwei committed Jan 17, 2025
1 parent 34ef146 commit 68c2918
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
import org.opensearch.common.util.concurrent.ReleasableLock;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.core.Assertions;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.IndexSettings;
Expand Down Expand Up @@ -771,7 +774,7 @@ private VersionValue getVersionFromMap(BytesRef id) {
}

private boolean canOptimizeAddDocument(Index index) {
if (index.getAutoGeneratedIdTimestamp() != IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP) {
if (index.getAutoGeneratedIdTimestamp() != IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP) {// 不带主键写入
assert index.getAutoGeneratedIdTimestamp() >= 0 : "autoGeneratedIdTimestamp must be positive but was: "
+ index.getAutoGeneratedIdTimestamp();
switch (index.origin()) {
Expand Down Expand Up @@ -983,7 +986,7 @@ public IndexResult index(Index index) throws IOException {
protected final IndexingStrategy planIndexingAsNonPrimary(Index index) throws IOException {
assert assertNonPrimaryOrigin(index);
// needs to maintain the auto_id timestamp in case this replica becomes primary
if (canOptimizeAddDocument(index)) {
if (canOptimizeAddDocument(index)) {// 如果不带主键的写入,肯定可以优化
mayHaveBeenIndexedBefore(index);
}
final IndexingStrategy plan;
Expand Down Expand Up @@ -1208,7 +1211,7 @@ private void addStaleDocs(final List<ParseContext.Document> docs, final IndexWri
*
* @opensearch.internal
*/
protected static final class IndexingStrategy {
protected static final class IndexingStrategy implements Writeable {
final boolean currentNotFoundOrDeleted;
final boolean useLuceneUpdateDocument;
final long versionForIndexing;
Expand Down Expand Up @@ -1246,6 +1249,18 @@ private IndexingStrategy(
: Optional.of(earlyResultOnPreFlightError);
}

private IndexingStrategy(StreamInput in) throws IOException {
this.currentNotFoundOrDeleted = in.readBoolean();
this.useLuceneUpdateDocument = in.readBoolean();
this.versionForIndexing = in.readVLong();
this.indexIntoLucene = in.readBoolean();
this.addStaleOpToLucene = in.readBoolean();
this.reservedDocs = in.readVInt();
this.earlyResultOnPreFlightError = Optional.empty();
assert reservedDocs == 0 || indexIntoLucene || addStaleOpToLucene : reservedDocs;

}

static IndexingStrategy optimizedAppendOnly(long versionForIndexing, int reservedDocs) {
return new IndexingStrategy(true, false, true, false, versionForIndexing, reservedDocs, null);
}
Expand Down Expand Up @@ -1283,6 +1298,11 @@ static IndexingStrategy failAsTooManyDocs(Exception e) {
final IndexResult result = new IndexResult(e, Versions.NOT_FOUND);
return new IndexingStrategy(false, false, false, false, Versions.NOT_FOUND, 0, result);
}

@Override
public void writeTo(StreamOutput out) throws IOException {

}
}

/**
Expand Down

0 comments on commit 68c2918

Please sign in to comment.