Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f7ecc0c

Browse files
committed
headers added
1 parent 5f40cb2 commit f7ecc0c

File tree

9 files changed

+148
-40
lines changed

9 files changed

+148
-40
lines changed

dsm_array.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* init.c
4+
* This module allocates large DSM segment to store arrays,
5+
* initializes it with block structure and provides functions to
6+
* allocate and free arrays
7+
*
8+
* Copyright (c) 2015-2016, Postgres Professional
9+
*
10+
* ------------------------------------------------------------------------
11+
*/
112
#include "pathman.h"
213
#include "storage/shmem.h"
314
#include "storage/dsm.h"
@@ -69,7 +80,7 @@ init_dsm_segment(size_t blocks_count, size_t block_size)
6980
bool ret;
7081

7182
/* lock here */
72-
LWLockAcquire(dsm_init_lock, LW_EXCLUSIVE);
83+
LWLockAcquire(pmstate->dsm_init_lock, LW_EXCLUSIVE);
7384

7485
/* if there is already an existing segment then attach to it */
7586
if (dsm_cfg->segment_handle != 0)
@@ -99,9 +110,8 @@ init_dsm_segment(size_t blocks_count, size_t block_size)
99110
* destroyed by the end of transaction
100111
*/
101112
dsm_pin_mapping(segment);
102-
103113
/* unlock here */
104-
LWLockRelease(dsm_init_lock);
114+
LWLockRelease(pmstate->dsm_init_lock);
105115

106116
return ret;
107117
}

hash.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* hash.sql
4+
* HASH partitioning functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
111
/*
212
* Creates hash partitions for specified relation
313
*/

init.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* init.c
4+
* Initialization functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
110
#include "pathman.h"
211
#include "miscadmin.h"
312
#include "executor/spi.h"
@@ -28,6 +37,33 @@ static int cmp_range_entries(const void *p1, const void *p2);
2837
void
2938
init_shmem_config()
3039
{
40+
bool found;
41+
42+
/* Check if module was initialized in postmaster */
43+
pmstate = ShmemInitStruct("pathman state", sizeof(PathmanState), &found);
44+
if (!found)
45+
{
46+
/*
47+
* Initialize locks in postmaster
48+
*/
49+
if (!IsUnderPostmaster)
50+
{
51+
/* Initialize locks */
52+
pmstate->load_config_lock = LWLockAssign();
53+
pmstate->dsm_init_lock = LWLockAssign();
54+
pmstate->edit_partitions_lock = LWLockAssign();
55+
}
56+
#ifdef WIN32
57+
else
58+
{
59+
elog(ERROR, "Pathman module must be initialized in postmaster. "
60+
"Put the following line to configuration file: "
61+
"shared_preload_libraries='pg_pathman'");
62+
initialization_needed = false;
63+
}
64+
#endif
65+
}
66+
3167
create_relations_hashtable();
3268
create_range_restrictions_hashtable();
3369
}
@@ -46,9 +82,9 @@ load_config(void)
4682
/* if config is not loaded */
4783
if (new_segment_created)
4884
{
49-
LWLockAcquire(load_config_lock, LW_EXCLUSIVE);
85+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
5086
load_relations_hashtable(new_segment_created);
51-
LWLockRelease(load_config_lock);
87+
LWLockRelease(pmstate->load_config_lock);
5288
}
5389
}
5490

