/// <summary> /// Runs the transaction /// </summary> static R RunTransaction <R>(Func <CommuteRef <R> > op, Isolation isolation) { var retries = maxRetries; while (retries > 0) { // Create a new transaction with a snapshot of the current state var t = new Transaction(state.Value); transaction.Value = t; try { var cref = op(); // Try to do the operations of the transaction return(ValidateAndCommit <R>(t, isolation, (R)t.state[cref.Ref.Id].Value, cref.Ref.Id)); } catch (ConflictException) { // Conflict found, so retry retries--; } finally { // Clear the current transaction on the way out transaction.Value = null; } // Wait one tick before trying again SpinWait sw = default; sw.SpinOnce(); } throw new DeadlockException(); }
public void SetupIsolatedSolutionAndUnrelatedPackages() { _solutionDir = Isolation.GetIsolatedTestSolutionDir(); _solutionFile = new FileInfo(Path.Combine(_solutionDir.FullName, Paths.AdapterTestsSolutionFile.Name)); _projectWithDependenciesFile = new FileInfo(Path.Combine(_solutionDir.FullName, Paths.ProjectWithDependenciesRelativeToSolutionDir)); _console = new ConsoleMock(); }
public static void ConfirmIsolation(XmlElement xmlElem, string name, Isolation value, bool compulsory) { XmlNode xmlNode; int isolationDegree; xmlNode = XMLReader.GetNode(xmlElem, name); if (xmlNode == null && compulsory == true) { throw new ConfigNotFoundException(name); } else if (xmlNode != null) { isolationDegree = int.Parse(xmlNode.InnerText); if (isolationDegree == 1) { Assert.AreEqual(Isolation.DEGREE_ONE, value); } else if (isolationDegree == 2) { Assert.AreEqual(Isolation.DEGREE_TWO, value); } else if (isolationDegree == 3) { Assert.AreEqual(Isolation.DEGREE_THREE, value); } else { throw new InvalidConfigException(name); } } }
/// <summary> /// Runs the transaction /// </summary> static R RunTransaction <R>(Func <R> op, Isolation isolation) { SpinWait sw = default; while (true) { // Create a new transaction with a snapshot of the current state var t = new Transaction(state.Items); transaction.Value = t; try { // Try to do the operations of the transaction return(ValidateAndCommit(t, isolation, op(), long.MinValue)); } catch (ConflictException) { // Conflict found, so retry } finally { // Clear the current transaction on the way out transaction.Value = null; // Announce changes OnChange(t.changes); } // Wait one tick before trying again sw.SpinOnce(); } }
public void AddPass() { Isolation isolation = new Isolation(); isolation.IdPrisoner = _getPrisoner.Id; isolation.StartDate = StartDate; isolation.EndDate = EndDate; _isolationEndpoint.AddIsolation(isolation); _eventAggregator.PublishOnUIThread(new NextPageEventModel(typeof(DetailsOfThePrisonerViewModel))); _eventAggregator.PublishOnUIThread(new SelectedPrisonerEventModel(_getPrisoner)); }
public string Save() { var bonds = DataObject.Bonds.Where(bond => Isolation.Count(atom => bond.Atoms.Contains(atom)) == 2); var mol = DataObject.BondDataProvider != null ? new Molecule(Isolation.ToList(), bonds) : new Molecule(Isolation.ToList()); var folder = Path.GetDirectoryName(_path); var file = Path.GetFileNameWithoutExtension(_path); var createdFile = folder + "/" + file + "_isolation.mol2"; Mol2Exporter.Export(mol, createdFile); return(createdFile); }
private void Validate() { foreach (var bond in Bonds3D) { if (Isolation.Count(atom => bond.Bond.Atoms.Contains(atom)) != 2) { continue; } bond.Color = Colors.Green; bond.IsValid = true; } }
public IsolationViewModel(Macrocycle cycle) { if (string.IsNullOrEmpty(_path)) { _path = cycle.Title; } DataObject = cycle; Atoms3D = new ObservableCollection <Atom3D>(DataObject.Atoms.Select(s => new Atom3D(s))); Bonds3D = new ObservableCollection <Bond3D>(DataObject.Bonds.Select(s => new Bond3D(s))); Isolation.CollectionChanged += IsolationOnCollectionChanged; DeleteCommand = new RelayCommand <Atom>(a => Isolation.Remove(a)); }
static void ValidateReads(Transaction t, HashMap <long, RefState> s, Isolation isolation) { if (isolation == Isolation.Serialisable) { // Check if something else wrote to what we were reading foreach (var read in t.reads) { if (s[read].Version != t.state[read].Version) { throw new ConflictException(); } } } }
/// <inheritdoc /> protected override void SerializeXml(XmlWriter writer) { foreach (var flag in Isolation.GetFlags()) { writer.WriteAttributeString(flag.ToString(), "true"); } base.SerializeXml(writer); if (ScopeIsolationExpression != null) { writer.WriteStartElement(nameof(ScopeIsolationExpression)); writer.WriteExpressionToXml(ScopeIsolationExpression); writer.WriteEndElement(); } }
private QueueStats Stats(Transaction txn, bool fast, Isolation isoDegree) { uint flags = 0; flags |= fast ? DbConstants.DB_FAST_STAT : 0; switch (isoDegree) { case Isolation.DEGREE_ONE: flags |= DbConstants.DB_READ_UNCOMMITTED; break; case Isolation.DEGREE_TWO: flags |= DbConstants.DB_READ_COMMITTED; break; } QueueStatStruct st = db.stat_qam(Transaction.getDB_TXN(txn), flags); return(new QueueStats(st)); }
static R ValidateAndCommit <R>(Transaction t, Isolation isolation, R result, long returnRefId) { // No writing, so no validation or commit needed if (t.writes.Count == 0 && t.commutes.Count == 0) { return(result); } // Attempt to apply the changes atomically state.Swap(s => { ValidateReads(t, s, isolation); s = CommitWrites(t, s); (s, result) = CommitCommutes(t, s, returnRefId, result); return(s); }); // Changes applied successfully return(result); }
public static bool ConfigIsolation(XmlElement xmlElem, string name, ref Isolation value, bool compulsory) { XmlNode xmlNode; int isolationDegree; xmlNode = XMLReader.GetNode(xmlElem, name); if (xmlNode == null && compulsory == false) { return(false); } else if (xmlNode == null && compulsory == true) { throw new ConfigNotFoundException(name); } isolationDegree = int.Parse(xmlNode.InnerText); if (isolationDegree == 1) { value = Isolation.DEGREE_ONE; } else if (isolationDegree == 2) { value = Isolation.DEGREE_TWO; } else if (isolationDegree == 3) { value = Isolation.DEGREE_THREE; } else { throw new InvalidConfigException(name); } return(true); }
protected override async Task BeginTransaction(DbConnection connection, Isolation level) { string str; switch (level) { case Isolation.Repeatable: str = "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;BEGIN;"; break; case Isolation.Lock: str = "SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;BEGIN;"; break; default: str = "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN;"; break; } MySqlCommand command = new MySqlCommand(str, (MySqlConnection)connection); try { if (Token == null) { await command.ExecuteNonQueryAsync(); } else { await command.ExecuteNonQueryAsync(Token.Value); } } finally { command.Dispose(); } }
public void TestIsolationDegree() { BTreeDatabase db; BTreeCursor cursor; CursorConfig cursorConfig; DatabaseEnvironment env; Transaction txn; testName = "TestIsolationDegree"; testHome = testFixtureHome + "/" + testName; Isolation[] isolationDegrees = new Isolation[3]; isolationDegrees[0] = Isolation.DEGREE_ONE; isolationDegrees[1] = Isolation.DEGREE_TWO; isolationDegrees[2] = Isolation.DEGREE_THREE; IsolationDelegate[] delegates = { new IsolationDelegate(CursorReadUncommited), new IsolationDelegate(CursorReadCommited), new IsolationDelegate(CursorRead) }; cursorConfig = new CursorConfig(); for (int i = 0; i < 3; i++) { cursorConfig.IsolationDegree = isolationDegrees[i]; GetCursorInBtreeDBInTDS(testHome + "/" + i.ToString(), testName, cursorConfig, out env, out db, out cursor, out txn); cursor.Close(); db.Close(); txn.Commit(); env.Close(); } }
/// <summary> /// Instantiate a new CursorConfig object /// </summary> public CursorConfig() { IsolationDegree = Isolation.DEGREE_THREE; Priority = CachePriority.DEFAULT; }
public void CreateIsolation(Isolation isolation) { _isolationRepository.CreateIsolation(isolation); }
/// <summary> /// Return the database statistical information for this database. /// </summary> /// <overloads> /// The statistical information is described by /// <see cref="HeapStats"/>. /// </overloads> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <param name="isoDegree"> /// The level of isolation for database reads. /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for /// databases which did not specify /// <see cref="DatabaseConfig.ReadUncommitted"/>. /// </param> /// <returns>Database statistical information.</returns> public HeapStats Stats(Transaction txn, Isolation isoDegree) { return Stats(txn, false, isoDegree); }
/// <summary> /// Instantiate a new TransactionConfig object /// </summary> public TransactionConfig() { IsolationDegree = Isolation.DEGREE_THREE; SyncAction = LogFlush.DEFAULT; }
/// <summary> /// Return the database statistical information for this database. /// </summary> /// <overloads> /// The statistical information is described by /// <see cref="BTreeStats"/>. /// </overloads> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <param name="isoDegree"> /// The level of isolation for database reads. /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for /// databases which did not specify /// <see cref="DatabaseConfig.ReadUncommitted"/>. /// </param> /// <returns>Database statistical information.</returns> public QueueStats Stats(Transaction txn, Isolation isoDegree) { return(Stats(txn, false, isoDegree)); }
public void TestIsolationDegree() { BTreeDatabase db; BTreeCursor cursor; CursorConfig cursorConfig; DatabaseEnvironment env; Transaction txn; testName = "TestIsolationDegree"; testHome = testFixtureHome + "/" + testName; Isolation[] isolationDegrees = new Isolation[3]; isolationDegrees[0] = Isolation.DEGREE_ONE; isolationDegrees[1] = Isolation.DEGREE_TWO; isolationDegrees[2] = Isolation.DEGREE_THREE; IsolationDelegate[] delegates = { new IsolationDelegate(CursorReadUncommited), new IsolationDelegate(CursorReadCommited), new IsolationDelegate(CursorRead)}; cursorConfig = new CursorConfig(); for (int i = 0; i < 3; i++) { cursorConfig.IsolationDegree = isolationDegrees[i]; GetCursorInBtreeDBInTDS(testHome + "/" + i.ToString(), testName, cursorConfig, out env, out db, out cursor, out txn); cursor.Close(); db.Close(); txn.Commit(); env.Close(); } }
/// <summary> /// Instantiate a new LockingInfo object /// </summary> public LockingInfo() { IsolationDegree = Isolation.DEGREE_THREE; ReadModifyWrite = false; }
public void UpdateIsolation(Isolation isolation) { _isolationRepository.UpdateIsolation(isolation); }
public override string ToString() { var sb = new StringBuilder(); sb.OptionIfExists("--build-arg ", BuildArguments); sb.OptionIfExists("--cpu-shares ", CpuShares?.ToString()); sb.OptionIfExists("--cgroup-parent ", ParentCGroup?.ToString()); sb.OptionIfExists("--cpu-period ", CpuPeriod?.ToString()); sb.OptionIfExists("--cpu-quota ", CpuQuota?.ToString()); sb.OptionIfExists("--cpuset-cpus", AllowCpuExecution); sb.OptionIfExists("--cpuset-mems ", AllowMemExecution); if (SkipImageVerification) { sb.Append(" --disable-content-trust=true"); } sb.OptionIfExists("-f ", File); if (ForceRemoveIntermediateContainers) { sb.Append(" --force-rm"); } if (null != Isolation.ToDocker()) { sb.Append($"--isolation {Isolation.ToDocker()}"); } sb.OptionIfExists("--label=", Labels); sb.OptionIfExists("-m ", Memory?.ToString()); sb.OptionIfExists("--memory-swap ", Swap?.ToString()); if (NoCache) { sb.Append(" --no-cache"); } if (AlwaysPull) { sb.Append(" --pull"); } if (Quiet) { sb.Append(" -q"); } if (RemoveIntermediateContainersOnSuccessfulBuild) { sb.Append(" --rm=true"); } sb.OptionIfExists("--shm-size ", ShmSize?.ToString()); sb.OptionIfExists("-t ", Tags); sb.OptionIfExists("--ulimit=", UlimitOptions); if (NoCache) { sb.Append(" --no-cache"); } return(sb.ToString()); }
/// <summary> /// Instantiate a new CursorConfig object /// </summary> public CursorConfig() { IsolationDegree = Isolation.DEGREE_THREE; }
public static bool ConfigIsolation(XmlElement xmlElem, string name, ref Isolation value, bool compulsory) { XmlNode xmlNode; int isolationDegree; xmlNode = XMLReader.GetNode(xmlElem, name); if (xmlNode == null && compulsory == false) return false; else if (xmlNode == null && compulsory == true) throw new ConfigNotFoundException(name); isolationDegree = int.Parse(xmlNode.InnerText); if (isolationDegree == 1) value = Isolation.DEGREE_ONE; else if (isolationDegree == 2) value = Isolation.DEGREE_TWO; else if (isolationDegree == 3) value = Isolation.DEGREE_THREE; else throw new InvalidConfigException(name); return true; }
public static void ConfirmIsolation(XmlElement xmlElem, string name, Isolation value, bool compulsory) { XmlNode xmlNode; int isolationDegree; xmlNode = XMLReader.GetNode(xmlElem, name); if (xmlNode == null && compulsory == true) throw new ConfigNotFoundException(name); else if (xmlNode != null) { isolationDegree = int.Parse(xmlNode.InnerText); if (isolationDegree == 1) Assert.AreEqual(Isolation.DEGREE_ONE, value); else if (isolationDegree == 2) Assert.AreEqual(Isolation.DEGREE_TWO, value); else if (isolationDegree == 3) Assert.AreEqual(Isolation.DEGREE_THREE, value); else throw new InvalidConfigException(name); } }
public void DeleteIsolation(Isolation isolation) { _isolationRepository.DeleteIsolation(isolation); }
public void SetPrisonerStatusTrue(Isolation isolation) { _isolationRepository.SetPrisonerStatusTrue(isolation); }
/// <summary> /// Return the database statistical information which does not require /// traversal of the database. /// </summary> /// <overloads> /// <para> /// Among other things, this method makes it possible for applications /// to request key and record counts without incurring the performance /// penalty of traversing the entire database. /// </para> /// <para> /// The statistical information is described by the /// <see cref="BTreeStats"/>, <see cref="HashStats"/>, /// <see cref="QueueStats"/>, and <see cref="RecnoStats"/> classes. /// </para> /// </overloads> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <param name="isoDegree"> /// The level of isolation for database reads. /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for /// databases which did not specify /// <see cref="DatabaseConfig.ReadUncommitted"/>. /// </param> /// <returns> /// The database statistical information which does not require /// traversal of the database. /// </returns> public QueueStats FastStats(Transaction txn, Isolation isoDegree) { return(Stats(txn, true, isoDegree)); }
public void SetupIsolatedSolutionAndUnrelatedPackages() { _solutionDir = Isolation.GetIsolatedTestSolutionDir(); _solutionFile = Path.Combine(_solutionDir.FullName, Paths.AdapterTestsSolutionFile.Name); _packageSource = Isolation.GetIsolatedEmptyPackageSource(); }
/// <summary> /// Represents a BEGIN TRANSACTION statement with an explicit /// isolation level. For certain SQL dialects specifying an isolation /// level may result in a SET TRANSACTION ISOLATION LEVEL being added /// immediately before this statement. /// </summary> /// <param name="isolation">The isolation level for the command, /// some levels are only supported by certain SQL dialects.</param> public BeginTransaction(Isolation isolation) { Isolation = isolation; }
public async Task UpdatePass(int idIsolation, Isolation isolation) { var json = JsonConvert.SerializeObject(isolation); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await _apiHelper.ApiClient.PutAsync("api/Isolation/" + idIsolation, stringContent); }
/// <summary> /// Return the database statistical information which does not require /// traversal of the database. /// </summary> /// <overloads> /// <para> /// Among other things, this method makes it possible for applications /// to request key and record counts without incurring the performance /// penalty of traversing the entire database. /// </para> /// <para> /// The statistical information is described by the /// <see cref="BTreeStats"/>, <see cref="HashStats"/>, /// <see cref="HeapStats"/>, <see cref="QueueStats"/>, and /// <see cref="RecnoStats"/> classes. /// </para> /// </overloads> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <param name="isoDegree"> /// The level of isolation for database reads. /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for /// databases which did not specify /// <see cref="DatabaseConfig.ReadUncommitted"/>. /// </param> /// <returns> /// The database statistical information which does not require /// traversal of the database. /// </returns> public HeapStats FastStats(Transaction txn, Isolation isoDegree) { return Stats(txn, true, isoDegree); }
private HeapStats Stats(Transaction txn, bool fast, Isolation isoDegree) { uint flags = 0; flags |= fast ? DbConstants.DB_FAST_STAT : 0; switch (isoDegree) { case Isolation.DEGREE_ONE: flags |= DbConstants.DB_READ_UNCOMMITTED; break; case Isolation.DEGREE_TWO: flags |= DbConstants.DB_READ_COMMITTED; break; } HeapStatStruct st = db.stat_heap(Transaction.getDB_TXN(txn), flags); return new HeapStats(st); }
/// <summary> /// Renders the argument string from this instance. /// </summary> /// <returns></returns> public override string ToString() { var sb = new StringBuilder(); // Container identification sb.OptionIfExists("--name ", Name); sb.OptionIfExists("--pid=", Pid); sb.OptionIfExists("--uts=", Uts); sb.OptionIfExists("--ipc=", Ipc); if (!string.IsNullOrWhiteSpace(CidFile)) { sb.Append($" --cidfile=\"{CidFile}\""); } if (null != HostIpMappings && 0 != HostIpMappings.Count) { sb.Append(" --add-host="); foreach (var mapping in HostIpMappings) { sb.Append($"--add-host={mapping.Item1}:{mapping.Item2}"); } } if (Ulimit.Count > 0) { foreach (var ulimit in Ulimit) { sb.Append($" --ulimit {ulimit}"); } } // Block IO bandwidth (Blkio) constraint if (null != BlockIoWeight) { sb.Append($" --blkio-weight {BlockIoWeight.Value}"); } sb.OptionIfExists("--blkio-weight-device=", BlockIoWeightDevices); sb.OptionIfExists("--device-read-bps ", DeviceReadBps); sb.OptionIfExists("--device-read-iops=", DeviceReadIops); sb.OptionIfExists("--device-write-bps=", DeviceWriteBps); sb.OptionIfExists("--device-write-iops=", DeviceWriteIops); // Runtime privilege and Linux capabilities sb.OptionIfExists("--cap-add=", CapabilitiesToAdd); sb.OptionIfExists("--cap-drop=", CapabilitiesToRemove); if (Privileged) { sb.Append(" --privileged"); } sb.OptionIfExists("--device=", Device); // Network settings sb.OptionIfExists("--dns=", Dns); sb.OptionIfExists("--dns-opt=", DnsOpt); sb.OptionIfExists("--dns-search=", DnsSearch); sb.OptionIfExists("--hostname ", Hostname); if (!PublishAllPorts) { sb.OptionIfExists("-p ", PortMappings); } else { sb.Append(" -P"); } // Native health check sb.OptionIfExists("--health-cmd=", HealthCheckCmd); sb.OptionIfExists("--health-interval=", HealthCheckInterval); sb.OptionIfExists("--health-timeout=", HealthCheckTimeout); sb.OptionIfExists("--health-start-period=", HealthCheckStartPeriod); sb.OptionIfExists("--no-healthcheck", HealthCheckDisabled); if (HealthCheckRetries > 0) { sb.Append($" --health-retries={HealthCheckRetries}"); } sb.OptionIfExists("--cgroup-parent ", ParentCGroup); sb.OptionIfExists("-e ", Environment); sb.OptionIfExists("--env-file=", EnvironmentFiles); if (Interactive) { sb.Append(" -i"); } if (Tty) { sb.Append(" -t"); } sb.OptionIfExists("-u ", AsUser); if (AutoRemoveContainer) { sb.Append(" --rm"); } sb.OptionIfExists("-v ", Volumes); sb.OptionIfExists("--volume-driver ", VolumeDriver); sb.OptionIfExists("--volumes-from=", VolumesFrom); sb.OptionIfExists("-w ", WorkingDirectory); sb.OptionIfExists("--link=", Links); sb.OptionIfExists("-l ", Labels); sb.OptionIfExists("--group-add=", Groups); sb.OptionIfExists("--network ", Network); sb.OptionIfExists("--ip ", Ipv4); sb.OptionIfExists("--ip6 ", Ipv6); if (RestartPolicy.No != RestartPolicy) { switch (RestartPolicy) { case RestartPolicy.Always: sb.Append(" --restart always"); break; case RestartPolicy.OnFailure: sb.Append(" --restart on-failure"); break; case RestartPolicy.UnlessStopped: sb.Append(" --restart unless-stopped"); break; default: sb.Append(" --restart no"); break; } } // Memory management sb.SizeOptionIfValid("--memory=", Memory, 4 * 1024 * 1024 /*4m*/); sb.SizeOptionIfValid("--memory-swap=", MemorySwap); sb.OptionIfExists("--memory-swappiness=", MemorySwappiness); sb.SizeOptionIfValid("--memory-reservation=", MemoryReservation); sb.SizeOptionIfValid("--kernel-memory=", KernelMemory); if (OomKillDisable) { sb.Append(" --oom-kill-disable"); } // Cpu management if (!Cpus.IsApproximatelyEqualTo(float.MinValue)) { sb.Append($" --cpus=\"{Cpus}\""); } sb.OptionIfExists("--cpuset-cpus=", CpusetCpus); if (CpuShares != int.MinValue) { sb.Append($" --cpu-shares=\"{CpuShares}\""); } // Runtime if (Runtime != ContainerRuntime.Default) { sb.Append($" --runtime={Runtime.ToString().ToLower()}"); } var isolation = Isolation.ToDocker(); if (null != isolation) { sb.Append($" --isolation {Isolation.ToDocker()}"); } return(sb.ToString()); }