|
@@ -6,6 +6,7 @@
|
|
*/
|
|
*/
|
|
package org.elasticsearch.xpack.core.ml.job.process.autodetect.output;
|
|
package org.elasticsearch.xpack.core.ml.job.process.autodetect.output;
|
|
|
|
|
|
|
|
+import org.elasticsearch.TransportVersion;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
@@ -28,44 +29,57 @@ public class FlushAcknowledgement implements ToXContentObject, Writeable {
|
|
public static final ParseField TYPE = new ParseField("flush");
|
|
public static final ParseField TYPE = new ParseField("flush");
|
|
public static final ParseField ID = new ParseField("id");
|
|
public static final ParseField ID = new ParseField("id");
|
|
public static final ParseField LAST_FINALIZED_BUCKET_END = new ParseField("last_finalized_bucket_end");
|
|
public static final ParseField LAST_FINALIZED_BUCKET_END = new ParseField("last_finalized_bucket_end");
|
|
|
|
+ public static final ParseField REFRESH_REQUIRED = new ParseField("refresh_required");
|
|
|
|
|
|
public static final ConstructingObjectParser<FlushAcknowledgement, Void> PARSER = new ConstructingObjectParser<>(
|
|
public static final ConstructingObjectParser<FlushAcknowledgement, Void> PARSER = new ConstructingObjectParser<>(
|
|
TYPE.getPreferredName(),
|
|
TYPE.getPreferredName(),
|
|
- a -> new FlushAcknowledgement((String) a[0], (Long) a[1])
|
|
|
|
|
|
+ a -> new FlushAcknowledgement((String) a[0], (Long) a[1], (Boolean) a[2])
|
|
);
|
|
);
|
|
|
|
|
|
static {
|
|
static {
|
|
PARSER.declareString(ConstructingObjectParser.constructorArg(), ID);
|
|
PARSER.declareString(ConstructingObjectParser.constructorArg(), ID);
|
|
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), LAST_FINALIZED_BUCKET_END);
|
|
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), LAST_FINALIZED_BUCKET_END);
|
|
|
|
+ PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), REFRESH_REQUIRED);
|
|
}
|
|
}
|
|
|
|
|
|
private final String id;
|
|
private final String id;
|
|
private final Instant lastFinalizedBucketEnd;
|
|
private final Instant lastFinalizedBucketEnd;
|
|
|
|
+ private final boolean refreshRequired;
|
|
|
|
|
|
- public FlushAcknowledgement(String id, Long lastFinalizedBucketEndMs) {
|
|
|
|
|
|
+ public FlushAcknowledgement(String id, Long lastFinalizedBucketEndMs, Boolean refreshRequired) {
|
|
this.id = id;
|
|
this.id = id;
|
|
// The C++ passes 0 when last finalized bucket end is not available, so treat 0 as null
|
|
// The C++ passes 0 when last finalized bucket end is not available, so treat 0 as null
|
|
this.lastFinalizedBucketEnd = (lastFinalizedBucketEndMs != null && lastFinalizedBucketEndMs > 0)
|
|
this.lastFinalizedBucketEnd = (lastFinalizedBucketEndMs != null && lastFinalizedBucketEndMs > 0)
|
|
? Instant.ofEpochMilli(lastFinalizedBucketEndMs)
|
|
? Instant.ofEpochMilli(lastFinalizedBucketEndMs)
|
|
: null;
|
|
: null;
|
|
|
|
+ this.refreshRequired = refreshRequired == null || refreshRequired;
|
|
}
|
|
}
|
|
|
|
|
|
- public FlushAcknowledgement(String id, Instant lastFinalizedBucketEnd) {
|
|
|
|
|
|
+ public FlushAcknowledgement(String id, Instant lastFinalizedBucketEnd, Boolean refreshRequired) {
|
|
this.id = id;
|
|
this.id = id;
|
|
// Round to millisecond accuracy to ensure round-tripping via XContent results in an equal object
|
|
// Round to millisecond accuracy to ensure round-tripping via XContent results in an equal object
|
|
long epochMillis = (lastFinalizedBucketEnd != null) ? lastFinalizedBucketEnd.toEpochMilli() : 0;
|
|
long epochMillis = (lastFinalizedBucketEnd != null) ? lastFinalizedBucketEnd.toEpochMilli() : 0;
|
|
this.lastFinalizedBucketEnd = (epochMillis > 0) ? Instant.ofEpochMilli(epochMillis) : null;
|
|
this.lastFinalizedBucketEnd = (epochMillis > 0) ? Instant.ofEpochMilli(epochMillis) : null;
|
|
|
|
+ this.refreshRequired = refreshRequired == null || refreshRequired;
|
|
}
|
|
}
|
|
|
|
|
|
public FlushAcknowledgement(StreamInput in) throws IOException {
|
|
public FlushAcknowledgement(StreamInput in) throws IOException {
|
|
id = in.readString();
|
|
id = in.readString();
|
|
lastFinalizedBucketEnd = in.readOptionalInstant();
|
|
lastFinalizedBucketEnd = in.readOptionalInstant();
|
|
|
|
+ if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_012)) {
|
|
|
|
+ refreshRequired = in.readBoolean();
|
|
|
|
+ } else {
|
|
|
|
+ refreshRequired = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
out.writeString(id);
|
|
out.writeString(id);
|
|
out.writeOptionalInstant(lastFinalizedBucketEnd);
|
|
out.writeOptionalInstant(lastFinalizedBucketEnd);
|
|
|
|
+ if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_500_012)) {
|
|
|
|
+ out.writeBoolean(refreshRequired);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public String getId() {
|
|
public String getId() {
|
|
@@ -76,6 +90,10 @@ public class FlushAcknowledgement implements ToXContentObject, Writeable {
|
|
return lastFinalizedBucketEnd;
|
|
return lastFinalizedBucketEnd;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean getRefreshRequired() {
|
|
|
|
+ return refreshRequired;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
builder.startObject();
|
|
builder.startObject();
|
|
@@ -87,13 +105,14 @@ public class FlushAcknowledgement implements ToXContentObject, Writeable {
|
|
lastFinalizedBucketEnd.toEpochMilli()
|
|
lastFinalizedBucketEnd.toEpochMilli()
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+ builder.field(REFRESH_REQUIRED.getPreferredName(), refreshRequired);
|
|
builder.endObject();
|
|
builder.endObject();
|
|
return builder;
|
|
return builder;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int hashCode() {
|
|
public int hashCode() {
|
|
- return Objects.hash(id, lastFinalizedBucketEnd);
|
|
|
|
|
|
+ return Objects.hash(id, lastFinalizedBucketEnd, refreshRequired);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -105,6 +124,8 @@ public class FlushAcknowledgement implements ToXContentObject, Writeable {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
FlushAcknowledgement other = (FlushAcknowledgement) obj;
|
|
FlushAcknowledgement other = (FlushAcknowledgement) obj;
|
|
- return Objects.equals(id, other.id) && Objects.equals(lastFinalizedBucketEnd, other.lastFinalizedBucketEnd);
|
|
|
|
|
|
+ return Objects.equals(id, other.id)
|
|
|
|
+ && Objects.equals(lastFinalizedBucketEnd, other.lastFinalizedBucketEnd)
|
|
|
|
+ && refreshRequired == other.refreshRequired;
|
|
}
|
|
}
|
|
}
|
|
}
|