pin_i Class Reference
[Pinning Records]

Inherits smlevel_top.

Collaboration diagram for pin_i:

Collaboration graph
[legend]
List of all members.

Detailed Description

Pin records in the buffer pool and operate on them.

Certain operations on the records referenced by a pin_i may invalidate the pin_i. For example, if you pin a record, then truncate it or append to it while holding a pin_i, the pin_i must be considered invalidated because appending to the record might necessarily require moving it.

The pin functions take a lock mode parameter that tells the storage manager how to lock the record initially. The options are SH and EX. EX should be used when the pinned record will be updated (through update_rec, unpdate_rec_hdr, append_rec, or truncate_rec). Using EX in these cases will improve performance and reduce the risk of deadlock, but it is not necessary for correctness.

If you pin with SH, and subsequently modify the record through pin_i, the pin_i method(s) will upgrade locks as necessary to maintain ACID properties.

These methods will not perform needless unfix/refix operations: you may pin many small records on the same page in sequence and avoid unfixing the page between pins.

Examples:

create_rec.cpp, log_exceed.cpp, sort_stream.cpp, and vtable_example.cpp.

Definition at line 184 of file pin.h.

Public Member Functions

NORET pin_i ()
 Constructor. Does not pin anything until pin() is called.
NORET ~pin_i ()
 Destructor. Unpins anything currently pinned.
rc_t pin (const rid_t &rid, smsize_t start, lock_mode_t lmode=SH)
 Pin a portion of the record starting at a given location.
rc_t pin (const rid_t &rid, smsize_t start, lock_mode_t lock_mode, latch_mode_t latch_mode)
 Pin a portion of the record starting at a given location.
void unpin ()
 Unpin whatever record was pinned.
bool is_mine () const
 True if the running thread owns this pin_i.
void set_ref_bit (int value)
 Set the reference bit to use for the buffer frame containing the pinned body page when the page is unpinned.
rc_t repin (lock_mode_t lmode=SH)
 Efficiently repin a record after is size has changed or after it has been unpinned.
rc_t next_bytes (bool &eof)
 Pin the next range of bytes in the record.
bool pinned () const
 True if something currently pinned.
bool pinned_all () const
 True if the entire record pinned.
bool up_to_date () const
 True if record is pinned and the pin_i is valid.
smsize_t start_byte () const
 Return the byte-offset (within the record) the of the pinned portion.
smsize_t length () const
 Return the length of the pinned portion.
smsize_t hdr_size () const
 Return the size of the pinned record's header.
smsize_t body_size () const
 Return the size of the pinned record's body.
bool is_large () const
 True if the record is too large to fit on a file page.
bool is_small () const
 True if the record is small enough to fit on a file page.
int large_impl () const
 The kind of large-record implementation used for the pinned record.
const rid_t & rid () const
 Return the record ID of the pinned record.
const char * hdr () const
 Return a pointer to the pinned record's header in the buffer pool.
const char * body ()
 Return a pointer into the pinned-record-portion in the buffer pool.
rc_t update_rec (smsize_t start, const vec_t &data, int *old_value=0)
 Overwrite a portion of the pinned record with new data.
rc_t update_rec_hdr (smsize_t start, const vec_t &hdr)
 Update the pinned record's header.
rc_t append_rec (const vec_t &data)
 Append to a pinned record.
rc_t truncate_rec (smsize_t amount)
 Shorten a record.
const record_t * rec () const
const char * hdr_page_data ()
 Return a pointer to the page containing the record.
lpid_t page_containing (smsize_t offset, smsize_t &start_byte) const
 Return the ID of the page containing the given byte of the record.


Member Function Documentation

rc_t pin_i::pin ( const rid_t &  rid,
smsize_t  start,
lock_mode_t  lmode = SH 
)

Pin a portion of the record starting at a given location.

Parameters:
[in] rid ID of the record of interest
[in] start Offset of the first byte of interest.
[in] lmode Lock mode to use. Pin the page containing the first byte of interest. A record lock in the given mode is acquired (if it is not already subsumed by a coarser lock or by a higher lock mode).
Only the slotted page containing the record header is fixed at this point. Its latch mode is inferred from the lock mode. If any part of the record is pinned, the slotted page containing the header is also fixed. Thus, if the record is large (or very large), data pages won't be fixed in the buffer pool until the body() method is called.

