com.sleepycat.je.recovery
Class DirtyINMap

java.lang.Object
  extended by com.sleepycat.je.recovery.DirtyINMap

 class DirtyINMap
extends Object

Manages the by-level map of checkpoint references that are to be flushed by a checkpoint or Database.sync, the MapLNs to be flushed, the highest level by database to be flushed, and the state of the checkpoint. An single instance of this class is used for checkpoints and has the same lifetime as the checkpointer and environment. An instance per Database.sync is created as needed. Only one checkpoint can occur at a time, but multiple syncs may occur concurrently with each other and with the checkpoint. The methods in this class are synchronized to protect internal state from concurrent access by the checkpointer and eviction, and to coordinate state changes between the two. Eviction must participate in the checkpoint so that INs cascade up properly; see coordinateEvictionWithCheckpoint. When INs are latched along with synchronization on a DirtyINMap, the order must be: 1) IN latches and 2) synchronize on DirtyINMap. For example, the evictor latches the parent and child IN before calling the synchronized method coordinateEvictionWithCheckpoint, and selectDirtyINsForCheckpoint latches the IN before calling the synchronized method selectForCheckpoint.


Nested Class Summary
(package private) static class DirtyINMap.CkptState
           
 
Constructor Summary
DirtyINMap(EnvironmentImpl envImpl)
           
 
Method Summary
(package private)  Integer addIN(IN in, boolean updateMemoryBudget)
          Add a node unconditionally to the dirty map.
(package private)  void beginCheckpoint(boolean flushAll, boolean flushExtraLevel)
          Must be called before starting a checkpoint, and must not be called for Database.sync.
(package private)  boolean containsNode(Integer level, Long nodeId)
           
(package private)  boolean coordinateEvictionWithCheckpoint(IN target, IN parent)
          Coordinates an eviction with an in-progress checkpoint and returns whether or not provisional logging is needed.
(package private)  void flushMapLNs(long checkpointStart)
          Flushes all saved dirty/temp MapLNs and clears the saved set.
(package private)  void flushRoot(long checkpointStart)
          Flushes the DB mapping tree root at the end of the checkpoint, if either mapping DB is dirty and the root was not flushed previously during the checkpoint.
(package private)  int getHighestFlushLevel(DatabaseImpl db)
           
(package private)  Integer getLowestLevelSet()
          Get the lowest level currently stored in the map.
(package private)  int getNumEntries()
           
(package private)  int getNumLevels()
           
(package private)  void removeLevel(Integer level)
          Removes the set corresponding to the given level.
(package private)  Checkpointer.CheckpointReference removeNextNode(Integer level)
           
(package private)  Checkpointer.CheckpointReference removeNode(Integer level, Long nodeId)
           
(package private)  void reset()
          Must be called after a checkpoint or Database.sync is complete.
(package private)  void selectDirtyINsForCheckpoint()
          Scan the INList for all dirty INs, excluding temp DB INs.
(package private)  void selectDirtyINsForDbSync(DatabaseImpl dbImpl)
          Scan the INList for all dirty INs for a given database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirtyINMap

DirtyINMap(EnvironmentImpl envImpl)
Method Detail

coordinateEvictionWithCheckpoint

boolean coordinateEvictionWithCheckpoint(IN target,
                                         IN parent)
Coordinates an eviction with an in-progress checkpoint and returns whether or not provisional logging is needed.

Returns:
true if the target must be logged provisionally.

beginCheckpoint

void beginCheckpoint(boolean flushAll,
                     boolean flushExtraLevel)
Must be called before starting a checkpoint, and must not be called for Database.sync. Updates memory budget and sets checkpoint state.


reset

void reset()
Must be called after a checkpoint or Database.sync is complete. Updates memory budget and clears checkpoint state.


selectDirtyINsForCheckpoint

void selectDirtyINsForCheckpoint()
                           throws DatabaseException
Scan the INList for all dirty INs, excluding temp DB INs. Save them in a tree-level ordered map for level ordered flushing. Take this opportunity to recalculate the memory budget tree usage. This method itself is not synchronized to allow concurrent eviction. Synchronization is performed on a per-IN basis to protect the data structures here, and eviction can occur in between INs.

Throws:
DatabaseException

selectDirtyINsForDbSync

void selectDirtyINsForDbSync(DatabaseImpl dbImpl)
                       throws DatabaseException
Scan the INList for all dirty INs for a given database. Arrange them in level sorted map for level ordered flushing. This method is not synchronized to allow concurrent eviction. Coordination between eviction and Database.sync is not required.

Throws:
DatabaseException

getHighestFlushLevel

int getHighestFlushLevel(DatabaseImpl db)

getNumLevels

int getNumLevels()

addIN

Integer addIN(IN in,
              boolean updateMemoryBudget)
Add a node unconditionally to the dirty map. The dirty map is keyed by level (Integers) and holds sets of IN references.

Parameters:
updateMemoryBudget - if true then update the memory budget as the map is changed; if false then addCostToMemoryBudget must be called later.
Returns:
level of IN added to the dirty map. The level is returned rather than a boolean simply to avoid allocating another Integer in the caller.

getLowestLevelSet

Integer getLowestLevelSet()
Get the lowest level currently stored in the map.


removeLevel

void removeLevel(Integer level)
Removes the set corresponding to the given level.


containsNode

boolean containsNode(Integer level,
                     Long nodeId)

removeNode

Checkpointer.CheckpointReference removeNode(Integer level,
                                            Long nodeId)

removeNextNode

Checkpointer.CheckpointReference removeNextNode(Integer level)

flushMapLNs

void flushMapLNs(long checkpointStart)
           throws DatabaseException
Flushes all saved dirty/temp MapLNs and clears the saved set.

If dirty, a MapLN must be flushed at each checkpoint to record updated utilization info in the checkpoint interval. If it is a temporary DB, the MapLN must be flushed because all temp DBs must be encountered by recovery so they can be removed if they were not closed (and removed) by the user.

This method is not synchronized because it takes the Btree root latch, and we must never latch something in the Btree after synchronizing on DirtyINMap; see class comments. Special synchronization is performed for accessing internal state; see below.

Parameters:
checkpointStart - start LSN of the checkpoint in progress. To reduce unnecessary logging, the MapLN is only flushed if it has not been written since that LSN.
Throws:
DatabaseException

flushRoot

void flushRoot(long checkpointStart)
         throws DatabaseException
Flushes the DB mapping tree root at the end of the checkpoint, if either mapping DB is dirty and the root was not flushed previously during the checkpoint. This method is not synchronized because it does not access internal state. Also, it takes the DbTree root latch and although this latch should never be held by eviction, for consistency we should not latch something related to the Btree after synchronizing on DirtyINMap; see class comments.

Parameters:
checkpointStart - start LSN of the checkpoint in progress. To reduce unnecessary logging, the Root is only flushed if it has not been written since that LSN.
Throws:
DatabaseException

getNumEntries

int getNumEntries()


Copyright (c) 2004-2012 Oracle. All rights reserved.