#include <CompoundId.h>
Static Public Member Functions | |
template<class PageOrBlockId> | |
static BlockNum | getBlockNum (PageOrBlockId pageId) |
Extracts the BlockNum from a PageId or BlockId. | |
template<class PageOrBlockId> | |
static void | setBlockNum (PageOrBlockId &pageId, BlockNum blockNum) |
Sets just the BlockNum of a PageId or BlockId. | |
template<class PageOrBlockId> | |
static void | incBlockNum (PageOrBlockId &pageId) |
Increments the BlockNum of a PageId or BlockId. | |
template<class PageOrBlockId> | |
static void | decBlockNum (PageOrBlockId &pageId) |
Decrements the BlockNum of a PageId or BlockId. | |
template<class PageOrBlockId> | |
static DeviceId | getDeviceId (PageOrBlockId pageId) |
Extracts the DeviceId from a PageId or BlockId. | |
template<class PageOrBlockId> | |
static void | setDeviceId (PageOrBlockId &pageId, DeviceId deviceId) |
Sets just the DeviceId of a PageId or BlockId. | |
static PageId | getPageId (SegByteId segByteId) |
Extracts the PageId component of a SegByteId. | |
static void | setPageId (SegByteId &segByteId, PageId pageId) |
Sets the PageId component of a SegByteId. | |
static uint | getByteOffset (SegByteId segByteId) |
Extracts the byte offset component of a SegByteId. | |
static void | setByteOffset (SegByteId &segByteId, uint offset) |
Sets the byte offset component of a SegByteId. | |
static int | comparePageIds (PageId p1, PageId p2) |
Compares two PageIds. | |
static int | compareSegByteIds (SegByteId t1, SegByteId t2) |
Compares two SegByteIds. | |
static uint | getMaxDeviceCount () |
| |
Static Public Attributes | |
static const uint | MAX_DEVICES = 0x1000 |
Maximum number of devices, based on mask sizes. | |
static const uint | MAX_BYTE_OFFSET = 0xFFFFF |
Maximum byte offset on a page. | |
Static Private Attributes | |
static const uint64_t | DEVICE_ID_MASK = 0xFFF0000000000000ULL |
static const uint64_t | BYTE_OFFSET_MASK = 0x000FFFFF00000000ULL |
static const uint64_t | BLOCK_NUM_MASK = 0x00000000FFFFFFFFULL |
static const uint | DEVICE_ID_SHIFT = 52 |
Number of bits to right-shift a masked PageId to extract the DeviceId. | |
static const uint | BYTE_OFFSET_SHIFT = 32 |
Number of bits to right-shift a masked PageId to extract the BlockNum. |
These ID's are encoded into 64-bit integers representing logical or physical storage locations as follows:
MSB [ 12-bit DeviceId : 20-bit byte offset: 32-bit BlockNum ] LSB *
where DeviceId is the ID of some cached device, BlockNum is the block number of some block within that device (actual offset is determined by the device type and block size), and the byte offset is a 0-based byte location within that block.
The bit arrangement above allows for page sizes up to 1M. Combined with a 32-bit BlockNum, this allows a device size up to 4 petabytes. It also optimizes for translation between PageId and BlockId, rather than for byte offset access. The main justification is that PageId/BlockId translation has to occur for every page accessed, and in many cases the byte offset may not even be used. However, this means that SegByteId should only be used as a means of compact persistent representation; any time significant byte offset arithmetic has to be done, the byte offset should be manipulated as a separate uint.
TODO: autoconf support for parameterizing the CompoundId representation, since one size may not fit all. Also, could use architecture-dependent code for speeding up the accessors.
For a PageId or BlockId, the byte offset portion is always 0 (except for NULL_PAGE_ID and NULL_BLOCK_ID).
Definition at line 72 of file CompoundId.h.
static BlockNum CompoundId::getBlockNum | ( | PageOrBlockId | pageId | ) | [inline, static] |
Extracts the BlockNum from a PageId or BlockId.
pageId | the PageId or BlockId to access |
Definition at line 108 of file CompoundId.h.
References opaqueToInt().
Referenced by SegPageBackupRestoreDevice::backupPage(), LinearDeviceSegment::getAvailableDevicePages(), CacheImpl< PageT, VictimPolicyT >::getPageOffset(), ScratchSegment::lockPage(), SegPageBackupRestoreDevice::restorePage(), ScratchSegment::translateBlockId(), LinearDeviceSegment::translateBlockId(), and LinearDeviceSegment::translatePageId().
00109 { 00110 return (opaqueToInt(pageId) & BLOCK_NUM_MASK); 00111 }
static void CompoundId::setBlockNum | ( | PageOrBlockId & | pageId, | |
BlockNum | blockNum | |||
) | [inline, static] |
Sets just the BlockNum of a PageId or BlockId.
pageId | the PageId or BlockId to modify | |
blockNum | the new BlockNum to set |
Definition at line 121 of file CompoundId.h.
References opaqueToInt().
Referenced by Database::allocateHeader(), Database::createDataSegment(), SegStorageTestBase::createLinearDeviceSegment(), Database::createShadowLog(), Database::createTempSegment(), Database::createTxnLogSegment(), Database::loadHeader(), CacheImpl< PageT, VictimPolicyT >::lockScratchPage(), CacheTest::makeBlockId(), SegmentFactory::newTempDeviceSegment(), SparseBitmapTest::openStorage(), ScratchSegment::translatePageId(), and LinearDeviceSegment::translatePageId().
00122 { 00123 assert(blockNum == (blockNum & BLOCK_NUM_MASK)); 00124 pageId = PageOrBlockId( 00125 (opaqueToInt(pageId) & DEVICE_ID_MASK) | blockNum); 00126 }
static void CompoundId::incBlockNum | ( | PageOrBlockId & | pageId | ) | [inline, static] |
Increments the BlockNum of a PageId or BlockId.
pageId | the PageId or BlockId to modify |
Definition at line 134 of file CompoundId.h.
Referenced by CacheImpl< PageT, VictimPolicyT >::prefetchBatch().
00135 { 00136 setBlockNum(pageId,getBlockNum(pageId) + 1); 00137 }
static void CompoundId::decBlockNum | ( | PageOrBlockId & | pageId | ) | [inline, static] |
Decrements the BlockNum of a PageId or BlockId.
pageId | the PageId or BlockId to modify |
Definition at line 145 of file CompoundId.h.
Referenced by LogicalTxnLog::deallocateCheckpointedLog().
00146 { 00147 setBlockNum(pageId,getBlockNum(pageId) - 1); 00148 }
static DeviceId CompoundId::getDeviceId | ( | PageOrBlockId | pageId | ) | [inline, static] |
Extracts the DeviceId from a PageId or BlockId.
pageId | the PageId or BlockId to access |
Definition at line 158 of file CompoundId.h.
References opaqueToInt().
Referenced by LinearDeviceSegment::getDeviceId(), CachePage::isScratchLocked(), ScratchSegment::lockPage(), CacheImpl< PageT, VictimPolicyT >::lockPage(), CacheImpl< PageT, VictimPolicyT >::mapPage(), DeviceIdPagePredicate::operator()(), CacheImpl< PageT, VictimPolicyT >::prefetchBatch(), CacheImpl< PageT, VictimPolicyT >::transferPageAsync(), and CacheImpl< PageT, VictimPolicyT >::unlockPage().
00159 { 00160 return DeviceId( 00161 (opaqueToInt(pageId) & DEVICE_ID_MASK) >> DEVICE_ID_SHIFT); 00162 }
static void CompoundId::setDeviceId | ( | PageOrBlockId & | pageId, | |
DeviceId | deviceId | |||
) | [inline, static] |
Sets just the DeviceId of a PageId or BlockId.
pageId | the PageId or BlockId to modify | |
deviceId | the new DeviceId to set |
Definition at line 172 of file CompoundId.h.
References opaqueToInt().
Referenced by Database::allocateHeader(), Database::createDataSegment(), SegStorageTestBase::createLinearDeviceSegment(), Database::createShadowLog(), Database::createTempSegment(), Database::createTxnLogSegment(), Database::loadHeader(), CacheImpl< PageT, VictimPolicyT >::lockScratchPage(), CacheTest::makeBlockId(), SegmentFactory::newTempDeviceSegment(), SparseBitmapTest::openStorage(), and ScratchSegment::translatePageId().
00173 { 00174 assert(opaqueToInt(deviceId) < MAX_DEVICES); 00175 pageId = PageOrBlockId( 00176 (uint64_t(opaqueToInt(deviceId)) << DEVICE_ID_SHIFT) 00177 | getBlockNum(pageId)); 00178 }
static PageId CompoundId::getPageId | ( | SegByteId | segByteId | ) | [inline, static] |
Extracts the PageId component of a SegByteId.
segByteId | the SegByteId to access |
Definition at line 187 of file CompoundId.h.
References opaqueToInt().
Referenced by LogicalTxnLog::commitTxnWithGroup(), LogicalTxnLog::deallocateCheckpointedLog(), Database::recover(), and SegInputStream::seekSegPos().
00188 { 00189 return PageId(opaqueToInt(segByteId) & ~BYTE_OFFSET_MASK); 00190 }
static void CompoundId::setPageId | ( | SegByteId & | segByteId, | |
PageId | pageId | |||
) | [inline, static] |
Sets the PageId component of a SegByteId.
segByteId | the SegByteId to modify | |
pageId | the new PageId to set |
Definition at line 199 of file CompoundId.h.
References opaqueToInt().
Referenced by LogicalTxnLog::commitTxn(), SegOutputStream::getSegPos(), SegInputStream::getSegPos(), and LogicalTxnLog::rollbackTxn().
00200 { 00201 segByteId = SegByteId( 00202 opaqueToInt(pageId) 00203 | (opaqueToInt(segByteId) & BYTE_OFFSET_MASK)); 00204 }
static uint CompoundId::getByteOffset | ( | SegByteId | segByteId | ) | [inline, static] |
Extracts the byte offset component of a SegByteId.
segByteId | the SegByteId to access |
Definition at line 213 of file CompoundId.h.
References opaqueToInt().
Referenced by SegInputStream::seekSegPos().
00214 { 00215 return (opaqueToInt(segByteId) & BYTE_OFFSET_MASK) >> BYTE_OFFSET_SHIFT; 00216 }
static void CompoundId::setByteOffset | ( | SegByteId & | segByteId, | |
uint | offset | |||
) | [inline, static] |
Sets the byte offset component of a SegByteId.
segByteId | the SegByteId to modify | |
offset | the new byte offset to set |
Definition at line 225 of file CompoundId.h.
References opaqueToInt().
Referenced by LogicalTxnLog::commitTxn(), SegOutputStream::getSegPos(), SegInputStream::getSegPos(), and LogicalTxnLog::rollbackTxn().
00226 { 00227 assert(offset == (offset & (BYTE_OFFSET_MASK >> BYTE_OFFSET_SHIFT))); 00228 segByteId = SegByteId( 00229 opaqueToInt(getPageId(segByteId)) 00230 | (SegByteIdPrimitive(offset) << BYTE_OFFSET_SHIFT)); 00231 }
static int CompoundId::comparePageIds | ( | PageId | p1, | |
PageId | p2 | |||
) | [inline, static] |
Compares two PageIds.
p1 | first PageId to compare | |
p2 | second PageId to compare |
Definition at line 243 of file CompoundId.h.
static int CompoundId::compareSegByteIds | ( | SegByteId | t1, | |
SegByteId | t2 | |||
) | [inline, static] |
Compares two SegByteIds.
t1 | first SegByteId to compare | |
t2 | second SegByteId to compare |
Definition at line 259 of file CompoundId.h.
static uint CompoundId::getMaxDeviceCount | ( | ) | [inline, static] |
Definition at line 269 of file CompoundId.h.
00270 { 00271 return MAX_DEVICES; 00272 }
const uint64_t CompoundId::DEVICE_ID_MASK = 0xFFF0000000000000ULL [static, private] |
Definition at line 75 of file CompoundId.h.
const uint64_t CompoundId::BYTE_OFFSET_MASK = 0x000FFFFF00000000ULL [static, private] |
Definition at line 76 of file CompoundId.h.
const uint64_t CompoundId::BLOCK_NUM_MASK = 0x00000000FFFFFFFFULL [static, private] |
Definition at line 77 of file CompoundId.h.
const uint CompoundId::DEVICE_ID_SHIFT = 52 [static, private] |
Number of bits to right-shift a masked PageId to extract the DeviceId.
Definition at line 82 of file CompoundId.h.
const uint CompoundId::BYTE_OFFSET_SHIFT = 32 [static, private] |
Number of bits to right-shift a masked PageId to extract the BlockNum.
Definition at line 87 of file CompoundId.h.
const uint CompoundId::MAX_DEVICES = 0x1000 [static] |
const uint CompoundId::MAX_BYTE_OFFSET = 0xFFFFF [static] |
Maximum byte offset on a page.
Definition at line 98 of file CompoundId.h.
Referenced by SegOutputStream::getSegPos(), and SegInputStream::seekSegPos().