Skip to content

Commit

Permalink
Add compatibility header and switch to ProcNumber
Browse files Browse the repository at this point in the history
A change was introduced by https://www.postgresql.org/message-id/[email protected]
renaming BackendId to ProcNumber. Switch to ProcNumber and maintain a
translation macro for backward compatibility.
  • Loading branch information
bonnefoa committed Mar 28, 2024
1 parent c69f9ee commit 30af785
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pg_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "jit/jit.h"
#include "pgstat.h"
#include "storage/lwlock.h"
#include "version_compat.h"

/* Location of external text file */
#define PG_TRACING_TEXT_FILE PG_STAT_TMP_DIR "/pg_tracing.stat"
Expand Down Expand Up @@ -176,7 +177,7 @@ typedef struct pgTracingTraceContext
*/
typedef struct pgTracingParallelContext
{
BackendId leader_backend_id; /* Backend id of the leader, set to
ProcNumber leader_backend_id; /* Backend id of the leader, set to
* InvalidBackendId if unused */
pgTracingTraceContext trace_context;
} pgTracingParallelContext;
Expand Down
12 changes: 6 additions & 6 deletions src/pg_tracing_parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pg_tracing_shmem_parallel_startup(void)
{
SpinLockInit(&pg_tracing_parallel->mutex);
for (int i = 0; i < max_parallel_workers; i++)
pg_tracing_parallel->trace_contexts[i].leader_backend_id = InvalidBackendId;
pg_tracing_parallel->trace_contexts[i].leader_backend_id = INVALID_PROC_NUMBER;
}
}

Expand All @@ -54,12 +54,12 @@ add_parallel_context(const struct pgTracingTraceContext *trace_context,
for (int i = 0; i < max_parallel_workers; i++)
{
ctx = pg_tracing_parallel->trace_contexts + i;
Assert(ctx->leader_backend_id != MyBackendId);
if (ctx->leader_backend_id != InvalidBackendId)
Assert(ctx->leader_backend_id != MyProcNumber);
if (ctx->leader_backend_id != INVALID_PROC_NUMBER)
continue;
/* Slot is available */
parallel_context_index = i;
ctx->leader_backend_id = MyBackendId;
ctx->leader_backend_id = MyProcNumber;
/* We can do the rest outside the lock */
break;
}
Expand All @@ -85,7 +85,7 @@ remove_parallel_context(void)
return;

SpinLockAcquire(&pg_tracing_parallel->mutex);
pg_tracing_parallel->trace_contexts[parallel_context_index].leader_backend_id = InvalidBackendId;
pg_tracing_parallel->trace_contexts[parallel_context_index].leader_backend_id = INVALID_PROC_NUMBER;
SpinLockRelease(&pg_tracing_parallel->mutex);
parallel_context_index = -1;
}
Expand All @@ -100,7 +100,7 @@ fetch_parallel_context(pgTracingTraceContext * trace_context)
SpinLockAcquire(&pg_tracing_parallel->mutex);
for (int i = 0; i < max_parallel_workers; i++)
{
if (pg_tracing_parallel->trace_contexts[i].leader_backend_id != ParallelLeaderBackendId)
if (pg_tracing_parallel->trace_contexts[i].leader_backend_id != ParallelLeaderProcNumber)
continue;
/* Found a matching a trace context, fetch it */
*trace_context = pg_tracing_parallel->trace_contexts[i].trace_context;
Expand Down
28 changes: 28 additions & 0 deletions src/version_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*-------------------------------------------------------------------------
*
* src/version_compat.h
* Compatibility macros for writing code agnostic to PostgreSQL versions
*
*-------------------------------------------------------------------------
*/

#ifndef VERSION_COMPAT_H
#define VERSION_COMPAT_H

#include "postgres.h"

#if PG_VERSION_NUM < 170000

/*
* Compatibility with changes introduced in
* https://www.postgresql.org/message-id/[email protected]
*/

#define INVALID_PROC_NUMBER InvalidBackendId
#define MyProcNumber MyBackendId
#define ProcNumber BackendId
#define ParallelLeaderProcNumber ParallelLeaderBackendId

#endif

#endif /* VERSION_COMPAT_H */

0 comments on commit 30af785

Please sign in to comment.