Zero  0.1.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Static Private Member Functions | Private Attributes | Friends | List of all members
lsn_t Class Reference

Log Sequence Number. See Log Sequence Numbers (LSN). More...

#include <lsn.h>

Inheritance diagram for lsn_t:
sm_save_point_t

Public Types

enum  { PARTITION_BITS = 16 }
 
enum  { PARTITION_SHIFT = (64 - PARTITION_BITS) }
 

Public Member Functions

 lsn_t ()
 
 lsn_t (lsndata_t data)
 
 lsn_t (uint32_t f, sm_diskaddr_t r)
 
lsndata_t data () const
 
void set (lsndata_t data)
 
bool valid () const
 
uint32_t hi () const
 
uint32_t file () const
 
sm_diskaddr_t lo () const
 
sm_diskaddr_t rba () const
 
void copy_rba (const lsn_t &other)
 
void set_rba (sm_diskaddr_t &other)
 
lsn_tadvance (int amt)
 
lsn_toperator+= (long delta)
 
lsn_t operator+ (long delta) const
 
bool operator> (const lsn_t &l) const
 
bool operator< (const lsn_t &l) const
 
bool operator>= (const lsn_t &l) const
 
bool operator<= (const lsn_t &l) const
 
bool operator== (const lsn_t &l) const
 
bool operator!= (const lsn_t &l) const
 
std::string str ()
 
bool is_null () const
 

Static Public Member Functions

static uint64_t mask ()
 

Static Public Attributes

static const int sm_diskaddr_max
 
static const lsn_t null
 
static const lsn_t max
 

Private Types

enum  { file_hwm = 0xffff }
 

Static Private Member Functions

static uint32_t to_file (uint64_t f)
 
static uint64_t get_file (uint64_t data)
 
static uint64_t from_file (uint32_t data)
 
static sm_diskaddr_t to_rba (uint64_t r)
 
static uint64_t get_rba (uint64_t data)
 
static uint64_t from_rba (sm_diskaddr_t data)
 

Private Attributes

lsndata_t _data
 

Friends

std::ostream & operator<< (std::ostream &, const lsn_t &)
 

Detailed Description

Log Sequence Number. See Log Sequence Numbers (LSN).

A log sequence number points to a record in the log. It consists of two parts:

All state is stored in a single 64-bit value. This reading or setting is atomic on 64-bit platforms (though updates still need protection).

Warning
This is NOT atomic on 32-bit platforms.

Because all state fits in 64 bits, there is a trade-off between maximum supported log partition size and number of partitions. Two reasonable choices are:

48-bit offsets are larger, but (slightly) more expensive and likely to wrap sooner. 32-bit offsets are still pretty big, and the chance of wrapping is much smaller (though a production system could theoretically hit the limit, since the count persists as long as the database exists. For now we go with the 32-32 split.

lsn_t no longer cares whether the disk can handle the full range it supports. If you support 48-bit partition sizes and the disk can only handle 32-bit offsets, the largest file will just happen to be smaller than lsn_t technically supports.

lsn_t does not cater to unaligned accesses. Log writes, in particular, are expected to be 8-byte aligned. The extra wasted bytes just aren't worth the performance hit of allowing misalignment.

Note
Once the database runs long enough we will run out of partition numbers (only 64k possible). Fortunately, this is a log, so lsn_t don't last forever. Eventually things become durable and the log partition file gets reclaimed (deleted). As long as the first partition is gone before the last one fills, we can simply wrap and change the sense of lsn_t comparisions.

Member Enumeration Documentation

§ anonymous enum

anonymous enum
private
Enumerator
file_hwm 

§ anonymous enum

anonymous enum
Enumerator
PARTITION_BITS 

§ anonymous enum

anonymous enum
Enumerator
PARTITION_SHIFT 

Constructor & Destructor Documentation

§ lsn_t() [1/3]

lsn_t::lsn_t ( )
inline

§ lsn_t() [2/3]

lsn_t::lsn_t ( lsndata_t  data)
inline

§ lsn_t() [3/3]

lsn_t::lsn_t ( uint32_t  f,
sm_diskaddr_t  r 
)
inline

Member Function Documentation

§ advance()

lsn_t& lsn_t::advance ( int  amt)
inline

§ copy_rba()

void lsn_t::copy_rba ( const lsn_t other)
inline

§ data()

lsndata_t lsn_t::data ( ) const
inline

§ file()

uint32_t lsn_t::file ( ) const
inline

§ from_file()

static uint64_t lsn_t::from_file ( uint32_t  data)
inlinestaticprivate

§ from_rba()

static uint64_t lsn_t::from_rba ( sm_diskaddr_t  data)
inlinestaticprivate

§ get_file()

static uint64_t lsn_t::get_file ( uint64_t  data)
inlinestaticprivate

§ get_rba()

static uint64_t lsn_t::get_rba ( uint64_t  data)
inlinestaticprivate

§ hi()

uint32_t lsn_t::hi ( ) const
inline

§ is_null()

bool lsn_t::is_null ( ) const
inline

§ lo()

sm_diskaddr_t lsn_t::lo ( ) const
inline

§ mask()

static uint64_t lsn_t::mask ( )
inlinestatic

§ operator!=()

bool lsn_t::operator!= ( const lsn_t l) const
inline

§ operator+()

lsn_t lsn_t::operator+ ( long  delta) const
inline

§ operator+=()

lsn_t& lsn_t::operator+= ( long  delta)
inline

§ operator<()

bool lsn_t::operator< ( const lsn_t l) const
inline

§ operator<=()

bool lsn_t::operator<= ( const lsn_t l) const
inline

§ operator==()

bool lsn_t::operator== ( const lsn_t l) const
inline

§ operator>()

bool lsn_t::operator> ( const lsn_t l) const
inline

§ operator>=()

bool lsn_t::operator>= ( const lsn_t l) const
inline

§ rba()

sm_diskaddr_t lsn_t::rba ( ) const
inline

§ set()

void lsn_t::set ( lsndata_t  data)
inline

§ set_rba()

void lsn_t::set_rba ( sm_diskaddr_t other)
inline

§ str()

std::string lsn_t::str ( )

§ to_file()

static uint32_t lsn_t::to_file ( uint64_t  f)
inlinestaticprivate

§ to_rba()

static sm_diskaddr_t lsn_t::to_rba ( uint64_t  r)
inlinestaticprivate

§ valid()

bool lsn_t::valid ( ) const
inline

Friends And Related Function Documentation

§ operator<<

std::ostream& operator<< ( std::ostream &  o,
const lsn_t l 
)
friend

Member Data Documentation

§ _data

lsndata_t lsn_t::_data
private

§ max

const lsn_t lsn_t::max
static

§ null

const lsn_t lsn_t::null
static

§ sm_diskaddr_max

const int lsn_t::sm_diskaddr_max
static

The documentation for this class was generated from the following files: