~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

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

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * sinval.h
 
4
 *        POSTGRES shared cache invalidation communication definitions.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.40 2005-01-10 21:57:19 tgl Exp $
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef SINVAL_H
 
15
#define SINVAL_H
 
16
 
 
17
#include "storage/backendid.h"
 
18
#include "storage/itemptr.h"
 
19
#include "storage/relfilenode.h"
 
20
 
 
21
 
 
22
/*
 
23
 * We currently support three types of shared-invalidation messages: one that
 
24
 * invalidates an entry in a catcache, one that invalidates a relcache entry,
 
25
 * and one that invalidates an smgr cache entry.  More types could be added
 
26
 * if needed.  The message type is identified by the first "int16" field of
 
27
 * the message struct.  Zero or positive means a catcache inval message (and
 
28
 * also serves as the catcache ID field).  -1 means a relcache inval message.
 
29
 * -2 means an smgr inval message.  Other negative values are available to
 
30
 * identify other inval message types.
 
31
 *
 
32
 * Catcache inval events are initially driven by detecting tuple inserts,
 
33
 * updates and deletions in system catalogs (see CacheInvalidateHeapTuple).
 
34
 * An update generates two inval events, one for the old tuple and one for
 
35
 * the new --- this is needed to get rid of both positive entries for the
 
36
 * old tuple, and negative cache entries associated with the new tuple's
 
37
 * cache key.  (This could perhaps be optimized down to one event when the
 
38
 * cache key is not changing, but for now we don't bother to try.)  Note that
 
39
 * the inval events themselves don't actually say whether the tuple is being
 
40
 * inserted or deleted.
 
41
 *
 
42
 * Note that some system catalogs have multiple caches on them (with different
 
43
 * indexes).  On detecting a tuple invalidation in such a catalog, separate
 
44
 * catcache inval messages must be generated for each of its caches.  The
 
45
 * catcache inval messages carry the hash value for the target tuple, so
 
46
 * that the catcache only needs to search one hash chain not all its chains,
 
47
 * and so that negative cache entries can be recognized with good accuracy.
 
48
 * (Of course this assumes that all the backends are using identical hashing
 
49
 * code, but that should be OK.)
 
50
 */
 
51
 
 
52
typedef struct
 
53
{
 
54
        /* note: field layout chosen with an eye to alignment concerns */
 
55
        int16           id;                             /* cache ID --- must be first */
 
56
        ItemPointerData tuplePtr;       /* tuple identifier in cached relation */
 
57
        Oid                     dbId;                   /* database ID, or 0 if a shared relation */
 
58
        uint32          hashValue;              /* hash value of key for this catcache */
 
59
} SharedInvalCatcacheMsg;
 
60
 
 
61
#define SHAREDINVALRELCACHE_ID  (-1)
 
62
 
 
63
typedef struct
 
64
{
 
65
        int16           id;                             /* type field --- must be first */
 
66
        Oid                     dbId;                   /* database ID, or 0 if a shared relation */
 
67
        Oid                     relId;                  /* relation ID */
 
68
} SharedInvalRelcacheMsg;
 
69
 
 
70
#define SHAREDINVALSMGR_ID              (-2)
 
71
 
 
72
typedef struct
 
73
{
 
74
        int16           id;                             /* type field --- must be first */
 
75
        RelFileNode rnode;                      /* physical file ID */
 
76
} SharedInvalSmgrMsg;
 
77
 
 
78
typedef union
 
79
{
 
80
        int16           id;                             /* type field --- must be first */
 
81
        SharedInvalCatcacheMsg cc;
 
82
        SharedInvalRelcacheMsg rc;
 
83
        SharedInvalSmgrMsg sm;
 
84
} SharedInvalidationMessage;
 
85
 
 
86
 
 
87
extern int      SInvalShmemSize(int maxBackends);
 
88
extern void CreateSharedInvalidationState(int maxBackends);
 
89
extern void InitBackendSharedInvalidationState(void);
 
90
extern void SendSharedInvalidMessage(SharedInvalidationMessage *msg);
 
91
extern void ReceiveSharedInvalidMessages(
 
92
                                  void (*invalFunction) (SharedInvalidationMessage *msg),
 
93
                                                         void (*resetFunction) (void));
 
94
 
 
95
extern bool DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself);
 
96
extern bool TransactionIdIsInProgress(TransactionId xid);
 
97
extern bool IsBackendPid(int pid);
 
98
extern TransactionId GetOldestXmin(bool allDbs);
 
99
extern int      CountActiveBackends(void);
 
100
extern int      CountEmptyBackendSlots(void);
 
101
 
 
102
/* Use "struct PGPROC", not PGPROC, to avoid including proc.h here */
 
103
extern struct PGPROC *BackendIdGetProc(BackendId procId);
 
104
 
 
105
extern void XidCacheRemoveRunningXids(TransactionId xid,
 
106
                                                  int nxids, TransactionId *xids);
 
107
 
 
108
/* signal handler for catchup events (SIGUSR1) */
 
109
extern void CatchupInterruptHandler(SIGNAL_ARGS);
 
110
 
 
111
/*
 
112
 * enable/disable processing of catchup events directly from signal handler.
 
113
 * The enable routine first performs processing of any catchup events that
 
114
 * have occurred since the last disable.
 
115
 */
 
116
extern void EnableCatchupInterrupt(void);
 
117
extern bool DisableCatchupInterrupt(void);
 
118
 
 
119
#endif   /* SINVAL_H */