public void TestPostProcessing3Event() { TransactionExecution texUpdate = new TransactionExecution(null, this.versionDb); while (texUpdate.Progress == TxProgress.Initi) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.InitTx(); } texUpdate.Read(TABLE_ID, DEFAULT_KEY, out bool received, out object payload); while (!received) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.Read(TABLE_ID, DEFAULT_KEY, out received, out payload); } texUpdate.Update(TABLE_ID, DEFAULT_KEY, "value_update"); texUpdate.maxCommitTsOfWrites = 4L; texUpdate.Commit(); while (texUpdate.Progress != TxProgress.Close) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.CurrentProc(); } VersionEntry newVersionEntry = this.GetVersionByKey(2L); Assert.AreEqual(5L, newVersionEntry.BeginTimestamp); Assert.AreEqual(long.MaxValue, newVersionEntry.EndTimestamp); Assert.AreEqual(-1L, newVersionEntry.TxId); VersionEntry oldVersionEntry = this.GetVersionByKey(1L); Assert.AreEqual(0L, oldVersionEntry.BeginTimestamp); Assert.AreEqual(5L, oldVersionEntry.EndTimestamp); Assert.AreEqual(-1L, oldVersionEntry.TxId); }
/// <summary> /// Returns the given Pokemon's held items in the given version. /// </summary> private async Task <IEnumerable <VersionHeldItemContext> > GetHeldItems(Pokemon pokemon, VersionEntry version) { var allHeldItems = pokemon.HeldItems; var relevantHeldItems = allHeldItems.Where(h => { var versionGroupNames = h.VersionDetails.Select(vd => vd.Version.Name); return(versionGroupNames.Contains(version.Name)); }).ToArray(); var itemEntries = await ItemService.UpsertMany(relevantHeldItems.Select(m => m.Item)); return(itemEntries.Select((item, index) => { var context = VersionHeldItemContext.From(item); var detail = relevantHeldItems[index].VersionDetails.Single(d => d.Version.Name == version.Name); context.Rarity = detail.Rarity; return context; })); }
private void _Load() { string filename = Path.Combine(Settings.RESOURCEPATH, "VersionTable.xml"); XmlDocument xml = new XmlDocument(); try { xml.Load(filename); } catch (Exception exc) { string msg = string.Format("Error loading version table {0}:\n", filename) + exc.Message.ToString() + "\n" + exc.Source.ToString() + "\n" + exc.StackTrace.ToString() + "\n" ; Log.Error(msg); return; } if (xml.ChildNodes.Count != 2) { throw new Exception("INVALID VERSION TABLE FILE!"); } XmlNode node = xml.ChildNodes[0]; if (node.Name.ToLower() != "xml") { throw new Exception("INVALID VERSION TABLE FILE!"); } node = xml.ChildNodes[1]; if (node.Name.ToLower() != "versions") { throw new Exception("INVALID VERSION TABLE FILE!"); } foreach (XmlNode childnode in node.ChildNodes) { XmlElement element = childnode as XmlElement; if (element == null) { continue; // Skip comments and such } if (element.Attributes.Count < 3) { throw new Exception("INVALID VERSION TABLE FILE!"); } //<version build="95718" type="1" version="0.1" remarks="Update 1" /> int cl = int.Parse(element.Attributes["build"].InnerText); int type = int.Parse(element.Attributes["type"].InnerText); string version = element.Attributes["version"].InnerText; string remarks = element.HasAttribute("remarks") ? element.Attributes["remarks"].InnerText : null; VersionEntry v = new VersionEntry(cl, type, version, remarks); _versions.Add(v); } }
private bool ParseConfig(string filename) { var doc = XElement.Load(filename); foreach (var c in doc.Descendants()) { switch (c.Name.ToString().ToLower()) { case "realm": { var name = string.Empty; var ins = new VersionEntry { AuthServer = string.Empty, SHA256 = string.Empty }; foreach (var a in c.Attributes()) { switch (a.Name.ToString().ToLower()) { case "name": name = a.Value; break; default: return(false); } } foreach (var e in c.Elements()) { switch (e.Name.ToString().ToLower()) { case "exe": foreach (var attr in e.Attributes()) { switch (attr.Name.ToString().ToLower()) { case "path": ins.Path = attr.Value; break; case "sha256": ins.SHA256 = attr.Value; break; default: return(false); } } break; case "authserver": foreach (var attr in e.Attributes()) { switch (attr.Name.ToString().ToLower()) { case "host": ins.AuthServer = attr.Value; break; default: return(false); } } break; case "fov": foreach (var attr in e.Attributes()) { switch (attr.Name.ToString().ToLower()) { case "value": if (!float.TryParse(e.FirstAttribute.Value, out ins.Fov)) { throw new FormatException("Unable to parse FoV"); } break; default: return(false); } } break; case "clr": foreach (var attr in e.Attributes()) { switch (attr.Name.ToString().ToLower()) { case "path": ins.CLRDll = attr.Value; break; case "type": ins.CLRTypeName = attr.Value; break; case "method": ins.CLRMethodName = attr.Value; break; default: return(false); } } break; default: return(false); } } if (name == string.Empty) { return(false); } _versionEntries[name] = ins; break; } } } return(true); }
/// <summary> /// Called after a thread checked and can commit. This will assign it a /// unique stamp to use for writing. This method will enter the new stamp /// into the stamp.Version. It must be done here to guarantee that no /// GetReaderTicket will return your stamp number before it has been /// written into your stamp lock! After completing your write, place your /// changes into the ticket, and this class will trim the old versions at /// the correct time. It is critical that this be done, which is why this /// method returns it as an out param - to make sure no exception can /// cause us to lose the ref to the ticket, if it is already in the chain. /// </summary> public static void NewVersion(WriteStamp stamp, out WriteTicket ticket) { // this version is running under the _checkLock, guaranteed to be alone! var newNode = new VersionEntry(); ticket = newNode; var newStamp = _current.Stamp + 1; newNode.SetStamp(newStamp); stamp.Version = newStamp; _current.Later = newNode; _current = newNode; }
static VersionList() { // base version, has 0 stamp, and no changes _oldestRead = _current = new VersionEntry(); }
public static void TrimCopies() { bool tookFlag = false; try { try { } finally { tookFlag = Interlocked.CompareExchange(ref _trimFlag, 1, 0) == 0; } if (!tookFlag) return; var old = _oldestRead; SimpleHashSet toTrim = null; while (old != _current && Interlocked.CompareExchange(ref old.ReaderCount, int.MinValue, 0) == 0) { // we do not want to move "old" to an element which still has not finished writing, since // we must maintain the invariant that says _oldestRead.Changes have already been trimmed. if (old.Later.Changes == null) break; // likewise, thanks to that same invariant, we first move forward, then take Changes... old = old.Later; if (toTrim == null) toTrim = new SimpleHashSet(); toTrim.UnionWith(old.Changes); } if (toTrim == null) return; old.Changes = null; _oldestRead = old; var version = old.Stamp; toTrim.TrimCopies(version); } finally { if (tookFlag) Interlocked.Exchange(ref _trimFlag, 0); } }
public void TestPostProcessing4Event() { TransactionExecution texUpdate = new TransactionExecution(null, this.versionDb); texUpdate.DEBUG_MODE = true; while (texUpdate.Progress == TxProgress.Initi) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.InitTx(); } texUpdate.Read(TABLE_ID, DEFAULT_KEY, out bool received, out object payload); while (!received) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.Read(TABLE_ID, DEFAULT_KEY, out received, out payload); } texUpdate.Update(TABLE_ID, DEFAULT_KEY, "value_update"); texUpdate.maxCommitTsOfWrites = 4L; texUpdate.Upload(); while (texUpdate.CurrentProc == null) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.Upload(); } texUpdate.SetCommitTimestamp(); while (texUpdate.CurrentProc == new Procedure(texUpdate.SetCommitTimestamp)) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.SetCommitTimestamp(); } texUpdate.Validate(); while (texUpdate.CurrentProc == new Procedure(texUpdate.Validate)) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.Validate(); } Assert.AreEqual(new Procedure(texUpdate.WriteToLog), texUpdate.CurrentProc); texUpdate.WriteToLog(); while (texUpdate.CurrentProc == new Procedure(texUpdate.WriteToLog)) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.WriteToLog(); } TransactionExecution texDelete = new TransactionExecution(null, this.versionDb); texDelete.DEBUG_MODE = true; while (texDelete.Progress == TxProgress.Initi) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.InitTx(); } texDelete.Read(TABLE_ID, DEFAULT_KEY, out bool receivedRead, out object payloadRead); while (!receivedRead) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.Read(TABLE_ID, DEFAULT_KEY, out receivedRead, out payloadRead); } texDelete.Delete(TABLE_ID, DEFAULT_KEY, out object payloadDelete); texDelete.Upload(); while (texDelete.CurrentProc == null) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.Upload(); } texUpdate.PostProcessingAfterCommit(); while (texUpdate.Progress != TxProgress.Close) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.PostProcessingAfterCommit(); } VersionEntry newVersionEntry = this.GetVersionByKey(2L); Assert.AreEqual(5L, newVersionEntry.BeginTimestamp); Assert.AreEqual(long.MaxValue, newVersionEntry.EndTimestamp); Assert.AreEqual(texDelete.txId, newVersionEntry.TxId); VersionEntry oldVersionEntry = this.GetVersionByKey(1L); Assert.AreEqual(0L, oldVersionEntry.BeginTimestamp); Assert.AreEqual(5L, oldVersionEntry.EndTimestamp); Assert.AreEqual(-1L, oldVersionEntry.TxId); }
public void TestPostProcessing2Event() { TransactionExecution texUpdate = new TransactionExecution(null, this.versionDb); texUpdate.DEBUG_MODE = true; while (texUpdate.Progress == TxProgress.Initi) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.InitTx(); } texUpdate.Read(TABLE_ID, DEFAULT_KEY, out bool received, out object payload); while (!received) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.Read(TABLE_ID, DEFAULT_KEY, out received, out payload); } texUpdate.Update(TABLE_ID, DEFAULT_KEY, "value_update"); texUpdate.Upload(); while (texUpdate.CurrentProc == null) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.Upload(); } texUpdate.Abort(); while (texUpdate.CurrentProc != new Procedure(texUpdate.PostProcessingAfterAbort)) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texUpdate.Abort(); } TransactionExecution texDelete = new TransactionExecution(null, this.versionDb); texDelete.DEBUG_MODE = true; while (texDelete.Progress == TxProgress.Initi) { this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.InitTx(); } texDelete.Read(TABLE_ID, DEFAULT_KEY, out bool receivedRead, out object payloadRead); while (!receivedRead) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.Read(TABLE_ID, DEFAULT_KEY, out receivedRead, out payloadRead); } texDelete.Delete(TABLE_ID, DEFAULT_KEY, out object payloadDelete); texDelete.Upload(); while (texDelete.CurrentProc == null) { this.versionDb.Visit(TABLE_ID, 0); this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0); texDelete.Upload(); } texUpdate.PostProcessingAfterAbort(); while (texUpdate.Progress != TxProgress.Close) { this.versionDb.Visit(TABLE_ID, 0); texUpdate.PostProcessingAfterAbort(); } Assert.AreEqual(null, this.GetVersionByKey(2L)); VersionEntry versionEntry = this.GetVersionByKey(1L); Assert.AreEqual(0L, versionEntry.BeginTimestamp); Assert.AreEqual(long.MaxValue, versionEntry.EndTimestamp); Assert.AreEqual(texDelete.txId, versionEntry.TxId); }
static VersionList() { // base version, has 0 stamp, and no changes _oldestRead = _current = new VersionEntry() { Changes = Enumerable.Empty<IShielded>() }; }