Skip to content

Commit 80788e6

Browse files
committed
Add constructors to simplify GarnetObjectStoreOutput initialization.
1 parent 0b59e41 commit 80788e6

16 files changed

Lines changed: 92 additions & 88 deletions

libs/server/AOF/AofProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static void ObjectStoreUpsert(BasicContext<byte[], IGarnetObject, ObjectInput, G
447447
ref var value = ref Unsafe.AsRef<SpanByte>(ptr + sizeof(AofHeader) + key.TotalSize);
448448
var valB = garnetObjectSerializer.Deserialize(value.ToByteArray());
449449

450-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new(outputPtr, outputLength) };
450+
var output = new GarnetObjectStoreOutput(new(outputPtr, outputLength));
451451
basicContext.Upsert(ref keyB, ref valB);
452452
if (!output.SpanByteAndMemory.IsSpanByte)
453453
output.SpanByteAndMemory.Memory.Dispose();
@@ -467,7 +467,7 @@ static void ObjectStoreRMW(BasicContext<byte[], IGarnetObject, ObjectInput, Garn
467467
objectStoreInput.DeserializeFrom(curr);
468468

469469
// Call RMW with the reconstructed key & ObjectInput
470-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new(outputPtr, outputLength) };
470+
var output = new GarnetObjectStoreOutput(new(outputPtr, outputLength));
471471
if (basicContext.RMW(ref keyB, ref objectStoreInput, ref output).IsPending)
472472
basicContext.CompletePending(true);
473473

libs/server/Custom/CustomRespCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private bool TryCustomObjectCommand<TGarnetApi>(GarnetObjectType objType, byte s
141141
var header = new RespInputHeader(objType) { SubId = subid };
142142
var input = new ObjectInput(header, ref parseState, startIdx: 1);
143143

144-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(null) };
144+
var output = new GarnetObjectStoreOutput();
145145

146146
GarnetStatus status;
147147

