public bool LocalLookup(GrainId grain, out List <ActivationAddress> addresses) { localLookups.Increment(); SiloAddress silo = CalculateTargetSilo(grain, false); // No need to check that silo != null since we're passing excludeThisSiloIfStopping = false if (log.IsVerbose) { log.Verbose("Silo {0} tries to lookup for {1}-->{2} ({3}-->{4})", MyAddress, grain, silo, grain.GetUniformHashCode(), silo.GetConsistentHashCode()); } // check if we own the grain if (silo.Equals(MyAddress)) { LocalDirectoryLookups.Increment(); addresses = GetLocalDirectoryData(grain); if (addresses == null) { // it can happen that we cannot find the grain in our partition if there were // some recent changes in the membership if (log.IsVerbose2) { log.Verbose2("LocalLookup mine {0}=null", grain); } return(false); } if (log.IsVerbose2) { log.Verbose2("LocalLookup mine {0}={1}", grain, addresses.ToStrings()); } LocalDirectorySuccesses.Increment(); localSuccesses.Increment(); return(true); } // handle cache cacheLookups.Increment(); addresses = GetLocalCacheData(grain); if (addresses == null) { if (log.IsVerbose2) { log.Verbose2("TryFullLookup else {0}=null", grain); } return(false); } if (log.IsVerbose2) { log.Verbose2("LocalLookup cache {0}={1}", grain, addresses.ToStrings()); } cacheSuccesses.Increment(); localSuccesses.Increment(); return(true); }
public void TestToStrings() { List <int?> test = new List <int?> { 1, null, 3, 4 }; Assert.That(test.ToStrings(), Is.EqualTo(new[] { "1", "3", "4" })); Assert.That(test.ToStrings(true), Is.EqualTo(new[] { "1", "null", "3", "4" })); Assert.That(test.ToStrings(true, "—"), Is.EqualTo(new[] { "1", "—", "3", "4" })); }
/// <summary> /// Updates existing configuration. /// </summary> /// <param name="input">The input string in XML format to use to update the existing configuration.</param> /// <returns></returns> public void Update(string input) { var xml = ParseXml(new StringReader(input)); var disallowed = new List <string>(); CheckSubtree(UpdatableXml, xml, "", disallowed); if (disallowed.Count > 0) { throw new ArgumentException("Cannot update configuration with" + disallowed.ToStrings()); } var dict = ToChildDictionary(xml); XmlElement globals; if (dict.TryGetValue("Globals", out globals)) { this.Globals.Load(globals); ConfigChanged("Globals"); foreach (var key in ToChildDictionary(globals).Keys) { ConfigChanged("Globals/" + key); } } XmlElement defaults; if (dict.TryGetValue("Defaults", out defaults)) { this.Defaults.Load(defaults); CalculateOverrides(); ConfigChanged("Defaults"); foreach (var key in ToChildDictionary(defaults).Keys) { ConfigChanged("Defaults/" + key); } } }
private async Task HandoffMyPartitionUponStop(Dictionary <GrainId, IGrainInfo> batchUpdate, bool isFullCopy) { if (batchUpdate.Count == 0 || silosHoldingMyPartition.Count == 0) { if (logger.IsVerbose) { logger.Verbose((isFullCopy ? "FULL" : "DELTA") + " handoff finished with empty delta (nothing to send)"); } return; } if (logger.IsVerbose) { logger.Verbose("Sending {0} items to my {1}: (ring status is {2})", batchUpdate.Count, silosHoldingMyPartition.ToStrings(), localDirectory.RingStatusToString()); } var tasks = new List <Task>(); var n = 0; var chunk = new Dictionary <GrainId, IGrainInfo>(); // Note that batchUpdate will not change while this method is executing foreach (var pair in batchUpdate) { chunk[pair.Key] = pair.Value; n++; if ((n % HANDOFF_CHUNK_SIZE != 0) && (n != batchUpdate.Count)) { // If we haven't filled in a chunk yet, keep looping. continue; } foreach (SiloAddress silo in silosHoldingMyPartition) { SiloAddress captureSilo = silo; Dictionary <GrainId, IGrainInfo> captureChunk = chunk; bool captureIsFullCopy = isFullCopy; if (logger.IsVerbose) { logger.Verbose("Sending handed off partition to " + captureSilo); } Task pendingRequest; if (lastPromise.TryGetValue(captureSilo, out pendingRequest)) { try { await pendingRequest; } catch (Exception) { } } Task task = localDirectory.Scheduler.RunOrQueueTask( () => localDirectory.GetDirectoryReference(captureSilo).AcceptHandoffPartition( localDirectory.MyAddress, captureChunk, captureIsFullCopy), localDirectory.RemGrainDirectory.SchedulingContext); lastPromise[captureSilo] = task; tasks.Add(task); } // We need to use a new Dictionary because the call to AcceptHandoffPartition, which reads the current Dictionary, // happens asynchronously (and typically after some delay). chunk = new Dictionary <GrainId, IGrainInfo>(); // This is a quick temporary solution. We send a full copy by sending one chunk as a full copy and follow-on chunks as deltas. // Obviously, this will really mess up if there's a failure after the first chunk but before the others are sent, since on a // full copy receive the follower dumps all old data and replaces it with the new full copy. // On the other hand, over time things should correct themselves, and of course, losing directory data isn't necessarily catastrophic. isFullCopy = false; } await Task.WhenAll(tasks); }
public async Task <List <ActivationAddress> > FullLookup(GrainId grain) { fullLookups.Increment(); SiloAddress silo = CalculateTargetSilo(grain, false); // No need to check that silo != null since we're passing excludeThisSiloIfStopping = false if (log.IsVerbose) { log.Verbose("Silo {0} fully lookups for {1}-->{2} ({3}-->{4})", MyAddress, grain, silo, grain.GetUniformHashCode(), silo.GetConsistentHashCode()); } // We assyme that getting here means the grain was not found locally (i.e., in TryFullLookup()). // We still check if we own the grain locally to avoid races between the time TryFullLookup() and FullLookup() were called. if (silo.Equals(MyAddress)) { LocalDirectoryLookups.Increment(); var localResult = DirectoryPartition.LookUpGrain(grain); if (localResult == null) { // it can happen that we cannot find the grain in our partition if there were // some recent changes in the membership if (log.IsVerbose2) { log.Verbose2("FullLookup mine {0}=none", grain); } return(new List <ActivationAddress>()); } var a = localResult.Item1.Select(t => ActivationAddress.GetAddress(t.Item1, grain, t.Item2)).Where(addr => IsValidSilo(addr.Silo)).ToList(); if (log.IsVerbose2) { log.Verbose2("FullLookup mine {0}={1}", grain, a.ToStrings()); } LocalDirectorySuccesses.Increment(); return(a); } // Just a optimization. Why sending a message to someone we know is not valid. if (!IsValidSilo(silo)) { throw new OrleansException(String.Format("Current directory at {0} is not stable to perform the lookup for grain {1} (it maps to {2}, which is not a valid silo). Retry later.", MyAddress, grain, silo)); } RemoteLookupsSent.Increment(); Tuple <List <Tuple <SiloAddress, ActivationId> >, int> result = await GetDirectoryReference(silo).LookUp(grain, NUM_RETRIES); // update the cache List <Tuple <SiloAddress, ActivationId> > entries = result.Item1.Where(t => IsValidSilo(t.Item1)).ToList(); List <ActivationAddress> addresses = entries.Select(t => ActivationAddress.GetAddress(t.Item1, grain, t.Item2)).ToList(); if (log.IsVerbose2) { log.Verbose2("FullLookup remote {0}={1}", grain, addresses.ToStrings()); } if (entries.Count > 0) { DirectoryCache.AddOrUpdate(grain, entries, result.Item2); } return(addresses); }
/// <summary> /// Updates existing configuration. /// </summary> /// <param name="input">The input string in XML format to use to update the existing configuration.</param> /// <returns></returns> public void Update(string input) { var xml = ParseXml(new StringReader(input)); var disallowed = new List<string>(); CheckSubtree(updatableXml, xml, "", disallowed); if (disallowed.Count > 0) throw new ArgumentException("Cannot update configuration with" + disallowed.ToStrings()); var dict = ToChildDictionary(xml); XmlElement globals; if (dict.TryGetValue("Globals", out globals)) { Globals.Load(globals); ConfigChanged("Globals"); foreach (var key in ToChildDictionary(globals).Keys) { ConfigChanged("Globals/" + key); } } XmlElement defaults; if (dict.TryGetValue("Defaults", out defaults)) { Defaults.Load(defaults); CalculateOverrides(); ConfigChanged("Defaults"); foreach (var key in ToChildDictionary(defaults).Keys) { ConfigChanged("Defaults/" + key); } } }
public bool LocalLookup(GrainId grain, out List<ActivationAddress> addresses) { localLookups.Increment(); SiloAddress silo = CalculateTargetSilo(grain, false); // No need to check that silo != null since we're passing excludeThisSiloIfStopping = false if (log.IsVerbose) log.Verbose("Silo {0} tries to lookup for {1}-->{2} ({3}-->{4})", MyAddress, grain, silo, grain.GetUniformHashCode(), silo.GetConsistentHashCode()); // check if we own the grain if (silo.Equals(MyAddress)) { LocalDirectoryLookups.Increment(); addresses = GetLocalDirectoryData(grain); if (addresses == null) { // it can happen that we cannot find the grain in our partition if there were // some recent changes in the membership if (log.IsVerbose2) log.Verbose2("LocalLookup mine {0}=null", grain); return false; } if (log.IsVerbose2) log.Verbose2("LocalLookup mine {0}={1}", grain, addresses.ToStrings()); LocalDirectorySuccesses.Increment(); localSuccesses.Increment(); return true; } // handle cache cacheLookups.Increment(); addresses = GetLocalCacheData(grain); if (addresses == null) { if (log.IsVerbose2) log.Verbose2("TryFullLookup else {0}=null", grain); return false; } if (log.IsVerbose2) log.Verbose2("LocalLookup cache {0}={1}", grain, addresses.ToStrings()); cacheSuccesses.Increment(); localSuccesses.Increment(); return true; }
void OnGUI() { if (allGrids.Count == 0) { EditorGUILayout.LabelField("No grids available!"); return; } _selectedGridIndex = EditorGUILayout.Popup("Grid to Edit", _selectedGridIndex, allGrids.ToStrings <Grid>()); Grid selectedGrid = allGrids[_selectedGridIndex]; Sprite selectedSprite = DrawTileSpriteSelector(); _clearSprite = EditorGUILayout.ToggleLeft("Clear Tile Mode", _clearSprite); DrawGridTiles(selectedGrid, selectedSprite); }