Fix context for some errors

This commit is contained in:
Arthur Petukhovsky
2022-09-12 14:23:55 +00:00
parent f8aecd53cd
commit 780e44c07b
3 changed files with 34 additions and 30 deletions
+16 -2
View File
@@ -429,8 +429,22 @@ impl PostgresBackend {
// full cause of the error, not just the top-level context + its trace.
// We don't want to send that in the ErrorResponse though,
// because it's not relevant to the compute node logs.
error!("query handler for '{}' failed: {:?}", query_string, e);
self.write_message_noflush(&BeMessage::ErrorResponse(&e.to_string()))?;
//
// We also don't want to log full stacktrace when the error is primitive,
// such as usual connection closed.
let short_error = format!("{:#}", e);
if e.root_cause()
.to_string()
.contains("connection closed unexpectedly")
{
error!(
"query handler for '{}' failed: {}",
query_string, short_error
);
} else {
error!("query handler for '{}' failed: {:?}", query_string, e);
}
self.write_message_noflush(&BeMessage::ErrorResponse(&short_error))?;
// TODO: untangle convoluted control flow
if e.to_string().contains("failed to run") {
return Ok(ProcessMsgResult::Break);
+5 -7
View File
@@ -103,16 +103,14 @@ impl postgres_backend::Handler for SafekeeperPostgresHandler {
self.zttid = ZTenantTimelineId::new(tenantid, timelineid);
match cmd {
SafekeeperPostgresCommand::StartWalPush => ReceiveWalConn::new(pgb)
.run(self)
.context("failed to run ReceiveWalConn"),
SafekeeperPostgresCommand::StartReplication { start_lsn } => ReplicationConn::new(pgb)
.run(self, pgb, start_lsn)
.context("failed to run ReplicationConn"),
SafekeeperPostgresCommand::StartWalPush => ReceiveWalConn::new(pgb).run(self),
SafekeeperPostgresCommand::StartReplication { start_lsn } => {
ReplicationConn::new(pgb).run(self, pgb, start_lsn)
}
SafekeeperPostgresCommand::IdentifySystem => self.handle_identify_system(pgb),
SafekeeperPostgresCommand::JSONCtrl { ref cmd } => handle_json_ctrl(self, pgb, cmd),
}
.context(format!("timeline {timelineid}"))?;
.context(format!("Failed to process query for timeline {timelineid}"))?;
Ok(())
}
+13 -21
View File
@@ -12,11 +12,12 @@ use anyhow::Result;
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use tracing::*;
use utils::zid::ZTenantTimelineId;
use crate::handler::SafekeeperPostgresHandler;
use crate::safekeeper::{AcceptorProposerMessage, AppendResponse};
use crate::safekeeper::{AcceptorProposerMessage, AppendResponse, ServerInfo};
use crate::safekeeper::{
AppendRequest, AppendRequestHeader, ProposerAcceptorMessage, ProposerElected, ProposerGreeting,
AppendRequest, AppendRequestHeader, ProposerAcceptorMessage, ProposerElected,
};
use crate::safekeeper::{SafeKeeperState, Term, TermHistory, TermSwitchEntry};
use crate::timeline::Timeline;
@@ -65,10 +66,9 @@ pub fn handle_json_ctrl(
append_request: &AppendLogicalMessage,
) -> Result<()> {
info!("JSON_CTRL request: {:?}", append_request);
let tli = GlobalTimelines::get(spg.zttid)?;
// need to init safekeeper state before AppendRequest
prepare_safekeeper(&tli)?;
let tli = prepare_safekeeper(spg.zttid)?;
// if send_proposer_elected is true, we need to update local history
if append_request.send_proposer_elected {
@@ -95,23 +95,15 @@ pub fn handle_json_ctrl(
/// Prepare safekeeper to process append requests without crashes,
/// by sending ProposerGreeting with default server.wal_seg_size.
fn prepare_safekeeper(tli: &Arc<Timeline>) -> Result<()> {
let greeting_request = ProposerAcceptorMessage::Greeting(ProposerGreeting {
protocol_version: 2, // current protocol
pg_version: 0, // unknown
proposer_id: [0u8; 16],
system_id: 0,
ztli: tli.zttid.timeline_id,
tenant_id: tli.zttid.tenant_id,
tli: 0,
wal_seg_size: WAL_SEGMENT_SIZE as u32, // 16MB, default for tests
});
let response = tli.process_msg(&greeting_request)?;
match response {
Some(AcceptorProposerMessage::Greeting(_)) => Ok(()),
_ => anyhow::bail!("not GreetingResponse"),
}
fn prepare_safekeeper(zttid: ZTenantTimelineId) -> Result<Arc<Timeline>> {
GlobalTimelines::create(
zttid,
ServerInfo {
pg_version: 0, // unknown
wal_seg_size: WAL_SEGMENT_SIZE as u32,
system_id: 0,
},
)
}
fn send_proposer_elected(tli: &Arc<Timeline>, term: Term, lsn: Lsn) -> Result<()> {