To ensure data consistency and performance in concurrent operations, HBase has a wide variety of efficient reentrant locks, including row-level rowlock, mvcc,region-level read and write locks, store-level read and write locks, memstore-level read and write locks, and so on.
1, row-level lock Rowlock
In HBase, the rowlock mechanism is adopted in order to solve the consistency problem of row level in concurrent operation. Ensure that only the same thread operates on the same line at the same time. Of course Rowlock has the concept of lease leases, exceeding the term, automatically releasing the row lock
2, MVCC
In the case of concurrency performance, Rowlock is only used with write data, and HBase uses a MVCC solution for read-write concurrency.
The basic principle is that the writer operation will pass through a series of processes such as Wal, Memstore, first after the rowlock operation, immediately assign a writer number, each CF column cell in the store will take this writer, The writer number is marked to end before the write operation is finished, and each read operation at the beginning (readpoint) assigns the largest end writer number, which is the latest end writer number ( The values in Memstore can be written without ending, and these values cannot be read, so the flush cache must wait for all values in the Memstore to be write-terminated. Detailed MVCC analysis can be found in the previously written blog:http://blog.csdn.net/yangbutao/article/details/8998800
3, Region-level lock
When doing the update operation, you need to determine whether the resource meets the requirements, and if it reaches the critical point, apply the flush operation and wait until the resource meets the requirements (see Checkresource in region)
The Region Update update lock (Updateslock), which writes locks at Internalflushcache, causes blocking during put, delete, increment operations (these operations add read locks).
Region Close Protection Lock (lock), which blocks other operations (read-Lock) on region, such as compact, flush, scan, and other writes, when a region close or split operation (write lock) is blocked.
4, store-level locks
The flush process includes,
A, prepare (based on Memstore do snapshot)
B, Flushcache (generate temporary files based on snapshot)
C, commit (confirm the flush operation completed, rename temporary file is the official file name, clear mem snapshot)
During the commit phase of the flush process, the completecompaction phase of the compact process (rename temporary compact file name, cleanup of the old file), close store (Close store), Bulkloadhfile, blocking write operations to the store.
5, Memstore level of the lock
Writes to the store call the Memstore operation, blocking other operations (such as Add, delete, GetNextRow) when Memstore is snapshot and clearing snapshot.