~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/include/storage/fsm_internals.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * fsm_internal.h
 
4
 *        internal functions for free space map
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL$
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef FSM_INTERNALS_H
 
15
#define FSM_INTERNALS_H
 
16
 
 
17
#include "storage/buf.h"
 
18
#include "storage/bufpage.h"
 
19
#include "lib/stringinfo.h"
 
20
 
 
21
/*
 
22
 * Structure of a FSM page. See src/backend/storage/freespace/README for
 
23
 * details.
 
24
 */
 
25
typedef struct
 
26
{
 
27
        /*
 
28
         * fsm_search_avail() tries to spread the load of multiple backends
 
29
         * by returning different pages to different backends in a round-robin
 
30
         * fashion. fp_next_slot points to the next slot to be returned
 
31
         * (assuming there's enough space on it for the request). It's defined
 
32
         * as an int, because it's updated without an exclusive lock. uint16
 
33
         * would be more appropriate, but int is more likely to be atomically
 
34
         * fetchable/storable.
 
35
         */
 
36
        int fp_next_slot;
 
37
 
 
38
        /*
 
39
         * fp_nodes contains the binary tree, stored in array. The first
 
40
         * NonLeafNodesPerPage elements are upper nodes, and the following
 
41
         * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero.
 
42
         */
 
43
        uint8   fp_nodes[1];
 
44
} FSMPageData;
 
45
 
 
46
typedef FSMPageData *FSMPage;
 
47
 
 
48
/*
 
49
 * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page.
 
50
 * These definitions are internal to fsmpage.c.
 
51
 */
 
52
#define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
 
53
                                          offsetof(FSMPageData, fp_nodes))
 
54
 
 
55
#define NonLeafNodesPerPage (BLCKSZ / 2 - 1)
 
56
#define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage)
 
57
 
 
58
/*
 
59
 * Number of FSM "slots" on a FSM page. This is what should be used
 
60
 * outside fsmpage.c.
 
61
 */
 
62
#define SlotsPerFSMPage LeafNodesPerPage
 
63
 
 
64
/* Prototypes for functions in fsmpage.c */
 
65
extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext,
 
66
                                                        bool exclusive_lock_held);
 
67
extern uint8 fsm_get_avail(Page page, int slot);
 
68
extern uint8 fsm_get_max_avail(Page page);
 
69
extern bool fsm_set_avail(Page page, int slot, uint8 value);
 
70
extern bool fsm_truncate_avail(Page page, int nslots);
 
71
extern bool fsm_rebuild_page(Page page);
 
72
 
 
73
#endif   /* FSM_INTERNALS_H */