Header And Logo

PostgreSQL
| The world's most advanced open source database.

fsm_internals.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * fsm_internal.h
00004  *    internal functions for free space map
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/fsm_internals.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef FSM_INTERNALS_H
00015 #define FSM_INTERNALS_H
00016 
00017 #include "storage/buf.h"
00018 #include "storage/bufpage.h"
00019 
00020 /*
00021  * Structure of a FSM page. See src/backend/storage/freespace/README for
00022  * details.
00023  */
00024 typedef struct
00025 {
00026     /*
00027      * fsm_search_avail() tries to spread the load of multiple backends by
00028      * returning different pages to different backends in a round-robin
00029      * fashion. fp_next_slot points to the next slot to be returned (assuming
00030      * there's enough space on it for the request). It's defined as an int,
00031      * because it's updated without an exclusive lock. uint16 would be more
00032      * appropriate, but int is more likely to be atomically
00033      * fetchable/storable.
00034      */
00035     int         fp_next_slot;
00036 
00037     /*
00038      * fp_nodes contains the binary tree, stored in array. The first
00039      * NonLeafNodesPerPage elements are upper nodes, and the following
00040      * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero.
00041      */
00042     uint8       fp_nodes[1];
00043 } FSMPageData;
00044 
00045 typedef FSMPageData *FSMPage;
00046 
00047 /*
00048  * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page.
00049  * These definitions are internal to fsmpage.c.
00050  */
00051 #define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
00052                       offsetof(FSMPageData, fp_nodes))
00053 
00054 #define NonLeafNodesPerPage (BLCKSZ / 2 - 1)
00055 #define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage)
00056 
00057 /*
00058  * Number of FSM "slots" on a FSM page. This is what should be used
00059  * outside fsmpage.c.
00060  */
00061 #define SlotsPerFSMPage LeafNodesPerPage
00062 
00063 /* Prototypes for functions in fsmpage.c */
00064 extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext,
00065                  bool exclusive_lock_held);
00066 extern uint8 fsm_get_avail(Page page, int slot);
00067 extern uint8 fsm_get_max_avail(Page page);
00068 extern bool fsm_set_avail(Page page, int slot, uint8 value);
00069 extern bool fsm_truncate_avail(Page page, int nslots);
00070 extern bool fsm_rebuild_page(Page page);
00071 
00072 #endif   /* FSM_INTERNALS_H */