public virtual async Task updateOtherGrainState() { var metadatagrainfactory = GrainFactory.GetGrain <IMetadataGrain>(0); foreach (KeyValuePair <string, ConsistencyLevel> entry in State.readers) { switch (entry.Value) { case ConsistencyLevel.STRONG: IStatefulGrain stategrain = await metadatagrainfactory.GetGrain(entry.Key, false, entry.Value); await stategrain.SetState(State); break; } } foreach (KeyValuePair <string, ConsistencyLevel> entry in State.writers) { switch (entry.Value) { case ConsistencyLevel.STRONG: IStatefulGrain stategrain = await metadatagrainfactory.GetGrain(entry.Key, true, entry.Value); await stategrain.SetState(State); break; case ConsistencyLevel.EVENTUAL: throw new NotImplementedException(); } } }
public async void periodicDataUpdate(object source, ElapsedEventArgs e) { var metadatagrainfactory = GrainFactory.GetGrain <IMetadataGrain>(0); //TODO: this may break if the reader is created before any writer IStatefulGrain writergrain = await metadatagrainfactory.GetGrain(State.writers.First().Key, true, State.writers.First().Value); GrainState state = await writergrain.GetState(); await SetState(state); }
private static void BasicTest() { var metadatagrain = Orleans.GrainClient.GrainFactory.GetGrain <IMetadataGrain>(0); var stopwatch = Stopwatch.StartNew(); Task <IStatefulGrain> writertsk = metadatagrain.GetGrain(true, ConsistencyLevel.STRONG); writertsk.Wait(); IStatefulGrain writer = writertsk.Result; stopwatch.Stop(); Console.WriteLine("Time to create a writer {0}", stopwatch.ElapsedMilliseconds); stopwatch.Start(); Task <IStatefulGrain> readertsk = metadatagrain.GetGrain(false, ConsistencyLevel.STRONG); readertsk.Wait(); IStatefulGrain reader = readertsk.Result; stopwatch.Stop(); Console.WriteLine("Time to create a reader {0}", stopwatch.ElapsedMilliseconds); stopwatch.Start(); Task <Context> tskcnt = writer.SetValue(new KeyValuePair <string, string>("hello", "1")); tskcnt.Wait(); Context cnt = tskcnt.Result; stopwatch.Stop(); Console.WriteLine("Time to first write {0}", stopwatch.ElapsedMilliseconds); writer.SetValue(new KeyValuePair <string, string>("how", "2")).Wait(); writer.SetValue(new KeyValuePair <string, string>("are", "3")).Wait(); stopwatch.Start(); writer.SetValue(new KeyValuePair <string, string>("you", "4")).Wait(); stopwatch.Stop(); Console.WriteLine("Time to 4th write {0}", stopwatch.ElapsedMilliseconds); Task task1 = readData(reader, cnt, "how", 1); Task.Delay(30).Wait(); Task task2 = readData(reader, cnt, "are", 2); task1.Wait(); task2.Wait(); stopwatch.Start(); Task <string> value = reader.GetValue("are", cnt); value.Wait(); Console.WriteLine("\n\n{0}\n\n", value.Result); stopwatch.Stop(); Console.WriteLine("Time to read {0}", stopwatch.ElapsedMilliseconds); }
private async Task updateState(Context cntxt) { if (State.currentContext.timestamp < cntxt.timestamp) { var metadatagrainfactory = GrainFactory.GetGrain <IMetadataGrain>(0); //TODO: this may break if the reader is created before any writer IStatefulGrain writergrain = await metadatagrainfactory.GetGrain(State.writers.First().Key, true, State.writers.First().Value); GrainState state = await writergrain.GetState(); await SetState(state); } }
public override async Task updateOtherGrainState() { IWITWDMetadataGrain metadatagrain = GetMetadataGrain(); var fullReplicas = metadatagrain.GetAllFullReplicas().Result; foreach (string entry in fullReplicas) { IStatefulGrain stategrain = await metadatagrain.GetGrain(entry, false, ConsistencyLevel.EVENTUAL); await stategrain.SetState(State); break; } }
private static Task readData(IStatefulGrain reader, Context cnt, string find, int id) { return(Task.Run(() => { var stopwatch = Stopwatch.StartNew(); cnt.id = id; Task <string> value = reader.GetValue(find, cnt); value.Wait(); Console.WriteLine("\n\n{0}:{1}\n\n", id, value.Result); stopwatch.Stop(); Console.WriteLine("Time to read {0}:{1}", id, stopwatch.ElapsedMilliseconds); return 0; })); }
public GrainStateStorageBridge(string grainTypeName, IStatefulGrain grain, IStorageProvider store) { if (grainTypeName == null) { throw new ArgumentNullException("grainTypeName", "No grain type name supplied"); } if (store == null) { throw new ArgumentNullException("store", "No storage provider supplied"); } if (grain == null || grain.GrainState == null) { throw new ArgumentNullException("grain.GrainState", "No grain state object supplied"); } this.grainTypeName = grainTypeName; this.grain = grain; this.baseGrain = grain as Grain; this.store = store; }
internal void SetGrain(Grain grain) { if (grain == null) { throw new ArgumentNullException(nameof(grain)); } statefulGrain = grain as IStatefulGrain; if (statefulGrain == null) { throw new ArgumentException("Attempt to configure storage bridge for a non-perisstent grain.", nameof(grain)); } if (statefulGrain.GrainState == null) { throw new ArgumentException("No grain state object supplied", nameof(grain)); } this.baseGrain = grain; }
public async Task <IStatefulGrain> GetGrain(string primaryKey, bool readwrite, ConsistencyLevel level) { IStatefulGrain grain = null; if (readwrite == true) { switch (level) { case ConsistencyLevel.STRONG: grain = GrainFactory.GetGrain <IStronglyConsistentWriter>(primaryKey); break; case ConsistencyLevel.EVENTUAL: throw new NotImplementedException(); } } else { switch (level) { case ConsistencyLevel.STRONG: grain = GrainFactory.GetGrain <IStronglyConsistentReader>(primaryKey); break; case ConsistencyLevel.READ_MY_WRITE: grain = GrainFactory.GetGrain <IReadMyWriteReader>(primaryKey); break; case ConsistencyLevel.BOUNDED: grain = GrainFactory.GetGrain <IBoundedStalenessReader>(primaryKey); break; case ConsistencyLevel.EVENTUAL: grain = GrainFactory.GetGrain <IEventuallyConsistentReader>(primaryKey); break; } } return(grain); }
public async Task <IStatefulGrain> GetGrain(bool readwrite, ConsistencyLevel level) { IStatefulGrain grain = null; string primaryKey = null; if (readwrite == true) { switch (level) { case ConsistencyLevel.STRONG: //TODO: Implement policy to see if new grain is needed. //For now, we create a new grain each time primaryKey = MetadataGrain.STRONG_WRITER + State.numInstances; State.numInstances++; grain = GrainFactory.GetGrain <IStronglyConsistentWriter>(primaryKey); foreach (KeyValuePair <string, ConsistencyLevel> entry in State.readers) { await grain.RegisterReaderGrain(entry.Key, entry.Value); } foreach (KeyValuePair <string, ConsistencyLevel> entry in State.writers) { await grain.RegisterWriterGrain(entry.Key, entry.Value); IStatefulGrain writergrain = null; switch (entry.Value) { case ConsistencyLevel.STRONG: writergrain = GrainFactory.GetGrain <IStronglyConsistentWriter>(entry.Key); break; case ConsistencyLevel.EVENTUAL: throw new NotImplementedException(); } await writergrain.RegisterWriterGrain(primaryKey, ConsistencyLevel.STRONG); } State.writers.Add(primaryKey, ConsistencyLevel.STRONG); break; case ConsistencyLevel.EVENTUAL: throw new NotImplementedException(); } } else { switch (level) { case ConsistencyLevel.STRONG: //TODO: Implement policy to see if new grain is needed. //For now, we create a new grain each time primaryKey = MetadataGrain.STRONG_READER + State.numInstances; State.numInstances++; grain = GrainFactory.GetGrain <IStronglyConsistentReader>(primaryKey); break; case ConsistencyLevel.READ_MY_WRITE: primaryKey = MetadataGrain.RMW_READER + State.numInstances; State.numInstances++; grain = GrainFactory.GetGrain <IReadMyWriteReader>(primaryKey); break; case ConsistencyLevel.BOUNDED: primaryKey = MetadataGrain.BOUNDED_STALENESS_READER + State.numInstances; State.numInstances++; grain = GrainFactory.GetGrain <IBoundedStalenessReader>(primaryKey); break; case ConsistencyLevel.EVENTUAL: primaryKey = MetadataGrain.EVENTUAL_READER + State.numInstances; State.numInstances++; grain = GrainFactory.GetGrain <IEventuallyConsistentReader>(primaryKey); break; } KeyValuePair <string, ConsistencyLevel> strongwriter = State.writers.First(writer => writer.Value == ConsistencyLevel.STRONG); await grain.RegisterWriterGrain(strongwriter.Key, strongwriter.Value); foreach (KeyValuePair <string, ConsistencyLevel> entry in State.writers) { IStatefulGrain writergrain = null; switch (entry.Value) { case ConsistencyLevel.STRONG: writergrain = GrainFactory.GetGrain <IStronglyConsistentWriter>(entry.Key); break; case ConsistencyLevel.EVENTUAL: throw new NotImplementedException(); } await writergrain.RegisterReaderGrain(primaryKey, level); } State.readers.Add(primaryKey, ConsistencyLevel.STRONG); } return(grain); }