Skip to content

Commit

Permalink
Rename StatusCode.OK to Found (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored Feb 23, 2022
1 parent cc2505b commit 93c6898
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 102 deletions.
14 changes: 7 additions & 7 deletions cs/remote/samples/FixedLenClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,35 +154,35 @@ static async Task AsyncSamples(ClientSession<long, long, long, long, byte, Funct
long key = 25;
(status, _) = await session.ReadAsync(key);
if (!status.NotFound)
throw new Exception($"Error! Key = {key}; Status = expected NOTFOUND, actual {status}");
throw new Exception($"Error! Key = {key}; Status = expected NotFound, actual {status}");

key = 9999;
(status, _) = await session.ReadAsync(9999);
if (!status.NotFound)
throw new Exception($"Error! Key = {key}; Status = expected NOTFOUND, actual {status}");
throw new Exception($"Error! Key = {key}; Status = expected NotFound, actual {status}");

key = 9998;
await session.DeleteAsync(key);

(status, _) = await session.ReadAsync(9998);
if (!status.NotFound)
throw new Exception($"Error! Key = {key}; Status = expected NOTFOUND, actual {status}");
throw new Exception($"Error! Key = {key}; Status = expected NotFound, actual {status}");

(status, output) = await session.RMWAsync(9998, 10);
if (!status.Found || output != 10)
throw new Exception($"Error! Key = {key}; Status = expected NOTFOUND, actual {status}; output = expected {10}, actual {output}");
throw new Exception($"Error! Key = {key}; Status = expected NotFound, actual {status}; output = expected {10}, actual {output}");

(status, output) = await session.ReadAsync(key);
if (!status.Found || output != 10)
throw new Exception($"Error! Key = {key}; Status = expected OK, actual {status}; output = expected {10}, actual {output}");
throw new Exception($"Error! Key = {key}; Status = expected Found, actual {status}; output = expected {10}, actual {output}");

(status, output) = await session.RMWAsync(key, 10);
if (!status.Found || output != 20)
throw new Exception($"Error! Key = {key}; Status = expected OK, actual {status} output = expected {10}, actual {output}");
throw new Exception($"Error! Key = {key}; Status = expected Found, actual {status} output = expected {10}, actual {output}");

(status, output) = await session.ReadAsync(key);
if (!status.Found || output != 20)
throw new Exception($"Error! Key = {key}; Status = expected OK, actual {status}, output = expected {10}, actual {output}");
throw new Exception($"Error! Key = {key}; Status = expected Found, actual {status}, output = expected {10}, actual {output}");
}
}
}
5 changes: 4 additions & 1 deletion cs/remote/src/FASTER.client/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct Status
/// <summary>
/// Whether a Read or RMW found the key
/// </summary>
public bool Found => (statusCode & StatusCode.BasicMask) == StatusCode.OK;
public bool Found => (statusCode & StatusCode.BasicMask) == StatusCode.Found;

/// <summary>
/// Whether a Read or RMW did not find the key
Expand Down Expand Up @@ -61,5 +61,8 @@ public bool IsCompletedSuccessfully
return basicCode != StatusCode.Pending && basicCode != StatusCode.Error;
}
}

/// <inheritdoc />
public override string ToString() => this.statusCode.ToString();
}
}
2 changes: 1 addition & 1 deletion cs/remote/src/FASTER.client/StatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal enum StatusCode : byte
/// the operation completed successfully
/// For Upsert, item was upserted successfully
/// </summary>
OK,
Found,
/// <summary>
/// For Read and RMW, item being read was not found
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions cs/samples/HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ static void InMemorySample()
using var tryAddSession = store.NewSession(new TryAddFunctions<long, long>());
key = 3; input1 = 30; input2 = 31;

// First TryAdd - success; status should be NOTFOUND (does not already exist)
// First TryAdd - success; status should be NotFound (does not already exist)
status = tryAddSession.RMW(ref key, ref input1);

// Second TryAdd - failure; status should be OK (already exists)
// Second TryAdd - failure; status should be Found (already exists)
var status2 = tryAddSession.RMW(ref key, ref input2);

