Skip to content

Commit

Permalink
Eliminated GrainState
Browse files Browse the repository at this point in the history
  • Loading branch information
dVakulen committed Nov 23, 2015
1 parent 4c9743e commit 1213d61
Show file tree
Hide file tree
Showing 35 changed files with 336 additions and 413 deletions.
175 changes: 0 additions & 175 deletions src/Orleans/CodeGeneration/GrainState.cs

This file was deleted.

12 changes: 1 addition & 11 deletions src/Orleans/CodeGeneration/TypeUtils.cs
Expand Up @@ -442,17 +442,7 @@ public static bool IsGrainMethodInvokerType(Type type)
}
return generalType.GetTypeInfo().IsAssignableFrom(type) && TypeHasAttribute(type, typeof(MethodInvokerAttribute));
}

public static bool IsGrainStateType(Type type)
{
var generalType = typeof(GrainState);
if (type.Assembly.ReflectionOnly)
{
generalType = ToReflectionOnlyType(generalType);
}
return generalType.GetTypeInfo().IsAssignableFrom(type) && TypeHasAttribute(type, typeof(GrainStateAttribute));
}


public static Type ResolveType(string fullName)
{
return CachedTypeResolver.Instance.ResolveType(fullName);
Expand Down
8 changes: 4 additions & 4 deletions src/Orleans/Core/Grain.cs
Expand Up @@ -41,7 +41,7 @@ public abstract class Grain : IAddressable
{
private IGrainRuntime runtime;

internal GrainState GrainState { get; set; }
internal object GrainState { get; set; }

internal IStorage Storage { get; set; }

Expand Down Expand Up @@ -278,8 +278,8 @@ internal string CaptureRuntimeEnvironment()
/// Base class for a Grain with declared persistent state.
/// </summary>
/// <typeparam name="TGrainState">The class of the persistent state object</typeparam>
public class Grain<TGrainState> : Grain
where TGrainState : GrainState
public class Grain<TGrainState> : Grain
where TGrainState : class
{

/// <summary>
Expand Down Expand Up @@ -310,7 +310,7 @@ protected Grain(IGrainIdentity identity, IGrainRuntime runtime, TGrainState stat
/// </summary>
protected TGrainState State
{
get { return base.GrainState as TGrainState; }
get { return (TGrainState)GrainState; }
}

protected virtual Task ClearStateAsync()
Expand Down
18 changes: 12 additions & 6 deletions src/Orleans/Core/GrainStateStorageBridge.cs
Expand Up @@ -37,6 +37,7 @@ internal class GrainStateStorageBridge : IStorage
private readonly IStorageProvider store;
private readonly Grain grain;
private readonly string grainTypeName;
private string eTag;

public GrainStateStorageBridge(string grainTypeName, Grain grain, IStorageProvider store)
{
Expand Down Expand Up @@ -68,8 +69,13 @@ public async Task ReadStateAsync()
GrainReference grainRef = grain.GrainReference;
try
{
await store.ReadStateAsync(grainTypeName, grainRef, grain.GrainState);

var etagged = await store.ReadStateAsync(grainTypeName, grainRef, grain.GrainState);
grain.GrainState = etagged.State;
if (!string.IsNullOrEmpty(etagged.ETag))
{
eTag = etagged.ETag;
}

StorageStatisticsGroup.OnStorageRead(store, grainTypeName, grainRef, sw.Elapsed);
}
catch (Exception exc)
Expand Down Expand Up @@ -97,8 +103,7 @@ public async Task WriteStateAsync()
Exception errorOccurred;
try
{
await store.WriteStateAsync(grainTypeName, grainRef, grain.GrainState);

eTag = await store.WriteStateAsync(grainTypeName, grainRef, new ETagged<object>(grain.GrainState, eTag));
StorageStatisticsGroup.OnStorageWrite(store, grainTypeName, grainRef, sw.Elapsed);
errorOccurred = null;
}
Expand Down Expand Up @@ -152,9 +157,10 @@ public async Task ClearStateAsync()
try
{
// Clear (most likely Delete) state from external storage
await store.ClearStateAsync(grainTypeName, grainRef, grain.GrainState);
eTag = await store.ClearStateAsync(grainTypeName, grainRef, new ETagged<object>(grain.GrainState, eTag));

// Null out the in-memory copy of the state
grain.GrainState.SetAll(null);
grain.GrainState = null;

// Update counters
StorageStatisticsGroup.OnStorageDelete(store, grainTypeName, grainRef, sw.Elapsed);
Expand Down
4 changes: 2 additions & 2 deletions src/Orleans/Orleans.csproj
Expand Up @@ -90,14 +90,14 @@
<Compile Include="Async\UnobservedExceptionsHandlerClass.cs" />
<Compile Include="Async\TaskExtensions.cs" />
<Compile Include="CodeGeneration\CodeGeneratorManager.cs" />
<Compile Include="CodeGeneration\GrainState.cs" />
<Compile Include="CodeGeneration\ICodeGeneratorCache.cs" />
<Compile Include="CodeGeneration\IGrainMethodInvoker.cs" />
<Compile Include="CodeGeneration\IRuntimeCodeGenerator.cs" />
<Compile Include="CodeGeneration\ISourceCodeGenerator.cs" />
<Compile Include="CodeGeneration\Language.cs" />
<Compile Include="CodeGeneration\OrleansCodeGenerationTargetAttribute.cs" />
<Compile Include="CodeGeneration\SkipCodeGenerationAttribute.cs" />
<Compile Include="Runtime\ETagged.cs" />
<Compile Include="Serialization\IExternalSerializer.cs" />
<Compile Include="Configuration\LimitNames.cs" />
<Compile Include="Configuration\LimitValue.cs" />
Expand Down Expand Up @@ -416,4 +416,4 @@
<Message Text="[OrleansDllBootstrapUsingCodeGen] - Invoking Code Generator" />
<Exec Command="&quot;$(BootstrapOutputPath)ClientGenerator.exe&quot; &quot;@$(ArgsFile)&quot;" />
</Target>
</Project>
</Project>
7 changes: 4 additions & 3 deletions src/Orleans/Providers/IMemoryStorageGrain.cs
Expand Up @@ -23,6 +23,7 @@ MIT License

using System.Collections.Generic;
using System.Threading.Tasks;
using Orleans.Runtime;

namespace Orleans.Storage
{
Expand All @@ -37,7 +38,7 @@ public interface IMemoryStorageGrain : IGrainWithIntegerKey
/// <param name="grainType">Type of this grain [fully qualified class name]</param>
/// <param name="grainId">Grain id for this grain.</param>
/// <returns>Value promise for the currently stored grain state for the specified grain.</returns>
Task<IDictionary<string, object>> ReadStateAsync(string grainType, string grainId);
Task<ETagged<object>> ReadStateAsync(string grainType, string grainId);

/// <summary>
/// Async method to cause update of the specified grain state data into memory store.
Expand All @@ -46,14 +47,14 @@ public interface IMemoryStorageGrain : IGrainWithIntegerKey
/// <param name="grainId">Grain id for this grain.</param>
/// <param name="grainState">New state data to be stored for this grain.</param>
/// <returns>Completion promise for the update operation for stored grain state for the specified grain.</returns>
Task WriteStateAsync(string grainType, string grainId, IDictionary<string, object> grainState);
Task WriteStateAsync(string grainType, string grainId, ETagged<object> grainState);

/// <summary>
/// Async method to cause deletion of the specified grain state data from memory store.
/// </summary>
/// <param name="grainType">Type of this grain [fully qualified class name]</param>
/// <param name="grainId">Grain id for this grain.</param>
/// <returns>Completion promise for the update operation for stored grain state for the specified grain.</returns>
Task DeleteStateAsync(string grainType, string grainId);
Task DeleteStateAsync(string grainType, string grainId, string etag);
}
}
8 changes: 4 additions & 4 deletions src/Orleans/Providers/IStorageProvider.cs
Expand Up @@ -25,7 +25,7 @@ MIT License
using System.Net;
using System.Runtime.Serialization;
using System.Threading.Tasks;

using Orleans.Core;
using Orleans.Runtime;
using Orleans.Providers;

Expand All @@ -46,21 +46,21 @@ public interface IStorageProvider : IProvider
/// <param name="grainReference">Grain reference object for this grain.</param>
/// <param name="grainState">State data object to be populated for this grain.</param>
/// <returns>Completion promise for the Read operation on the specified grain.</returns>
Task ReadStateAsync(string grainType, GrainReference grainReference, GrainState grainState);
Task<ETagged<TState>> ReadStateAsync<TState>(string grainType, GrainReference grainReference, TState grainState);

/// <summary>Write data function for this storage provider instance.</summary>
/// <param name="grainType">Type of this grain [fully qualified class name]</param>
/// <param name="grainReference">Grain reference object for this grain.</param>
/// <param name="grainState">State data object to be written for this grain.</param>
/// <returns>Completion promise for the Write operation on the specified grain.</returns>
Task WriteStateAsync(string grainType, GrainReference grainReference, GrainState grainState);
Task<string> WriteStateAsync(string grainType, GrainReference grainReference, ETagged<object> grainState);

/// <summary>Delete / Clear data function for this storage provider instance.</summary>
/// <param name="grainType">Type of this grain [fully qualified class name]</param>
/// <param name="grainReference">Grain reference object for this grain.</param>
/// <param name="grainState">Copy of last-known state data object for this grain.</param>
/// <returns>Completion promise for the Delete operation on the specified grain.</returns>
Task ClearStateAsync(string grainType, GrainReference grainReference, GrainState grainState);
Task<string> ClearStateAsync(string grainType, GrainReference grainReference, ETagged<object> grainState);
}

/// <summary>
Expand Down

0 comments on commit 1213d61

Please sign in to comment.