Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Clock Sweep algorithm in PostgreSQL

2025-03-29 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 "how to understand the Clock Sweep algorithm in PostgreSQL". In the operation of actual cases, many people will encounter such a dilemma, so 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!

I. data structure

BufferDesc

Shared descriptor (status) data for shared buffer

/ * * Flags for buffer descriptors * buffer descriptor tag * * Note: TAG_VALID essentially means that there is a buffer hashtable * entry associated with the buffer's tag. * Note: TAG_VALID essentially means that there is a buffer hash table entry associated with the token of the buffer. * / / buffer header lock # define BM_LOCKED (1U nextVictimBuffer, & expected, wrapped); if (success) / / if successful, increase the count StrategyControl- > completePasses++ / / release the spin lock SpinLockRelease (& StrategyControl- > buffer_strategy_lock);} / return victim return victim;} / * * pg_atomic_compare_exchange_u32-CAS operation * pg_atomic_compare_exchange_u32-CAS operation * * Atomically compare the current value of ptr with * expected and store newval * iff ptr and * expected have the same value. The current value of * ptr will * always be stored in * expected. * the atom compares the current value of ptr with * expected, and stores newval to ptr if the values of ptr and * compare are the same. The current value of * * ptr is usually stored in * expected. * Return true if values have been exchanged, false otherwise. * return T if the value has been exchanged, otherwise return F. * * Full barrier semantics. * complete barrier semantics. * / static inline boolpg_atomic_compare_exchange_u32 (volatile pg_atomic_uint32 * ptr, uint32 * expected, uint32 newval) {AssertPointerAlignment (ptr, 4); AssertPointerAlignment (expected, 4); return pg_atomic_compare_exchange_u32_impl (ptr, expected, newval) } boolpg_atomic_compare_exchange_u32_impl (volatile pg_atomic_uint32 * ptr, uint32 * expected, uint32 newval) {bool ret; / * * Do atomic op under a spinlock. It might look like we could just skip * the cmpxchg if the lock isn't available, but that'd just emulate a * 'weak' compare and swap. I.e. One that allows spurious failures. Since * several algorithms rely on a strong variant and that is efficiently * implementable on most major architectures let's emulate it here as * well. * perform atomic operations under spin lock protection. * it seems that if the lock is impossible, we can skip cmpxchg, but this only simulates a "shallow" comparison and exchange. * for example, this will cause spurious failures. Because there are several algorithms that rely on a powerful variant that can be effectively implemented on most major architectures * we also simulate it here. * / SpinLockAcquire ((slock_t *) & ptr- > sema); / * perform compare/exchange logic * / / perform comparison / exchange logic ret = ptr- > value = * is expected;//ptr consistent with * expected? * expected = ptr- > value;//*expected is assigned ptr if (ret) ptr- > value = newval / / if the value is consistent, ptr is set to the new value / * and release lock * / / release the spin lock SpinLockRelease ((slock_t *) & ptr- > sema); / / return the result return ret;} "how to understand the Clock Sweep algorithm in PostgreSQL". 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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report