@@ -296,7 +296,7 @@ public bool InvokeCustomObjectCommand<TGarnetApi>(ref TGarnetApi storageApi, Cus
296296
customCommandParseState.InitializeWithArguments(args);
297297
var input = new ObjectInput(header, ref customCommandParseState);
298298

299-
var _output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(null) };
299+
var _output = new GarnetObjectStoreOutput();
300300
GarnetStatus status;
301301
if (customObjCommand.type == CommandType.ReadModifyWrite)
302302
{

libs/server/Objects/Types/GarnetObjectStoreOutput.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public struct GarnetObjectStoreOutput
6565
/// </summary>
6666
public bool HasRemoveKey => (OutputFlags & ObjectStoreOutputFlags.RemoveKey) == ObjectStoreOutputFlags.RemoveKey;
6767

68+
public GarnetObjectStoreOutput()
69+
{
70+
SpanByteAndMemory = new(null);
71+
}
72+
73+
public GarnetObjectStoreOutput(SpanByteAndMemory spam)
74+
{
75+
SpanByteAndMemory = spam;
76+
}
77+
6878
public void ConvertToHeap()
6979
{
7080
// Does not convert to heap when going pending, because we immediately complete pending operations for object store.

libs/server/Resp/Objects/HashCommands.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Text;
66
using Garnet.common;
7-
using Tsavorite.core;
87

98
namespace Garnet.server
109
{
@@ -95,7 +94,7 @@ private bool HashGet<TGarnetApi>(RespCommand command, ref TGarnetApi storageApi)
9594
var input = new ObjectInput(header, ref parseState, startIdx: 1);
9695

9796
// Prepare GarnetObjectStore output
98-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
97+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
9998

10099
var status = storageApi.HashGet(keyBytes, ref input, ref output);
101100

@@ -138,7 +137,7 @@ private bool HashGetAll<TGarnetApi>(RespCommand command, ref TGarnetApi storageA
138137
var input = new ObjectInput(header, respProtocolVersion);
139138

140139
// Prepare GarnetObjectStore output
141-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
140+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
142141

143142
var status = storageApi.HashGetAll(keyBytes, ref input, ref output);
144143

@@ -182,7 +181,7 @@ private bool HashGetMultiple<TGarnetApi>(RespCommand command, ref TGarnetApi sto
182181
var input = new ObjectInput(header, ref parseState, startIdx: 1);
183182

184183
// Prepare GarnetObjectStore output
185-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
184+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
186185

187186
var status = storageApi.HashGetMultiple(keyBytes, ref input, ref output);
188187

@@ -265,15 +264,15 @@ private bool HashRandomField<TGarnetApi>(RespCommand command, ref TGarnetApi sto
265264
var input = new ObjectInput(header, countWithMetadata, seed);
266265

267266
// Prepare GarnetObjectStore output
268-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
267+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
269268

270269
var status = GarnetStatus.NOTFOUND;
271270

272271
// This prevents going to the backend if HRANDFIELD is called with a count of 0
273272
if (paramCount != 0)
274273
{
275274
// Prepare GarnetObjectStore output
276-
output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
275+
output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
277276
status = storageApi.HashRandomField(keyBytes, ref input, ref output);
278277
}
279278

@@ -504,7 +503,7 @@ private unsafe bool HashKeys<TGarnetApi>(RespCommand command, ref TGarnetApi sto
504503
var input = new ObjectInput(header);
505504

506505
// Prepare GarnetObjectStore output
507-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
506+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
508507

509508
var status = command == RespCommand.HKEYS
510509
? storageApi.HashKeys(keyBytes, ref input, ref output)
@@ -562,7 +561,7 @@ private unsafe bool HashIncrement<TGarnetApi>(RespCommand command, ref TGarnetAp
562561
var input = new ObjectInput(header, ref parseState, startIdx: 1);
563562

564563
// Prepare GarnetObjectStore output
565-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
564+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
566565

567566
var status = storageApi.HashIncrement(keyBytes, ref input, ref output);
568567

@@ -656,7 +655,7 @@ private unsafe bool HashExpire<TGarnetApi>(RespCommand command, ref TGarnetApi s
656655
var header = new RespInputHeader(GarnetObjectType.Hash) { HashOp = HashOperation.HEXPIRE };
657656
var input = new ObjectInput(header, ref fieldsParseState);
658657

659-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
658+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
660659

661660
var status = storageApi.HashExpire(key, expireAt, isMilliseconds, expireOption, ref input, ref output);
662661

@@ -746,7 +745,7 @@ private unsafe bool HashTimeToLive<TGarnetApi>(RespCommand command, ref TGarnetA
746745
var header = new RespInputHeader(GarnetObjectType.Hash) { HashOp = HashOperation.HTTL };
747746
var input = new ObjectInput(header, ref fieldsParseState);
748747

749-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
748+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
750749

751750
var status = storageApi.HashTimeToLive(key, isMilliseconds, isTimestamp, ref input, ref output);
752751

@@ -808,7 +807,7 @@ private unsafe bool HashPersist<TGarnetApi>(ref TGarnetApi storageApi)
808807
var header = new RespInputHeader(GarnetObjectType.Hash) { HashOp = HashOperation.HPERSIST };
809808
var input = new ObjectInput(header, ref fieldsParseState);
810809

811-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
810+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
812811

813812
var status = storageApi.HashPersist(key, ref input, ref output);
814813

libs/server/Resp/Objects/ListCommands.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Text;
66
using Garnet.common;
7-
using Tsavorite.core;
87

98
namespace Garnet.server
109
{
@@ -106,7 +105,7 @@ private unsafe bool ListPop<TGarnetApi>(RespCommand command, ref TGarnetApi stor
106105
var input = new ObjectInput(header, popCount);
107106

108107
// Prepare GarnetObjectStore output
109-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
108+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
110109

111110
var statusOp = command == RespCommand.LPOP
112111
? storageApi.ListLeftPop(keyBytes, ref input, ref output)
@@ -154,7 +153,7 @@ private unsafe bool ListPosition<TGarnetApi>(ref TGarnetApi storageApi)
154153
var input = new ObjectInput(header, ref parseState, startIdx: 1);
155154

156155
// Prepare GarnetObjectStore output
157-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
156+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
158157

159158
var statusOp = storageApi.ListPosition(keyBytes, ref input, ref output);
160159

@@ -561,7 +560,7 @@ private bool ListRange<TGarnetApi>(ref TGarnetApi storageApi)
561560
var input = new ObjectInput(header, start, end);
562561

563562
// Prepare GarnetObjectStore output
564-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
563+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
565564

566565
var statusOp = storageApi.ListRange(keyBytes, ref input, ref output);
567566

@@ -615,7 +614,7 @@ private bool ListIndex<TGarnetApi>(ref TGarnetApi storageApi)
615614
var input = new ObjectInput(header, index);
616615

617616
// Prepare GarnetObjectStore output
618-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
617+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
619618

620619
var statusOp = storageApi.ListIndex(keyBytes, ref input, ref output);
621620

@@ -890,7 +889,7 @@ public bool ListSet<TGarnetApi>(ref TGarnetApi storageApi)
890889
var input = new ObjectInput(header, ref parseState, startIdx: 1);
891890

892891
// Prepare GarnetObjectStore output
893-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
892+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
894893

895894
var statusOp = storageApi.ListSet(keyBytes, ref input, ref output);
896895

libs/server/Resp/Objects/SetCommands.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Diagnostics;
66
using System.Text;
77
using Garnet.common;
8-
using Tsavorite.core;
98

109
namespace Garnet.server
1110
{
@@ -414,7 +413,7 @@ private unsafe bool SetMembers<TGarnetApi>(ref TGarnetApi storageApi)
414413
var input = new ObjectInput(header);
415414

416415
// Prepare GarnetObjectStore output
417-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
416+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
418417

419418
var status = storageApi.SetMembers(keyBytes, ref input, ref output);
420419

@@ -466,7 +465,7 @@ private unsafe bool SetIsMember<TGarnetApi>(RespCommand cmd, ref TGarnetApi stor
466465
var input = new ObjectInput(header, ref parseState, startIdx: 1);
467466

468467
// Prepare GarnetObjectStore output
469-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
468+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
470469

471470
var status = storageApi.SetIsMember(keyBytes, ref input, ref output);
472471

@@ -546,7 +545,7 @@ private unsafe bool SetPop<TGarnetApi>(ref TGarnetApi storageApi)
546545
var input = new ObjectInput(header, countParameter);
547546

548547
// Prepare GarnetObjectStore output
549-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
548+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
550549

551550
var status = storageApi.SetPop(keyBytes, ref input, ref output);
552551

@@ -661,7 +660,7 @@ private unsafe bool SetRandomMember<TGarnetApi>(ref TGarnetApi storageApi)
661660
var input = new ObjectInput(header, countParameter, seed);
662661

663662
// Prepare GarnetObjectStore output
664-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
663+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
665664

666665
var status = storageApi.SetRandomMember(keyBytes, ref input, ref output);
667666

libs/server/Resp/Objects/SharedObjectCommands.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33

44
using Garnet.common;
5-
using Tsavorite.core;
65

76
namespace Garnet.server
87
{
@@ -67,7 +66,7 @@ private unsafe bool ObjectScan<TGarnetApi>(GarnetObjectType objectType, ref TGar
6766
}
6867

6968
// Prepare GarnetObjectStore output
70-
var output = new GarnetObjectStoreOutput { SpanByteAndMemory = new SpanByteAndMemory(dcurr, (int)(dend - dcurr)) };
69+
var output = new GarnetObjectStoreOutput(new(dcurr, (int)(dend - dcurr)));
7170
var status = storageApi.ObjectScan(keyBytes, ref input, ref output);
7271

7372
switch (status)

0 commit comments

Comments
 (0)