Skip to content

Commit 12a7f50

Browse files
committed
graph: Allow using redis as an IPFS cache
1 parent 9444d38 commit 12a7f50

File tree

7 files changed

+213
-41
lines changed

7 files changed

+213
-41
lines changed

Cargo.lock

Lines changed: 80 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ itertools = "0.13.0"
6868
lazy_static = "1.5.0"
6969
prost = "0.13"
7070
prost-types = "0.13"
71+
redis = { version = "0.31.0", features = ["aio", "connection-manager", "tokio-comp"] }
7172
regex = "1.5.4"
7273
reqwest = "0.12.15"
7374
serde = { version = "1.0.126", features = ["rc"] }

docs/environment-variables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ those.
9191
file not found or logical issue working as a safety mechanism to
9292
prevent infinite spamming of IPFS servers and network congestion
9393
(default: 100 000).
94+
- `GRAPH_IPFS_CACHE_LOCATION`: When set, files retrieved from IPFS will be
95+
cached in that location; future accesses to the same file will be served
96+
from cache rather than IPFS. This can either be a URL starting with
97+
`redis://`, in which case there must be a Redis instance running at that
98+
URL, or an absolute file system path which must be a directory writable
99+
by the `graph-node` process (experimental)
94100

95101
## GraphQL
96102

graph/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ num-bigint = { version = "=0.2.6", features = ["serde"] }
4343
num-integer = { version = "=0.1.46" }
4444
num-traits = "=0.2.19"
4545
rand.workspace = true
46+
redis = { workspace = true }
4647
regex = "1.5.4"
4748
semver = { version = "1.0.23", features = ["serde"] }
4849
serde = { workspace = true }
@@ -85,7 +86,7 @@ tonic = { workspace = true }
8586
prost = { workspace = true }
8687
prost-types = { workspace = true }
8788

88-
futures03 = { version = "0.3.1", package = "futures", features = ["compat"] }
89+
futures03 = { version = "0.3.31", package = "futures", features = ["compat"] }
8990
wasmparser = "0.118.1"
9091
thiserror = "2.0.12"
9192
parking_lot = "0.12.3"

graph/src/env/mappings.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::fmt;
22
use std::path::PathBuf;
33

4-
use super::*;
4+
use anyhow::anyhow;
55

6+
use super::*;
67
#[derive(Clone)]
78
pub struct EnvVarsMapping {
89
/// Forces the cache eviction policy to take its own memory overhead into account.
@@ -159,7 +160,16 @@ pub struct InnerMappingHandlers {
159160
}
160161

161162
fn validate_ipfs_cache_location(path: PathBuf) -> Result<PathBuf, anyhow::Error> {
162-
let path = path.canonicalize()?;
163+
if path.starts_with("redis://") {
164+
// We validate this later when we set up the Redis client
165+
return Ok(path);
166+
}
167+
let path = path.canonicalize().map_err(|e| {
168+
anyhow!(
169+
"GRAPH_IPFS_CACHE_LOCATION {} is invalid: {e}",
170+
path.display()
171+
)
172+
})?;
163173
if !path.is_absolute() {
164174
return Err(anyhow::anyhow!(
165175
"GRAPH_IPFS_CACHE_LOCATION must be an absolute path: {}",

0 commit comments

Comments
 (0)