@@ -10,7 +10,7 @@ namespace Garnet.server
10
10
{
11
11
sealed partial class StorageSession : IDisposable
12
12
{
13
- // These are classes so instantiate once and re-initialize
13
+ // These contain classes so instantiate once and re-initialize
14
14
private ArrayKeyIterationFunctions . MainStoreGetDBSize mainStoreDbSizeFuncs ;
15
15
private ArrayKeyIterationFunctions . ObjectStoreGetDBSize objectStoreDbSizeFuncs ;
16
16
@@ -180,48 +180,61 @@ internal int DbSize()
180
180
mainStoreDbSizeFuncs . Initialize ( ) ;
181
181
long cursor = 0 ;
182
182
basicContext . Session . ScanCursor ( ref cursor , long . MaxValue , mainStoreDbSizeFuncs ) ;
183
- int count = mainStoreDbSizeFuncs . count ;
183
+ int count = mainStoreDbSizeFuncs . Count ;
184
184
if ( objectStoreBasicContext . Session != null )
185
185
{
186
186
objectStoreDbSizeFuncs ??= new ( ) ;
187
187
objectStoreDbSizeFuncs . Initialize ( ) ;
188
188
cursor = 0 ;
189
189
objectStoreBasicContext . Session . ScanCursor ( ref cursor , long . MaxValue , objectStoreDbSizeFuncs ) ;
190
- count += objectStoreDbSizeFuncs . count ;
190
+ count += objectStoreDbSizeFuncs . Count ;
191
191
}
192
192
193
193
return count ;
194
194
}
195
195
196
196
internal static unsafe class ArrayKeyIterationFunctions
197
197
{
198
- internal sealed class MainStoreGetDBKeys : IScanIteratorFunctions < SpanByte , SpanByte >
198
+ internal class GetDBKeysInfo
199
199
{
200
- List < byte [ ] > keys ;
201
- byte * patternB ;
202
- int patternLength ;
200
+ // This must be a class as it is passed through pending IO operations, so it is wrapped by higher structures for inlining as a generic type arg.
201
+ internal List < byte [ ] > keys ;
202
+ internal byte * patternB ;
203
+ internal int patternLength ;
204
+ internal Type matchType ;
203
205
204
- internal void Initialize ( List < byte [ ] > keys , byte * patternB , int length )
206
+ internal void Initialize ( List < byte [ ] > keys , byte * patternB , int length , Type matchType = null )
205
207
{
206
208
this . keys = keys ;
207
209
this . patternB = patternB ;
208
210
this . patternLength = length ;
211
+ this . matchType = matchType ;
209
212
}
213
+ }
214
+
215
+ internal sealed class MainStoreGetDBKeys : IScanIteratorFunctions < SpanByte , SpanByte >
216
+ {
217
+ private readonly GetDBKeysInfo info ;
218
+
219
+ internal MainStoreGetDBKeys ( ) => info = new ( ) ;
220
+
221
+ internal void Initialize ( List < byte [ ] > keys , byte * patternB , int length )
222
+ => info . Initialize ( keys , patternB , length ) ;
210
223
211
224
public bool SingleReader ( ref SpanByte key , ref SpanByte value , RecordMetadata recordMetadata , long numberOfRecords , out CursorRecordResult cursorRecordResult )
212
225
=> ConcurrentReader ( ref key , ref value , recordMetadata , numberOfRecords , out cursorRecordResult ) ;
213
226
214
227
public bool ConcurrentReader ( ref SpanByte key , ref SpanByte value , RecordMetadata recordMetadata , long numberOfRecords , out CursorRecordResult cursorRecordResult )
215
228
{
216
- if ( ( patternB != null && ! GlobUtils . Match ( patternB , patternLength , key . ToPointer ( ) , key . Length , true ) )
229
+ if ( ( info . patternB != null && ! GlobUtils . Match ( info . patternB , info . patternLength , key . ToPointer ( ) , key . Length , true ) )
217
230
|| ( value . MetadataSize != 0 && MainSessionFunctions . CheckExpiry ( ref value ) ) )
218
231
{
219
232
cursorRecordResult = CursorRecordResult . Skip ;
220
233
}
221
234
else
222
235
{
223
236
cursorRecordResult = CursorRecordResult . Accept ;
224
- keys . Add ( key . ToByteArray ( ) ) ;
237
+ info . keys . Add ( key . ToByteArray ( ) ) ;
225
238
}
226
239
return true ;
227
240
}
@@ -233,18 +246,12 @@ public void OnException(Exception exception, long numberOfRecords) { }
233
246
234
247
internal sealed class ObjectStoreGetDBKeys : IScanIteratorFunctions < byte [ ] , IGarnetObject >
235
248
{
236
- List < byte [ ] > keys ;
237
- byte * patternB ;
238
- int patternLength ;
239
- private Type matchType ;
249
+ private readonly GetDBKeysInfo info ;
250
+
251
+ internal ObjectStoreGetDBKeys ( ) => info = new ( ) ;
240
252
241
253
internal void Initialize ( List < byte [ ] > keys , byte * patternB , int length , Type matchType = null )
242
- {
243
- this . keys = keys ;
244
- this . patternB = patternB ;
245
- this . patternLength = length ;
246
- this . matchType = matchType ;
247
- }
254
+ => info . Initialize ( keys , patternB , length , matchType ) ;
248
255
249
256
public bool SingleReader ( ref byte [ ] key , ref IGarnetObject value , RecordMetadata recordMetadata , long numberOfRecords , out CursorRecordResult cursorRecordResult )
250
257
=> ConcurrentReader ( ref key , ref value , recordMetadata , numberOfRecords , out cursorRecordResult ) ;
@@ -257,25 +264,25 @@ public bool ConcurrentReader(ref byte[] key, ref IGarnetObject value, RecordMeta
257
264
return true ;
258
265
}
259
266
260
- if ( patternB != null )
267
+ if ( info . patternB != null )
261
268
{
262
269
fixed ( byte * keyPtr = key )
263
270
{
264
- if ( ! GlobUtils . Match ( patternB , patternLength , keyPtr , key . Length , true ) )
271
+ if ( ! GlobUtils . Match ( info . patternB , info . patternLength , keyPtr , key . Length , true ) )
265
272
{
266
273
cursorRecordResult = CursorRecordResult . Skip ;
267
274
return true ;
268
275
}
269
276
}
270
277
}
271
278
272
- if ( matchType != null && value . GetType ( ) != matchType )
279
+ if ( info . matchType != null && value . GetType ( ) != info . matchType )
273
280
{
274
281
cursorRecordResult = CursorRecordResult . Skip ;
275
282
return true ;
276
283
}
277
284
278
- keys . Add ( key ) ;
285
+ info . keys . Add ( key ) ;
279
286
cursorRecordResult = CursorRecordResult . Accept ;
280
287
return true ;
281
288
}
@@ -285,12 +292,23 @@ public void OnStop(bool completed, long numberOfRecords) { }
285
292
public void OnException ( Exception exception , long numberOfRecords ) { }
286
293
}
287
294
288
- internal sealed class MainStoreGetDBSize : IScanIteratorFunctions < SpanByte , SpanByte >
295
+ internal class GetDBSizeInfo
289
296
{
290
- // This must be a class as it is passed through pending IO operations
297
+ // This must be a class as it is passed through pending IO operations, so it is wrapped by higher structures for inlining as a generic type arg.
291
298
internal int count ;
292
299
293
300
internal void Initialize ( ) => count = 0 ;
301
+ }
302
+
303
+ internal sealed class MainStoreGetDBSize : IScanIteratorFunctions < SpanByte , SpanByte >
304
+ {
305
+ private readonly GetDBSizeInfo info ;
306
+
307
+ internal int Count => info . count ;
308
+
309
+ internal MainStoreGetDBSize ( ) => info = new ( ) ;
310
+
311
+ internal void Initialize ( ) => info . Initialize ( ) ;
294
312
295
313
public bool SingleReader ( ref SpanByte key , ref SpanByte value , RecordMetadata recordMetadata , long numberOfRecords , out CursorRecordResult cursorRecordResult )
296
314
{
@@ -299,7 +317,7 @@ public bool SingleReader(ref SpanByte key, ref SpanByte value, RecordMetadata re
299
317
else
300
318
{
301
319
cursorRecordResult = CursorRecordResult . Accept ;
302
- ++ count ;
320
+ ++ info . count ;
303
321
}
304
322
return true ;
305
323
}
@@ -312,10 +330,13 @@ public void OnException(Exception exception, long numberOfRecords) { }
312
330
313
331
internal sealed class ObjectStoreGetDBSize : IScanIteratorFunctions < byte [ ] , IGarnetObject >
314
332
{
315
- // This must be a class as it is passed through pending IO operations
316
- internal int count ;
333
+ private readonly GetDBSizeInfo info ;
317
334
318
- internal void Initialize ( ) => count = 0 ;
335
+ internal int Count => info . count ;
336
+
337
+ internal ObjectStoreGetDBSize ( ) => info = new ( ) ;
338
+
339
+ internal void Initialize ( ) => info . Initialize ( ) ;
319
340
320
341
public bool SingleReader ( ref byte [ ] key , ref IGarnetObject value , RecordMetadata recordMetadata , long numberOfRecords , out CursorRecordResult cursorRecordResult )
321
342
{
@@ -324,7 +345,7 @@ public bool SingleReader(ref byte[] key, ref IGarnetObject value, RecordMetadata
324
345
else
325
346
{
326
347
cursorRecordResult = CursorRecordResult . Accept ;
327
- ++ count ;
348
+ ++ info . count ;
328
349
}
329
350
return true ;
330
351
}
0 commit comments