-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing translog sync interval option to index settings (#518)…
… (#544) * fix: add missing translog sync interval option to index settings Additionally, server response contains separate `translog` object, which cannot be deserialized by present translog option deserializers. Therefore, this commit introduces a corresponding `Translog` class, similarly to how it is done for the `blocks` property. * fix: encapsulate translog options into translog in index settings Now that all the translog options are stored in a separate object, we should remove the separate fields to avoid confusion. Public methods (getters, builder setters) should remain intact, mark them deprecated and point them to the corresponding translog fields. Deserializer should still recognize string-valued translog attributes, keep the deprecated setters as field deserializers. Serializer does not have to produce string-valued translog attributes, as server parses `translog` attribute. Do not write translog contents to old `translog.xxx` fields. * refactor: use ModelTestCase in tests for json serialization/deserialization --------- (cherry picked from commit 1323796) Signed-off-by: Maksim Strutovskii <strutovsky.m.a@gmail.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a09f260
commit ccb59f5
Showing
11 changed files
with
344 additions
and
210 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
170 changes: 170 additions & 0 deletions
170
java-client/src/main/java/org/opensearch/client/opensearch/indices/Translog.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,170 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.opensearch.indices; | ||
|
||
import jakarta.json.stream.JsonGenerator; | ||
import org.opensearch.client.json.JsonpDeserializable; | ||
import org.opensearch.client.json.JsonpDeserializer; | ||
import org.opensearch.client.json.JsonpMapper; | ||
import org.opensearch.client.json.JsonpSerializable; | ||
import org.opensearch.client.json.ObjectBuilderDeserializer; | ||
import org.opensearch.client.json.ObjectDeserializer; | ||
import org.opensearch.client.opensearch._types.Time; | ||
import org.opensearch.client.util.ObjectBuilder; | ||
import org.opensearch.client.util.ObjectBuilderBase; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.function.Function; | ||
|
||
|
||
@JsonpDeserializable | ||
public class Translog implements JsonpSerializable { | ||
|
||
@Nullable | ||
private final String durability; | ||
|
||
@Nullable | ||
private final String flushThresholdSize; | ||
|
||
@Nullable | ||
private final Time syncInterval; | ||
|
||
private Translog(Builder builder) { | ||
|
||
this.durability = builder.durability; | ||
this.flushThresholdSize = builder.flushThresholdSize; | ||
this.syncInterval = builder.syncInterval; | ||
|
||
} | ||
|
||
public static Translog of(Function<Builder, ObjectBuilder<Translog>> fn) { | ||
return fn.apply(new Builder()).build(); | ||
} | ||
|
||
/** | ||
* API name: {@code durability} | ||
*/ | ||
@Nullable | ||
public final String durability() { | ||
return this.durability; | ||
} | ||
|
||
/** | ||
* API name: {@code flush_threshold_size} | ||
*/ | ||
@Nullable | ||
public final String flushThresholdSize() { | ||
return this.flushThresholdSize; | ||
} | ||
|
||
/** | ||
* API name: {@code sync_interval} | ||
*/ | ||
@Nullable | ||
public final Time syncInterval() { | ||
return this.syncInterval; | ||
} | ||
|
||
/** | ||
* Serialize this object to JSON. | ||
*/ | ||
public void serialize(JsonGenerator generator, JsonpMapper mapper) { | ||
generator.writeStartObject(); | ||
serializeInternal(generator, mapper); | ||
generator.writeEnd(); | ||
} | ||
|
||
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { | ||
|
||
if (this.durability != null) { | ||
generator.writeKey("durability"); | ||
generator.write(this.durability); | ||
|
||
} | ||
if (this.flushThresholdSize != null) { | ||
generator.writeKey("flush_threshold_size"); | ||
generator.write(this.flushThresholdSize); | ||
|
||
} | ||
if (this.syncInterval != null) { | ||
generator.writeKey("sync_interval"); | ||
this.syncInterval.serialize(generator, mapper); | ||
|
||
} | ||
|
||
} | ||
|
||
// --------------------------------------------------------------------------------------------- | ||
|
||
/** | ||
* Builder for {@link Translog}. | ||
*/ | ||
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<Translog> { | ||
|
||
@Nullable | ||
private String durability; | ||
|
||
@Nullable | ||
private String flushThresholdSize; | ||
|
||
@Nullable | ||
private Time syncInterval; | ||
|
||
/** | ||
* API name: {@code durability} | ||
*/ | ||
public final Translog.Builder durability(@Nullable String value) { | ||
this.durability = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* API name: {@code flush_threshold_size} | ||
*/ | ||
public final Translog.Builder flushThresholdSize(@Nullable String value) { | ||
this.flushThresholdSize = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* API name: {@code sync_interval} | ||
*/ | ||
public final Translog.Builder syncInterval(@Nullable Time value) { | ||
this.syncInterval = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds a {@link Translog}. | ||
* | ||
* @throws NullPointerException | ||
* if some of the required fields are null. | ||
*/ | ||
public Translog build() { | ||
_checkSingleUse(); | ||
|
||
return new Translog(this); | ||
} | ||
} | ||
|
||
/** | ||
* Json deserializer for {@link Translog} | ||
*/ | ||
public static final JsonpDeserializer<Translog> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, | ||
Translog::setupTranslogDeserializer); | ||
|
||
protected static void setupTranslogDeserializer(ObjectDeserializer<Translog.Builder> op) { | ||
|
||
op.add(Translog.Builder::durability, JsonpDeserializer.stringDeserializer(), "durability"); | ||
op.add(Translog.Builder::flushThresholdSize, JsonpDeserializer.stringDeserializer(), "flush_threshold_size"); | ||
op.add(Translog.Builder::syncInterval, Time._DESERIALIZER, "sync_interval"); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.