Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing translog sync interval option to index settings #518

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Added
- Add support for knn_vector field type ([#529](https://github.com/opensearch-project/opensearch-java/pull/524))
- Add translog option object and missing translog sync interval option in index settings ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))

### Dependencies
- Bumps `jackson` from 2.14.2 to 2.15.2 ((#537)[https://github.com/opensearch-project/opensearch-java/pull/537])

### Changed

### Deprecated
- Deprecate translogDurability and translogFlushThresholdSize in IndexSettings in favor of a separate translog object ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@

package org.opensearch.client.opensearch.indices;

import org.opensearch.client.opensearch._types.Time;
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.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: indices._types.IndexSettings

Expand Down Expand Up @@ -199,10 +200,7 @@ public class IndexSettings implements JsonpSerializable {
private final Integer maxSlicesPerScroll;

@Nullable
private final String translogDurability;

@Nullable
private final String translogFlushThresholdSize;
private final Translog translog;

@Nullable
private final Boolean queryStringLenient;
Expand Down Expand Up @@ -280,8 +278,7 @@ private IndexSettings(Builder builder) {
this.verifiedBeforeClose = builder.verifiedBeforeClose;
this.format = builder.format;
this.maxSlicesPerScroll = builder.maxSlicesPerScroll;
this.translogDurability = builder.translogDurability;
this.translogFlushThresholdSize = builder.translogFlushThresholdSize;
this.translog = builder.translog;
this.queryStringLenient = builder.queryStringLenient;
this.priority = builder.priority;
this.topMetricsMaxSize = builder.topMetricsMaxSize;
Expand Down Expand Up @@ -680,20 +677,32 @@ public final Integer maxSlicesPerScroll() {
return this.maxSlicesPerScroll;
}

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

/**
* API name: {@code translog.durability}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
@Nullable
public final String translogDurability() {
return this.translogDurability;
return this.translog != null ? this.translog.durability() : null;
}

/**
* API name: {@code translog.flush_threshold_size}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
@Nullable
public final String translogFlushThresholdSize() {
return this.translogFlushThresholdSize;
return this.translog != null ? this.translog.flushThresholdSize() : null;
}

/**
Expand Down Expand Up @@ -1016,14 +1025,9 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.write(this.maxSlicesPerScroll);

}
if (this.translogDurability != null) {
generator.writeKey("translog.durability");
generator.write(this.translogDurability);

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

}
if (this.queryStringLenient != null) {
Expand Down Expand Up @@ -1221,10 +1225,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<I
private Integer maxSlicesPerScroll;

@Nullable
private String translogDurability;

@Nullable
private String translogFlushThresholdSize;
private Translog translog;

@Nullable
private Boolean queryStringLenient;
Expand Down Expand Up @@ -1716,19 +1717,43 @@ 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}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
public final Builder translogDurability(@Nullable String value) {
this.translogDurability = value;
if (translog == null) {
translog = Translog.of(b -> b.durability(value));
} else {
translog = Translog.of(b -> b.durability(value)
.flushThresholdSize(translog.flushThresholdSize())
.syncInterval(translog.syncInterval()));
}
return this;
}

/**
* API name: {@code translog.flush_threshold_size}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
public final Builder translogFlushThresholdSize(@Nullable String value) {
this.translogFlushThresholdSize = value;
if (translog == null) {
translog = Translog.of(b -> b.flushThresholdSize(value));
} else {
translog = Translog.of(b -> b.flushThresholdSize(value)
.durability(translog.durability())
.syncInterval(translog.syncInterval()));
}
return this;
}

Expand Down Expand Up @@ -1920,6 +1945,7 @@ 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(),
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