Comments (6)
So,
SELECT ... LOCK IN SHARE MODE
should place read locks on rows it returns.
(a read lock is compatible with another read lock. write lock is not compatible
with either read or a write lock)
Tasks to do:
- Lock_table and Row_lock should support read locks
- ha_rocksdb should recognize LOCK IN SHARE MODE and request read locks.
from mysql-5.6.
Looking at how to change LockTable/Row_locks to support read-write locks.
MySQL has rwlock.h, but in include/atomic/rwlock.h one can find
#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0)
that is, these rw locks are actually mutexes.
from mysql-5.6.
On using pthread_rwlock_*
pthread_rwlock_t provides RW-locks.
The API provides functions pthread_rwlock_timedwrlock() and
pthread_rwlock_timedrdlock() which wait for the lock and support timeouts.
One problem is that there is no way for other thread to abort the wait.
Current exclusive-locking code uses {thd_enter_cond(); mysql_cond_timedwait()}
which allows KILL command to abort the wait by signaling the condition.
Another issue is that a user of pthread_rwlock* will need to keep track
of what locks he already has. Man page for pthread_rwlock_timedrdlock() says:
The calling thread may deadlock if at the time the call is made it holds
a write lock on rwlock.
This can be fixed by keeping tracks of the write locks that are acquired by
the current transaction and simply not trying to acquire a read lock if we
already have a write lock on the same row.
Man page for pthread_rwlock_timedwrlock() says:
The calling thread may deadlock if at the time the call is made it holds
the read-write lock.
That is, there seems to be no way to "upgrade" a read lock into a write lock.
from mysql-5.6.
On lock recursivity.
The user can issue
SELECT * FROM t1 WHERE pk=1 FOR UPDATE;
SELECT * FROM t1 WHERE pk=1 LOCK IN SHARE MODE;
in arbitrary order. (Current) exclusive locks allow multiple get_lock() calls which must be followed by multiple release_lock() calls.
Row_lock::owner_data and Row_lock::busy store information about how many times the owner has acquired the lock.
The situation gets more complex when we have multiple readers who may have acquired read locks multiple times, as well as the writer who may also hold read locks.
Possible ways out:
- Support recursive locks.
- Demand that the callers don't acquire locks they already have.
== Recursive locks ==
Row_lock should remember who has locked it (and how many times).
Currently Row_lock stores info about the thread that holds the write lock, and how many times it has acquired it. We will also need a list of read lock owners + counts.
(Q: is it ok to have a list or array or any other structure?)
Advantages:
- Lock subsystem will have simple API.
Disadvantages:
- Locking Internals will be heavy and complex. If there are a lot of read locks, we will be inefficient.
(however, transaction will do its lock lookups while not holding the mutex. as opposed to scanning the read lock holders which will be done while holding row lock's mutex)
== Non-recursive locks ==
Before a transaction attempts to get a lock, it should check it against the locks it has.
Currently a transaction stores locks it has acquired in an array. The array may have duplicates.
We will need to switch to std::unordered_map (or something similar), and we will also need to keep a list of locks acquired by the current statement (if the statement fails, we will need to release those)
Advantages:
- Lock_table implementation is simpler.
Disadvantages:
- Lock_table API will be complex.
- Transactions will need to maintain hash tables of their locks, which is an extra expense ( number-of-locks-transaction-holds is typically greater than number-of-read-lock-holders-for-a-certain-row).
from mysql-5.6.
Now, implementing a recursive r/w locks with capability to upgrade read lock + write lock. The implementation has a limit of how many read locks can be held for a given row. This limitation can be lifted in the future.
from mysql-5.6.
Implementation: https://reviews.facebook.net/D38265
Limitations:
- There is max. limit on the number of read locks one can have
- There is one
mysql_cond_t
condition, and everyone who wishes to acquire a read or a write lock wait for it. Then, mysql_cond_broadcast() is used to wake up all of the waiters. This may cause unneeded wake-ups. - The question of read lockers starving a write locker is left to OS thread scheduling.
from mysql-5.6.
Related Issues (20)
- DROP TABLE may take long time to wait for Seek() by drop_index_thread HOT 1
- UPDATE for table with VARCHAR pk gives "Can't find record" error HOT 5
- UPDATE may hang when it does a full table scan and updates PK values HOT 3
- Add kv_format_version into RDBSE_KEYDEF and data dictionary
- Include RocksDB utility tools into MySQL binary HOT 4
- rocksdb.rocksdb test asserts with message "Failed to get column family info from index id" HOT 8
- SIGSEGV on create table contention HOT 2
- Release Row Locks when necessary, Transaction API variant
- Add more information to SHOW ENGINE ROCKSDB TRANSACTION STATUS
- DML statements over reverse-ordered CFs are very slow after #86. HOT 5
- rocksdb.cardinality and other tests fail assert in rocksdb::port::PthreadCall HOT 23
- Range scan with equal predicates returns wrong results with bloom filter HOT 7
- Possible memory leak in RDBSE_KEYDEF::setup
- background space reclaim isn't working after DROP DATABASE HOT 1
- Enable specifying per column family options without a separate config file
- Add rocksdb-specific tests to parts suite
- Refine checkpoint logic in MyRocks
- Using SingleDelete() in MyRocks
- Reduce rocksdb_sys_vars suite to one test
- Automatically setup bootstrap for rocksdb tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql-5.6.