rc_t pin_i::pin ( const rid_t &  rid,
smsize_t  start,
lock_mode_t  lock_mode,
latch_mode_t  latch_mode 
)

Pin a portion of the record starting at a given location.

Pin a record with the given lock mode and latch mode. See pin(rid, start, lock_mode);

void pin_i::set_ref_bit ( int  value  ) 

Set the reference bit to use for the buffer frame containing the pinned body page when the page is unpinned.

Parameters:
[in] value 0 or greater. A value of 0 is a "hate" hint indicating that the frame can be reused as soon as necessary. By default, a value of 1 is used indicating the page will be cached until at least 1 sweep of the buffer clock hand has passed. Higher values cause the page to remain cached longer.

rc_t pin_i::repin ( lock_mode_t  lmode = SH  ) 

Efficiently repin a record after is size has changed or after it has been unpinned.

Parameters:
[in] lmode SH or EX

rc_t pin_i::next_bytes ( bool &  eof  ) 

Pin the next range of bytes in the record.

Parameters:
[out] eof Set to true if there are no more bytes to pin. When eof is reached, the previously pinned range remains pinned.

bool pin_i::up_to_date (  )  const [inline]

True if record is pinned and the pin_i is valid.

The pin_i is valid if it is up-to-date with the LSN on the page. In other words, use this to verify that the page has not been updated since it was pinned by this pin_i

Definition at line 289 of file pin.h.

References pinned().

Here is the call graph for this function:

int pin_i::large_impl (  )  const [inline]

The kind of large-record implementation used for the pinned record.

Values returned are: 0, 1, or 2.

Definition at line 313 of file pin.h.

const char* pin_i::hdr (  )  const [inline]

Return a pointer to the pinned record's header in the buffer pool.

Attention:
Do NOT update anything directly in the buffer pool. This returns a const string because it is for the purpose of reading or copy-out.

Definition at line 324 of file pin.h.

References pinned().

Here is the call graph for this function:

const char* pin_i::body (  ) 

Return a pointer into the pinned-record-portion in the buffer pool.

Attention:
Do NOT update anything directly in the buffer pool. This returns a const string because it is for the purpose of reading or copy-out.

rc_t pin_i::update_rec ( smsize_t  start,
const vec_t data,
int *  old_value = 0 
)

Overwrite a portion of the pinned record with new data.

Parameters:
[in] start The offset from the beginning of the record of the place to perform the update.
[in] data A vector containing the data to place in the record at location start.
[out] old_value deprecated The portion of the record containing the start byte need not be pinned before this is called.

rc_t pin_i::update_rec_hdr ( smsize_t  start,
const vec_t hdr 
)

Update the pinned record's header.

Parameters:
[in] start The offset from the beginning of the header of the place to perform the update.
[in] hdr A vector containing the data to place in the header at location start.

rc_t pin_i::append_rec ( const vec_t data  ) 

Append to a pinned record.

Parameters:
[in] data A vector containing the data to append to the record's body. The end of the record need not be pinned before this is called.

rc_t pin_i::truncate_rec ( smsize_t  amount  ) 

Shorten a record.

Parameters:
[in] amount Number of bytes to chop off the end of the pinned record's body. The end of the record need not be pinned before this is called.

const char* pin_i::hdr_page_data (  ) 

Return a pointer to the page containing the record.

This allows you to read the entire page.

Attention:
Do NOT update anything directly in the buffer pool. This returns a const string because it is for the purpose of reading or copy-out.

lpid_t pin_i::page_containing ( smsize_t  offset,
smsize_t &  start_byte 
) const

Return the ID of the page containing the given byte of the record.

Parameters:
[in] offset The offset from the beginning of the record of the byte of interest
[out] start_byte The offset from the beginning of the page of the byte of interest
Returns:
The page ID of the page containing the byte of interest.


The documentation for this class was generated from the following file:
Generated on Wed Jul 7 17:22:43 2010 for Shore Storage Manager by  doxygen 1.4.7