org.apache.ignite.internal.processors.cache.persistence

## Class DataStructure

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.persistence.DataStructure

All Implemented Interfaces:
  PageLockListener

Direct Known Subclasses:
  BPlusTree, PagesList

    public abstract class DataStructure
    extends Object
    implements PageLockListener

Base class for all the data structures based on `PageMemory`.

### Field Summary

Fields
`protected int` `grpId`
`protected PageMemory` `pageMem`
`protected ReuseList` `reuseList`
`static Random` `rnd` For tests.
`protected IgniteWriteAheadLogManager` `wal`

### Constructor Summary

Constructors
Constructor and Description
`DataStructure(int cacheId, PageMemory pageMem, IgniteWriteAheadLogManager wal)`

### Method Summary

Methods
`protected long` `acquirePage(long pageId)`
`protected long` `allocatePage(ReuseBag bag)`
`protected long` `allocatePageNoReuse()`
`int` `groupId()`
`protected void` `init(long pageId, PageIO init)`
`protected boolean` `needWalDeltaRecord(long pageId, long page, Boolean walPlc)`
`void` `onBeforeReadLock(int cacheId, long pageId, long page)`
`void` `onBeforeWriteLock(int cacheId, long pageId, long page)`
`void` `onReadLock(int cacheId, long pageId, long page, long pageAddr)`
`void` `onReadUnlock(int cacheId, long pageId, long page, long pageAddr)`
`void` `onWriteLock(int cacheId, long pageId, long page, long pageAddr)`
`void` `onWriteUnlock(int cacheId, long pageId, long page, long pageAddr)`
`protected int` `pageSize()`
`static int` `randomInt(int max)`
`protected <X,R> R` `read(long pageId, long page, PageHandler<X,R> h, X arg, int intArg, R lockFailed)`
`protected <X,R> R` `read(long pageId, PageHandler<X,R> h, X arg, int intArg, R lockFailed)`
`protected long` `readLock(long pageId, long page)`
`protected void` `readUnlock(long pageId, long page, long pageAddr)`
`protected long` `recyclePage(long pageId, long page, long pageAddr, Boolean walPlc)`
`protected void` `releasePage(long pageId, long page)`
`protected long` `tryWriteLock(long pageId, long page)`
`protected <X,R> R` `write(long pageId, long page, PageHandler<X,R> h, X arg, int intArg, R lockFailed)`
`protected <R> R` `write(long pageId, PageHandler<?,R> h, int intArg, R lockFailed)`
`protected <X,R> R` `write(long pageId, PageHandler<X,R> h, PageIO init, X arg, int intArg, R lockFailed)`
`protected <X,R> R` `write(long pageId, PageHandler<X,R> h, X arg, int intArg, R lockFailed)`
`protected long` `writeLock(long pageId, long page)`
`protected void` `writeUnlock(long pageId, long page, long pageAddr, boolean dirty)` Note: Default WAL record policy will be used.
`protected void` `writeUnlock(long pageId, long page, long pageAddr, Boolean walPlc, boolean dirty)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### rnd

    public static Random rnd

For tests.

#### grpId

    protected final int grpId

#### pageMem

    protected final PageMemory pageMem

#### wal

    protected final IgniteWriteAheadLogManager wal

#### reuseList

    protected ReuseList reuseList

### Constructor Detail

#### DataStructure

    public DataStructure(int cacheId,
                 PageMemory pageMem,
                 IgniteWriteAheadLogManager wal)

Parameters:
  `cacheId` - Cache group ID.
  `pageMem` - Page memory.
  `wal` - Write ahead log manager.

### Method Detail

#### groupId

    public final int groupId()

Returns:
  Cache group ID.

#### randomInt

    public static int randomInt(int max)

Parameters:
  `max` - Max.
Returns:
  Random value from `0` (inclusive) to the given max value (exclusive).

#### allocatePage

    protected final long allocatePage(ReuseBag bag)
                               throws IgniteCheckedException

Parameters:
  `bag` - Reuse bag.
Returns:
  Allocated page.
Throws:
  `IgniteCheckedException` - If failed.

#### allocatePageNoReuse

    protected long allocatePageNoReuse()
                                throws IgniteCheckedException

Returns:
  Page ID of newly allocated page.
Throws:
  `IgniteCheckedException` - If failed.

#### acquirePage

    protected final long acquirePage(long pageId)
                              throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
Returns:
  Page absolute pointer.
Throws:
  `IgniteCheckedException` - If failed.

#### releasePage

    protected final void releasePage(long pageId,
                   long page)

Parameters:
  `pageId` - Page ID.
  `page` - Page pointer.

#### tryWriteLock

    protected final long tryWriteLock(long pageId,
                    long page)

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
Returns:
  Page address or `0` if failed to lock due to recycling.

#### writeLock

    protected final long writeLock(long pageId,
                 long page)

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
Returns:
  Page address.

#### writeUnlock

    protected final void writeUnlock(long pageId,
                   long page,
                   long pageAddr,
                   boolean dirty)

Note: Default WAL record policy will be used.

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
  `pageAddr` - Page address.
  `dirty` - Dirty flag.

#### readLock

    protected final long readLock(long pageId,
                long page)

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
Returns:
  Page address.

#### readUnlock

    protected final void readUnlock(long pageId,
                  long page,
                  long pageAddr)

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
  `pageAddr` - Page address.

#### writeUnlock

    protected final void writeUnlock(long pageId,
                   long page,
                   long pageAddr,
                   Boolean walPlc,
                   boolean dirty)

Parameters:
  `pageId` - Page ID
  `page` - Page pointer.
  `pageAddr` - Page address.
  `walPlc` - Full page WAL record policy.
  `dirty` - Dirty flag.

#### needWalDeltaRecord

    protected final boolean needWalDeltaRecord(long pageId,
                             long page,
                             Boolean walPlc)

Parameters:
  `pageId` - Page ID.
  `page` - Page pointer.
  `walPlc` - Full page WAL record policy.
Returns:
  `true` If we need to make a delta WAL record for the change in this page.

#### write

    protected final <R> R write(long pageId,
              PageHandler<?,R> h,
              int intArg,
              R lockFailed)
                     throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `h` - Handler.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### write

    protected final <X,R> R write(long pageId,
                PageHandler<X,R> h,
                X arg,
                int intArg,
                R lockFailed)
                     throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `h` - Handler.
  `arg` - Argument.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### write

    protected final <X,R> R write(long pageId,
                long page,
                PageHandler<X,R> h,
                X arg,
                int intArg,
                R lockFailed)
                     throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `page` - Page pointer.
  `h` - Handler.
  `arg` - Argument.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### write

    protected final <X,R> R write(long pageId,
                PageHandler<X,R> h,
                PageIO init,
                X arg,
                int intArg,
                R lockFailed)
                     throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `h` - Handler.
  `init` - IO for new page initialization or `null` if it is an existing page.
  `arg` - Argument.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### read

    protected final <X,R> R read(long pageId,
               PageHandler<X,R> h,
               X arg,
               int intArg,
               R lockFailed)
                    throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `h` - Handler.
  `arg` - Argument.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### read

    protected final <X,R> R read(long pageId,
               long page,
               PageHandler<X,R> h,
               X arg,
               int intArg,
               R lockFailed)
                    throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `page` - Page pointer.
  `h` - Handler.
  `arg` - Argument.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
Returns:
  Handler result.
Throws:
  `IgniteCheckedException` - If failed.

#### init

    protected final void init(long pageId,
            PageIO init)
                       throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `init` - IO for new page initialization.
Throws:
  `IgniteCheckedException` - if failed.

#### recyclePage

    protected final long recyclePage(long pageId,
                   long page,
                   long pageAddr,
                   Boolean walPlc)
                              throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `page` - Page pointer.
  `pageAddr` - Page address.
  `walPlc` - Full page WAL record policy.
Returns:
  Rotated page ID.
Throws:
  `IgniteCheckedException` - If failed.

#### pageSize

    protected final int pageSize()

Returns:
  Page size.

#### onBeforeWriteLock

    public void onBeforeWriteLock(int cacheId,
                         long pageId,
                         long page)

Specified by:
  `onBeforeWriteLock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.

#### onWriteLock

    public void onWriteLock(int cacheId,
                   long pageId,
                   long page,
                   long pageAddr)

Specified by:
  `onWriteLock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.
  `pageAddr` - Page address.

#### onWriteUnlock

    public void onWriteUnlock(int cacheId,
                     long pageId,
                     long page,
                     long pageAddr)

Specified by:
  `onWriteUnlock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.
  `pageAddr` - Page address.

#### onBeforeReadLock

    public void onBeforeReadLock(int cacheId,
                        long pageId,
                        long page)

Specified by:
  `onBeforeReadLock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.

#### onReadLock

    public void onReadLock(int cacheId,
                  long pageId,
                  long page,
                  long pageAddr)

Specified by:
  `onReadLock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.
  `pageAddr` - Page address.

#### onReadUnlock

    public void onReadUnlock(int cacheId,
                    long pageId,
                    long page,
                    long pageAddr)

Specified by:
  `onReadUnlock` in interface `PageLockListener`
Parameters:
  `cacheId` - Cache ID.
  `pageId` - Page ID.
  `page` - Page pointer.
  `pageAddr` - Page address.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017