// Read, result should be input1 (first TryAdd)
var status3 = session.Read(ref key, ref output);

if (!status.Found && status2.Found && status3.Found && output == input1)
if (status.NotFound && status2.Found && status3.Found && output == input1)
Console.WriteLine("(4) Success!");
else
Console.WriteLine("(4) Error!");
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Index/Common/CompletedOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public struct CompletedOutput<TKey, TValue, TInput, TOutput, TContext>
public RecordMetadata RecordMetadata;

/// <summary>
/// The status of the operation: OK or NOTFOUND
/// The status of the operation
/// </summary>
public Status Status;

Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Index/FASTER/FASTERBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ internal Status Free()
Free(1);
epoch.Dispose();
overflowBucketsAllocator.Dispose();
return new(StatusCode.OK);
return new(StatusCode.Found);
}

private Status Free(int version)
Expand All @@ -288,7 +288,7 @@ private Status Free(int version)

state[version].tableRaw = null;
state[version].tableAligned = null;
return new(StatusCode.OK);
return new(StatusCode.Found);
}

/// <summary>
Expand Down
21 changes: 3 additions & 18 deletions cs/src/core/Index/FASTER/FASTERImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ internal Status InternalContainsKeyInMemory<Input, Output, Context, FasterSessio
return new(StatusCode.NotFound);
}
else
return new(StatusCode.OK);
return new(StatusCode.Found);
}
else
{
Expand Down Expand Up @@ -2105,22 +2105,7 @@ ref hlog.GetValue(newPhysicalAddress),
/// <param name="operationStatus">Internal status of the trial.</param>
/// <param name="asyncOp">When operation issued via async call</param>
/// <param name="request">IO request, if operation went pending</param>
/// <returns>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>OK</term>
/// <term>The operation has been completed successfully.</term>
/// </item>
/// <item>
/// <term>PENDING</term>
/// <term>The operation is still pending and will callback when done.</term>
/// </item>
/// </list>
/// </returns>
/// <returns>Operation status</returns>
internal Status HandleOperationStatus<Input, Output, Context, FasterSession>(
FasterExecutionContext<Input, Output, Context> opCtx,
FasterExecutionContext<Input, Output, Context> currentCtx,
Expand Down Expand Up @@ -2492,7 +2477,7 @@ internal OperationStatus InternalTryCopyToTail<Input, Output, Context, FasterSes
Address = Constants.kInvalidAddress
};

StatusCode advancedStatusCode = StatusCode.OK;
StatusCode advancedStatusCode = StatusCode.Found;
if (copyToReadCache)
{
BlockAllocateReadCache(allocatedSize, out newLogicalAddress, currentCtx, fasterSession);
Expand Down
8 changes: 4 additions & 4 deletions cs/src/core/Index/Interfaces/TryAddFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace FASTER.core
{
/// <summary>
/// Functions that make RMW behave as an atomic TryAdd operation, where Input is the value being added.
/// Return Status.NOTFOUND => TryAdd succeededed (item added).
/// Return Status.OK => TryAdd failed (item not added, key was already present).
/// Return Status.NotFound => TryAdd succeededed (item added).
/// Return Status.Found => TryAdd failed (item not added, key was already present).
/// </summary>
/// <typeparam name="Key"></typeparam>
/// <typeparam name="Value"></typeparam>
Expand All @@ -21,8 +21,8 @@ public class TryAddFunctions<Key, Value, Context> : SimpleFunctions<Key, Value,

/// <summary>
/// Functions that make RMW behave as an atomic TryAdd operation, where Input is the value being added.
/// Return Status.NOTFOUND => TryAdd succeededed (item added)
/// Return Status.OK => TryAdd failed (item not added, key was already present)
/// Return Status.NotFound => TryAdd succeededed (item added)
/// Return Status.Found => TryAdd failed (item not added, key was already present)
/// </summary>
/// <typeparam name="Key"></typeparam>
/// <typeparam name="Value"></typeparam>
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Utilities/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal Status(OperationStatus operationStatus) : this()
/// <summary>
/// Create a <see cref="Found"/> Status value.
/// </summary>
public static Status CreateFound() => new(StatusCode.OK);
public static Status CreateFound() => new(StatusCode.Found);

/// <summary>
/// Create a <see cref="IsPending"/> Status value. Use the Is* properties to query.
Expand All @@ -85,7 +85,7 @@ internal Status(OperationStatus operationStatus) : this()
/// <summary>
/// Whether a Read or RMW found the key
/// </summary>
public bool Found => (this.Record.statusCode & StatusCode.BasicMask) == StatusCode.OK;
public bool Found => (this.Record.statusCode & StatusCode.BasicMask) == StatusCode.Found;

/// <summary>
/// Whether a Read or RMW did not find the key
Expand Down
27 changes: 12 additions & 15 deletions cs/src/core/Utilities/StatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ internal enum StatusCode : byte
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item>Upsert ConcurrentWriter: <see cref="OK"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>RMW InPlaceUpdater: <see cref="OK"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>RMW CopyUpdater: <see cref="OK"/> | <see cref="CopyUpdatedRecord"/></item>
/// <item>Upsert ConcurrentWriter: <see cref="Found"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>RMW InPlaceUpdater: <see cref="Found"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>RMW CopyUpdater: <see cref="Found"/> | <see cref="CopyUpdatedRecord"/></item>
/// <list type="bullet">
/// <item>If NeedCopyUpdate returns false: <see cref="OK"/></item>
/// <item>If NeedCopyUpdate returns false: <see cref="Found"/></item>
/// </list>
/// <item>Delete ConcurrentDeleter: <see cref="OK"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>Read ConcurrentReader: <see cref="OK"/></item>
/// <item>Delete ConcurrentDeleter: <see cref="Found"/> | <see cref="InPlaceUpdatedRecord"/></item>
/// <item>Read ConcurrentReader: <see cref="Found"/></item>
/// <list type="bullet">
/// <item>If in immutable region and copying to tail: <see cref="OK"/> | <see cref="CopiedRecord"/></item>
/// <item>If in immutable region and copying to tail: <see cref="Found"/> | <see cref="CopiedRecord"/></item>
/// </list>
/// <item>Read Pending to SingleReader: <see cref="OK"/></item>
/// <item>Read Pending to SingleReader: <see cref="Found"/></item>
/// <list type="bullet">
/// <item>If copying to tail: <see cref="OK"/> | <see cref="CopiedRecord"/></item>
/// <item>If copying to readCache: <see cref="OK"/> | <see cref="CopiedRecordToReadCache"/></item>
/// <item>If copying to tail: <see cref="Found"/> | <see cref="CopiedRecord"/></item>
/// <item>If copying to readCache: <see cref="Found"/> | <see cref="CopiedRecordToReadCache"/></item>
/// </list>
/// </list>
/// </remarks>
OK = 0x00,
Found = 0x00,

/// <summary>
/// The key for the operation was not found. For Read, that is all that is returned for an unfound key. For other operations, see
Expand Down Expand Up @@ -72,11 +72,8 @@ internal enum StatusCode : byte
BasicMask = 0x0F,
#endregion

// These are the advanced codes for additional info such as "did we CopyToTail?" or detailed info like "how exactly did this operation achieve its OK status?"
// These are the advanced codes for additional info such as "did we CopyToTail?" or detailed info like "how exactly did this operation achieve its Found status?"
#region Advanced status codes
// Placeholder for "no advanced bit set"; we want nothing to show in debugger for this ("OK" is shown if the StatusCode is 0)
// None = 0x00,

/// <summary>
/// Indicates that a new record for a previously non-existent key was appended to the log.
/// </summary>
Expand Down
30 changes: 15 additions & 15 deletions cs/test/BasicFASTERTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void NativeInMemWriteRead([Values] TestUtils.DeviceType deviceType)
session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
}
Expand All @@ -109,7 +109,7 @@ public void NativeInMemWriteReadDelete([Values] TestUtils.DeviceType deviceType)

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

session.Delete(ref key1, Empty.Default, 0);

Expand All @@ -122,7 +122,7 @@ public void NativeInMemWriteReadDelete([Values] TestUtils.DeviceType deviceType)
session.Upsert(ref key2, ref value2, Empty.Default, 0);
status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
Assert.AreEqual(value2.vfield1, output.value.vfield1);
Assert.AreEqual(value2.vfield2, output.value.vfield2);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public void NativeInMemWriteReadDelete2()
{
var key1 = new KeyStruct { kfield1 = i, kfield2 = 14 };
var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
}
}

Expand Down Expand Up @@ -356,7 +356,7 @@ public unsafe void NativeInMemRMWRefKeys([Values] TestUtils.DeviceType deviceTyp

status = session.Read(ref key, ref input, ref output, Empty.Default, 0);

AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
Assert.AreEqual(2 * value.vfield1, output.value.vfield1);
Assert.AreEqual(2 * value.vfield2, output.value.vfield2);
}
Expand Down Expand Up @@ -413,7 +413,7 @@ public unsafe void NativeInMemRMWNoRefKeys([Values] TestUtils.DeviceType deviceT

status = session.Read(ref key, ref input, ref output, Empty.Default, 0);

AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
Assert.AreEqual(2 * value.vfield1, output.value.vfield1);
Assert.AreEqual(2 * value.vfield2, output.value.vfield2);
}
Expand All @@ -438,7 +438,7 @@ public void ReadNoRefKeyInputOutput([Values] TestUtils.DeviceType deviceType)

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(key1, input, out OutputStruct output, Empty.Default, 111);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

// Verify the read data
Assert.AreEqual(value.vfield1, output.value.vfield1);
Expand All @@ -459,7 +459,7 @@ public void ReadNoRefKey([Values] TestUtils.DeviceType deviceType)

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(key1, out OutputStruct output, Empty.Default, 1);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

// Verify the read data
Assert.AreEqual(value.vfield1, output.value.vfield1);
Expand All @@ -484,7 +484,7 @@ public void ReadWithoutInput([Values] TestUtils.DeviceType deviceType)

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(ref key1, ref output, Empty.Default, 99);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

// Verify the read data
Assert.AreEqual(value.vfield1, output.value.vfield1);
Expand Down Expand Up @@ -513,7 +513,7 @@ public void ReadWithoutSerialID()

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.Read(ref key1, ref input, ref output, Empty.Default);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
Expand All @@ -535,7 +535,7 @@ public void ReadBareMinParams([Values] TestUtils.DeviceType deviceType)
session.Upsert(ref key1, ref value, Empty.Default, 0);

var (status, output) = session.Read(key1);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
Expand Down Expand Up @@ -563,7 +563,7 @@ public void ReadAtAddressReadFlagsNone()

session.Upsert(ref key1, ref value, Empty.Default, 0);
var status = session.ReadAtAddress(readAtAddress, ref input, ref output, ReadFlags.None, Empty.Default, 0);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
Expand Down Expand Up @@ -698,7 +698,7 @@ public void UpsertDefaultsTest([Values] TestUtils.DeviceType deviceType)

session.Upsert(ref key1, ref value);
var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

Assert.AreEqual(1, fht.EntryCount);
Assert.AreEqual(value.vfield1, output.value.vfield1);
Expand All @@ -724,7 +724,7 @@ public void UpsertNoRefNoDefaultsTest()

session.Upsert(key1, value, Empty.Default, 0);
var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);

Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
Expand Down Expand Up @@ -763,7 +763,7 @@ public void UpsertSerialNumberTest()
{
var status = session.Read(ref key, ref input, ref output, serialNo: maxLap + 1);

AssertCompleted(new(StatusCode.OK), status);
AssertCompleted(new(StatusCode.Found), status);
Assert.AreEqual(value.vfield1, output.value.vfield1);
Assert.AreEqual(value.vfield2, output.value.vfield2);
}
Expand Down
Loading

0 comments on commit 93c6898

Please sign in to comment.