Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP...

32
Under the Hoods of Cache Fusion, GES, GRD and GCS Arup Nanda Principal Database Architect Starwood Hotels

Transcript of Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP...

Page 1: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Under the Hoods of Cache Fusion, GES, GRD and GCS

Arup NandaPrincipal Database Architect

Starwood Hotels

Page 2: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

About Me• Oracle Database Admin for 16 years

• RAC (and OPS) since 1999• RAC (and OPS) since 1999

• Troubleshoot, tune performance

• Developed and Teach a course: RAC Performance Tuning

2© Arup Nanda, 2010

Page 3: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Why this Session?• If I have a 100MB database, I can have a 100

MB buffer cache and I never have to go to the gdisk, right?

• How does Cache Fusion know where to get the block from?

• How are block locks vary from row locks?

• I’m confused about Global Cache Service (GCS), Global Resource Directory (GRD) and Gl b l E S i (GES)Global Enqueue Service (GES)

• We will understand how all these actually work

3© Arup Nanda, 2010

Page 4: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer Cache

Select * from EMP

S t Gl b l

Server Process

System Global Area

4© Arup Nanda, 2010

Page 5: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

RAC – More than 1 Buffer Cache

Select * from EMP Select * from EMPCache FusionFusion

S t Gl b l

Server Process

S t Gl b l

Server Process

System Global Area

System Global Area

5© Arup Nanda, 2010

Page 6: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

To Cache Fusion or Not?• When a block is requested, the buffer cache

is searched• If not found, there are two options

– Get from disk– Get from the other cache

• If found, there are three options:– Send the buffer to the user– Examine other caches for the presence of this

bufferbuffer– Get from the disk

• How does it decide which option to take?How does it decide which option to take?

6© Arup Nanda, 2010

Page 7: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer States• The buffer can be retrieved in two modes

– Consistent Read (CR)Consistent Read (CR)

– Current

• There can be several CR copies of a buffer• There can be several CR copies of a buffer

• There can be only one current mode– For an instance

• Each current buffer is Shared Current

• Only one buffer in the entire cluster can be Exclusive Current c us e Cu e t

7© Arup Nanda, 2010

Page 8: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Block – Row Relationship

Instance 2Instance 1

Row 1

Row 2

Row 3

Row 4

Block8© Arup Nanda, 2010

Page 9: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Update on One InstanceUPDATE ROW1 …

Instance 2Instance 1

R 1Row 1

Row 2

Row 3

Row 4

Block

9© Arup Nanda, 2010

Page 10: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Update a Different Row on Node 2UPDATE ROW2 …

Instance 2Instance 1

R 1 R 1Row 1

Row 2

Row 1

Row 2Cache Fusion

Row 3

Row 4

Row 3

Row 4

Cache Fusion

Block Block

10© Arup Nanda, 2010

Page 11: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer Versions

Instance 2Instance 1

R 1 R 1SCN=20 SCN=30

Row 1

Row 2

Row 1

Row 2

Row 3

Row 4

Row 3

Row 4

Block Block

SCN=1011© Arup Nanda, 2010

Page 12: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer VersionsUPDATE ROW3 …

Instance 2Instance 1

Row 1 R 1

SCN=20 SCN=30Row 1

SCN=40

Row 1

Row 2

R 3

Row 1

Row 2

Row 1

Row 2

R 3Row 3

Row 4Row 3

Row 4

Row 3

Row 4

Block BlockBlock

SCN=1012© Arup Nanda, 2010

Page 13: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer State 1UPDATE ROW1 …

Instance 2Instance 1

R 1SCN=20

Row 1

Row 2

Row 3

Row 4Exclusive Exclusive

BlockCurrentCurrent

SCN=10SCN=10

13© Arup Nanda, 2010

Page 14: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Update a Different Row on Node 2UPDATE ROW2 …

Instance 2Instance 1

R 1 R 1SCN=30SCN=20

Row 1

Row 2

Row 1

Row 2Cache Fusion

Row 3

Row 4

Row 3

Row 4

Cache Fusion

Exclusive Exclusive Consistent Consistent

Block BlockCurrentCurrentReadRead

SCN 10SCN=10

14© Arup Nanda, 2010

Page 15: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer VersionsUPDATE ROW3 …

Instance 2Instance 1

R 1 R 1

SCN=20 SCN=30

R 1

SCN=40

Row 1

Row 2

Row 1

Row 2

Row 1

Row 2CF

Row 3

Row 4

Row 3

Row 4

Row 3

Row 4ConsistentConsistent ExclusiveExclusive ConsistentConsistent

CF

Block BlockBlockConsistent

ReadConsistent

ReadExclusive Current

Exclusive Current

Consistent Read

Consistent Read

SCN=1015© Arup Nanda, 2010

Page 16: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Putting it all together• When the block comes from the disk to the

buffer cachebuffer cache– If the intent is to modify, it’s gotten in

CURRENT modeCURRENT mode

– If the intent is to read, it’s gotten in CR mode

• There can be only one Shared Current per• There can be only one Shared Current per instance

Multiple SCURs in the cluster– Multiple SCURs in the cluster

• Many CR copies in the instance

16© Arup Nanda, 2010

Page 17: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Past Image• Sequence of Events

– Instance 1 has version 1 of the block2 2– Instance 2 has version 2

– Instance 2 updates the block -> current block changesg

– Instance 1 wants to update the block– Instance 2 prepares a copy of the block before

sending itsending it• This “copy” is called a Past Image (PI) of the

