Skip to content

Commit

Permalink
Fix consistency issues (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: dududu <[email protected]>
  • Loading branch information
roji and weianweigan authored Sep 12, 2023
1 parent ea6ec4f commit c1d2689
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions Milvus.Client/MilvusCollection.Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Milvus.Client;

public partial class MilvusCollection
{
private const ulong GuaranteeTimestampStrong = 0;
private const ulong GuaranteeTimestampEventually = 1;
private const ulong GuaranteeTimestampBounded = 2;

/// <summary>
/// Inserts rows of data into a collection.
/// </summary>
Expand Down Expand Up @@ -201,25 +205,18 @@ public async Task<SearchResults> SearchAsync<T>(
}

// Note that we send both the consistency level and the guarantee timestamp, although the latter is derived
// from the former and should be sufficient. TODO: Confirm this.
// from the former and should be sufficient.
if (parameters?.ConsistencyLevel is null)
{
if (parameters?.GuaranteeTimestamp is null)
{
request.UseDefaultConsistency = true;
}
else
{
request.ConsistencyLevel = Grpc.ConsistencyLevel.Customized;
request.GuaranteeTimestamp = parameters.GuaranteeTimestamp.Value;
}
request.UseDefaultConsistency = true;
request.GuaranteeTimestamp = CalculateGuaranteeTimestamp(Name, ConsistencyLevel.Session, userProvidedGuaranteeTimestamp: null);
}
else
{
request.ConsistencyLevel = (Grpc.ConsistencyLevel)parameters.ConsistencyLevel.Value;
request.GuaranteeTimestamp =
CalculateGuaranteeTimestamp(
Name, parameters.ConsistencyLevel.Value, parameters.GuaranteeTimestamp);
CalculateGuaranteeTimestamp(Name, parameters.ConsistencyLevel.Value,
parameters.GuaranteeTimestamp);
}

Grpc.PlaceholderValue placeholderValue = new() { Tag = Constants.VectorTag };
Expand Down Expand Up @@ -417,18 +414,11 @@ public async Task<IReadOnlyList<FieldData>> QueryAsync(
}

// Note that we send both the consistency level and the guarantee timestamp, although the latter is derived
// from the former and should be sufficient. TODO: Confirm this.
// from the former and should be sufficient.
if (parameters?.ConsistencyLevel is null)
{
if (parameters?.GuaranteeTimestamp is null)
{
request.UseDefaultConsistency = true;
}
else
{
request.ConsistencyLevel = Grpc.ConsistencyLevel.Customized;
request.GuaranteeTimestamp = parameters.GuaranteeTimestamp.Value;
}
request.UseDefaultConsistency = true;
request.GuaranteeTimestamp = CalculateGuaranteeTimestamp(Name, ConsistencyLevel.Session, userProvidedGuaranteeTimestamp: null);
}
else
{
Expand Down Expand Up @@ -634,18 +624,16 @@ ulong CalculateGuaranteeTimestamp(

ulong guaranteeTimestamp = consistencyLevel switch
{
ConsistencyLevel.Strong => 0,
ConsistencyLevel.Strong => GuaranteeTimestampStrong,

ConsistencyLevel.Session
=> _client.CollectionLastMutationTimestamps.TryGetValue(collectionName, out ulong lastMutationTimestamp)
? lastMutationTimestamp
: 1,
: GuaranteeTimestampEventually,

// TODO: This follows pymilvus, but confirm.
// TODO: The Java SDK subtracts a graceful period from the current timestamp instead.
ConsistencyLevel.BoundedStaleness => 2,
ConsistencyLevel.BoundedStaleness => GuaranteeTimestampBounded,

ConsistencyLevel.Eventually => 1,
ConsistencyLevel.Eventually => GuaranteeTimestampEventually,

ConsistencyLevel.Customized => userProvidedGuaranteeTimestamp
?? throw new ArgumentException(
Expand Down

0 comments on commit c1d2689

Please sign in to comment.