summaryrefslogtreecommitdiff
path: root/src/backend/replication/backup_manifest.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2021-08-19 09:20:13 +0900
committerMichael Paquier <michael@paquier.xyz>2021-08-19 09:20:13 +0900
commit2576dcfb76aa71e4222bac5a3a43f71875bfa9e8 (patch)
treee035f807a855e56aee90d73bf63798d19133b1a1 /src/backend/replication/backup_manifest.c
parent2313dda9d493d3685ac7328b49dc6f5a87c1c295 (diff)
Revert refactoring of hex code to src/common/
This is a combined revert of the following commits: - c3826f8, a refactoring piece that moved the hex decoding code to src/common/. This code was cleaned up by aef8948, as it originally included no overflow checks in the same way as the base64 routines in src/common/ used by SCRAM, making it unsafe for its purpose. - aef8948, a more advanced refactoring of the hex encoding/decoding code to src/common/ that added sanity checks on the result buffer for hex decoding and encoding. As reported by Hans Buschmann, those overflow checks are expensive, and it is possible to see a performance drop in the decoding/encoding of bytea or LOs the longer they are. Simple SQLs working on large bytea values show a clear difference in perf profile. - ccf4e27, a cleanup made possible by aef8948. The reverts of all those commits bring back the performance of hex decoding and encoding back to what it was in ~13. Fow now and post-beta3, this is the simplest option. Reported-by: Hans Buschmann Discussion: https://postgr.es/m/1629039545467.80333@nidsa.net Backpatch-through: 14
Diffstat (limited to 'src/backend/replication/backup_manifest.c')
-rw-r--r--src/backend/replication/backup_manifest.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/backend/replication/backup_manifest.c b/src/backend/replication/backup_manifest.c
index 88824440252..921de47a6c2 100644
--- a/src/backend/replication/backup_manifest.c
+++ b/src/backend/replication/backup_manifest.c
@@ -13,11 +13,11 @@
#include "postgres.h"
#include "access/timeline.h"
-#include "common/hex.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "replication/backup_manifest.h"
+#include "utils/builtins.h"
#include "utils/json.h"
static void AppendStringToManifest(backup_manifest_info *manifest, char *s);
@@ -150,12 +150,10 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
}
else
{
- uint64 dstlen = pg_hex_enc_len(pathlen);
-
appendStringInfoString(&buf, "{ \"Encoded-Path\": \"");
- enlargeStringInfo(&buf, dstlen);
- buf.len += pg_hex_encode(pathname, pathlen,
- &buf.data[buf.len], dstlen);
+ enlargeStringInfo(&buf, 2 * pathlen);
+ buf.len += hex_encode(pathname, pathlen,
+ &buf.data[buf.len]);
appendStringInfoString(&buf, "\", ");
}
@@ -178,7 +176,6 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
{
uint8 checksumbuf[PG_CHECKSUM_MAX_LENGTH];
int checksumlen;
- uint64 dstlen;
checksumlen = pg_checksum_final(checksum_ctx, checksumbuf);
if (checksumlen < 0)
@@ -188,10 +185,9 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
appendStringInfo(&buf,
", \"Checksum-Algorithm\": \"%s\", \"Checksum\": \"",
pg_checksum_type_name(checksum_ctx->type));
- dstlen = pg_hex_enc_len(checksumlen);
- enlargeStringInfo(&buf, dstlen);
- buf.len += pg_hex_encode((char *) checksumbuf, checksumlen,
- &buf.data[buf.len], dstlen);
+ enlargeStringInfo(&buf, 2 * checksumlen);
+ buf.len += hex_encode((char *) checksumbuf, checksumlen,
+ &buf.data[buf.len]);
appendStringInfoChar(&buf, '"');
}
@@ -311,9 +307,8 @@ SendBackupManifest(backup_manifest_info *manifest)
{
StringInfoData protobuf;
uint8 checksumbuf[PG_SHA256_DIGEST_LENGTH];
- char *checksumstringbuf;
+ char checksumstringbuf[PG_SHA256_DIGEST_STRING_LENGTH];
size_t manifest_bytes_done = 0;
- uint64 dstlen;
if (!IsManifestEnabled(manifest))
return;
@@ -334,11 +329,10 @@ SendBackupManifest(backup_manifest_info *manifest)
sizeof(checksumbuf)) < 0)
elog(ERROR, "failed to finalize checksum of backup manifest");
AppendStringToManifest(manifest, "\"Manifest-Checksum\": \"");
- dstlen = pg_hex_enc_len(sizeof(checksumbuf));
- checksumstringbuf = palloc0(dstlen + 1); /* includes \0 */
- pg_hex_encode((char *) checksumbuf, sizeof(checksumbuf),
- checksumstringbuf, dstlen);
- checksumstringbuf[dstlen] = '\0';
+
+ hex_encode((char *) checksumbuf, sizeof checksumbuf, checksumstringbuf);
+ checksumstringbuf[PG_SHA256_DIGEST_STRING_LENGTH - 1] = '\0';
+
AppendStringToManifest(manifest, checksumstringbuf);
AppendStringToManifest(manifest, "\"}\n");