Quadcap Embeddable Database

com.quadcap.sql.file.SubPageManager Class Reference

Inheritance diagram for com.quadcap.sql.file.SubPageManager:

com.quadcap.sql.file.PageManager List of all members.

Detailed Description

This class implements a sub-page manager which operates by allocating pages as needed from the main file and chopping them up into smaller pages of the appropriate size.

Author:
Stan Bailes

Definition at line 56 of file SubPageManager.java.

Public Member Functions

 SubPageManager (BlockFile file, int pageShift, long rootBlock) throws IOException
 Construct a new sub-page manager bound to the specified block file.

long newPage () throws IOException
 Allocate a new block.

void freePage (long block) throws IOException
 Free a block.

final int pageOffset (long page)
 Return the byte offset of this page in the base block.

Page getPage (long block) throws IOException
 Return the specified page.

Object getLock ()
 Return the (file) lock.

final int getPageSize ()
 Return this manager's block size.

RandomAccessInputStream getInputStream (long block) throws IOException
 Return a new input stream, reading from the region with the specified root block.

RandomAccessOutputStream getOutputStream (long block) throws IOException
 Return a new output stream, writing to the region with the specified root block.

RandomAccess getStream (long blockRef) throws IOException
void freeStream (long page) throws IOException
 Destroy the stream with the specified root page and free up the storage it was using.

String toString ()
 Return a displayable representation for this object.


Static Public Member Functions

final long pageBlock (long page)
 Return the number of the block that contains this page.

String toString (long page)

Package Functions

final long makePageNo (long blk, long page)

Static Package Functions

final long fIns (long v, int[] f)
final long fMask (int[] f)
final long fEnd (int[] f)
final long fExt (long v, int[] f)
final int pageShift (long page)
 Return the page shift for this page.


Package Attributes

BlockFile file
long rootBlock
 rootBlock is the root block of the entire block file, and will always be zero in this implementation.

int pageSize
 The size of a subpage.

int pageShift
 The page shift (file.pageSize >> pageShift == pageSize).

int offset
 The offset into the root block of our freelist head.

int pagesPerBlock
 (1 << pageShift)


Static Package Attributes

final long PAGE_FREE = 0xabcddbca5438182fL
int[] PAGE_SHIFT = {63,4}
 Sub-page numbers are encoded as follows:.

int[] PAGE_NUM = {59,16}
int[] BLOCK_NUM = {43,44}

Private Member Functions

final long allocateNewBlock () throws IOException
 Allocate new block and slice it up into sub-pages.


Constructor & Destructor Documentation

com.quadcap.sql.file.SubPageManager.SubPageManager BlockFile  file,
int  pageShift,
long  rootBlock
throws IOException
 

Construct a new sub-page manager bound to the specified block file.

Definition at line 82 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.file, com.quadcap.sql.file.BlockFile.getPageSize(), com.quadcap.sql.file.SubPageManager.pageShift, com.quadcap.sql.file.SubPageManager.pageSize, and com.quadcap.sql.file.SubPageManager.rootBlock.


Member Function Documentation

final long com.quadcap.sql.file.SubPageManager.allocateNewBlock  )  throws IOException [private]
 

Allocate new block and slice it up into sub-pages.

Link the sub-pages together and return the head of the list. Lock must be held!

Definition at line 196 of file SubPageManager.java.

References com.quadcap.sql.file.Cacheable.decrRefCount(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.SubPageManager.file, com.quadcap.sql.file.BlockFile.getBlock(), com.quadcap.sql.file.SubPageManager.getPage(), com.quadcap.sql.file.SubPageManager.makePageNo(), com.quadcap.sql.file.BlockFile.newPage(), com.quadcap.sql.file.SubPageManager.PAGE_FREE, com.quadcap.sql.file.SubPageManager.pagesPerBlock, com.quadcap.sql.file.SubPageManager.toString(), com.quadcap.sql.file.Page.writeLong(), and com.quadcap.sql.file.Block.writeLong().

Referenced by com.quadcap.sql.file.SubPageManager.newPage().

final long com.quadcap.sql.file.SubPageManager.fEnd int[]  f  )  [static, package]
 

Definition at line 255 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.fEnd().

Referenced by com.quadcap.sql.file.SubPageManager.fEnd(), and com.quadcap.sql.file.SubPageManager.fIns().

final long com.quadcap.sql.file.SubPageManager.fExt long  v,
int[]  f
[static, package]
 

Definition at line 258 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.fExt().

Referenced by com.quadcap.sql.file.SubPageManager.fExt().

final long com.quadcap.sql.file.SubPageManager.fIns long  v,
int[]  f
[static, package]
 

Definition at line 249 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.fEnd(), com.quadcap.sql.file.SubPageManager.fIns(), and com.quadcap.sql.file.SubPageManager.fMask().

Referenced by com.quadcap.sql.file.SubPageManager.fIns().

final long com.quadcap.sql.file.SubPageManager.fMask int[]  f  )  [static, package]
 

Definition at line 252 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.fMask().