@@ -195,8 +231,8 @@ create_relations_hashtable()
195231
void
196232
load_check_constraints(Oid parent_oid, Snapshot snapshot)
197233
{
198-
PartRelationInfo *prel;
199-
RangeRelation *rangerel;
234+
PartRelationInfo *prel = NULL;
235+
RangeRelation *rangerel = NULL;
200236
SPIPlanPtr plan;
201237
bool found;
202238
int ret,
@@ -227,7 +263,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
227263
{
228264
SPITupleTable *tuptable = SPI_tuptable;
229265
Oid *children;
230-
RangeEntry *ranges;
266+
RangeEntry *ranges = NULL;
231267
Datum min;
232268
Datum max;
233269
int hash;

init.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* init.sql
4+
* Creates config table and provides common utility functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
111
/*
212
* Pathman config
313
* relname - schema qualified relation name

pathman.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* pathman.h
4+
* structures and prototypes for pathman functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
110
#ifndef PATHMAN_H
211
#define PATHMAN_H
312

@@ -98,6 +107,15 @@ typedef struct RangeRelation
98107
DsmArray ranges;
99108
} RangeRelation;
100109

110+
typedef struct PathmanState
111+
{
112+
LWLock *load_config_lock;
113+
LWLock *dsm_init_lock;
114+
LWLock *edit_partitions_lock;
115+
} PathmanState;
116+
117+
PathmanState *pmstate;
118+
101119
#define PATHMAN_GET_DATUM(value, by_val) ( (by_val) ? (value) : PointerGetDatum(&value) )
102120

103121
typedef int IndexRange;
@@ -132,12 +150,6 @@ List *irange_list_intersect(List *a, List *b);
132150
int irange_list_length(List *rangeset);
133151
bool irange_list_find(List *rangeset, int index, bool *lossy);
134152

135-
136-
LWLock *load_config_lock;
137-
LWLock *dsm_init_lock;
138-
LWLock *edit_partitions_lock;
139-
140-
141153
/* Dynamic shared memory functions */
142154
void init_dsm_config(void);
143155
bool init_dsm_segment(size_t blocks_count, size_t block_size);

pg_pathman.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* pg_pathman.c
4+
* This module sets planner hooks, handles SELECT queries and produces
5+
* paths for partitioned tables
6+
*
7+
* Copyright (c) 2015-2016, Postgres Professional
8+
*
9+
* ------------------------------------------------------------------------
10+
*/
111
#include "pathman.h"
212
#include "postgres.h"
313
#include "fmgr.h"
@@ -103,13 +113,15 @@ static void set_pathkeys(PlannerInfo *root, RelOptInfo *childrel, Path *path);
103113
void
104114
_PG_init(void)
105115
{
116+
#ifndef WIN32
106117
if (IsUnderPostmaster)
107118
{
108119
elog(ERROR, "Pathman module must be initialized in postmaster. "
109120
"Put the following line to configuration file: "
110121
"shared_preload_libraries='pg_pathman'");
111-
initialization_needed = false;
122+
initialization_needed = false;
112123
}
124+
#endif
113125

114126
set_rel_pathlist_hook_original = set_rel_pathlist_hook;
115127
set_rel_pathlist_hook = pathman_set_rel_pathlist_hook;
@@ -246,16 +258,11 @@ pathman_shmem_startup(void)
246258
{
247259
/* Initialize locks */
248260
RequestAddinLWLocks(3);
249-
load_config_lock = LWLockAssign();
250-
dsm_init_lock = LWLockAssign();
251-
edit_partitions_lock = LWLockAssign();
252-
253-
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
254261

255262
/* Allocate shared memory objects */
263+
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
256264
init_dsm_config();
257265
init_shmem_config();
258-
259266
LWLockRelease(AddinShmemInitLock);
260267

261268
/* Invoke original hook if needed */

pl_funcs.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* pl_funcs.c
4+
* Utility C functions for stored procedures
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
110
#include "pathman.h"
211
#include "utils/lsyscache.h"
312
#include "utils/typcache.h"
@@ -29,13 +38,13 @@ PG_FUNCTION_INFO_V1( get_max_range_value );
2938
Datum
3039
on_partitions_created(PG_FUNCTION_ARGS)
3140
{
32-
LWLockAcquire(load_config_lock, LW_EXCLUSIVE);
41+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
3342

3443
/* Reload config */
3544
/* TODO: reload just the specified relation */
3645
load_relations_hashtable(false);
3746

38-
LWLockRelease(load_config_lock);
47+
LWLockRelease(pmstate->load_config_lock);
3948

4049
PG_RETURN_NULL();
4150
}
@@ -51,10 +60,10 @@ on_partitions_updated(PG_FUNCTION_ARGS)
5160
prel = get_pathman_relation_info(relid, NULL);
5261
if (prel != NULL)
5362
{
54-
LWLockAcquire(load_config_lock, LW_EXCLUSIVE);
63+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
5564
remove_relation_info(relid);
5665
load_relations_hashtable(false);
57-
LWLockRelease(load_config_lock);
66+
LWLockRelease(pmstate->load_config_lock);
5867
}
5968

6069
PG_RETURN_NULL();
@@ -65,13 +74,13 @@ on_partitions_removed(PG_FUNCTION_ARGS)
6574
{
6675
Oid relid;
6776

68-
LWLockAcquire(load_config_lock, LW_EXCLUSIVE);
77+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
6978

7079
/* parent relation oid */
7180
relid = DatumGetInt32(PG_GETARG_DATUM(0));
7281
remove_relation_info(relid);
7382

74-
LWLockRelease(load_config_lock);
83+
LWLockRelease(pmstate->load_config_lock);
7584

7685
PG_RETURN_NULL();
7786
}
@@ -129,10 +138,10 @@ find_or_create_range_partition(PG_FUNCTION_ARGS)
129138
Oid child_oid;
130139

131140
/* Lock config before appending new partitions */
132-
LWLockAcquire(load_config_lock, LW_EXCLUSIVE);
141+
LWLockAcquire(pmstate->load_config_lock, LW_EXCLUSIVE);
133142

134143
/* Restrict concurrent partition creation */
135-
LWLockAcquire(edit_partitions_lock, LW_EXCLUSIVE);
144+
LWLockAcquire(pmstate->edit_partitions_lock, LW_EXCLUSIVE);
136145

137146
/*
138147
* Check if someone else has already created partition.
@@ -141,8 +150,8 @@ find_or_create_range_partition(PG_FUNCTION_ARGS)
141150
pos = range_binary_search(rangerel, &cmp_func, value, &found);
142151
if (found)
143152
{
144-
LWLockRelease(edit_partitions_lock);
145-
LWLockRelease(load_config_lock);
153+
LWLockRelease(pmstate->edit_partitions_lock);
154+
LWLockRelease(pmstate->load_config_lock);
146155
PG_RETURN_OID(ranges[pos].child_oid);
147156
}
148157

@@ -155,8 +164,8 @@ find_or_create_range_partition(PG_FUNCTION_ARGS)
155164
// elog(WARNING, "Worker finished");
156165

157166
/* Release locks */
158-
LWLockRelease(edit_partitions_lock);
159-
LWLockRelease(load_config_lock);
167+
LWLockRelease(pmstate->edit_partitions_lock);
168+
LWLockRelease(pmstate->load_config_lock);
160169

161170
/* Repeat binary search */
162171
ranges = dsm_array_get_pointer(&rangerel->ranges);
@@ -361,17 +370,13 @@ check_overlap(PG_FUNCTION_ARGS)
361370
Datum
362371
acquire_partitions_lock(PG_FUNCTION_ARGS)
363372
{
364-
// int relid = DatumGetInt32(PG_GETARG_DATUM(0));
365-
// LockRelationOid(relid, AccessExclusiveLock);
366-
LWLockAcquire(edit_partitions_lock, LW_EXCLUSIVE);
373+
LWLockAcquire(pmstate->edit_partitions_lock, LW_EXCLUSIVE);
367374
PG_RETURN_NULL();
368375
}
369376

370377
Datum
371378
release_partitions_lock(PG_FUNCTION_ARGS)
372379
{
373-
// int relid = DatumGetInt32(PG_GETARG_DATUM(0));
374-
// UnlockRelationOid(relid, AccessExclusiveLock);
375-
LWLockRelease(edit_partitions_lock);
380+
LWLockRelease(pmstate->edit_partitions_lock);
376381
PG_RETURN_NULL();
377382
}

range.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* range.sql
4+
* RANGE partitioning functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
111
/*
212
* Creates RANGE partitions for specified relation based on datetime attribute
313
*/

rangeset.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* rangeset.c
4+
* Index range functions
5+
*
6+
* Copyright (c) 2015-2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
110
#include "pathman.h"
211

312
/* Check if two ranges are intersecting */
@@ -213,7 +222,6 @@ irange_list_intersect(List *a, List *b)
213222
if (irange_upper(ra) >= irange_upper(rb))
214223
cb = lnext(cb);
215224
}
216-
217225
return result;
218226
}
219227

0 commit comments

Comments
 (0)