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

Add doc’s sequence number + primary term to get responses #3767

Merged
merged 3 commits into from
May 28, 2019
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
10 changes: 10 additions & 0 deletions src/Nest/Document/Multiple/MultiGet/Response/MultiGetHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface IMultiGetHit<out TDocument> where TDocument : class
string Type { get; }

long Version { get; }

long PrimaryTerm { get; }

long SequenceNumber { get; }
}

[JsonObject]
Expand Down Expand Up @@ -58,5 +62,11 @@ public class MultiGetHit<TDocument> : IMultiGetHit<TDocument>

[JsonProperty("_version")]
public long Version { get; internal set; }

[JsonProperty("_primary_term")]
public long PrimaryTerm { get; internal set; }

[JsonProperty("_seq_no")]
public long SequenceNumber { get; internal set; }
}
}
8 changes: 8 additions & 0 deletions src/Nest/Document/Single/Get/GetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public interface IGetResponse<out TDocument> : IResponse where TDocument : class

[JsonProperty("_version")]
long Version { get; }

[JsonProperty("_primary_term")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be long? on 6.x ? Not returned on older versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into this, there are other areas of the code that have implemented both properties as long and not long?...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are implemented as long in places where a value is always returned, and as nullable in places where a value is returned only if a request parameter is provided that indicates to return it

long? PrimaryTerm { get; }

[JsonProperty("_seq_no")]
long? SequenceNumber { get; }
}

[JsonObject(MemberSerialization.OptIn)]
Expand All @@ -47,5 +53,7 @@ public class GetResponse<TDocument> : ResponseBase, IGetResponse<TDocument> wher
public TDocument Source { get; internal set; }
public string Type { get; internal set; }
public long Version { get; internal set; }
public long? PrimaryTerm { get; internal set; }
public long? SequenceNumber { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ protected override void ExpectResponse(IMultiGetResponse response)
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
hit.Version.Should().Be(1);
if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
hit.PrimaryTerm.Should().BeGreaterOrEqualTo(1);
hit.SequenceNumber.Should().BeGreaterOrEqualTo(0);
}
hit.Source.ShouldAdhereToSourceSerializerWhenSet();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Tests/Tests/Document/Single/DocumentCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ [I] protected async Task DocumentIsUpdated() => await AssertOnGetAfterUpdate(r =
{
r.Source.Should().NotBeNull();
r.Version.Should().BeGreaterThan(1);
if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
r.SequenceNumber.Should().BeGreaterOrEqualTo(1);
r.PrimaryTerm.Should().BeGreaterThan(0);
}
r.Source.Description.Should().EndWith("updated");
});

Expand Down
6 changes: 6 additions & 0 deletions src/Tests/Tests/Document/Single/Get/GetApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ protected override void ExpectResponse(IGetResponse<Project> response)
response.Source.Should().NotBeNull();
response.Source.Name.Should().Be(ProjectId);
response.Source.ShouldAdhereToSourceSerializerWhenSet();

if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
response.SequenceNumber.Should().BeGreaterOrEqualTo(0);
response.PrimaryTerm.Should().BeGreaterOrEqualTo(1);
}
}
}

Expand Down