MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TranxNodeAllocator Class Reference

#include <semisync_master.h>

Classes

struct  Block

Public Member Functions

 TranxNodeAllocator (uint reserved_nodes)
TranxNodeallocate_node ()
int free_all_nodes ()
int free_nodes_before (TranxNode *node)

Detailed Description

This class provides memory allocating and freeing methods for TranxNode. The main target is performance.

How to allocate a node

The pointer of the first node after 'last_node' in current_block is returned. current_block will move to the next free Block when all nodes of it are in use. A new Block is allocated and is put into the rear of the Block link table if no Block is free.

The list starts up empty (ie, there is no allocated Block).

After some nodes are freed, there probably are some free nodes before the sequence of the allocated nodes, but we do not reuse it. It is better to keep the allocated nodes are in the sequence, for it is more efficient for allocating and freeing TranxNode.

How to free nodes

There are two methods for freeing nodes. They are free_all_nodes and free_nodes_before.

'A Block is free' means all of its nodes are free.

free_nodes_before

As all allocated nodes are in the sequence, 'Before one node' means all nodes before given node in the same Block and all Blocks before the Block which containing the given node. As such, all Blocks before the given one ('node') are free Block and moved into the rear of the Block link table. The Block containing the given 'node', however, is not. For at least the given 'node' is still in use. This will waste at most one Block, but it is more efficient.

Definition at line 72 of file semisync_master.h.

Constructor & Destructor Documentation

TranxNodeAllocator::TranxNodeAllocator ( uint  reserved_nodes)
inline
Parameters
reserved_nodesThe number of reserved TranxNodes. It is used to set 'reserved_blocks' which can contain at least 'reserved_nodes' number of TranxNodes. When freeing memory, we will reserve at least reserved_blocks of Blocks not freed.

Definition at line 82 of file semisync_master.h.

Member Function Documentation

TranxNode* TranxNodeAllocator::allocate_node ( )
inline

The pointer of the first node after 'last_node' in current_block is returned. current_block will move to the next free Block when all nodes of it are in use. A new Block is allocated and is put into the rear of the Block link table if no Block is free.

Returns
Return a TranxNode *, or NULL if an error occured.

Definition at line 107 of file semisync_master.h.

int TranxNodeAllocator::free_all_nodes ( )
inline

All nodes are freed.

Returns
Return 0, or 1 if an error occured.

Definition at line 139 of file semisync_master.h.

int TranxNodeAllocator::free_nodes_before ( TranxNode node)
inline

All Blocks before the given 'node' are free Block and moved into the rear of the Block link table.

Parameters
nodeAll nodes before 'node' will be freed
Returns
Return 0, or 1 if an error occured.

Definition at line 155 of file semisync_master.h.


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