In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is CBC latch and buffer pin". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
CBC is called cache buffer chain. Before we understand CBClatch and buffer pin, the first thing we need to understand is what oracle does when a process wants to query or modify data.
When an external service requests data from the database, the oracle internal process first looks for the relevant data in the buffer cache. If there is no relevant data in the buffer cache, it will find the relative block in the corresponding data file, and then the physical IO will occur and write it to the cache in the buffer cache. At this point, a new problem will arise? With so many buffer,oracle in buffer cache, how can you find out exactly what you need buffer?
There is an important concept in the hash algorithm, bucket. For example, when oracle wants to read the 23rd block of data in file 1, it will calculate the hash value x according to the file number and block number, and then locate it directly to bucketx according to the hash value x, and then oracle can read the contents of the bucket. To avoid hash conflicts, the bucket must be followed by a linked list, so what exists in the bucket must be the cbc chain header. When the process finds the bucketx according to the file number and block number, it traverses, finds the ba in each bh, and then can accurately find the relative buffer.
With the above knowledge, when a process accesses buffer, because sga is public memory, there must be a locking mechanism to protect sga. When the above process accesses the BH,Bucket, there will be a corresponding lock to protect, and this latch is CBC latch. When process A finds the bucketx, process A must apply for latch in order to gain access to BH. Because latch also takes up space, each latch manages multiple bucket, not a simple one-to-one relationship.
When process An acquires the latch, it can access or modify the BH, and when the BH is modified, a buffer pin lock is added to the BH. There are two common states in buffer pin: shared S and exclusive X. to put it simply, when you read logically, the state is S, and when you DML, it is state X. When no one is visiting, the default state of buffer pin is 0, and when that state is modified, the mission of CBC latch is achieved. Process A can then release the CBC latch and be accompanied by the buffer pin lock for the next step. When process A completes the operation on buffer, CBC latch will accompany process A through the final journey when the buffer pin is released.
We need to understand two modes of CBC latch, one is exclusive mode and the other is shared mode. Because CBC latch protects BH and linked lists. If you have not modified the relevant BH and linked list, you can apply for CBC latch in shared mode. If the state of buffer pin in BH is modified, exclusive mode is used. When the relevant state is modified, CBC latch will be released
All of the above is based on the fact that CBC latch is in exclusive mode, but when process B also wants to access the bucket that the latch is responsible for, it will be queued. This will lead to a lot of competition.
When the CBC latch is in shared mode, the latch will accompany the A process until the buffer pin is released. This increases the latch load time to solve the problem of a lot of competition.
For buffer pin. We all know that reading gets a shared bufferpin lock and writing gets an exclusive bufferpin lock. For blocking of buffer pin locks. As long as there is an exclusive lock, there will be congestion.
For example
Write: process A has acquired an exclusive buffer pin lock, process B also wants to write at this time, and can only wait for process A to release
Write and read: process A has acquired an exclusive buffer pin lock, and process B wants to read at this time, so you need to wait for process A to release the lock.
Let's first discuss BH in the shared state:
Process A, accompanied by CBClatch, modifies the buffer pin state in BH to S state. At this point, process B, accompanied by latch, also wants to access the BH, but finds that its status is S-shared. Process B will leave an S-status buffer pin in the BH
In this buffer pin state, copy the buffer to another buffer, generate a new BH to point to the buffer, and release the CBC latch when finished. At this point, the same buffer is added to the buffer, but there is an extra status=XCUR column in the BH of the original buffer. The cloned BH status has no value. At this point, process B gets the latch again, changing the status of the original BH to CR, that is, the CR block; the newly cloned status is XCUR, sets the buffer pin to X exclusive, and starts to modify the buffer. So that's why reading doesn't block writing.
If another C process wants to read the buffer at this time, but the buffer pin is status x, so C process can only wait, which is the common buffer busy waits.
This is the end of "what is CBC latch and buffer pin". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.