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

## Class DataStructure

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

Direct Known Subclasses:
  BPlusTree, PagesList

    public abstract class DataStructure
    extends Object

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

### Field Summary

Fields
`protected int` `grpId`
`protected String` `grpName`
`protected PageMetrics` `metrics`
`protected byte` `pageFlag`
`protected PageIoResolver` `pageIoRslvr`
`protected PageMemory` `pageMem`
`protected ReuseList` `reuseList`
`static Random` `rnd` For tests.
`protected @Nullable IgniteWriteAheadLogManager` `wal`

### Constructor Summary

Constructors
Constructor and Description
`DataStructure(String name, int cacheGrpId, @Nullable String grpName, PageMemory pageMem, @Nullable IgniteWriteAheadLogManager wal, PageLockTrackerManager pageLockTrackerManager, PageIoResolver pageIoRslvr, byte pageFlag)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected long` `acquirePage(long pageId, IoStatisticsHolder statHolder)`
`protected long` `allocatePage(ReuseBag bag)` Shorthand for `allocatePage(bag, true)`.
`protected long` `allocatePage(ReuseBag bag, boolean useRecycled)`
`protected long` `allocatePageNoReuse()`
`void` `close()` Frees the resources allocated by this structure.
`int` `groupId()`
`protected void` `init(long pageId, PageIO init)`
`String` `name()`
`protected boolean` `needWalDeltaRecord(long pageId, long page, Boolean walPlc)`
`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, IoStatisticsHolder statHolder)`
`protected <X,R> R` `read(long pageId, PageHandler<X,R> h, X arg, int intArg, R lockFailed, IoStatisticsHolder statHolder)`
`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, IoStatisticsHolder statHolder)`
`protected <R> R` `write(long pageId, PageHandler<?,R> h, int intArg, R lockFailed, IoStatisticsHolder statHolder)`
`protected <X,R> R` `write(long pageId, PageHandler<X,R> h, PageIO init, X arg, int intArg, R lockFailed, IoStatisticsHolder statHolder)`
`protected <X,R> R` `write(long pageId, PageHandler<X,R> h, X arg, int intArg, R lockFailed, IoStatisticsHolder statHolder)`
`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

#### grpName

    protected final String grpName

#### pageMem

    protected final PageMemory pageMem

#### wal

    @Nullable
    protected final @Nullable IgniteWriteAheadLogManager wal

#### reuseList

    protected ReuseList reuseList

#### pageIoRslvr

    protected final PageIoResolver pageIoRslvr

#### pageFlag

    protected final byte pageFlag

#### metrics

    protected final PageMetrics metrics

### Constructor Detail

#### DataStructure

    public DataStructure(String name,
                         int cacheGrpId,
                         @Nullable
                         @Nullable String grpName,
                         PageMemory pageMem,
                         @Nullable
                         @Nullable IgniteWriteAheadLogManager wal,
                         PageLockTrackerManager pageLockTrackerManager,
                         PageIoResolver pageIoRslvr,
                         byte pageFlag)

Parameters:
  `name` - Structure name (for debugging purposes).
  `cacheGrpId` - Cache group id.
  `grpName` - Group name.
  `pageMem` - Page memory.
  `wal` - Write ahead log manager.
  `pageLockTrackerManager` - Page lock tracker manager.
  `pageIoRslvr` - Page IO resolver.
  `pageFlag` - Default flag value for allocated pages.

### Method Detail

#### name

    public final String name()

Returns:
  Tree name.

#### 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

Shorthand for `allocatePage(bag, true)`.

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

#### allocatePage

    protected final long allocatePage(ReuseBag bag,
                                      boolean useRecycled)
                               throws IgniteCheckedException

Parameters:
  `bag` - Reuse Bag.
  `useRecycled` - Use recycled page.
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,
                                     IoStatisticsHolder statHolder)
                              throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `statHolder` - Statistics holder to track IO operations.
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,
                                IoStatisticsHolder statHolder)
                         throws IgniteCheckedException

Parameters:
  `pageId` - Page ID.
  `h` - Handler.
  `intArg` - Argument of type `int`.
  `lockFailed` - Result in case of lock failure due to page recycling.
  `statHolder` - Statistics holder to track IO operations.
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,
                                  IoStatisticsHolder statHolder)
                           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.
  `statHolder` - Statistics holder to track IO operations.
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,
                                  IoStatisticsHolder statHolder)
                           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.
  `statHolder` - Statistics holder to track IO operations.
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,
                                  IoStatisticsHolder statHolder)
                           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.
  `statHolder` - Statistics holder to track IO operations.
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,
                                 IoStatisticsHolder statHolder)
                          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.
  `statHolder` - Statistics holder to track IO operations.
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,
                                 IoStatisticsHolder statHolder)
                          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.
  `statHolder` - Statistics holder to track IO operations.
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:
  Recycled page ID.
Throws:
  `IgniteCheckedException` - If failed.

#### pageSize

    protected int pageSize()

Returns:
  Page size without encryption overhead.

#### close

    public void close()

Frees the resources allocated by this structure.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.15.0
Release Date | : April 25 2023