Skip to content

Commit 17ea8ff

Browse files
author
Nikita Glukhov
committed
Add jsonbc dictionary background workers
1 parent f26c21e commit 17ea8ff

File tree

9 files changed

+436
-15
lines changed

9 files changed

+436
-15
lines changed

src/backend/postmaster/bgworker.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "storage/shmem.h"
3535
#include "tcop/tcopprot.h"
3636
#include "utils/ascii.h"
37+
#include "utils/jsonbc_dict.h"
3738
#include "utils/ps_status.h"
3839
#include "utils/timeout.h"
3940

@@ -129,6 +130,9 @@ static const struct
129130
},
130131
{
131132
"ApplyWorkerMain", ApplyWorkerMain
133+
},
134+
{
135+
"JsonbcDictWorkerMain", JsonbcDictWorkerMain
132136
}
133137
};
134138

src/backend/postmaster/pgstat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,9 @@ pgstat_get_wait_ipc(WaitEventIPC w)
35763576
case WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE:
35773577
event_name = "LogicalSyncStateChange";
35783578
break;
3579+
case WAIT_EVENT_JSONBC_DICT_WORKER:
3580+
event_name = "JsonbcDictionaryWorker";
3581+
break;
35793582
/* no default case, so that compiler will warn */
35803583
}
35813584

src/backend/storage/ipc/ipci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "storage/sinvaladt.h"
4646
#include "storage/spin.h"
4747
#include "utils/backend_random.h"
48+
#include "utils/jsonbc_dict.h"
4849
#include "utils/snapmgr.h"
4950

5051

@@ -270,6 +271,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
270271
SyncScanShmemInit();
271272
AsyncShmemInit();
272273
BackendRandomShmemInit();
274+
JsonbcDictWorkerShmemInit();
273275

274276
#ifdef EXEC_BACKEND
275277

src/backend/utils/adt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OBJS = acl.o amutils.o arrayfuncs.o array_expanded.o array_selfuncs.o \
1717
geo_ops.o geo_selfuncs.o geo_spgist.o inet_cidr_ntop.o inet_net_pton.o \
1818
int.o int8.o json.o jsonb.o jsonb_gin.o jsonb_op.o jsonb_util.o \
1919
jsonfuncs.o json_generic.o json_gin.o json_op.o \
20-
jsonbc_util.o jsonbc_dict.o \
20+
jsonbc_util.o jsonbc_dict.o jsonbc_dict_worker.o \
2121
like.o lockfuncs.o mac.o mac8.o misc.o nabstime.o name.o \
2222
network.o network_gist.o network_selfuncs.o network_spgist.o \
2323
numeric.o numutils.o oid.o oracle_compat.o \

src/backend/utils/adt/jsonbc_dict.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333

3434
#define JSONBC_DICT_TAB "pg_jsonbc_dict"
3535

36-
static JsonbcKeyId
37-
jsonbcDictGetIdByNameSlow(JsonbcDictId dict, JsonbcKeyName name,
38-
JsonbcKeyId nextKeyId);
39-
4036
void
4137
jsonbcDictRemoveEntryById(JsonbcDictId dict, JsonbcKeyId key)
4238
{
@@ -99,7 +95,7 @@ jsonbcDictInsertEntry(JsonbcDictId dict, JsonbcKeyName name,
9995
return nextKeyId;
10096
}
10197

102-
static JsonbcKeyId
98+
JsonbcKeyId
10399
jsonbcDictGetIdByNameSeqCached(JsonbcDictId dict, JsonbcKeyName name)
104100
{
105101
text *txt = cstring_to_text_with_len(name.s, name.len);
@@ -144,7 +140,7 @@ jsonbcDictGetIdByNameSeq(JsonbcDictId dict, JsonbcKeyName name, bool insert)
144140
{
145141
JsonbcKeyId nextKeyId = (JsonbcKeyId) nextval_internal(dict, false);
146142

147-
id = jsonbcDictInsertEntry(dict, name, nextKeyId);
143+
id = jsonbcDictWorkerGetIdByName(dict, name, nextKeyId);
148144

149145
jsonbcDictInvalidateCache(dict, name);
150146
}
@@ -249,7 +245,7 @@ jsonbcDictGetNameById(JsonbcDictId dict, JsonbcKeyId id)
249245
}
250246

251247
#ifndef JSONBC_DICT_UPSERT
252-
static JsonbcKeyId
248+
JsonbcKeyId
253249
jsonbcDictGetIdByNameSlow(JsonbcDictId dict, JsonbcKeyName name,
254250
JsonbcKeyId nextKeyId)
255251
{
@@ -259,8 +255,9 @@ jsonbcDictGetIdByNameSlow(JsonbcDictId dict, JsonbcKeyName name,
259255
#else
260256
static SPIPlanPtr savedPlanInsert = NULL;
261257

262-
static JsonbcKeyId
263-
jsonbcDictGetIdByNameSlow(JsonbcDictId dict, JsonbcKeyName name)
258+
JsonbcKeyId
259+
jsonbcDictGetIdByNameSlow(JsonbcDictId dict, JsonbcKeyName name,
260+
JsonbcKeyId nextKeyId)
264261
{
265262
Oid argTypes[3] = {JsonbcDictIdTypeOid, TEXTOID, JsonbcKeyIdTypeOid};
266263
Datum args[3];

0 commit comments

Comments
 (0)