Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions lore-aws/src/dynamodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ const QUERY_ROWS: [f64; 10] = [

pub const METRICS_ACCUMULATION_OPERATION_LATENCY_METRIC_NAME: &str =
"accumulation_operation_duration";

/// Temporary environment variable to allow enabling/disabling query pagination.
/// TODO(jcohen): Remove this when we're confident in the pagination support.
static ENABLE_QUERY_PAGINATION: LazyLock<bool> =
LazyLock::new(|| match std::env::var("LORE_ENABLE_QUERY_PAGINATION") {
Ok(v) => v.eq_ignore_ascii_case("true"),
Err(_) => true, // Default to enabled if the env var isn't present
});

pub trait DynamoDbQuery {
fn index_name(&self) -> Option<String> {
None
Expand Down Expand Up @@ -575,6 +566,10 @@ impl DynamoDbImpl {
where
T: DynamoDbQuery + 'static,
{
if matches!(query.select(), Some(Select::Count)) && query.limit().is_some() {
panic!("Combining Select::Count and a limit is disallowed for paginated queries to avoid fetching count one row at a time.");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A panic is not an appropriate way to handle this. This should either be a combination that's structurally not possible and verified at compile time or it should be a properly handled runtime error.

}

let base_labels = {
let mut labels = self
.instruments
Expand Down Expand Up @@ -651,12 +646,7 @@ impl DynamoDbImpl {
// the desired number of rows, there's no need to continue fetching more
// rows.
// 3. *Unless* the query is also a count query (in which case we need to fetch
// until there's no more data to collect to ensure we get the correct count).
// TODO(jcohen): We should probably disallow the combination of `Select::Count`
// and a limit to avoid the degenerate case of fetching a full count one row at
// a time.
if *ENABLE_QUERY_PAGINATION
&& let Some(last_evaluated_key) = r.last_evaluated_key
if let Some(last_evaluated_key) = r.last_evaluated_key
&& !last_evaluated_key.is_empty()
&& (query.limit().is_none()
|| matches!(query.select(), Some(Select::Count))
Expand Down
7 changes: 3 additions & 4 deletions lore-client/src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::println;
use crate::styling::cli_styles;
use crate::util::get_repository_path;

// TODO(UCS-12558): Cleanup logging args
#[derive(Parser)]
#[command(name = "lore", styles = cli_styles())]
#[clap(about, long_about = None)]
Expand All @@ -31,15 +30,15 @@ pub struct LoreCli {
pub repository: Option<String>,

/// Set the logging level
#[clap(global = true, long = "log-level", value_name = "level")]
#[clap(global = true, long = "log-level", value_name = "level", conflicts_with_all = ["debug", "silent"])]
pub level: Option<String>,

/// Enable debug output
#[clap(global = true, long, short, action)]
#[clap(global = true, long, short, action, conflicts_with_all = ["level", "silent"])]
pub debug: bool,

/// Suppress all output
#[clap(global = true, hide = true, long, short, action)]
#[clap(global = true, hide = true, long, short, action, conflicts_with_all = ["level", "debug"])]
pub silent: bool,

/// Time execution of command
Expand Down
6 changes: 3 additions & 3 deletions lore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let path_sep = MAIN_SEPARATOR;

let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set");

// list all .rs files in `lore` so that we run this script to update the c header
for entry in glob("src/**/*.rs").expect("glob syntax error") {
Expand All @@ -32,10 +32,10 @@ fn main() -> Result<(), Box<dyn Error>> {
// list input configuration files so that we run this script to update the c header
println!("cargo:rerun-if-changed=cbindgen.toml");

let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = env::var("OUT_DIR").expect("OUT_DIR must be set");
let header_gen = format!("{out_dir}{path_sep}lore.h");
let source_gen = format!("{out_dir}{path_sep}lore.c");
let config = cbindgen::Config::from_file("cbindgen.toml").unwrap();
let config = cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml");

// run cbindgen to generate `lore.h`
match cbindgen::Builder::new()
Expand Down
Loading