问题标签 [optimistic-concurrency]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
concurrency - 活动预订的并发性
我正在实施一个活动预订网站。从商店的角度来看,只有当座位实际预订给客户时,才必须从数据库中减少座位。
我的问题是关于并发的。例如,假设有一个可用座位数量为 1 的事件。
如果 2 位用户试图同时购买同一个活动席位,当其中一位客户成功支付席位时,我希望第二位客户无法支付席位,因为席位已被预订。
是否可以进行这样的预订以使其他客户无法预订?
ormlite-servicestack - 支持 servicestack ormlite 时间戳
是否可以在 servicestack-ormlite 中使用 SqlServer Timestamp 实现乐观并发?
目前,如果我正在使用它,ormlite 正在尝试更新它,我想我需要一个属性来告诉 ormlite 这是行版本。
如果确实存在这样的注释,我想添加它应该不容易,我唯一的问题是是否应该使用属性来完成?如果是的话我应该把这个属性放在哪里谢谢
concurrency - RavenDB 不断抛出 ConcurrencyException
我不断收到 ConcurrencyException 尝试连续多次更新同一个文档。PUT attempted on document '<id>' using a non current etag
是消息。
在我们的 UI 中每次保存时,我们都会使用 MassTransit 发布一个事件。此事件被发送到订阅者队列,但我将事件处理程序置于离线状态(测试离线订阅者)。一旦事件处理程序上线,就会读取队列并按预期处理消息。
但是,由于同一个对象多次在队列中,第一次写入成功,下一次写入失败并抛出此并发异常。
我使用工厂类在我的所有应用程序中拥有一致的 IDocumentStore 和 IDocumentSession。我专门UseOptimisticConcurrency = false
在 GetSession() 方法中设置了。
事件处理程序看起来像这样。IDocumentSession 使用依赖注入进行注入。这是获取 IDocumentSession 实例的逻辑。
这是具有 ConcurrencyException 的实际 EventHandler。
我想暂时忽略任何并发异常,直到我们可以与业务一起解决如何处理并发问题。
那么,有什么想法为什么我会得到 ConcurrencyException 吗?无论文档之前是否已更新,我都希望进行保存。
entity-framework - Code First - 在没有死锁的事务中检索和更新记录
我有一个 EF 代码优先上下文,它表示处理应用程序可以检索和运行的作业队列。这些处理应用程序可以在不同的机器上运行,但指向同一个数据库。
上下文提供了一个方法,QueueItem
如果有任何工作要做,则返回 a 或 null,称为CollectQueueItem
。
为了确保没有两个应用程序可以获取相同的作业,收集发生在一个带有ISOLATION LEVEL
of的事务中REPEATABLE READ
。这意味着如果有两次尝试同时获取同一个作业,则将选择一个作为deadlock victim
并回滚。我们可以通过捕获DbUpdateException
和返回来处理这个问题null
。
这是该CollectQueueItem
方法的代码:
我在 LinqPad 中进行了测试,以检查它是否按预期工作。这是下面的测试:
我跑了几次测试。如果没有REPEATABLE READ
隔离级别,相同的作业将由不同的 theads 检索(在 234 个重复项中可见)。使用REPEATABLE READ
,作业只检索一次,但性能会受到影响,并且有 634 个死锁事务。
我的问题是:有没有办法在 EF 中获得这种行为而不会出现死锁或冲突的风险?我知道在现实生活中竞争会减少,因为处理器不会不断地访问数据库,但是,有没有办法安全地做到这一点而不必处理 DbUpdateException?我可以在没有REPEATABLE READ
隔离级别的情况下获得更接近版本的性能吗?或者死锁实际上并没有那么糟糕,我可以放心地忽略异常,让处理器在几毫秒后重试,并接受如果不是所有事务都同时发生,性能会很好?
提前致谢!
apache-zookeeper - ZooKeeper 可以在一次操作中获取 znode 数据和 znode 数据版本(stat)吗?
我正在开发一个使用 ZooKeeper 作为数据存储的应用程序。对于应用程序中的一种方法,我需要使用乐观并发控制。例如,我需要实现一个获取 znode 数据的 get 方法,并且我使用 znode 数据版本进行乐观并发控制检查。据我了解,一次操作无法获取 znode 数据和 znode 数据版本。如果更新 znode 数据的竞争激烈,get 方法将不起作用,因为在获取 znode 数据后 znode 数据可能会发生变化。所以我在问 -有没有一种方法可以在一次操作中获得 znode 数据和 znode 数据版本(或 znode stat),而在两者之间没有任何锁定尝试?
hibernate - StaleObjectStateException 与 OptimisticLockException
当我的应用程序中出现乐观并发问题时,我的应用程序中会抛出 StaleObjectStateException 而不是 OptimisticLockException(正如我所读到的那样,我应该期待这个)。无需发布代码,因为这是最基本的并发问题 - 时间戳列中的错误版本。
我应该如何获得 OptimisticLockException,而不是另一个?
c# - Concurrency with Entity Framework & SQL (ADO.NET)
I have an issue with some concurrency. I read into the Optimistic Concurrency Handling in http://blogs.msdn.com/b/alexj/archive/2009/05/20/tip-19-how-to-use-optimistic-concurrency-in-the-entity-framework.aspx
I have a piece of code to test this in practice in my WCF service:
Furthermore, I have set the "Coins" Concurrency Mode in the model to "Fixed". However, this goes through and the value saved in the database is "1". I have tried with a few sets of values so it's not that it is "correct by accident". Why isn't an OptimisticConcurrencyException being raised here?
[update #1] By trying out the first response below and combining them, I managed to get a DbUpdateConcurrencyException out sometimes. It's still not the OptimisticConcurrencyException I am expecting but it is something. Basically I have no clue why it is not happening all the time.
Looks like there is a concurrency issue here!! :D
[update #2] Alright, I figured a part of it now and it was mostly stupid user error. DbUpdateConcurrencyException is thrown only once since second time, the second clause will update it to the value it is already in, so that part is logical. If two entities have been fetched from the same context, the latter change will simply be taken into account so in a "one database connection" case as suggested by the first response, no concurrency exception is raised. This is logical since it is up to the programmer to not access the object through multiple handles.
What I do not get though is the difference between DbUpdateConcurrencyException and OptimisticConcurrencyException. I have not being able to raise the latter.
hibernate - OptimisticLock 再次尝试更新同一个对象
我收到以下异常:
org.hibernate.StaleObjectStateException:行已被另一个事务更新或删除(或未保存的值映射不正确):[
当我尝试再次使用表单更新对象时会发生这种情况。所以第一次它运行良好,但是当我再次尝试更新同一个对象时,我得到了那个异常。
它可以在会话中刷新吗?
这是我的实体
@PersistenceContext(unitName = "JPAService", type = PersistenceContextType.EXTENDED)
private EntityManager nasc;
这是我的服务:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
谢谢!
spring - Implementing Optimistic lock using Hibernate and Spring
I am trying to implement Optimistic locking in-order to avoid lost update situation. In my application when two user fetch same record and the first user updates it with some changes. This change is not visible to the second user who view the same record and he makes some changes by himself and updates it. Due to which the first persons change is lost. In-order to prevent this I have written the following but still the issue persist. I am new to this concept, not able to identify the issue.
I have tried to achieve this by reading doc 11.3.4. Customizing automatic versioning section.
The configuration file
/li>Entity Class
/li>DAO Impl
/li>
Thanks in advance
c# - 实体框架中的并发异常
当在实体框架(CF、C#)中调用SaveChanges
/SaveChangesAsync
时,如果发生更改冲突(例如,自上次读取之后值已更新),那么我应该捕获这两个DbUpdateConcurrencyException
异常中的哪一个?OptimisticConcurrencyException
它们之间有什么区别?