Questions tagged [optimistic-concurrency]

A concurrency control method applied to transactional systems that allows multiple transactions to frequently complete for resources without interfering with each other

A concurrency control method applied to transactional systems such as relational database management systems and software transactional memory. OCC assumes that multiple transactions can frequently complete without interfering with each other. While running, transactions use data resources without acquiring locks on those resources. Before committing, each transaction verifies that no other transaction has modified the data it has read.

Optimistic concurrency is generally used in environments with a low contention for data. Optimistic concurrency improves performance because no locking of records is required, and locking of records requires additional server resources. Also, in order to maintain record locks, a persistent connection to the database server is required.

http://en.wikipedia.org/wiki/Optimistic_concurrency_control
http://msdn.microsoft.com/en-us/library/aa0416cz%28v=vs.110%29.aspx

209 questions
30
votes
4 answers

Optimistic locking in a stateless application with JPA / Hibernate

I'm wondering what would be the best way to implement optimistic locking (optimistic concurrency control) in a system where entity instances with a certain version can not be kept between requests. This is actually a pretty common scenario but…
deamon
  • 78,414
  • 98
  • 279
  • 415
21
votes
2 answers

Concurrency exceptions in Entity Framework

When calling SaveChanges / SaveChangesAsync in Entity Framework (CF, C#), if a change conflict occurs (for example, the values has been updated since last read thingy), then which of these two exceptions DbUpdateConcurrencyException OR…
Flair
  • 2,533
  • 4
  • 15
  • 22
15
votes
3 answers

Event Sourcing and optimistic concurrency control

When you want code works under race conditions, commonly developers uses Optimistic concurrency control (OCC). From Wikipedia: ...before committing, each transaction verifies that no other transaction has modified the data it has read. If the…
15
votes
2 answers

Getting Affected Rows by UPDATE statement in RAW plpgsql

This has been asked multiple times here and here, but none of the answers are suitable in my case because I do not want to execute my update statement in a PL/PgSQL function and use GET DIAGNOSTICS integer_var = ROW_COUNT. I have to do this in raw…
12
votes
5 answers

What's a good end user message for optimistic concurrency failures

I'm trying to come up with some good words to explain an optimistic concurrency exception to a user. It turns out it's a lot harder that I thought it would be. the best I have so far is: Someone else has already modified the record you were…
ilivewithian
  • 18,642
  • 19
  • 93
  • 158
11
votes
2 answers

StaleObjectStateException vs OptimisticLockException

A StaleObjectStateException is being thrown in my app instead of OptimisticLockException (as I read I should expect this one) when optimistic concurrency problem occurs in my app. No need to post code, as it's the most basic concurrency problem -…
Dayton Tex
  • 754
  • 3
  • 8
  • 17
10
votes
1 answer

How to enable concurrency checking using EF 5.0 Code First?

I would like to do a check-then-update in an atomic operation. I am using dbcontext to manage the transaction. I was expecting to get an exception if the record has been modified by another thread but no exception is thrown. Any help would be…
user1342718
  • 107
  • 1
  • 5
9
votes
4 answers

What is an efficient way to handle inserts of unique "immutable" entities by multiple producers with optimistic concurrency approach?

Assume a system with multiple concurrent producers that each strives to persist some graph of objects with the following common entities uniquely identifiable by their names: CREATE TABLE CommonEntityGroup( Id INT NOT NULL IDENTITY(1, 1) PRIMARY…
9
votes
2 answers

Entity Framework Many-to-Many Self Relationship and Optimistic Concurrency Control

I have an entity that has a Many-to-Many self-relationship. As an example consider this entity: public class User { public int ID { get; set; } public string UserName { get; set; } public virtual ICollection Friends { get; set;…
Farhad Alizadeh Noori
  • 2,066
  • 14
  • 22
8
votes
1 answer

MongoDB Optimistic Concurrency Control With .NET

Using the .NET MongoDB API (MongoDB.Driver), what is the recommended approach for implementing optimistic concurrency control? For example, is there anything analogous to SQL Server's ROWVERSION/TIMESTAMP, e.g., a property that is automatically…
Ricardo Peres
  • 11,795
  • 4
  • 45
  • 64
7
votes
2 answers

Is it possible to make conditional inserts with Azure Table Storage

Is it possible to make a conditional insert with the Windows Azure Table Storage Service? Basically, what I'd like to do is to insert a new row/entity into a partition of the Table Storage Service if and only if nothing changed in that partition…
7
votes
2 answers

ConcurrentDictionary's optimistically concurrent Remove method

I was looking for a method in ConcurrentDictionary that allows me to remove an entry by key, if and only if the value is equal to one that I specify, something like the equivalent of TryUpdate, but for removals. The only method that does this seems…
Evgeniy Berezovsky
  • 16,237
  • 8
  • 74
  • 131
7
votes
2 answers

Implementing optimistic concurrency on a legacy database

I have a database with some tables and also data in them.I need to implement for all tables optimistic concurrency. I was wondering what would be the best way. Query with a predicate will be created on the application side. My concern is how-to…
user256034
  • 3,929
  • 5
  • 34
  • 43
7
votes
2 answers

RESTful API and bulk operations

I have a middle tier which performs CRUD operations on a shared database. When I converted the product to .NET Core I thought I'd also look at using REST for the API as CRUD is supposed to be what it does well. It seems like REST is a great…
Quarkly
  • 3,157
  • 1
  • 30
  • 55
7
votes
2 answers

RowVersion implementation on Entity Framework for PostgreSQL

I am using Entity Framework 6 with PostgreSQL. I have an entity in which I want to prevent concurrency issues, following this documentation I added a RowVersion property with [Timestamp] attribute, however after saving changes to the entity the…
1
2 3
13 14