@@ -14,7 +14,13 @@ public partial class FasterKV<Key, Value> : FasterBase, IFasterKV<Key, Value>
14
14
internal struct RmwAsyncOperation < Input , Output , Context > : IAsyncOperation < Input , Output , Context , RmwAsyncResult < Input , Output , Context > >
15
15
{
16
16
AsyncIOContext < Key , Value > diskRequest ;
17
- internal RmwAsyncOperation ( AsyncIOContext < Key , Value > diskRequest ) => this . diskRequest = diskRequest ;
17
+ RMWOptions rmwOptions ;
18
+
19
+ internal RmwAsyncOperation ( AsyncIOContext < Key , Value > diskRequest , ref RMWOptions rmwOptions )
20
+ {
21
+ this . diskRequest = diskRequest ;
22
+ this . rmwOptions = rmwOptions ;
23
+ }
18
24
19
25
/// <inheritdoc/>
20
26
public RmwAsyncResult < Input , Output , Context > CreateCompletedResult ( Status status , Output output , RecordMetadata recordMetadata ) => new ( status , output , recordMetadata ) ;
@@ -25,8 +31,8 @@ public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<
25
31
{
26
32
Status status = ! this . diskRequest . IsDefault ( )
27
33
? fasterKV . InternalCompletePendingRequestFromContext ( fasterSession , this . diskRequest , ref pendingContext , out AsyncIOContext < Key , Value > newDiskRequest )
28
- : fasterKV . CallInternalRMW ( fasterSession , ref pendingContext , ref pendingContext . key . Get ( ) , ref pendingContext . input . Get ( ) , ref pendingContext . output , pendingContext . userContext ,
29
- pendingContext . serialNum , out newDiskRequest ) ;
34
+ : fasterKV . CallInternalRMW ( fasterSession , ref pendingContext , ref pendingContext . key . Get ( ) , ref pendingContext . input . Get ( ) , ref pendingContext . output , ref this . rmwOptions ,
35
+ pendingContext . userContext , pendingContext . serialNum , out newDiskRequest ) ;
30
36
output = pendingContext . output ;
31
37
this . diskRequest = newDiskRequest ;
32
38
return status ;
@@ -35,7 +41,7 @@ public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<
35
41
/// <inheritdoc/>
36
42
public ValueTask < RmwAsyncResult < Input , Output , Context > > DoSlowOperation ( FasterKV < Key , Value > fasterKV , IFasterSession < Key , Value , Input , Output , Context > fasterSession ,
37
43
PendingContext < Input , Output , Context > pendingContext , CancellationToken token )
38
- => SlowRmwAsync ( fasterKV , fasterSession , pendingContext , diskRequest , token ) ;
44
+ => SlowRmwAsync ( fasterKV , fasterSession , pendingContext , rmwOptions , diskRequest , token ) ;
39
45
40
46
/// <inheritdoc/>
41
47
public bool HasPendingIO => ! this . diskRequest . IsDefault ( ) ;
@@ -67,13 +73,13 @@ internal RmwAsyncResult(Status status, TOutput output, RecordMetadata recordMeta
67
73
}
68
74
69
75
internal RmwAsyncResult ( FasterKV < Key , Value > fasterKV , IFasterSession < Key , Value , Input , TOutput , Context > fasterSession ,
70
- PendingContext < Input , TOutput , Context > pendingContext , AsyncIOContext < Key , Value > diskRequest , ExceptionDispatchInfo exceptionDispatchInfo )
76
+ PendingContext < Input , TOutput , Context > pendingContext , ref RMWOptions rmwOptions , AsyncIOContext < Key , Value > diskRequest , ExceptionDispatchInfo exceptionDispatchInfo )
71
77
{
72
78
Status = new ( StatusCode . Pending ) ;
73
79
this . Output = default ;
74
80
this . RecordMetadata = default ;
75
81
updateAsyncInternal = new AsyncOperationInternal < Input , TOutput , Context , RmwAsyncOperation < Input , TOutput , Context > , RmwAsyncResult < Input , TOutput , Context > > (
76
- fasterKV , fasterSession , pendingContext , exceptionDispatchInfo , new ( diskRequest ) ) ;
82
+ fasterKV , fasterSession , pendingContext , exceptionDispatchInfo , new ( diskRequest , ref rmwOptions ) ) ;
77
83
}
78
84
79
85
/// <summary>Complete the RMW operation, issuing additional (rare) I/O asynchronously if needed. It is usually preferable to use Complete() instead of this.</summary>
@@ -105,7 +111,7 @@ public ValueTask<RmwAsyncResult<Input, TOutput, Context>> CompleteAsync(Cancella
105
111
106
112
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
107
113
internal ValueTask < RmwAsyncResult < Input , Output , Context > > RmwAsync < Input , Output , Context , FasterSession > ( FasterSession fasterSession ,
108
- ref Key key , ref Input input , Context context , long serialNo , CancellationToken token = default )
114
+ ref Key key , ref Input input , ref RMWOptions rmwOptions , Context context , long serialNo , CancellationToken token = default )
109
115
where FasterSession : IFasterSession < Key , Value , Input , Output , Context >
110
116
{
111
117
var pcontext = new PendingContext < Input , Output , Context > { IsAsync = true } ;
@@ -115,7 +121,7 @@ internal ValueTask<RmwAsyncResult<Input, Output, Context>> RmwAsync<Input, Outpu
115
121
try
116
122
{
117
123
Output output = default ;
118
- var status = CallInternalRMW ( fasterSession , ref pcontext , ref key , ref input , ref output , context , serialNo , out diskRequest ) ;
124
+ var status = CallInternalRMW ( fasterSession , ref pcontext , ref key , ref input , ref output , ref rmwOptions , context , serialNo , out diskRequest ) ;
119
125
if ( ! status . IsPending )
120
126
return new ValueTask < RmwAsyncResult < Input , Output , Context > > ( new RmwAsyncResult < Input , Output , Context > ( status , output , new RecordMetadata ( pcontext . recordInfo , pcontext . logicalAddress ) ) ) ;
121
127
}
@@ -126,29 +132,30 @@ internal ValueTask<RmwAsyncResult<Input, Output, Context>> RmwAsync<Input, Outpu
126
132
fasterSession . UnsafeSuspendThread ( ) ;
127
133
}
128
134
129
- return SlowRmwAsync ( this , fasterSession , pcontext , diskRequest , token ) ;
135
+ return SlowRmwAsync ( this , fasterSession , pcontext , rmwOptions , diskRequest , token ) ;
130
136
}
131
137
132
138
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
133
139
private Status CallInternalRMW < Input , Output , Context > ( IFasterSession < Key , Value , Input , Output , Context > fasterSession , ref PendingContext < Input , Output , Context > pcontext ,
134
- ref Key key , ref Input input , ref Output output , Context context , long serialNo , out AsyncIOContext < Key , Value > diskRequest )
140
+ ref Key key , ref Input input , ref Output output , ref RMWOptions rmwOptions , Context context , long serialNo , out AsyncIOContext < Key , Value > diskRequest )
135
141
{
136
142
OperationStatus internalStatus ;
143
+ var keyHash = rmwOptions . KeyHash ?? comparer . GetHashCode64 ( ref key ) ;
137
144
do
138
- internalStatus = InternalRMW ( ref key , ref input , ref output , ref context , ref pcontext , fasterSession , serialNo ) ;
145
+ internalStatus = InternalRMW ( ref key , keyHash , ref input , ref output , ref context , ref pcontext , fasterSession , serialNo ) ;
139
146
while ( HandleImmediateRetryStatus ( internalStatus , fasterSession , ref pcontext ) ) ;
140
147
141
148
return HandleOperationStatus ( fasterSession . Ctx , ref pcontext , internalStatus , out diskRequest ) ;
142
149
}
143
150
144
151
private static async ValueTask < RmwAsyncResult < Input , Output , Context > > SlowRmwAsync < Input , Output , Context > (
145
152
FasterKV < Key , Value > @this , IFasterSession < Key , Value , Input , Output , Context > fasterSession ,
146
- PendingContext < Input , Output , Context > pcontext , AsyncIOContext < Key , Value > diskRequest , CancellationToken token = default )
153
+ PendingContext < Input , Output , Context > pcontext , RMWOptions rmwOptions , AsyncIOContext < Key , Value > diskRequest , CancellationToken token = default )
147
154
{
148
155
ExceptionDispatchInfo exceptionDispatchInfo ;
149
156
( diskRequest , exceptionDispatchInfo ) = await WaitForFlushOrIOCompletionAsync ( @this , fasterSession . Ctx , pcontext . flushEvent , diskRequest , token ) ;
150
157
pcontext . flushEvent = default ;
151
- return new RmwAsyncResult < Input , Output , Context > ( @this , fasterSession , pcontext , diskRequest , exceptionDispatchInfo ) ;
158
+ return new RmwAsyncResult < Input , Output , Context > ( @this , fasterSession , pcontext , ref rmwOptions , diskRequest , exceptionDispatchInfo ) ;
152
159
}
153
160
}
154
161
}
0 commit comments