From e23f114363c003ec2f920a2a9e9210fd0038dc29 Mon Sep 17 00:00:00 2001 From: ad Date: Wed, 18 Sep 2024 16:17:06 +0200 Subject: [PATCH] when fetching if record is None is 404 --- .flox/env/manifest.lock | 119 +++++++++++ .flox/env/manifest.toml | 1 + Cargo.lock | 425 +++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- src/main.rs | 22 ++- src/record.rs | 36 ++-- 6 files changed, 563 insertions(+), 43 deletions(-) diff --git a/.flox/env/manifest.lock b/.flox/env/manifest.lock index 8c96979..0c000af 100644 --- a/.flox/env/manifest.lock +++ b/.flox/env/manifest.lock @@ -27,6 +27,9 @@ "snappy": { "pkg-path": "snappy" }, + "tokio-console": { + "pkg-path": "tokio-console" + }, "wrk": { "pkg-path": "wrk" } @@ -1019,6 +1022,122 @@ "group": "toplevel", "priority": 5 }, + { + "attr_path": "tokio-console", + "broken": false, + "derivation": "/nix/store/kknw8d0sm0yinsyss7hq711ld90pigdg-tokio-console-0.1.10.drv", + "description": "Debugger for asynchronous Rust code", + "install_id": "tokio-console", + "license": "[ MIT ]", + "locked_url": "https://github.com/flox/nixpkgs?rev=4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "name": "tokio-console-0.1.10", + "pname": "tokio-console", + "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev_count": 680062, + "rev_date": "2024-09-11T13:54:33Z", + "scrape_date": "2024-09-14T03:13:36Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "0.1.10", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/4day5ks7a1ap4b03240f8z5nzv6b2841-tokio-console-0.1.10" + }, + "system": "aarch64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "tokio-console", + "broken": false, + "derivation": "/nix/store/qqkharydwy1yhb2f3vghywi3kd3wrcqj-tokio-console-0.1.10.drv", + "description": "Debugger for asynchronous Rust code", + "install_id": "tokio-console", + "license": "[ MIT ]", + "locked_url": "https://github.com/flox/nixpkgs?rev=4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "name": "tokio-console-0.1.10", + "pname": "tokio-console", + "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev_count": 680062, + "rev_date": "2024-09-11T13:54:33Z", + "scrape_date": "2024-09-14T03:13:36Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "0.1.10", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/4nainrg91i4q0pxjq035zzk9wgbfcfi1-tokio-console-0.1.10" + }, + "system": "aarch64-linux", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "tokio-console", + "broken": false, + "derivation": "/nix/store/sl5m0ngpqvs6wzgkziz5xmzih8z44nc6-tokio-console-0.1.10.drv", + "description": "Debugger for asynchronous Rust code", + "install_id": "tokio-console", + "license": "[ MIT ]", + "locked_url": "https://github.com/flox/nixpkgs?rev=4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "name": "tokio-console-0.1.10", + "pname": "tokio-console", + "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev_count": 680062, + "rev_date": "2024-09-11T13:54:33Z", + "scrape_date": "2024-09-14T03:13:36Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "0.1.10", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/6337wndzj91i1np9mxqzy0zsdr8yiz9j-tokio-console-0.1.10" + }, + "system": "x86_64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "tokio-console", + "broken": false, + "derivation": "/nix/store/riq3lpxdsl32rai8n6nsdqzmxpxfl9dg-tokio-console-0.1.10.drv", + "description": "Debugger for asynchronous Rust code", + "install_id": "tokio-console", + "license": "[ MIT ]", + "locked_url": "https://github.com/flox/nixpkgs?rev=4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "name": "tokio-console-0.1.10", + "pname": "tokio-console", + "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev_count": 680062, + "rev_date": "2024-09-11T13:54:33Z", + "scrape_date": "2024-09-14T03:13:36Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "0.1.10", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/29svm5qfdhml1gcgvg6a625fchi9ijsy-tokio-console-0.1.10" + }, + "system": "x86_64-linux", + "group": "toplevel", + "priority": 5 + }, { "attr_path": "wrk", "broken": false, diff --git a/.flox/env/manifest.toml b/.flox/env/manifest.toml index 4dbbbbc..c6ad85a 100644 --- a/.flox/env/manifest.toml +++ b/.flox/env/manifest.toml @@ -17,6 +17,7 @@ pcre.pkg-path = "pcre" wrk.pkg-path = "wrk" heaptrack.pkg-path = "heaptrack" samply.pkg-path = "samply" +tokio-console.pkg-path = "tokio-console" # Set environment variables in the `[vars]` section. These variables may not # reference one another, and are added to the environment without first diff --git a/Cargo.lock b/Cargo.lock index 10cfaf2..6f5f85d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,39 @@ version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-trait" +version = "0.1.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -93,6 +126,53 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 1.0.1", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -232,6 +312,45 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "console-api" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ed14aa9c9f927213c6e4f3ef75faaad3406134efe84ba2cb7983431d5f0931" +dependencies = [ + "futures-core", + "prost", + "prost-types", + "tonic", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e3a111a37f3333946ebf9da370ba5c5577b18eb342ec683eb488dd21980302" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures-task", + "hdrhistogram", + "humantime", + "hyper-util", + "prost", + "prost-types", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -257,6 +376,30 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crypto-common" version = "0.1.6" @@ -295,6 +438,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -355,6 +504,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec54ac60a7f2ee9a97cad9946f9bf629a3bc6a7ae59e68983dc9318f5a54b81a" +[[package]] +name = "flate2" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -522,7 +681,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap", + "indexmap 2.5.0", "slab", "tokio", "tokio-util", @@ -541,19 +700,38 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap", + "indexmap 2.5.0", "slab", "tokio", "tokio-util", "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "base64 0.21.7", + "byteorder", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "headers" version = "0.3.9" @@ -701,6 +879,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec", @@ -725,6 +904,19 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-timeout" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper 1.4.1", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -771,6 +963,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.5.0" @@ -778,7 +980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -793,6 +995,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -808,6 +1019,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "leveldb" version = "0.8.6" @@ -859,6 +1076,21 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md5" version = "0.7.0" @@ -887,6 +1119,12 @@ dependencies = [ "unicase", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.0" @@ -943,6 +1181,25 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -1097,6 +1354,38 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" +dependencies = [ + "prost", +] + [[package]] name = "quote" version = "1.0.37" @@ -1153,8 +1442,17 @@ checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1165,9 +1463,15 @@ checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.4", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.4" @@ -1205,7 +1509,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "system-configuration", "tokio", "tokio-native-tls", @@ -1241,6 +1545,7 @@ dependencies = [ "bincode", "bytes", "clap", + "console-subscriber", "db-key 0.1.0", "env_logger", "futures", @@ -1425,6 +1730,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1494,6 +1808,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "sync_wrapper" version = "1.0.1" @@ -1557,6 +1877,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -1587,6 +1917,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", + "tracing", "windows-sys 0.52.0", ] @@ -1622,6 +1953,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-tungstenite" version = "0.21.0" @@ -1647,6 +1989,36 @@ dependencies = [ "tokio", ] +[[package]] +name = "tonic" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f6ba989e4b2c58ae83d862d3a3e27690b6e3ae630d0deb59f3697f32aa88ad" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.22.1", + "bytes", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.4.1", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "prost", + "socket2", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -1655,11 +2027,16 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite", + "rand", + "slab", "tokio", + "tokio-util", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -1682,9 +2059,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -1692,6 +2081,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "once_cell", + "regex", + "sharded-slab", + "thread_local", + "tracing", + "tracing-core", ] [[package]] @@ -1784,6 +2189,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 25f1504..e9be86b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ base64 = "0.22.1" bincode = "1.3.3" bytes = "1.7.1" clap = { version = "4.5.17", features = ["derive"] } +console-subscriber = "0.4.0" db-key = "0.1.0" env_logger = "0.11.5" futures = "0.3.30" @@ -19,7 +20,7 @@ md5 = "0.7.0" rand = "0.8.5" reqwest = "0.12.7" serde = { version = "1.0.210", features = ["derive"] } -tokio = { version = "1.40.0", features = ["full"] } +tokio = { version = "1.40.0", features = ["full", "tracing"] } warp = "0.3.7" [profile.profiling] diff --git a/src/main.rs b/src/main.rs index 17806d1..8a47280 100644 --- a/src/main.rs +++ b/src/main.rs @@ -282,15 +282,7 @@ async fn handle_put_record( } let value_md5_hash = if verify_checksums { - match task::spawn_blocking(move || format!("{:x}", md5::compute(value))).await { - Ok(value_md5_hash) => value_md5_hash, - Err(e) => { - error!("put_record: failed to compute md5 hash for value: {}", e); - return Ok(warp::http::Response::builder() - .status(warp::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(e.to_string())); - } - } + format!("{:x}", md5::compute(value)) } else { String::new() }; @@ -355,7 +347,7 @@ async fn handle_get_record( debug!("get_record: key: {}", key); let record = { - match leveldb.get_record_or_default(&key).await { + match leveldb.get_record(&key).await { Ok(record) => record, Err(e) => { error!( @@ -369,6 +361,16 @@ async fn handle_get_record( } }; + if record.is_none() { + return Ok(warp::http::Response::builder() + .status(warp::http::StatusCode::NOT_FOUND) + .header("Content-Md5", "") + .header("Content-Length", "0") + .body(String::new())); + } + + let record = record.unwrap(); + // TODO fallbacks if record.deleted() != record::Deleted::No { debug!( diff --git a/src/record.rs b/src/record.rs index 36c49f7..275cbfa 100644 --- a/src/record.rs +++ b/src/record.rs @@ -59,17 +59,6 @@ impl Default for Record { } } -impl TryFrom>> for Record { - type Error = anyhow::Error; - - fn try_from(value: Option>) -> anyhow::Result { - match value { - Some(data) => Self::from_bytes(&data), - None => Ok(Record::default()), - } - } -} - pub(crate) type LevelDbKey = i32; pub(crate) fn leveldb_key_from_str(key: &str) -> LevelDbKey { @@ -107,7 +96,7 @@ impl LevelDb { Ok(()) } - pub(crate) async fn get_record_or_default(&self, key: &str) -> anyhow::Result { + pub(crate) async fn get_record(&self, key: &str) -> anyhow::Result> { let read_options = leveldb::options::ReadOptions::new(); let leveldb_key = leveldb_key_from_str(key); @@ -116,9 +105,16 @@ impl LevelDb { .get(read_options, leveldb_key) .with_context(|| format!("Failed to get key {} from LevelDB", key))?; - record - .try_into() - .with_context(|| format!("Failed to deserialize record for key {}", key)) + if let Some(record) = record { + Ok(Some(Record::from_bytes(&record)?)) + } else { + Ok(None) + } + } + + pub(crate) async fn get_record_or_default(&self, key: &str) -> anyhow::Result { + let record = self.get_record(key).await?; + Ok(record.unwrap_or(Record::default())) } } @@ -230,16 +226,6 @@ mod tests { Ok(()) } - #[test] - fn test_record_try_from_none() -> anyhow::Result<()> { - let record: Option> = None; - let deserialized_record: Record = record.try_into()?; - let expected_record = Record::default(); - assert_eq!(deserialized_record, expected_record); - - Ok(()) - } - #[test] fn test_record_with_empty_read_volumes() -> anyhow::Result<()> { let record = Record {