Line data Source code
1 : use hyper::{Body, Request, Response, StatusCode, Uri};
2 :
3 : use once_cell::sync::Lazy;
4 : use postgres_ffi::WAL_SEGMENT_SIZE;
5 : use safekeeper_api::models::{SkTimelineInfo, TimelineCopyRequest};
6 : use serde::{Deserialize, Serialize};
7 : use std::collections::{HashMap, HashSet};
8 : use std::fmt;
9 : use std::str::FromStr;
10 : use std::sync::Arc;
11 : use storage_broker::proto::SafekeeperTimelineInfo;
12 : use storage_broker::proto::TenantTimelineId as ProtoTenantTimelineId;
13 : use tokio::fs::File;
14 : use tokio::io::AsyncReadExt;
15 : use tokio_util::sync::CancellationToken;
16 : use utils::failpoint_support::failpoints_handler;
17 : use utils::http::request::parse_query_param;
18 :
19 : use std::io::Write as _;
20 : use tokio::sync::mpsc;
21 : use tokio_stream::wrappers::ReceiverStream;
22 : use tracing::{info_span, Instrument};
23 : use utils::http::endpoint::{request_span, ChannelWriter};
24 :
25 : use crate::debug_dump::TimelineDigestRequest;
26 : use crate::receive_wal::WalReceiverState;
27 : use crate::safekeeper::Term;
28 : use crate::safekeeper::{ServerInfo, TermLsn};
29 : use crate::send_wal::WalSenderState;
30 : use crate::timeline::PeerInfo;
31 : use crate::{copy_timeline, debug_dump, patch_control_file, pull_timeline};
32 :
33 : use crate::timelines_global_map::TimelineDeleteForceResult;
34 : use crate::GlobalTimelines;
35 : use crate::SafeKeeperConf;
36 : use utils::{
37 : auth::SwappableJwtAuth,
38 : http::{
39 : endpoint::{self, auth_middleware, check_permission_with},
40 : error::ApiError,
41 : json::{json_request, json_response},
42 : request::{ensure_no_body, parse_request_param},
43 : RequestExt, RouterBuilder,
44 : },
45 : id::{NodeId, TenantId, TenantTimelineId, TimelineId},
46 : lsn::Lsn,
47 : };
48 :
49 : use super::models::TimelineCreateRequest;
50 :
51 0 : #[derive(Debug, Serialize)]
52 : struct SafekeeperStatus {
53 : id: NodeId,
54 : }
55 :
56 : /// Healthcheck handler.
57 0 : async fn status_handler(request: Request<Body>) -> Result<Response<Body>, ApiError> {
58 0 : check_permission(&request, None)?;
59 0 : let conf = get_conf(&request);
60 0 : let status = SafekeeperStatus { id: conf.my_id };
61 0 : json_response(StatusCode::OK, status)
62 0 : }
63 :
64 0 : fn get_conf(request: &Request<Body>) -> &SafeKeeperConf {
65 0 : request
66 0 : .data::<Arc<SafeKeeperConf>>()
67 0 : .expect("unknown state type")
68 0 : .as_ref()
69 0 : }
70 :
71 : /// Same as TermLsn, but serializes LSN using display serializer
72 : /// in Postgres format, i.e. 0/FFFFFFFF. Used only for the API response.
73 2 : #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
74 : pub struct TermSwitchApiEntry {
75 : pub term: Term,
76 : pub lsn: Lsn,
77 : }
78 :
79 : impl From<TermSwitchApiEntry> for TermLsn {
80 0 : fn from(api_val: TermSwitchApiEntry) -> Self {
81 0 : TermLsn {
82 0 : term: api_val.term,
83 0 : lsn: api_val.lsn,
84 0 : }
85 0 : }
86 : }
87 :
88 : /// Augment AcceptorState with epoch for convenience
89 2 : #[derive(Debug, Serialize, Deserialize)]
90 : pub struct AcceptorStateStatus {
91 : pub term: Term,
92 : pub epoch: Term,
93 : pub term_history: Vec<TermSwitchApiEntry>,
94 : }
95 :
96 : /// Info about timeline on safekeeper ready for reporting.
97 0 : #[derive(Debug, Serialize, Deserialize)]
98 : pub struct TimelineStatus {
99 : pub tenant_id: TenantId,
100 : pub timeline_id: TimelineId,
101 : pub acceptor_state: AcceptorStateStatus,
102 : pub pg_info: ServerInfo,
103 : pub flush_lsn: Lsn,
104 : pub timeline_start_lsn: Lsn,
105 : pub local_start_lsn: Lsn,
106 : pub commit_lsn: Lsn,
107 : pub backup_lsn: Lsn,
108 : pub peer_horizon_lsn: Lsn,
109 : pub remote_consistent_lsn: Lsn,
110 : pub peers: Vec<PeerInfo>,
111 : pub walsenders: Vec<WalSenderState>,
112 : pub walreceivers: Vec<WalReceiverState>,
113 : }
114 :
115 0 : fn check_permission(request: &Request<Body>, tenant_id: Option<TenantId>) -> Result<(), ApiError> {
116 0 : check_permission_with(request, |claims| {
117 0 : crate::auth::check_permission(claims, tenant_id)
118 0 : })
119 0 : }
120 :
121 : /// Report info about timeline.
122 0 : async fn timeline_status_handler(request: Request<Body>) -> Result<Response<Body>, ApiError> {
123 0 : let ttid = TenantTimelineId::new(
124 0 : parse_request_param(&request, "tenant_id")?,
125 0 : parse_request_param(&request, "timeline_id")?,
126 : );
127 0 : check_permission(&request, Some(ttid.tenant_id))?;
128 :
129 0 : let tli = GlobalTimelines::get(ttid).map_err(ApiError::from)?;
130 0 : let (inmem, state) = tli.get_state().await;
131 0 : let flush_lsn = tli.get_flush_lsn().await;
132 :
133 0 : let epoch = state.acceptor_state.get_epoch(flush_lsn);
134 0 : let term_history = state
135 0 : .acceptor_state
136 0 : .term_history
137 0 : .0
138 0 : .into_iter()
139 0 : .map(|ts| TermSwitchApiEntry {
140 0 : term: ts.term,
141 0 : lsn: ts.lsn,
142 0 : })
143 0 : .collect();
144 0 : let acc_state = AcceptorStateStatus {
145 0 : term: state.acceptor_state.term,
146 0 : epoch,
147 0 : term_history,
148 0 : };
149 0 :
150 0 : let conf = get_conf(&request);
151 : // Note: we report in memory values which can be lost.
152 0 : let status = TimelineStatus {
153 0 : tenant_id: ttid.tenant_id,
154 0 : timeline_id: ttid.timeline_id,
155 0 : acceptor_state: acc_state,
156 0 : pg_info: state.server,
157 0 : flush_lsn,
158 0 : timeline_start_lsn: state.timeline_start_lsn,
159 0 : local_start_lsn: state.local_start_lsn,
160 0 : commit_lsn: inmem.commit_lsn,
161 0 : backup_lsn: inmem.backup_lsn,
162 0 : peer_horizon_lsn: inmem.peer_horizon_lsn,
163 0 : remote_consistent_lsn: inmem.remote_consistent_lsn,
164 0 : peers: tli.get_peers(conf).await,
165 0 : walsenders: tli.get_walsenders().get_all(),
166 0 : walreceivers: tli.get_walreceivers().get_all(),
167 0 : };
168 0 : json_response(StatusCode::OK, status)
169 0 : }
170 :
171 0 : async fn timeline_create_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
172 0 : let request_data: TimelineCreateRequest = json_request(&mut request).await?;
173 :
174 0 : let ttid = TenantTimelineId {
175 0 : tenant_id: request_data.tenant_id,
176 0 : timeline_id: request_data.timeline_id,
177 0 : };
178 0 : check_permission(&request, Some(ttid.tenant_id))?;
179 :
180 0 : let server_info = ServerInfo {
181 0 : pg_version: request_data.pg_version,
182 0 : system_id: request_data.system_id.unwrap_or(0),
183 0 : wal_seg_size: request_data.wal_seg_size.unwrap_or(WAL_SEGMENT_SIZE as u32),
184 0 : };
185 0 : let local_start_lsn = request_data.local_start_lsn.unwrap_or_else(|| {
186 0 : request_data
187 0 : .commit_lsn
188 0 : .segment_lsn(server_info.wal_seg_size as usize)
189 0 : });
190 0 : GlobalTimelines::create(ttid, server_info, request_data.commit_lsn, local_start_lsn)
191 0 : .await
192 0 : .map_err(ApiError::InternalServerError)?;
193 :
194 0 : json_response(StatusCode::OK, ())
195 0 : }
196 :
197 : /// Pull timeline from peer safekeeper instances.
198 0 : async fn timeline_pull_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
199 0 : check_permission(&request, None)?;
200 :
201 0 : let data: pull_timeline::Request = json_request(&mut request).await?;
202 :
203 0 : let resp = pull_timeline::handle_request(data)
204 0 : .await
205 0 : .map_err(ApiError::InternalServerError)?;
206 0 : json_response(StatusCode::OK, resp)
207 0 : }
208 :
209 0 : async fn timeline_copy_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
210 0 : check_permission(&request, None)?;
211 :
212 0 : let request_data: TimelineCopyRequest = json_request(&mut request).await?;
213 0 : let ttid = TenantTimelineId::new(
214 0 : parse_request_param(&request, "tenant_id")?,
215 0 : parse_request_param(&request, "source_timeline_id")?,
216 : );
217 :
218 0 : let source = GlobalTimelines::get(ttid)?;
219 :
220 0 : copy_timeline::handle_request(copy_timeline::Request{
221 0 : source,
222 0 : until_lsn: request_data.until_lsn,
223 0 : destination_ttid: TenantTimelineId::new(ttid.tenant_id, request_data.target_timeline_id),
224 0 : })
225 0 : .instrument(info_span!("copy_timeline", from=%ttid, to=%request_data.target_timeline_id, until_lsn=%request_data.until_lsn))
226 0 : .await
227 0 : .map_err(ApiError::InternalServerError)?;
228 :
229 0 : json_response(StatusCode::OK, ())
230 0 : }
231 :
232 0 : async fn timeline_digest_handler(request: Request<Body>) -> Result<Response<Body>, ApiError> {
233 0 : let ttid = TenantTimelineId::new(
234 0 : parse_request_param(&request, "tenant_id")?,
235 0 : parse_request_param(&request, "timeline_id")?,
236 : );
237 0 : check_permission(&request, Some(ttid.tenant_id))?;
238 :
239 0 : let from_lsn: Option<Lsn> = parse_query_param(&request, "from_lsn")?;
240 0 : let until_lsn: Option<Lsn> = parse_query_param(&request, "until_lsn")?;
241 :
242 0 : let request = TimelineDigestRequest {
243 0 : from_lsn: from_lsn.ok_or(ApiError::BadRequest(anyhow::anyhow!(
244 0 : "from_lsn is required"
245 0 : )))?,
246 0 : until_lsn: until_lsn.ok_or(ApiError::BadRequest(anyhow::anyhow!(
247 0 : "until_lsn is required"
248 0 : )))?,
249 : };
250 :
251 0 : let tli = GlobalTimelines::get(ttid).map_err(ApiError::from)?;
252 :
253 0 : let response = debug_dump::calculate_digest(&tli, request)
254 0 : .await
255 0 : .map_err(ApiError::InternalServerError)?;
256 0 : json_response(StatusCode::OK, response)
257 0 : }
258 :
259 : /// Download a file from the timeline directory.
260 : // TODO: figure out a better way to copy files between safekeepers
261 0 : async fn timeline_files_handler(request: Request<Body>) -> Result<Response<Body>, ApiError> {
262 0 : let ttid = TenantTimelineId::new(
263 0 : parse_request_param(&request, "tenant_id")?,
264 0 : parse_request_param(&request, "timeline_id")?,
265 : );
266 0 : check_permission(&request, Some(ttid.tenant_id))?;
267 :
268 0 : let filename: String = parse_request_param(&request, "filename")?;
269 :
270 0 : let tli = GlobalTimelines::get(ttid).map_err(ApiError::from)?;
271 :
272 0 : let filepath = tli.timeline_dir.join(filename);
273 0 : let mut file = File::open(&filepath)
274 0 : .await
275 0 : .map_err(|e| ApiError::InternalServerError(e.into()))?;
276 :
277 0 : let mut content = Vec::new();
278 0 : // TODO: don't store files in memory
279 0 : file.read_to_end(&mut content)
280 0 : .await
281 0 : .map_err(|e| ApiError::InternalServerError(e.into()))?;
282 :
283 0 : Response::builder()
284 0 : .status(StatusCode::OK)
285 0 : .header("Content-Type", "application/octet-stream")
286 0 : .body(Body::from(content))
287 0 : .map_err(|e| ApiError::InternalServerError(e.into()))
288 0 : }
289 :
290 : /// Deactivates the timeline and removes its data directory.
291 0 : async fn timeline_delete_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
292 0 : let ttid = TenantTimelineId::new(
293 0 : parse_request_param(&request, "tenant_id")?,
294 0 : parse_request_param(&request, "timeline_id")?,
295 : );
296 0 : let only_local = parse_query_param(&request, "only_local")?.unwrap_or(false);
297 0 : check_permission(&request, Some(ttid.tenant_id))?;
298 0 : ensure_no_body(&mut request).await?;
299 : // FIXME: `delete_force` can fail from both internal errors and bad requests. Add better
300 : // error handling here when we're able to.
301 0 : let resp = GlobalTimelines::delete(&ttid, only_local)
302 0 : .await
303 0 : .map_err(ApiError::InternalServerError)?;
304 0 : json_response(StatusCode::OK, resp)
305 0 : }
306 :
307 : /// Deactivates all timelines for the tenant and removes its data directory.
308 : /// See `timeline_delete_handler`.
309 0 : async fn tenant_delete_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
310 0 : let tenant_id = parse_request_param(&request, "tenant_id")?;
311 0 : let only_local = parse_query_param(&request, "only_local")?.unwrap_or(false);
312 0 : check_permission(&request, Some(tenant_id))?;
313 0 : ensure_no_body(&mut request).await?;
314 : // FIXME: `delete_force_all_for_tenant` can return an error for multiple different reasons;
315 : // Using an `InternalServerError` should be fixed when the types support it
316 0 : let delete_info = GlobalTimelines::delete_force_all_for_tenant(&tenant_id, only_local)
317 0 : .await
318 0 : .map_err(ApiError::InternalServerError)?;
319 0 : json_response(
320 0 : StatusCode::OK,
321 0 : delete_info
322 0 : .iter()
323 0 : .map(|(ttid, resp)| (format!("{}", ttid.timeline_id), *resp))
324 0 : .collect::<HashMap<String, TimelineDeleteForceResult>>(),
325 0 : )
326 0 : }
327 :
328 : /// Used only in tests to hand craft required data.
329 0 : async fn record_safekeeper_info(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
330 0 : let ttid = TenantTimelineId::new(
331 0 : parse_request_param(&request, "tenant_id")?,
332 0 : parse_request_param(&request, "timeline_id")?,
333 : );
334 0 : check_permission(&request, Some(ttid.tenant_id))?;
335 0 : let sk_info: SkTimelineInfo = json_request(&mut request).await?;
336 0 : let proto_sk_info = SafekeeperTimelineInfo {
337 0 : safekeeper_id: 0,
338 0 : tenant_timeline_id: Some(ProtoTenantTimelineId {
339 0 : tenant_id: ttid.tenant_id.as_ref().to_owned(),
340 0 : timeline_id: ttid.timeline_id.as_ref().to_owned(),
341 0 : }),
342 0 : term: sk_info.term.unwrap_or(0),
343 0 : last_log_term: sk_info.last_log_term.unwrap_or(0),
344 0 : flush_lsn: sk_info.flush_lsn.0,
345 0 : commit_lsn: sk_info.commit_lsn.0,
346 0 : remote_consistent_lsn: sk_info.remote_consistent_lsn.0,
347 0 : peer_horizon_lsn: sk_info.peer_horizon_lsn.0,
348 0 : safekeeper_connstr: sk_info.safekeeper_connstr.unwrap_or_else(|| "".to_owned()),
349 0 : http_connstr: sk_info.http_connstr.unwrap_or_else(|| "".to_owned()),
350 0 : backup_lsn: sk_info.backup_lsn.0,
351 0 : local_start_lsn: sk_info.local_start_lsn.0,
352 0 : availability_zone: None,
353 0 : };
354 :
355 0 : let tli = GlobalTimelines::get(ttid).map_err(ApiError::from)?;
356 0 : tli.record_safekeeper_info(proto_sk_info)
357 0 : .await
358 0 : .map_err(ApiError::InternalServerError)?;
359 :
360 0 : json_response(StatusCode::OK, ())
361 0 : }
362 :
363 0 : fn parse_kv_str<E: fmt::Display, T: FromStr<Err = E>>(k: &str, v: &str) -> Result<T, ApiError> {
364 0 : v.parse()
365 0 : .map_err(|e| ApiError::BadRequest(anyhow::anyhow!("cannot parse {k}: {e}")))
366 0 : }
367 :
368 : /// Dump debug info about all available safekeeper state.
369 0 : async fn dump_debug_handler(mut request: Request<Body>) -> Result<Response<Body>, ApiError> {
370 0 : check_permission(&request, None)?;
371 0 : ensure_no_body(&mut request).await?;
372 :
373 0 : let mut dump_all: Option<bool> = None;
374 0 : let mut dump_control_file: Option<bool> = None;
375 0 : let mut dump_memory: Option<bool> = None;
376 0 : let mut dump_disk_content: Option<bool> = None;
377 0 : let mut dump_term_history: Option<bool> = None;
378 0 : let mut tenant_id: Option<TenantId> = None;
379 0 : let mut timeline_id: Option<TimelineId> = None;
380 0 :
381 0 : let query = request.uri().query().unwrap_or("");
382 0 : let mut values = url::form_urlencoded::parse(query.as_bytes());
383 :
384 0 : for (k, v) in &mut values {
385 0 : match k.as_ref() {
386 0 : "dump_all" => dump_all = Some(parse_kv_str(&k, &v)?),
387 0 : "dump_control_file" => dump_control_file = Some(parse_kv_str(&k, &v)?),
388 0 : "dump_memory" => dump_memory = Some(parse_kv_str(&k, &v)?),
389 0 : "dump_disk_content" => dump_disk_content = Some(parse_kv_str(&k, &v)?),
390 0 : "dump_term_history" => dump_term_history = Some(parse_kv_str(&k, &v)?),
391 0 : "tenant_id" => tenant_id = Some(parse_kv_str(&k, &v)?),
392 0 : "timeline_id" => timeline_id = Some(parse_kv_str(&k, &v)?),
393 0 : _ => Err(ApiError::BadRequest(anyhow::anyhow!(
394 0 : "Unknown query parameter: {}",
395 0 : k
396 0 : )))?,
397 : }
398 : }
399 :
400 0 : let dump_all = dump_all.unwrap_or(false);
401 0 : let dump_control_file = dump_control_file.unwrap_or(dump_all);
402 0 : let dump_memory = dump_memory.unwrap_or(dump_all);
403 0 : let dump_disk_content = dump_disk_content.unwrap_or(dump_all);
404 0 : let dump_term_history = dump_term_history.unwrap_or(true);
405 0 :
406 0 : let args = debug_dump::Args {
407 0 : dump_all,
408 0 : dump_control_file,
409 0 : dump_memory,
410 0 : dump_disk_content,
411 0 : dump_term_history,
412 0 : tenant_id,
413 0 : timeline_id,
414 0 : };
415 :
416 0 : let resp = debug_dump::build(args)
417 0 : .await
418 0 : .map_err(ApiError::InternalServerError)?;
419 :
420 0 : let started_at = std::time::Instant::now();
421 0 :
422 0 : let (tx, rx) = mpsc::channel(1);
423 0 :
424 0 : let body = Body::wrap_stream(ReceiverStream::new(rx));
425 0 :
426 0 : let mut writer = ChannelWriter::new(128 * 1024, tx);
427 0 :
428 0 : let response = Response::builder()
429 0 : .status(200)
430 0 : .header(hyper::header::CONTENT_TYPE, "application/octet-stream")
431 0 : .body(body)
432 0 : .unwrap();
433 :
434 0 : let span = info_span!("blocking");
435 0 : tokio::task::spawn_blocking(move || {
436 0 : let _span = span.entered();
437 0 :
438 0 : let res = serde_json::to_writer(&mut writer, &resp)
439 0 : .map_err(std::io::Error::from)
440 0 : .and_then(|_| writer.flush());
441 0 :
442 0 : match res {
443 : Ok(()) => {
444 0 : tracing::info!(
445 0 : bytes = writer.flushed_bytes(),
446 0 : elapsed_ms = started_at.elapsed().as_millis(),
447 0 : "responded /v1/debug_dump"
448 0 : );
449 : }
450 0 : Err(e) => {
451 0 : tracing::warn!("failed to write out /v1/debug_dump response: {e:#}");
452 : // semantics of this error are quite... unclear. we want to error the stream out to
453 : // abort the response to somehow notify the client that we failed.
454 : //
455 : // though, most likely the reason for failure is that the receiver is already gone.
456 0 : drop(
457 0 : writer
458 0 : .tx
459 0 : .blocking_send(Err(std::io::ErrorKind::BrokenPipe.into())),
460 0 : );
461 : }
462 : }
463 0 : });
464 0 :
465 0 : Ok(response)
466 0 : }
467 :
468 0 : async fn patch_control_file_handler(
469 0 : mut request: Request<Body>,
470 0 : ) -> Result<Response<Body>, ApiError> {
471 0 : check_permission(&request, None)?;
472 :
473 0 : let ttid = TenantTimelineId::new(
474 0 : parse_request_param(&request, "tenant_id")?,
475 0 : parse_request_param(&request, "timeline_id")?,
476 : );
477 :
478 0 : let tli = GlobalTimelines::get(ttid).map_err(ApiError::from)?;
479 :
480 0 : let patch_request: patch_control_file::Request = json_request(&mut request).await?;
481 0 : let response = patch_control_file::handle_request(tli, patch_request)
482 0 : .await
483 0 : .map_err(ApiError::InternalServerError)?;
484 :
485 0 : json_response(StatusCode::OK, response)
486 0 : }
487 :
488 : /// Safekeeper http router.
489 0 : pub fn make_router(conf: SafeKeeperConf) -> RouterBuilder<hyper::Body, ApiError> {
490 0 : let mut router = endpoint::make_router();
491 0 : if conf.http_auth.is_some() {
492 0 : router = router.middleware(auth_middleware(|request| {
493 0 : #[allow(clippy::mutable_key_type)]
494 0 : static ALLOWLIST_ROUTES: Lazy<HashSet<Uri>> = Lazy::new(|| {
495 0 : ["/v1/status", "/metrics"]
496 0 : .iter()
497 0 : .map(|v| v.parse().unwrap())
498 0 : .collect()
499 0 : });
500 0 : if ALLOWLIST_ROUTES.contains(request.uri()) {
501 0 : None
502 : } else {
503 : // Option<Arc<SwappableJwtAuth>> is always provided as data below, hence unwrap().
504 0 : request
505 0 : .data::<Option<Arc<SwappableJwtAuth>>>()
506 0 : .unwrap()
507 0 : .as_deref()
508 : }
509 0 : }))
510 0 : }
511 :
512 : // NB: on any changes do not forget to update the OpenAPI spec
513 : // located nearby (/safekeeper/src/http/openapi_spec.yaml).
514 0 : let auth = conf.http_auth.clone();
515 0 : router
516 0 : .data(Arc::new(conf))
517 0 : .data(auth)
518 0 : .get("/v1/status", |r| request_span(r, status_handler))
519 0 : .put("/v1/failpoints", |r| {
520 0 : request_span(r, move |r| async {
521 0 : let cancel = CancellationToken::new();
522 0 : failpoints_handler(r, cancel).await
523 0 : })
524 0 : })
525 0 : // Will be used in the future instead of implicit timeline creation
526 0 : .post("/v1/tenant/timeline", |r| {
527 0 : request_span(r, timeline_create_handler)
528 0 : })
529 0 : .get("/v1/tenant/:tenant_id/timeline/:timeline_id", |r| {
530 0 : request_span(r, timeline_status_handler)
531 0 : })
532 0 : .delete("/v1/tenant/:tenant_id/timeline/:timeline_id", |r| {
533 0 : request_span(r, timeline_delete_handler)
534 0 : })
535 0 : .delete("/v1/tenant/:tenant_id", |r| {
536 0 : request_span(r, tenant_delete_handler)
537 0 : })
538 0 : .post("/v1/pull_timeline", |r| {
539 0 : request_span(r, timeline_pull_handler)
540 0 : })
541 0 : .get(
542 0 : "/v1/tenant/:tenant_id/timeline/:timeline_id/file/:filename",
543 0 : |r| request_span(r, timeline_files_handler),
544 0 : )
545 0 : .post(
546 0 : "/v1/tenant/:tenant_id/timeline/:source_timeline_id/copy",
547 0 : |r| request_span(r, timeline_copy_handler),
548 0 : )
549 0 : .patch(
550 0 : "/v1/tenant/:tenant_id/timeline/:timeline_id/control_file",
551 0 : |r| request_span(r, patch_control_file_handler),
552 0 : )
553 0 : // for tests
554 0 : .post("/v1/record_safekeeper_info/:tenant_id/:timeline_id", |r| {
555 0 : request_span(r, record_safekeeper_info)
556 0 : })
557 0 : .get("/v1/debug_dump", |r| request_span(r, dump_debug_handler))
558 0 : .get("/v1/tenant/:tenant_id/timeline/:timeline_id/digest", |r| {
559 0 : request_span(r, timeline_digest_handler)
560 0 : })
561 0 : }
562 :
563 : #[cfg(test)]
564 : mod tests {
565 : use super::*;
566 :
567 2 : #[test]
568 2 : fn test_term_switch_entry_api_serialize() {
569 2 : let state = AcceptorStateStatus {
570 2 : term: 1,
571 2 : epoch: 1,
572 2 : term_history: vec![TermSwitchApiEntry {
573 2 : term: 1,
574 2 : lsn: Lsn(0x16FFDDDD),
575 2 : }],
576 2 : };
577 2 : let json = serde_json::to_string(&state).unwrap();
578 2 : assert_eq!(
579 2 : json,
580 2 : "{\"term\":1,\"epoch\":1,\"term_history\":[{\"term\":1,\"lsn\":\"0/16FFDDDD\"}]}"
581 2 : );
582 2 : }
583 : }
|