PostgreSQL Source Code git master
Loading...
Searching...
No Matches
spccache.c File Reference
#include "postgres.h"
#include "access/reloptions.h"
#include "catalog/pg_tablespace.h"
#include "commands/tablespace.h"
#include "miscadmin.h"
#include "optimizer/optimizer.h"
#include "storage/bufmgr.h"
#include "utils/catcache.h"
#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/spccache.h"
#include "utils/syscache.h"
#include "varatt.h"
Include dependency graph for spccache.c:

Go to the source code of this file.

Data Structures

struct  TableSpaceCacheEntry
 

Functions

static void InvalidateTableSpaceCacheCallback (Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
 
static void InitializeTableSpaceCache (void)
 
static TableSpaceCacheEntryget_tablespace (Oid spcid)
 
void get_tablespace_page_costs (Oid spcid, double *spc_random_page_cost, double *spc_seq_page_cost)
 
int get_tablespace_io_concurrency (Oid spcid)
 
int get_tablespace_maintenance_io_concurrency (Oid spcid)
 

Variables

static HTABTableSpaceCacheHash = NULL
 

Function Documentation

◆ get_tablespace()

static TableSpaceCacheEntry * get_tablespace ( Oid  spcid)
static

Definition at line 108 of file spccache.c.

109{
111 HeapTuple tp;
113
114 /*
115 * Since spcid is always from a pg_class tuple, InvalidOid implies the
116 * default.
117 */
118 if (spcid == InvalidOid)
120
121 /* Find existing cache entry, if any. */
125 &spcid,
126 HASH_FIND,
127 NULL);
128 if (spc)
129 return spc;
130
131 /*
132 * Not found in TableSpace cache. Check catcache. If we don't find a
133 * valid HeapTuple, it must mean someone has managed to request tablespace
134 * details for a non-existent tablespace. We'll just treat that case as
135 * if no options were specified.
136 */
138 if (!HeapTupleIsValid(tp))
139 opts = NULL;
140 else
141 {
142 Datum datum;
143 bool isNull;
144
146 tp,
148 &isNull);
149 if (isNull)
150 opts = NULL;
151 else
152 {
153 bytea *bytea_opts = tablespace_reloptions(datum, false);
154
157 }
158 ReleaseSysCache(tp);
159 }
160
161 /*
162 * Now create the cache entry. It's important to do this only after
163 * reading the pg_tablespace entry, since doing so could cause a cache
164 * flush.
165 */
167 &spcid,
169 NULL);
170 spc->opts = opts;
171 return spc;
172}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
Oid MyDatabaseTableSpace
Definition globals.c:96
@ HASH_FIND
Definition hsearch.h:113
@ HASH_ENTER
Definition hsearch.h:114
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
MemoryContext CacheMemoryContext
Definition mcxt.c:169
static AmcheckOptions opts
Definition pg_amcheck.c:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
#define InvalidOid
static int fb(int x)
bytea * tablespace_reloptions(Datum reloptions, bool validate)
static void InitializeTableSpaceCache(void)
Definition spccache.c:79
static HTAB * TableSpaceCacheHash
Definition spccache.c:36
Definition c.h:718
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
static Size VARSIZE(const void *PTR)
Definition varatt.h:298

References CacheMemoryContext, fb(), HASH_ENTER, HASH_FIND, hash_search(), HeapTupleIsValid, InitializeTableSpaceCache(), InvalidOid, MemoryContextAlloc(), MyDatabaseTableSpace, ObjectIdGetDatum(), opts, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), tablespace_reloptions(), TableSpaceCacheHash, and VARSIZE().

Referenced by get_tablespace_io_concurrency(), get_tablespace_maintenance_io_concurrency(), and get_tablespace_page_costs().

◆ get_tablespace_io_concurrency()

int get_tablespace_io_concurrency ( Oid  spcid)

Definition at line 216 of file spccache.c.

217{
219
220 if (!spc->opts || spc->opts->effective_io_concurrency < 0)
222 else
223 return spc->opts->effective_io_concurrency;
224}
int effective_io_concurrency
Definition bufmgr.c:185
static TableSpaceCacheEntry * get_tablespace(Oid spcid)
Definition spccache.c:108

