Questions tagged [pessimistic-locking]

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete.

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete. The database record is locked immediately when the lock is requested and it is then guaranteed that the database record will be updated. Unlike optimistic locking, great care must be taken in the application design to avoid deadlocks.

178 questions
0
votes
0 answers

How to prevent parallel row read on database level with Spring Data JPA

I've tried to implement exclusive read access to some Entity (DB table row). The intention was to force any other reader to wait with row read until previous transaction is over. I've used @Lock(PESSIMISTIC_WRITE) from Spring Data JPA. Here is my…
Mamut
  • 133
  • 1
  • 10
0
votes
0 answers

Prevent race condition when bulk update job is running and transactional activity comes in

In our application two activites are running concurrent- Bulk updates activity Transactional activity When both these activites are perfomed on same record cocurrently we see invalid values. To prevent this I am thinking of using pessimistic…
0
votes
1 answer

Why Spring Data JPA Pessimistic lock not working as expected?

I'm trying to work with pessimistic locks in Spring Data JPA and Postgresql but pessimistic lock is not working as expected. Tried to concurrently update a record using pessimistic lock, since pessimistic lock should block until lock is available,…
0
votes
1 answer

Generate sequence number without gaps by multiple app instances

I want to write the device number generator which consists of SERIES and incremented NUMBER. When specific the SERIES reach max which is allowed to them then next SERIES will be in use starting with NUMBER 1…
Peter F
  • 59
  • 5
0
votes
1 answer

How to unlock @Lock(LockModeType.PESSIMISTIC_WRITE) if there is no transaction

I have put @Lock(LockModeType.PESSIMISTIC_WRITE) on a query and working on it in service layer with @Transactionsal annotation. The lock is acquired successfully. But for some cases, the transaction could not be happened. And this lock takes time to…
0
votes
1 answer

Lock all tables for editing for all other users when one user is editing data (in SQL Server) in asp.net

I am new to ASP.NET. I have a MVC web application accessing data from three tables in SQL Server. I have a requirement where if one user is editing data from one table then other users should not be allowed to edit any data. I have tried using a…
ajay
  • 11
  • 2
0
votes
2 answers

Event Sourcing and concurrent, contradictory events creation

I am having a hard time figuring this one out. Maybe you can help me. Problem statement: Imagine there is a system that records financial transactions of an account (like a wallet service). Transactions are stored in a database and each Transaction…
0
votes
1 answer

How to use pessimistic_write lock with Spanner using Spring boot JPA/hibernate

I am using spanner database with Spring boot and JPA. I have a requirement like, whenever employee information is read from employee table, no-one can read/update/delete the the same row information until transaction gets completed. I got to know…
0
votes
1 answer

JdbcPagingItemReader with SELECT FOR UDATE and SKIP LOCKED

I have a multi instance application and each instance is multi threaded. To make each thread only process rows not already fetched by another thread, I'm thinking of using pessimistic locks combined with skip locked. My database is PostgreSQL11 and…
0
votes
0 answers

HTTParty#lock seems to be overriding ActiveRecord’s #lock method

When trying to implement pessimistic locking on a Rails model, I'm not able to do so because HTTParty#lock gets called rather than the ActiveRecord method with the same name. I'm using AR 6.1.4.1 and HTTParty 0.20.0. User.lock.find(1) ArgumentError:…
0
votes
0 answers

What are opportunistic locks and how are they different from pessimistic locks?

I was recently going through mongodb a complete guide and found the following statement - "uses opportunistic locking in its WiredTiger storage engine". On searching about opportunistic locking on the internet I found this article it explains it to…
0
votes
0 answers

How to use pessimistic concurrency in a DDD pattern and EF Core?

I have a business layer, with a Order class and Item class. Suponse that I want to add a new line to the order. How the business logic has not known about the data access layer, I will use a service layer, with a method that is AddItemToOrder,…
0
votes
0 answers

Prevent concurrent access of endpoint in Spring Boot

I have created two API endpoints using Spring Boot. Ist endpoint: Does some get operation. IInd endpoint:Overwrites a Mongo DB Collection. My aim is to prevent concurrent access for multiple users for this second endpoint. And I don't want to block…
0
votes
1 answer

Is there a limit for row lock in MySql 5.7?

I faced an issue in MySql 5.7 that when I select 14 or more rows with FOR UPDATE a whole table is locked. Even though I select them by primary key (so, it's indexed and unique). Literally it looks like this. When I run this query: select * from…
mykola
  • 1,736
  • 5
  • 25
  • 37
0
votes
0 answers

Which type of locking should be used to ensure 1 trasaction at a time?

I have a situation where I need to pick one entry from a table [table containing only 1 column id which is also a primary key], and in the same transaction I want to increment the key value and save it in the database. During this transaction, I…