Referenced by com.quadcap.sql.file.SubPageManager.fIns(), and com.quadcap.sql.file.SubPageManager.fMask().

void com.quadcap.sql.file.SubPageManager.freePage long  block  )  throws IOException
 

Free a block.

Parameters:
block a previously allocated block

Implements com.quadcap.sql.file.PageManager.

Definition at line 153 of file SubPageManager.java.

References com.quadcap.sql.file.Cacheable.decrRefCount(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.SubPageManager.file, com.quadcap.sql.file.BlockFile.fileLock, com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.BlockFile.getBlock(), com.quadcap.sql.file.SubPageManager.getPage(), com.quadcap.sql.file.SubPageManager.offset, com.quadcap.sql.file.SubPageManager.PAGE_FREE, com.quadcap.sql.file.SubPageManager.pageShift, com.quadcap.sql.file.Page.readLong(), com.quadcap.sql.file.Block.readLong(), com.quadcap.sql.file.SubPageManager.rootBlock, com.quadcap.sql.file.SubPageManager.toString(), com.quadcap.sql.file.Block.writeLong(), and com.quadcap.sql.file.Page.writeLong().

Referenced by com.quadcap.sql.file.SubPageManager.freePage().

void com.quadcap.sql.file.SubPageManager.freeStream long  page  )  throws IOException
 

Destroy the stream with the specified root page and free up the storage it was using.

Parameters:
page the root page of the region
Exceptions:
IOException if the page number isn't valid, or if another error is detected trying to access the region.

Definition at line 396 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.file, com.quadcap.sql.file.BlockFile.fileLock, com.quadcap.sql.file.SubPageManager.freeStream(), and com.quadcap.sql.file.RandomAccess.resize().

Referenced by com.quadcap.sql.file.SubPageManager.freeStream().

RandomAccessInputStream com.quadcap.sql.file.SubPageManager.getInputStream long  block  )  throws IOException
 

Return a new input stream, reading from the region with the specified root block.

Parameters:
block the root block of the region
Returns:
an InputStream bound to the region.
Exceptions:
IOException if the block number isn't valid, or if another error is detected trying to access the region.

Definition at line 362 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.getInputStream(), and com.quadcap.sql.file.SubPageManager.getStream().

Referenced by com.quadcap.sql.file.SubPageManager.getInputStream().

Object com.quadcap.sql.file.SubPageManager.getLock  ) 
 

Return the (file) lock.

Implements com.quadcap.sql.file.PageManager.

Definition at line 344 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.file, and com.quadcap.sql.file.BlockFile.getLock().

RandomAccessOutputStream com.quadcap.sql.file.SubPageManager.getOutputStream long  block  )  throws IOException
 

Return a new output stream, writing to the region with the specified root block.

Parameters:
block the root block of the region
Returns:
an OutputStream bound to the region.
Exceptions:
IOException if the block number isn't valid, or if another error is detected trying to access the region.

Definition at line 377 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.getOutputStream(), and com.quadcap.sql.file.SubPageManager.getStream().

Referenced by com.quadcap.sql.file.SubPageManager.getOutputStream().

Page com.quadcap.sql.file.SubPageManager.getPage long  block  )  throws IOException
 

Return the specified page.

Implements com.quadcap.sql.file.PageManager.

Definition at line 334 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.getPage().

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.SubPageManager.getPage(), and com.quadcap.sql.file.SubPageManager.newPage().

final int com.quadcap.sql.file.SubPageManager.getPageSize  ) 
 

Return this manager's block size.

Implements com.quadcap.sql.file.PageManager.

Definition at line 349 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.pageSize.

RandomAccess com.quadcap.sql.file.SubPageManager.getStream long  blockRef  )  throws IOException
 

Definition at line 383 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.getStream().

Referenced by com.quadcap.sql.file.SubPageManager.getInputStream(), com.quadcap.sql.file.SubPageManager.getOutputStream(), and com.quadcap.sql.file.SubPageManager.getStream().

final long com.quadcap.sql.file.SubPageManager.makePageNo long  blk,
long  page
[package]
 

Definition at line 262 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.BLOCK_NUM, com.quadcap.sql.file.SubPageManager.makePageNo(), com.quadcap.sql.file.SubPageManager.PAGE_NUM, com.quadcap.sql.file.SubPageManager.PAGE_SHIFT, and com.quadcap.sql.file.SubPageManager.pageShift.

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), and com.quadcap.sql.file.SubPageManager.makePageNo().

long com.quadcap.sql.file.SubPageManager.newPage  )  throws IOException
 

Allocate a new block.

Implements com.quadcap.sql.file.PageManager.