References effective_io_concurrency, fb(), and get_tablespace().

Referenced by read_stream_begin_impl().

◆ get_tablespace_maintenance_io_concurrency()

int get_tablespace_maintenance_io_concurrency ( Oid  spcid)

Definition at line 230 of file spccache.c.

231{
233
234 if (!spc->opts || spc->opts->maintenance_io_concurrency < 0)
236 else
237 return spc->opts->maintenance_io_concurrency;
238}
int maintenance_io_concurrency
Definition bufmgr.c:192

References fb(), get_tablespace(), and maintenance_io_concurrency.

Referenced by heap_index_delete_tuples(), and read_stream_begin_impl().

◆ get_tablespace_page_costs()

void get_tablespace_page_costs ( Oid  spcid,
double spc_random_page_cost,
double spc_seq_page_cost 
)

Definition at line 183 of file spccache.c.

186{
188
189 Assert(spc != NULL);
190
191 if (spc_random_page_cost)
192 {
193 if (!spc->opts || spc->opts->random_page_cost < 0)
194 *spc_random_page_cost = random_page_cost;
195 else
196 *spc_random_page_cost = spc->opts->random_page_cost;
197 }
198
200 {
201 if (!spc->opts || spc->opts->seq_page_cost < 0)
203 else
204 *spc_seq_page_cost = spc->opts->seq_page_cost;
205 }
206}
#define Assert(condition)
Definition c.h:885
double random_page_cost
Definition costsize.c:131
double seq_page_cost
Definition costsize.c:130

References Assert, fb(), get_tablespace(), random_page_cost, and seq_page_cost.

Referenced by brincostestimate(), cost_bitmap_heap_scan(), cost_index(), cost_samplescan(), cost_seqscan(), cost_tidrangescan(), cost_tidscan(), genericcostestimate(), gincostestimate(), and system_time_samplescangetsamplesize().

◆ InitializeTableSpaceCache()

static void InitializeTableSpaceCache ( void  )
static

Definition at line 79 of file spccache.c.

80{
82
83 /* Initialize the hash table. */
84 ctl.keysize = sizeof(Oid);
85 ctl.entrysize = sizeof(TableSpaceCacheEntry);
87 hash_create("TableSpace cache", 16, &ctl,
89
90 /* Make sure we've initialized CacheMemoryContext. */
93
94 /* Watch for invalidation events. */
97 (Datum) 0);
98}
void CreateCacheMemoryContext(void)
Definition catcache.c:715
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:358
#define HASH_ELEM
Definition hsearch.h:95
#define HASH_BLOBS
Definition hsearch.h:97
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
unsigned int Oid
tree ctl
Definition radixtree.h:1838
static void InvalidateTableSpaceCacheCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition spccache.c:55
Size keysize
Definition hsearch.h:75

References CacheMemoryContext, CacheRegisterSyscacheCallback(), CreateCacheMemoryContext(), ctl, fb(), HASH_BLOBS, hash_create(), HASH_ELEM, InvalidateTableSpaceCacheCallback(), HASHCTL::keysize, and TableSpaceCacheHash.

Referenced by get_tablespace().

◆ InvalidateTableSpaceCacheCallback()

static void InvalidateTableSpaceCacheCallback ( Datum  arg,
SysCacheIdentifier  cacheid,
uint32  hashvalue 
)
static

Definition at line 55 of file spccache.c.

57{
58 HASH_SEQ_STATUS status;
60
62 while ((spc = (TableSpaceCacheEntry *) hash_seq_search(&status)) != NULL)
63 {
64 if (spc->opts)
65 pfree(spc->opts);
67 &spc->oid,
69 NULL) == NULL)
70 elog(ERROR, "hash table corrupted");
71 }
72}
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition dynahash.c:1415
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition dynahash.c:1380
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
@ HASH_REMOVE
Definition hsearch.h:115
void pfree(void *pointer)
Definition mcxt.c:1616

References elog, ERROR, fb(), HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), pfree(), and TableSpaceCacheHash.

Referenced by InitializeTableSpaceCache().

Variable Documentation

◆ TableSpaceCacheHash

HTAB* TableSpaceCacheHash = NULL
static