-
Notifications
You must be signed in to change notification settings - Fork 17
Neon logical replication support for PG14 #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,7 @@ | |
#include "miscadmin.h" | ||
#include "pgstat.h" | ||
#include "replication/logical.h" | ||
#include "replication/message.h" | ||
#include "replication/reorderbuffer.h" | ||
#include "replication/snapbuild.h" | ||
#include "storage/block.h" /* debugging output */ | ||
|
@@ -1592,6 +1593,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn) | |
int fd; | ||
char tmppath[MAXPGPATH]; | ||
char path[MAXPGPATH]; | ||
char prefix[MAXPGPATH]; | ||
int ret; | ||
struct stat stat_buf; | ||
Size sz; | ||
|
@@ -1714,6 +1716,10 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn) | |
(errcode_for_file_access(), | ||
errmsg("could not open file \"%s\": %m", tmppath))); | ||
|
||
/* NEON specific: persist snapshot in storage using logical message */ | ||
snprintf(prefix, sizeof(prefix), "neon-file:%s", path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: CWE 121 - Stack-based Buffer Overflow - Stack based buffer overflowThe software directly writes into a stack buffer. This might lead to a stack-based buffer overflow. Avoid directly writing into stack buffers without proper boundary checks. Replace unsafe functions like strcpy, strcat, wcscpy, and wcscat with their safer counterparts such as strlcpy, strlcat, wcslcpy, and wcslcat, and use functions like strncpy, stpncpy, and their wide-character variants with caution, ensuring manual null-termination and proper buffer size checks. Severity: High 🚨 References:You received this notification because a new code risk has been identified |
||
LogLogicalMessage(prefix, (char*)ondisk, needed_length, false); | ||
|
||
errno = 0; | ||
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE); | ||
if ((write(fd, ondisk, needed_length)) != needed_length) | ||
|
@@ -2020,6 +2026,7 @@ CheckPointSnapBuild(void) | |
DIR *snap_dir; | ||
struct dirent *snap_de; | ||
char path[MAXPGPATH + 21]; | ||
char prefix[MAXPGPATH + 31]; | ||
|
||
/* | ||
* We start off with a minimum of the last redo pointer. No new | ||
|
@@ -2078,6 +2085,10 @@ CheckPointSnapBuild(void) | |
{ | ||
elog(DEBUG1, "removing snapbuild snapshot %s", path); | ||
|
||
/* NEON specific: delete file from storage using logical message */ | ||
snprintf(prefix, sizeof(prefix), "neon-file:%s", path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: CWE 121 - Stack-based Buffer Overflow - Stack based buffer overflowThe software directly writes into a stack buffer. This might lead to a stack-based buffer overflow. Avoid directly writing into stack buffers without proper boundary checks. Replace unsafe functions like strcpy, strcat, wcscpy, and wcscat with their safer counterparts such as strlcpy, strlcat, wcslcpy, and wcslcat, and use functions like strncpy, stpncpy, and their wide-character variants with caution, ensuring manual null-termination and proper buffer size checks. Severity: High 🚨 References:You received this notification because a new code risk has been identified |
||
LogLogicalMessage(prefix, NULL, 0, false); | ||
|
||
/* | ||
* It's not particularly harmful, though strange, if we can't | ||
* remove the file here. Don't prevent the checkpoint from | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
#include "miscadmin.h" | ||
#include "pgstat.h" | ||
#include "replication/slot.h" | ||
#include "replication/message.h" | ||
#include "storage/fd.h" | ||
#include "storage/proc.h" | ||
#include "storage/procarray.h" | ||
|
@@ -605,6 +606,15 @@ ReplicationSlotDropPtr(ReplicationSlot *slot) | |
sprintf(path, "pg_replslot/%s", NameStr(slot->data.name)); | ||
sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name)); | ||
|
||
if (SlotIsLogical(slot)) | ||
{ | ||
/* NEON specific: delete slot from storage using logical message */ | ||
char prefix[MAXPGPATH]; | ||
snprintf(prefix, sizeof(prefix), "neon-file:%s/state", path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: CWE 121 - Stack-based Buffer Overflow - Stack based buffer overflowThe software directly writes into a stack buffer. This might lead to a stack-based buffer overflow. Avoid directly writing into stack buffers without proper boundary checks. Replace unsafe functions like strcpy, strcat, wcscpy, and wcscat with their safer counterparts such as strlcpy, strlcat, wcslcpy, and wcslcat, and use functions like strncpy, stpncpy, and their wide-character variants with caution, ensuring manual null-termination and proper buffer size checks. Severity: High 🚨 References:You received this notification because a new code risk has been identified |
||
elog(LOG, "Drop replication slot %s", path); | ||
LogLogicalMessage(prefix, NULL, 0, false); | ||
} | ||
|
||
/* | ||
* Rename the slot directory on disk, so that we'll no longer recognize | ||
* this as a valid slot. Note that if this fails, we've got to mark the | ||
|
@@ -1569,6 +1579,15 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) | |
SnapBuildOnDiskChecksummedSize); | ||
FIN_CRC32C(cp.checksum); | ||
|
||
if (SlotIsLogical(slot) && cp.slotdata.restart_lsn != InvalidXLogRecPtr) | ||
{ | ||
/* NEON specific: persist slot in storage using logical message */ | ||
char prefix[MAXPGPATH]; | ||
snprintf(prefix, sizeof(prefix), "neon-file:%s", path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Code Analysis Risk: CWE 121 - Stack-based Buffer Overflow - Stack based buffer overflowThe software directly writes into a stack buffer. This might lead to a stack-based buffer overflow. Avoid directly writing into stack buffers without proper boundary checks. Replace unsafe functions like strcpy, strcat, wcscpy, and wcscat with their safer counterparts such as strlcpy, strlcat, wcslcpy, and wcslcat, and use functions like strncpy, stpncpy, and their wide-character variants with caution, ensuring manual null-termination and proper buffer size checks. Severity: High 🚨 References:You received this notification because a new code risk has been identified |
||
elog(LOG, "Save replication slot at %s restart_lsn=%X/%X", path, LSN_FORMAT_ARGS(cp.slotdata.restart_lsn)); | ||
LogLogicalMessage(prefix, (char*)&cp, sizeof cp, false); | ||
} | ||
|
||
errno = 0; | ||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_WRITE); | ||
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static Code Analysis Risk: CWE 121 - Stack-based Buffer Overflow - Stack based buffer overflow
The software directly writes into a stack buffer. This might lead to a stack-based buffer overflow. Avoid directly writing into stack buffers without proper boundary checks. Replace unsafe functions like strcpy, strcat, wcscpy, and wcscat with their safer counterparts such as strlcpy, strlcat, wcslcpy, and wcslcat, and use functions like strncpy, stpncpy, and their wide-character variants with caution, ensuring manual null-termination and proper buffer size checks.
Severity: High 🚨
Status: Open 🔴
References:
You received this notification because a new code risk has been identified