Skip to content

Commit

Permalink
fix: add missing translog sync interval option to index settings
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Maksim Strutovskii <[email protected]>
  • Loading branch information
Mstrutov committed Jun 6, 2023
1 parent ae4ac0e commit 6ba68d8
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fix failure when deserialing response for tasks API ([#463](https://github.com/opensearch-project/opensearch-java/pull/463))
- Fix failure when deserializing boolean types for enums ([#463](https://github.com/opensearch-project/opensearch-java/pull/482))
- Fix missing minScore, postFilter, searchAfter, sort, trackScores in the MultisearchBody ([#516](https://github.com/opensearch-project/opensearch-java/pull/516))
- Fix missing translog sync interval option in index settings ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))

### Security

## [2.4.0] - 04/11/2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ public class IndexSettings implements JsonpSerializable {
@Nullable
private final Integer maxSlicesPerScroll;

@Nullable
private final Translog translog;

@Nullable
private final String translogDurability;

@Nullable
private final String translogFlushThresholdSize;

@Nullable
private final Time translogSyncInterval;

@Nullable
private final Boolean queryStringLenient;

Expand Down Expand Up @@ -274,8 +280,10 @@ private IndexSettings(Builder builder) {
this.verifiedBeforeClose = builder.verifiedBeforeClose;
this.format = builder.format;
this.maxSlicesPerScroll = builder.maxSlicesPerScroll;
this.translog = builder.translog;
this.translogDurability = builder.translogDurability;
this.translogFlushThresholdSize = builder.translogFlushThresholdSize;
this.translogSyncInterval = builder.translogSyncInterval;
this.queryStringLenient = builder.queryStringLenient;
this.priority = builder.priority;
this.topMetricsMaxSize = builder.topMetricsMaxSize;
Expand Down Expand Up @@ -672,6 +680,14 @@ public final Integer maxSlicesPerScroll() {
return this.maxSlicesPerScroll;
}

/**
* API name: {@code translog}
*/
@Nullable
public final Translog translog() {
return this.translog;
}

/**
* API name: {@code translog.durability}
*/
Expand All @@ -688,6 +704,14 @@ public final String translogFlushThresholdSize() {
return this.translogFlushThresholdSize;
}

/**
* API name: {@code translog.sync_interval}
*/
@Nullable
public final Time translogSyncInterval() {
return this.translogSyncInterval;
}

/**
* API name: {@code query_string.lenient}
*/
Expand Down Expand Up @@ -991,6 +1015,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("max_slices_per_scroll");
generator.write(this.maxSlicesPerScroll);

}
if (this.translog != null) {
generator.writeKey("translog");
this.translog.serialize(generator, mapper);

}
if (this.translogDurability != null) {
generator.writeKey("translog.durability");
Expand All @@ -1001,6 +1030,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("translog.flush_threshold_size");
generator.write(this.translogFlushThresholdSize);

}
if (this.translogSyncInterval != null) {
generator.writeKey("translog.sync_interval");
this.translogSyncInterval.serialize(generator, mapper);

}
if (this.queryStringLenient != null) {
generator.writeKey("query_string.lenient");
Expand Down Expand Up @@ -1186,12 +1220,18 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<I
@Nullable
private Integer maxSlicesPerScroll;

@Nullable
private Translog translog;

@Nullable
private String translogDurability;

@Nullable
private String translogFlushThresholdSize;

@Nullable
private Time translogSyncInterval;

@Nullable
private Boolean queryStringLenient;

Expand Down Expand Up @@ -1676,6 +1716,14 @@ public final Builder maxSlicesPerScroll(@Nullable Integer value) {
return this;
}

/**
* API name: {@code translog}
*/
public final Builder translog(@Nullable Translog value) {
this.translog = value;
return this;
}

/**
* API name: {@code translog.durability}
*/
Expand All @@ -1692,6 +1740,14 @@ public final Builder translogFlushThresholdSize(@Nullable String value) {
return this;
}

/**
* API name: {@code translog.sync_interval}
*/
public final Builder translogSyncInterval(@Nullable Time value) {
this.translogSyncInterval = value;
return this;
}

/**
* API name: {@code query_string.lenient}
*/
Expand Down Expand Up @@ -1863,10 +1919,13 @@ protected static void setupIndexSettingsDeserializer(ObjectDeserializer<IndexSet
op.add(Builder::format, JsonpDeserializer.stringDeserializer(), "format", "index.format");
op.add(Builder::maxSlicesPerScroll, JsonpDeserializer.integerDeserializer(), "max_slices_per_scroll",
"index.max_slices_per_scroll");
op.add(Builder::translog, Translog._DESERIALIZER, "translog", "index.translog");
op.add(Builder::translogDurability, JsonpDeserializer.stringDeserializer(), "translog.durability",
"index.translog.durability");
op.add(Builder::translogFlushThresholdSize, JsonpDeserializer.stringDeserializer(),
"translog.flush_threshold_size", "index.translog.flush_threshold_size");
op.add(Builder::translogSyncInterval, Time._DESERIALIZER,
"translog.sync_interval", "index.translog.sync_interval");
op.add(Builder::queryStringLenient, JsonpDeserializer.booleanDeserializer(), "query_string.lenient",
"index.query_string.lenient");
op.add(Builder::priority, JsonpDeserializer.stringDeserializer(), "priority", "index.priority");
Expand Down
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");

}

}
Loading

0 comments on commit 6ba68d8

Please sign in to comment.