From 42a0f5be0055199ba9ca4627444ee192ab0c48a8 Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 6 Oct 2022 13:18:31 -0400 Subject: [PATCH] WIP --- control_plane/src/storage.rs | 7 +++--- pageserver/src/lib.rs | 2 +- pgxn/neon/libpagestore.c | 28 ++++++++++++++---------- test_runner/fixtures/compare_fixtures.py | 4 ++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/control_plane/src/storage.rs b/control_plane/src/storage.rs index 933b7b7b65..7af3170799 100644 --- a/control_plane/src/storage.rs +++ b/control_plane/src/storage.rs @@ -61,7 +61,7 @@ impl ResponseErrorMessageExt for Response { let url = self.url().to_owned(); Err(PageserverHttpError::Response( match self.json::() { - Ok(err_body) => format!("Error: {}", err_body.msg), + Ok(err_body) => format!("Response error: {}", err_body.msg), Err(_) => format!("Http error ({}) at {}.", status.as_u16(), url), }, )) @@ -181,14 +181,15 @@ impl PageServerNode { new_timeline_id: Option, pg_version: u32, ) -> anyhow::Result { - let initial_tenant_id = self.tenant_create(new_tenant_id, HashMap::new())?; + let initial_tenant_id = self.tenant_create(new_tenant_id, HashMap::new()) + .context("Failed to create tenant")?; let initial_timeline_info = self.timeline_create( initial_tenant_id, new_timeline_id, None, None, Some(pg_version), - )?; + ).context("Failed to create timeline")?; Ok(initial_timeline_info.timeline_id) } diff --git a/pageserver/src/lib.rs b/pageserver/src/lib.rs index 9f31907a0b..6f935be709 100644 --- a/pageserver/src/lib.rs +++ b/pageserver/src/lib.rs @@ -16,7 +16,7 @@ pub mod tenant; pub mod tenant_config; pub mod tenant_mgr; pub mod tenant_tasks; -pub mod timelines; +// pub mod timelines; pub mod trace; pub mod virtual_file; pub mod walingest; diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index 6b6a042402..452fd871a3 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -272,7 +272,8 @@ typedef struct // Points directly to a NeonResponse. We can't just own the // NeonResponse because it's a "supertype", so it's not Sized. - StringInfo response; + char* response; + int len; } NeonRequestResponse; NeonRequestResponse page_cache[20]; @@ -285,13 +286,16 @@ pageserver_call(NeonRequest * request) // Compute hash char hash = 0; StringInfoData req_buff; - req_buff = zm_pack_request(request); + req_buff = nm_pack_request(request); for (int i = 0; i < req_buff.len; i++) { hash ^= req_buff.data[i]; } pfree(req_buff.data); // If result is cached, memcpy and return + // HACK keeping this commented out until I see why updating the + // cache causes segfault. + // // for (int i = 0; i < page_cache_size; i++) { // if (page_cache[i].request_hash == hash) { // int len = page_cache[0].response->len; @@ -318,15 +322,17 @@ pageserver_call(NeonRequest * request) } // Cache result - // page_cache[page_cache_head].request_hash = hash; - // page_cache[page_cache_head].response->len = len; - // // TODO free old result - // page_cache[page_cache_head].response->data = palloc0(len); - // memcpy(page_cache[page_cache_head].response->data, resp, len); - // page_cache_head = (page_cache_head + 1) % 20; - // if (page_cache_size < 20) { - // page_cache_size += 1; - // } + page_cache[page_cache_head].request_hash = hash; + if (page_cache_head < page_cache_size) { + pfree(page_cache[page_cache_head].response); + } + page_cache[page_cache_head].len = len; + page_cache[page_cache_head].response = palloc(len); + memcpy(page_cache[page_cache_head].response, resp, len); + page_cache_head = (page_cache_head + 1) % 20; + if (page_cache_size < 20) { + page_cache_size += 1; + } return resp; } diff --git a/test_runner/fixtures/compare_fixtures.py b/test_runner/fixtures/compare_fixtures.py index c5be558cd4..af71491df8 100644 --- a/test_runner/fixtures/compare_fixtures.py +++ b/test_runner/fixtures/compare_fixtures.py @@ -124,10 +124,10 @@ class NeonCompare(PgCompare): return self._pg_bin def flush(self): - self.pageserver_http_client.timeline_gc(self.env.initial_tenant, self.timeline, 0) + self.pageserver_http_client.timeline_gc(self.tenant, self.timeline, 0) def compact(self): - self.pageserver_http_client.timeline_compact(self.env.initial_tenant, self.timeline) + self.pageserver_http_client.timeline_compact(self.tenant, self.timeline) def report_peak_memory_use(self) -> None: self.zenbenchmark.record(