From 9a4b4cfe58b2cdd4bf20ff7a470439f474c063f0 Mon Sep 17 00:00:00 2001 From: Kosntantin Knizhnik Date: Mon, 23 Jun 2025 15:46:23 +0300 Subject: [PATCH] Add more trace and create debug image with asserts enabled --- compute/compute-node.Dockerfile | 2 +- pgxn/neon/communicator.c | 19 +++++++++++++++---- pgxn/neon/file_cache.c | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/compute/compute-node.Dockerfile b/compute/compute-node.Dockerfile index 685ac564b7..992855dcb9 100644 --- a/compute/compute-node.Dockerfile +++ b/compute/compute-node.Dockerfile @@ -164,7 +164,7 @@ FROM build-deps AS pg-build ARG PG_VERSION COPY vendor/postgres-${PG_VERSION:?} postgres RUN cd postgres && \ - export CONFIGURE_CMD="./configure CFLAGS='-O2 -g3 -fsigned-char' --enable-debug --with-openssl --with-uuid=ossp \ + export CONFIGURE_CMD="./configure CFLAGS='-O0 -g3 -fsigned-char' --enable-debug --enable-cassert --with-openssl --with-uuid=ossp \ --with-icu --with-libxml --with-libxslt --with-lz4" && \ if [ "${PG_VERSION:?}" != "v14" ]; then \ # zstd is available only from PG15 diff --git a/pgxn/neon/communicator.c b/pgxn/neon/communicator.c index 857a820b8c..43c76b5f7d 100644 --- a/pgxn/neon/communicator.c +++ b/pgxn/neon/communicator.c @@ -446,6 +446,12 @@ communicator_prefetch_pump_state(void) if (response == NULL) break; + if (response->tag != T_NeonGetPageResponse && response->tag != T_NeonErrorResponse) + { + neon_shard_log(slot->shard_no, ERROR, "Unexpected prefetch response %d, ring_receive=%ld, ring_flush=%ld, ring_unused=%ld", + response->tag, MyPState->ring_receive, MyPState->ring_flush, MyPState->ring_unused); + } + /* The slot should still be valid */ if (slot->status != PRFS_REQUESTED || slot->response != NULL || @@ -750,6 +756,12 @@ prefetch_read(PrefetchRequest *slot) slot->status, slot->response, (long) slot->my_ring_index, (long) MyPState->ring_receive); + if (response->tag != T_NeonGetPageResponse && response->tag != T_NeonErrorResponse) + { + neon_shard_log(shard_no, ERROR, "Unexpected prefetch response %d, ring_receive=%ld, ring_flush=%ld, ring_unused=%ld", + response->tag, MyPState->ring_receive, MyPState->ring_flush, MyPState->ring_unused); + } + /* update prefetch state */ MyPState->n_responses_buffered += 1; MyPState->n_requests_inflight -= 1; @@ -1388,13 +1400,13 @@ page_server_request(void const *req) { PG_TRY(); { + consume_prefetch_responses(); while (!page_server->send(shard_no, (NeonRequest *) req) || !page_server->flush(shard_no)) { /* do nothing */ } MyNeonCounters->pageserver_open_requests++; - consume_prefetch_responses(); resp = page_server->receive(shard_no); MyNeonCounters->pageserver_open_requests--; } @@ -2384,12 +2396,11 @@ communicator_read_slru_segment(SlruKind kind, int64 segno, neon_request_lsns *re .segno = segno }; + consume_prefetch_responses(); + do { while (!page_server->send(shard_no, &request.hdr) || !page_server->flush(shard_no)); - - consume_prefetch_responses(); - resp = page_server->receive(shard_no); } while (resp == NULL); diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index ff0a6b5b28..eba96c2073 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -1685,7 +1685,7 @@ lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, if (relkind != pagekind) { ereport(PANIC, - (errmsg("Inconsistent writing page %u %u/%u/%u.%u to LFC", blkno+i, RelFileInfoFmt(rinfo), forkNum), + (errmsg("Inconsistent writing %s page %u %u/%u/%u.%u to LFC", pagekind == RELKIND_INDEX ? "index" : "heap", blkno+i, RelFileInfoFmt(rinfo), forkNum), errbacktrace())); } } @@ -1745,7 +1745,7 @@ lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, if (entry->relkind != RELKIND_UNKNOWN && entry->relkind != relkind) { ereport(PANIC, - (errmsg("Writing unexpected page %u %u/%u/%u.%u to LFC", blkno, RelFileInfoFmt(rinfo), forkNum), + (errmsg("Writing unexpected %s page %u %u/%u/%u.%u to LFC", relkind == RELKIND_INDEX ? "index" : "heap", blkno, RelFileInfoFmt(rinfo), forkNum), errbacktrace())); } entry->relkind = relkind;