/// <summary> /// Performs a commit /// </summary> /// <param name="workspaceId">Workspace ID</param> /// <param name="changeSet">Changes to commit</param> /// <returns>Changes which were commited</returns> public CommitResult <Guid> Commit(Guid workspaceId, IsolatedChangeSet <Guid, object, EdgeData> changeSet) { bool isSnapshotIsolation = workspaceStateProvider.WorkspaceIsolationLevel(workspaceId) == IsolationLevel.Snapshot; if (isSnapshotIsolation) { workspaceExclusiveLockProvider.EnterLockExclusive(); } try { lock (commitSync) { if (!workspaceStateProvider.IsWorkspaceExpired(workspaceId)) { var result = commitDataService.AcceptCommit(changeSet); workspaceStateProvider.UpdateWorspace(workspaceId, result.ResultSnapshotId); subscriptionManagerService.InvokeEvents(workspaceId, result); return(result); } else { throw new TimeoutException("Workspace timeout has elapsed"); } } } finally { if (isSnapshotIsolation) { workspaceExclusiveLockProvider.ExitLockExclusive(); } } }
/// <summary> /// Opens a new workspace with assumed latest available snapshot /// </summary> /// <typeparam name="TDataType">Type of root entity interface for data navigation. This is the "all containing" entity, which has access to all other entities.</typeparam> /// <param name="isolationLevel">Workspace isolation</param> /// <param name="timeout">Workspace timeout</param> /// <returns>New workspace instance</returns> public Workspace <TDataType> OpenWorkspace <TDataType>(IsolationLevel isolationLevel, TimeSpan timeout) { if (!SnapshotIsolationEnabled && isolationLevel == IsolationLevel.Snapshot) { throw new ArgumentException("Snapshot isolation level disabled by configuration"); } if (isolationLevel == IsolationLevel.Exclusive) { workspaceExclusiveLockProvider.EnterLockExclusive(); } Guid snapshotId = snapshotsService.GetLatestSnapshotId(); return(new Workspace <TDataType>(snapshotId, timeout, provider, workspaceFacade, proxyCreatorService, typesService, isolationLevel, immutableProxyMap)); }
public void TestMethod1() { int nrThreads = 33; int nrRepeats = 300; int counter = 0; for (int j = 0; j < nrRepeats; j++) { WorkspaceExclusiveLockProvider provider = new WorkspaceExclusiveLockProvider(); Collection <Thread> threads = new Collection <Thread>(); for (int i = 0; i < nrThreads; i++) { Thread t = new Thread(() => { provider.EnterLockExclusive(); Interlocked.Increment(ref counter); Assert.AreEqual(1, counter); Interlocked.Decrement(ref counter); provider.ExitLockExclusive(); }); threads.Add(t); } foreach (var t in threads) { t.Start(); } foreach (var t in threads) { t.Join(); } } }