-
Notifications
You must be signed in to change notification settings - Fork 660
Expand file tree
/
Copy pathReadMethods.cs
More file actions
67 lines (59 loc) · 2.48 KB
/
ReadMethods.cs
File metadata and controls
67 lines (59 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using Garnet.common;
using Tsavorite.core;
namespace Garnet.server
{
/// <summary>
/// Object store functions
/// </summary>
public readonly unsafe partial struct ObjectSessionFunctions : ISessionFunctions<ObjectInput, ObjectOutput, long>
{
/// <inheritdoc />
public bool Reader<TSourceLogRecord>(in TSourceLogRecord srcLogRecord, ref ObjectInput input, ref ObjectOutput output, ref ReadInfo readInfo)
where TSourceLogRecord : ISourceLogRecord
{
if (!srcLogRecord.Info.ValueIsObject)
{
readInfo.Action = ReadAction.WrongType;
return false;
}
if (srcLogRecord.Info.HasExpiration && srcLogRecord.Expiration < DateTimeOffset.Now.UtcTicks)
{
// Do not set 'value = null' or otherwise mark this; Reads should not update the database. We rely on consistently checking for expiration everywhere.
readInfo.Action = ReadAction.Expire;
return false;
}
if (input.header.type != 0)
{
var garnetObject = (IGarnetObject)srcLogRecord.ValueObject;
if ((byte)input.header.type < CustomCommandManager.CustomTypeIdStartOffset)
{
var opResult = garnetObject.Operate(ref input, ref output, functionsState.respProtocolVersion);
if (output.HasWrongType)
return true;
return opResult;
}
if (IncorrectObjectType(ref input, garnetObject, ref output.SpanByteAndMemory))
{
output.OutputFlags |= ObjectOutputFlags.WrongType;
return true;
}
var customObjectCommand = GetCustomObjectCommand(ref input, input.header.type);
var writer = new RespMemoryWriter(functionsState.respProtocolVersion, ref output.SpanByteAndMemory);
try
{
var result = customObjectCommand.Reader(srcLogRecord.Key, ref input, garnetObject, ref writer, ref readInfo);
return result;
}
finally
{
writer.Dispose();
}
}
output.GarnetObject = (IGarnetObject)srcLogRecord.ValueObject;
return true;
}
}
}