Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi Z <chi@neon.tech>
  • Loading branch information
skyzh committed May 17, 2024
1 parent 01a6510 commit 1dc17e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
35 changes: 20 additions & 15 deletions pageserver/pagebench/src/cmd/aux_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use utils::id::TenantTimelineId;
use utils::lsn::Lsn;

use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use crate::util::tokio_thread_local_stats::AllThreadLocalStats;
use crate::util::{request_stats, tokio_thread_local_stats};
use std::sync::Arc;

/// Ingest aux files into the pageserver.
#[derive(clap::Parser)]
Expand All @@ -22,18 +19,17 @@ pub(crate) struct Args {
targets: Option<Vec<TenantTimelineId>>,
}

tokio_thread_local_stats::declare!(STATS: request_stats::Stats);

pub(crate) fn main(args: Args) -> anyhow::Result<()> {
tokio_thread_local_stats::main!(STATS, move |thread_local_stats| {
main_impl(args, thread_local_stats)
})
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();

let main_task = rt.spawn(main_impl(args));
rt.block_on(main_task).unwrap()
}

async fn main_impl(
args: Args,
_all_thread_local_stats: AllThreadLocalStats<request_stats::Stats>,
) -> anyhow::Result<()> {
async fn main_impl(args: Args) -> anyhow::Result<()> {
let args: &'static Args = Box::leak(Box::new(args));

let mgmt_api_client = Arc::new(pageserver_client::mgmt_api::Client::new(
Expand All @@ -45,8 +41,17 @@ async fn main_impl(
let timelines: Vec<TenantTimelineId> = crate::util::cli::targets::discover(
&mgmt_api_client,
crate::util::cli::targets::Spec {
limit_to_first_n_targets: Some(1),
targets: args.targets.clone(),
limit_to_first_n_targets: None,
targets: {
if let Some(targets) = &args.targets {
if targets.len() != 1 {
anyhow::bail!("must specify exactly one target");
}
Some(targets.clone())
} else {
None
}
},
},
)
.await?;
Expand Down
12 changes: 6 additions & 6 deletions pageserver/src/http/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,13 +2341,13 @@ async fn list_aux_files(
.await?;

let process = || async move {
let ctx = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Warn);
let ctx = RequestContext::new(TaskKind::MgmtRequest, DownloadBehavior::Download);
let files = timeline.list_aux_files(body.lsn, &ctx).await?;
Ok::<_, anyhow::Error>(files)
};

match process().await {
Ok(st) => json_response(StatusCode::ACCEPTED, st),
Ok(st) => json_response(StatusCode::OK, st),
Err(err) => json_response(
StatusCode::INTERNAL_SERVER_ERROR,
ApiError::InternalServerError(err).to_string(),
Expand All @@ -2374,7 +2374,7 @@ async fn ingest_aux_files(
let mut modification = timeline.begin_modification(Lsn(
timeline.get_last_record_lsn().0 + 8
) /* advance LSN by 8 */);
let ctx = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Warn);
let ctx = RequestContext::new(TaskKind::MgmtRequest, DownloadBehavior::Download);
for (fname, content) in body.aux_files {
modification
.put_file(&fname, content.as_bytes(), &ctx)
Expand All @@ -2385,7 +2385,7 @@ async fn ingest_aux_files(
};

match process().await {
Ok(st) => json_response(StatusCode::ACCEPTED, st),
Ok(st) => json_response(StatusCode::OK, st),
Err(err) => Err(ApiError::InternalServerError(err)),
}
}
Expand Down Expand Up @@ -2678,11 +2678,11 @@ pub fn make_router(
.get("/v1/utilization", |r| api_handler(r, get_utilization))
.post(
"/v1/tenant/:tenant_shard_id/timeline/:timeline_id/ingest_aux_files",
|r| api_handler(r, ingest_aux_files),
|r| testing_api_handler("ingest_aux_files", r, ingest_aux_files),
)
.post(
"/v1/tenant/:tenant_shard_id/timeline/:timeline_id/list_aux_files",
|r| api_handler(r, list_aux_files),
|r| testing_api_handler("list_aux_files", r, list_aux_files),
)
.any(handler_404))
}

0 comments on commit 1dc17e0

Please sign in to comment.