block – Note: the term Past Image is not documented in

Oracle Manuals. It’s just widely understood and acceptable.acceptab e

17© Arup Nanda, 2010

Page 18: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Cache Fusion in Operation

Time 0

Session1 Session2 Session3

Instance 1 Instance 2 Instance 3

DB

18© Arup Nanda, 2010

Page 19: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Time 1

l t * f t1

Session1 Session2 Session3

select * from t1

Instance 1 Instance 2 Instance 3

Buffer St t

SCUR

DB

State

19© Arup Nanda, 2010

Page 20: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Time 2

l t * f t1

Session1 Session2 Session3

select * from t1

Instance 1 Instance 2 Instance 3Cache Fusion

Buffer St t

SCUR CR

DB

State

20© Arup Nanda, 2010

Page 21: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Time 3

d t t1

Session1 Session2 Session3

update t1 ...

Instance 1 Instance 2 Instance 3Cache Fusion

Buffer St t

CR CR XCUR

DB

State

21© Arup Nanda, 2010

Page 22: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Time 4

d t t1

Session1 Session2 Session3

update t1 ...

Instance 1 Instance 2 Instance 3Cache Fusion

Buffer St t

XCUR CR PI

DB

State

22© Arup Nanda, 2010

Page 23: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Time 5

l h k i

Session1 Session2 Session3

alter system checkpoint

Instance 1 Instance 2 Instance 3Cache Fusion

Buffer St t

XCUR CR CR

DB

StatePast image

is gone

23© Arup Nanda, 2010

Page 24: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Buffer Lock• When an instance wants to change the state

of the buffer from CR to Exclusive Current– It must get a lock on that buffer

– This is called a Buffer Lock

– Different from a row lock

S i 1 S i 2Buffer Locks:

Instance 2Instance 1

Row 1 Row 1

SCN=20 SCN=30

Row 1

SCN=40

Session1 Session2Instance 1 = ExclusiveInstance 2 = NoneRow Locks: Row 1

Row 2

Row 3

Row 4

Row 1

Row 2

Row 3

Row 4

Row 1

Row 2

Row 3

Row 4

CF

Row Locks:Session 1 = Row 1 and Row 3S i 2 R 2

Block

Row 4

Block

Row 4

Block

Row 4Consistent

ReadConsistent

ReadExclusive Current

Exclusive Current

Consistent Read

Consistent Read

Session 2 = Row 2

24© Arup Nanda, 2010

Page 25: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Global Cache Service• Provides buffer from one instance to the

otherother– But does not know who has what type of

buffer lockbuffer lock

25© Arup Nanda, 2010

Page 26: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Global Enqueue Service• Used to be called Dynamic lock Manager

(DLM)( )• Holds the information on the locks on the

buffers• Each lock has a name shown in

V$LOCK_ELEMENT (or X$LE)( )• This is different from row locking, which is

on a specific rowp• If a buffer is locked, the lock element name

is shown in V$BH.LOCK_ELEMENT

26© Arup Nanda, 2010

Page 27: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Lock Queuing• Each Buffer in a RAC

instance has two queuesG t Q th– Grant Queue – the queue where the requesters are queued for the locks to be

t d i t i dgranted in a certain mode– Convert Queue – the queue

where the granted requests d b ifi d

2Grant Convert

are queued to be notified to the requesters

• The queues for a specificInst1

Queue Queue

Inst4The queues for a specific buffer are placed in a single instance

Inst2

Inst3

Inst5

Inst6

27© Arup Nanda, 2010

Page 28: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Master Instance• The instance that has the Grant and

Convert Queues of the Buffer is called the Master Instance of the Buffer

• A Buffer has only one Mastery• The Master may change

– Manuallyy– By a process known as Dynamic Resource

Mastering

• When an instance wants to get a lock, it has to check with the master

28© Arup Nanda, 2010

Page 29: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

Global Resource Directory• Someone has to keep a list of all buffers and

where they are masteredThi i ll d Gl b l R Di• This is called Global Resource Directory (GRD)

• GRD is present on all the instances of the• GRD is present on all the instances of the cluster

• To find out the master:select b.dbablk, r.kjblmaster master_nodefrom x$le l, x$kjbl r, x$bh bwhere b obj = <DataObjectId>where b.obj = <DataObjectId>and b.le_addr = l.le_addrand l.le_kjbl = r.kjbllockp

29© Arup Nanda, 2010

Page 30: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

30© Arup Nanda, 2010

Page 31: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

In Summary• Buffers are gotten in 2 modes

– CURRENT – is need to be modified– CR – if selected only for reading– CR – if selected only for reading

• Every time other node wants the buffer– it is copied to a new buffer and sent (CR processing)

Th b l f h b ff i• There can be only one current state of the buffer in an instance in Shared Mode

• Only one Exclusive Current in the Clustery• The Exclusive/Shared Current Locks on the Buffer is

handled by GES• Each buffer has a master node that holds the lock• Each buffer has a master node that holds the lock

Grant and Convert Queues• GRD maintains information on the buffers-masters

31© Arup Nanda, 2010

Page 32: Under the Hoods of Cache Fusion, GES, GRD and GCS – More than 1 Buffer Cache Select * from EMP Select * from EMP Cache Fusion St Glbl Server Process St Glbl Server Process System

My Blog: arup.blogspot.comMy Email: [email protected] Email: [email protected] the Scripts: proligence.com/cfscripts.zip

32© Arup Nanda, 2010