dotnet/orleans

Duplicate state created

jerviscui opened this issue · 1 comments

IGrainState creates the state through IActivatorProvider.
IGrainStorage.ReadStateAsync uses Activator.CreateInstance() to create the state once again when there is no data in the stage.
And even if it is created again, it should be created using the IActivatorProvider to keep the logic consistent?

IGrainStorage.ReadStateAsync:

T state = readRecords != null ? (T) readRecords.Item1 : default;
string etag = readRecords != null ? readRecords.Item2 : null;
bool recordExists = readRecords != null;
if(state == null)
{
    logger.LogInformation(
        (int)RelationalStorageProviderCodes.RelationalProviderNoStateFound,
        "Null grain state read (default will be instantiated): ServiceId={ServiceId} ProviderName={Name} GrainType={BaseGrainType} GrainId={GrainId} ETag={ETag}.",
        serviceId,
        name,
        baseGrainType,
        grainId,
        grainState.ETag);
    state = Activator.CreateInstance<T>();
}

grainState.State = state;