nginx's map and variable hashes are sized for the keys they hold
Signed-off-by: dawn <90008@klbr.net>
454 unmodified linesExpand all455456457458459459460461462463395 unmodified linesExpand all454 unmodified linesExpand allstruct Maps { rows: BTreeMap<&'static str, Vec<(String, String)>>,}
/// longer keys overflow nginx's `map_hash_bucket_size` and fail the whole config./// keys this long are what `map_hash_bucket_size` is sized for, longer ones would fail the whole config.const MAX_KEY_BYTES: usize = 400;
const COMMIT_SOURCES: [(&str, &str); 3] = [ ("$ks_atp_repo|$arg_ref", "$ks_git_commit"),395 unmodified linesExpand all484 unmodified linesExpand all48548648748848949048949049149249349449549649749849950050150288 unmodified lines484 unmodified linesExpand all ) .block(Block::new("events", NONE).directive("worker_connections", ["1024"])) .block( limit_zones(http, limits) // the bigger tables have to be set before the maps include. .directive("map_hash_bucket_size", ["512"]) // the bigger tables have to be set before the maps include. a bucket holds every key // that hashes to it, and git keys run to 400 bytes, so a few long ones need 4k. // nginx allocates only what the keys take. .directive("map_hash_bucket_size", ["4096"]) .directive( "map_hash_max_size", [map_hash_max_size(&maps_dir)?.to_string()], ) .directive("variables_hash_max_size", ["4096"]) .directive("variables_hash_bucket_size", ["256"]) .directive("include", [format!("{gen_path}/nginx/maps/*.conf")]) .directive( "limit_req_zone", ["$binary_remote_addr", "zone=ks_writes:10m", "rate=2r/s"],88 unmodified lines1381 unmodified linesExpand all1382138313841385138613871387138813891390139113921393139413951396139738 unmodified lines1381 unmodified linesExpand all let (config, manifest, generation) = test_fixture(temp.path()); let fragments = temp.path().join("fragments"); std::fs::create_dir_all(&fragments).unwrap(); let mut includes = String::new(); let long = "p".repeat(390); for part in 0..4 { let rows: String = (0..6000).map(|i| format!("k{part}x{i} v;\n")).collect(); let rows: String = (0..6000) .map(|i| match i % 4 { 0 => format!("k{part}x{i}{long} v;\n"), _ => format!("k{part}x{i} v;\n"), }) .collect(); let fragment = fragments.join(format!("{part}.conf")); std::fs::write(&fragment, rows).unwrap(); includes += &format!(" include {};\n", fragment.display()); }38 unmodified lines16 unmodified lines171819202121222324251305 unmodified linesExpand all16 unmodified linesconst EPOCH: i64 = 1_700_000_000;const SECRET: &str = "SECRET-DO-NOT-SERVE";/// longer request lines run into nginx's 8k header buffer and get a 414 before any routing.const MAX_TARGET: usize = 6000;/// longer keys overflow map_hash_bucket_size (512) and the config fails./// the longest keys git_xrpc writes.const MAX_KEY_BYTES: usize = 400;
type Dir = BTreeMap<String, Node>;
1305 unmodified linesExpand all