Definition at line 99 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.Page.clear(), com.quadcap.sql.file.Cacheable.decrRefCount(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.SubPageManager.file, com.quadcap.sql.file.BlockFile.fileLock, com.quadcap.sql.file.BlockFile.getBlock(), com.quadcap.sql.file.SubPageManager.getPage(), com.quadcap.sql.file.SubPageManager.offset, com.quadcap.sql.file.SubPageManager.PAGE_FREE, com.quadcap.sql.file.SubPageManager.pageShift, com.quadcap.sql.file.SubPageManager.pageSize, com.quadcap.sql.file.Page.read(), com.quadcap.sql.file.Page.readLong(), com.quadcap.sql.file.Block.readLong(), com.quadcap.sql.file.SubPageManager.rootBlock, com.quadcap.sql.file.SubPageManager.toString(), and com.quadcap.sql.file.Block.writeLong().

final long com.quadcap.sql.file.SubPageManager.pageBlock long  page  )  [static]
 

Return the number of the block that contains this page.

Definition at line 291 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.BLOCK_NUM, and com.quadcap.sql.file.SubPageManager.pageBlock().

Referenced by com.quadcap.sql.file.SubPageManager.pageBlock().

final int com.quadcap.sql.file.SubPageManager.pageOffset long  page  ) 
 

Return the byte offset of this page in the base block.

Definition at line 314 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.PAGE_NUM, com.quadcap.sql.file.SubPageManager.pageOffset(), and com.quadcap.sql.file.SubPageManager.pageSize.

Referenced by com.quadcap.sql.file.SubPageManager.pageOffset(), and com.quadcap.sql.file.SubPage.SubPage().

final int com.quadcap.sql.file.SubPageManager.pageShift long  page  )  [static, package]
 

Return the page shift for this page.

Definition at line 324 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.PAGE_SHIFT, and com.quadcap.sql.file.SubPageManager.pageShift.

String com.quadcap.sql.file.SubPageManager.toString long  page  )  [static]
 

Definition at line 412 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.PAGE_NUM.

String com.quadcap.sql.file.SubPageManager.toString  ) 
 

Return a displayable representation for this object.

Definition at line 407 of file SubPageManager.java.

References com.quadcap.sql.file.SubPageManager.offset, com.quadcap.sql.file.SubPageManager.pageSize, and com.quadcap.sql.file.SubPageManager.rootBlock.

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.SubPageManager.freePage(), and com.quadcap.sql.file.SubPageManager.newPage().


Member Data Documentation

int [] com.quadcap.sql.file.SubPageManager.BLOCK_NUM = {43,44} [static, package]
 

Definition at line 246 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.makePageNo(), and com.quadcap.sql.file.SubPageManager.pageBlock().

BlockFile com.quadcap.sql.file.SubPageManager.file [package]
 

Definition at line 57 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.SubPageManager.freeStream(), com.quadcap.sql.file.SubPageManager.getLock(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.SubPage.SubPage(), and com.quadcap.sql.file.SubPageManager.SubPageManager().

int com.quadcap.sql.file.SubPageManager.offset [package]
 

The offset into the root block of our freelist head.

Definition at line 71 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.SubPageManager.newPage(), and com.quadcap.sql.file.SubPageManager.toString().

final long com.quadcap.sql.file.SubPageManager.PAGE_FREE = 0xabcddbca5438182fL [static, package]
 

Definition at line 77 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.SubPageManager.freePage(), and com.quadcap.sql.file.SubPageManager.newPage().

int [] com.quadcap.sql.file.SubPageManager.PAGE_NUM = {59,16} [static, package]
 

Definition at line 241 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.makePageNo(), com.quadcap.sql.file.SubPageManager.pageOffset(), and com.quadcap.sql.file.SubPageManager.toString().

int [] com.quadcap.sql.file.SubPageManager.PAGE_SHIFT = {63,4} [static, package]
 

Sub-page numbers are encoded as follows:.

     sub_page {
        pageShift		bit4
        pageNum		bit16
        blockNum		bit44
     }
 

This has the desirable property of being backward compatible with the pre-sub-page block numbers, which will have pageShift and pageNum equal to zero.

Definition at line 240 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.makePageNo(), and com.quadcap.sql.file.SubPageManager.pageShift().

int com.quadcap.sql.file.SubPageManager.pageShift [package]
 

The page shift (file.pageSize >> pageShift == pageSize).

Definition at line 68 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.SubPageManager.makePageNo(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.SubPageManager.pageShift(), and com.quadcap.sql.file.SubPageManager.SubPageManager().

int com.quadcap.sql.file.SubPageManager.pageSize [package]
 

The size of a subpage.

Definition at line 65 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPage.clear(), com.quadcap.sql.file.SubPageManager.getPageSize(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.SubPageManager.pageOffset(), com.quadcap.sql.file.SubPageManager.SubPageManager(), com.quadcap.sql.file.SubPage.takeData(), and com.quadcap.sql.file.SubPageManager.toString().

int com.quadcap.sql.file.SubPageManager.pagesPerBlock [package]
 

(1 << pageShift)

Definition at line 74 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock().

long com.quadcap.sql.file.SubPageManager.rootBlock [package]
 

rootBlock is the root block of the entire block file, and will always be zero in this implementation.

Definition at line 62 of file SubPageManager.java.

Referenced by com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.SubPageManager.SubPageManager(), and com.quadcap.sql.file.SubPageManager.toString().