天天看點

關于 Private strand flush not complete----redo機制

1、錯誤消息

Tue Sep 24 14:27:48 2013

Thread 1 cannot allocate new log, sequence 22120

Private strand flush not complete

Current log# 4 seq# 22119 mem# 0: /u01/app/Oracle/oradata/orcl/redo04.log 

2、Meatlink 對此的描述(Doc ID 372557.1)

Oracle Database - Enterprise Edition - Version 10.2.0.1 to 11.2.0.3 [Release 10.2 to 11.2]

Information in this document applies to any platform.

Private strand flush not complete

Symptoms

"Private strand flush not complete" messages are being populated to the alert log, example:

Mon Jan 23 16:09:36 2012

Thread 1 cannot allocate new log, sequence 18358

Private strand flush not complete

Current log# 7 seq# 18357 mem# 0: /u03/oradata/bitst/redo07.log

Thread 1 advanced to log sequence 18358

Current log# 8 seq# 18358 mem# 0: /u03/oradata/bitst/redo08.log

Changes

When you switch logs all private strands have to be flushed to the current log before the switch is allowed to proceed.

--切換日值前,所有的private strands必須寫入到目前的redo logfile

Cause

The message means that we haven't completed writing all the redo information to the log when we are trying to switch. It is similar in nature to a "checkpoint not complete" except that is only involves the redo being written to the log. The log switch can not occur until all of the redo has been written.

-->該消息意味着在日志切換前我們不能夠完整的寫出redo到日志檔案。其本質類似于checkpoint not complete等待事件。所不同的是它僅僅涉及到正在被寫入到日志的redo

A "strand" is new terminology for 10g and it deals with latches for redo . -->strand是一個用于處理redo latch的新術語

Strands are a mechanism to allow multiple allocation latches for processes to write redo more efficiently in the redo buffer and is related to the log_parallelism parameter present in 9i.

The concept of a strand is to ensure that the redo generation rate for an instance is optimal and that when there is some kind of redo contention then the number of strands is dynamically adjusted to compensate.

-->最大的作用是用于確定redo産生的速率達到最佳,并在出現相關redo競争的時候動态調整strand的值進行補償

The initial allocation for the number of strands depends on the number of CPU's and is started with 2 strands with one strand for active redo generation.

For large scale enterprise systems the amount of redo generation is large and hence these strands are *made active* as and when the foregrounds encounter this redo contention (allocated latch related contention) when this concept of dynamic strands comes into play.

There is always shared strands and a number of private strands .

Oracle 10g has some major changes in the mechanisms for redo (and undo), which seem to be aimed at reducing contention.

-->在10g中有很大的變化,最主要的目的還是為了減少競争

Instead of redo being recorded in real time, it can be recorded 'privately' and pumped into the redo log buffer on commit.

Similarly the undo can be generated as 'in memory undo' and applied in bulk. This affect the memory used for redo management and the possibility to flush it in pieces. The message you get is related to internal Cache Redo File management.

...You can disregard these messages as normal messages. --->可以當作正常消息被忽略

Solution

These messages are not a cause for concern unless there is a significant time gap between the "cannot allocate new log" message and the "advanced to log sequence" message. --->如果"cannot allocate new log" 與"advanced to log sequence"有明顯的時間間隔,應考慮增加db_writer_processes

Increasing the value for db_writer_processes can in some situations help to avoid the message from being generated. Why, because one of the DBWR main function is to keep the buffer cache clean by writing out dirty buffer blocks. So having multiple db_writer_processes should be able to produce a higher throughput.

Finally, these messages have also been seen when there are issues with the storage side or network for the archive log destination, as this leads to delay or hang in LGWR switch. 

3、延伸思考

在高并發,多使用者的資料庫系統中,所有用戶端程序都是通過向redo log buffer寫入重做資料來確定資料的完整與一緻性。對于redo log buffer的管理,則通過latch的機制來實作。和redo相關的latch主要有兩個,一個是redo allocation latch,一個是redo copy latch。前者負責将為新的redo在redo log buffer中配置設定空間,後者則是pga中的redo複制到redo log buffer。下面是描述一下redo産生的流程。 

使用者程序産生redo(位于PGA中)====>伺服器程序擷取Redo Copy latch(存在多個取決于CPU_COUNT*2)====>服務程序擷取redo allocation latch(僅1個)====>配置設定log buffer====>釋放redo allocation latch====>将Redo Entry寫入Log Buffer====>釋放Redo Copy latch 

如前文Doc ID 372557.1所述,Oracle 9.2之後引入了log_parallelism機制,當該參數的值大于1的時候,資料庫會配置設定多個共享的redo log buffer,也就是說redo log buffer被再次細分,使得每個共享的buffer使用獨立的redo allocation latch來進行保護以提高redo的并發性。這些個共享的redo log buffer就被稱之為 shared strand。在10gR2以後了又多出了一個private strand,這個東東是從shared pool中配置設定而不是先前的log buffer。private strand為大量小的私有記憶體,通常每個大小在64kb-128kb左右,被獨立的redo allocation latch所保護。每個特定的小事務會綁定到獨立且空閑的private redolog strand,即綁定到一個活動事務。在這種新機制引入後,一旦使用者程序申請到private strand,redo不再儲存的pga中,是以不再需要redo copy latch這個過程。如果新事務申請不到private strand的redo allocation latch,則會繼續遵循舊的redo buffer機制,申請寫入shared strand中。由于新機制的引入,相應的redo的産生發生了一些變化,如下: 

新事務開始====>申請private strand的redo allocation latch(申請失敗則申請shared strand的redo allocation latch)====>在private strand中生産redo Entry====>flush/commit====>申請redo copy latch====>LGWR将redo entry批量寫入log File====>釋放redo copy latch====>釋放Private strand的redo allocation latch 

對于這個新的機制,在進行redo被寫出到logfile時,LGWR需要将shared strand與private strand的内容寫出。當redo flush發生時,所有的publicredo allocation latch需要被擷取,所有的public strands的redo copy latch需要被檢查,所有包含活動事務的private strands需要被持有。 

由上可知,Private strand flush not complete事件的出現是通過增加參數DBWn的值來避免。因為DBWn會觸發LGWR将redo寫入到logfile。