diff --git a/README.md b/README.md index 0b284c4..26d185d 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ directory, it will also be loaded automatically. | `PLC_URL` | `https://plc.wtf`, `https://plc.directory` if full network | base URL(s) of the PLC directory (comma-separated for multiple). | | `EPHEMERAL` | `false` | if enabled, no records are stored. events are deleted after a certain duration (`EPHEMERAL_TTL`). | | `EPHEMERAL_TTL` | `60min`, `3d` in relay mode | decides after how long events should be deleted. | +| `ONLY_INDEX_LINKS` | `false` | indexer only. if enabled, record blocks are not stored, only the index (records, counts, events) is kept. `getRecord`, `listRecords`, and `getRepo` will return errors. the event stream still works but create/update events will not include record values. | | `FULL_NETWORK` | `false` (indexer), `true` (relay) | if `true`, discovers and indexes all repositories in the network. | | `FILTER_SIGNALS` | | comma-separated list of NSID patterns to use for the filter (e.g. `app.bsky.feed.post,app.bsky.graph.*`). | | `FILTER_COLLECTIONS` | | comma-separated list of NSID patterns to use for the collections filter. | diff --git a/src/backfill/mod.rs b/src/backfill/mod.rs index 2418b5b..9f3984a 100644 --- a/src/backfill/mod.rs +++ b/src/backfill/mod.rs @@ -567,6 +567,7 @@ async fn process_did<'i>( tokio::task::spawn_blocking(move || { let filter = app_state.filter.load(); + let only_index_links = app_state.only_index_links; let mut count = 0; let mut delta = 0; let mut added_blocks = 0; @@ -646,7 +647,9 @@ async fn process_did<'i>( let cid_raw = cid.to_bytes(); let block_key = Slice::from(keys::block_key(collection, &cid_raw)); if !ephemeral { - batch.insert(&app_state.db.blocks, block_key.clone(), val.as_ref()); + if !only_index_links { + batch.insert(&app_state.db.blocks, block_key.clone(), val.as_ref()); + } batch.insert(&app_state.db.records, db_key, cid_raw); #[cfg(feature = "backlinks")] if let Ok(value) = serde_ipld_dagcbor::from_slice::(val.as_ref()) { @@ -675,7 +678,13 @@ async fn process_did<'i>( collection: CowStr::Borrowed(collection), rkey, action, - data: ephemeral.then_some(StoredData::Block(val)).unwrap_or_else(|| StoredData::Ptr(cid_obj.to_ipld().expect("valid cid"))), + data: if ephemeral { + StoredData::Block(val) + } else if only_index_links { + StoredData::Nothing + } else { + StoredData::Ptr(cid_obj.to_ipld().expect("valid cid")) + }, }; let bytes = rmp_serde::to_vec(&evt).into_diagnostic()?; batch.insert(&app_state.db.events, keys::event_key(event_id), bytes); diff --git a/src/config.rs b/src/config.rs index 47e1841..4c7b6e8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -368,6 +368,13 @@ pub struct Config { /// set via `HYDRANT_ENABLE_BACKLINKS=true`. pub enable_backlinks: bool, + /// if `true`, record blocks are not stored; only the index (records, counts, events) is kept. + /// `getRecord`, `listRecords`, and `getRepo` will return errors when this is enabled. + /// event stream still functions but create/update events will not include record values. + /// only valid in indexer mode (not relay). + /// set via `HYDRANT_ONLY_INDEX_LINKS=true`. + pub only_index_links: bool, + /// base URL(s) of relay or aggregator services to seed firehose PDS sources from at startup. /// /// hydrant calls `com.atproto.sync.listHosts` on each URL and adds the returned PDSes @@ -484,6 +491,7 @@ impl Default for Config { filter_collections: None, filter_excludes: None, enable_backlinks: false, + only_index_links: false, tier_rules: vec![], tier_policy: { let mut tiers = HashMap::new(); @@ -659,6 +667,7 @@ impl Config { }); let enable_backlinks: bool = cfg!("ENABLE_BACKLINKS", defaults.enable_backlinks); + let only_index_links: bool = cfg!("ONLY_INDEX_LINKS", defaults.only_index_links); // start with built-in tier definitions, then layer in any env-defined overrides. // format: HYDRANT_RATE_TIERS=name:base/mul/hourly/daily,... @@ -772,6 +781,7 @@ impl Config { filter_collections, filter_excludes, enable_backlinks, + only_index_links, tier_policy, tier_rules, cache_size, @@ -886,6 +896,9 @@ impl fmt::Display for Config { if self.enable_backlinks { config_line!(f, "backlinks", "enabled")?; } + if self.only_index_links { + config_line!(f, "only index links", "true")?; + } if !self.seed_hosts.is_empty() { config_line!( f, diff --git a/src/control/mod.rs b/src/control/mod.rs index 2dedf61..8b7a7f9 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -128,6 +128,11 @@ impl Hydrant { pub async fn new(config: Config) -> Result { info!("{config}"); + #[cfg(feature = "relay")] + if config.only_index_links { + miette::bail!("HYDRANT_ONLY_INDEX_LINKS is not supported in relay mode"); + } + // 1. open database and construct AppState let state = AppState::new(&config)?; diff --git a/src/control/repos/indexer.rs b/src/control/repos/indexer.rs index 7c7c09b..3a4f3b0 100644 --- a/src/control/repos/indexer.rs +++ b/src/control/repos/indexer.rs @@ -334,6 +334,10 @@ impl ReposControl { impl<'i> RepoHandle<'i> { /// gets a record from this repository. pub async fn get_record(&self, collection: &str, rkey: &str) -> Result> { + if self.state.only_index_links { + miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + } + let did = self.did.clone().into_static(); let db_key = keys::record_key(&did, collection, &DbRkey::new(rkey)); @@ -376,6 +380,9 @@ impl<'i> RepoHandle<'i> { reverse: bool, cursor: Option<&str>, ) -> Result { + if self.state.only_index_links { + miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + } let did = self.did.clone().into_static(); let state = self.state.clone(); @@ -479,6 +486,9 @@ impl<'i> RepoHandle<'i> { &self, ) -> Result> + Send + 'static>> { + if self.state.only_index_links { + miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + } use iroh_car::{CarHeader, CarWriter}; use jacquard_repo::{BlockStore, MemoryBlockStore, Mst}; use miette::WrapErr; diff --git a/src/ingest/indexer.rs b/src/ingest/indexer.rs index 91db48c..b0b63ea 100644 --- a/src/ingest/indexer.rs +++ b/src/ingest/indexer.rs @@ -476,6 +476,7 @@ impl FirehoseWorker { validated, &ctx.state.filter.load(), ctx.ephemeral, + ctx.state.only_index_links, )?; let repo_state = res.repo_state; *ctx.added_blocks += res.blocks_count; diff --git a/src/ops.rs b/src/ops.rs index c775b7f..bb142a9 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -210,6 +210,7 @@ pub fn apply_commit<'s>( validated: ValidatedCommit<'_>, filter: &FilterConfig, ephemeral: bool, + only_index_links: bool, ) -> Result> { let commit = validated.commit; let parsed = validated.parsed_blocks; @@ -257,7 +258,9 @@ pub fn apply_commit<'s>( blocks_count += 1; if !ephemeral { - batch.insert(&db.blocks, block_key.clone(), bytes.as_ref()); + if !only_index_links { + batch.insert(&db.blocks, block_key.clone(), bytes.as_ref()); + } batch.insert(&db.records, db_key.clone(), cid_raw); // accumulate counts if action == DbAction::Create { @@ -314,10 +317,12 @@ pub fn apply_commit<'s>( data: block .map(StoredData::Block) .or_else(|| { - op.cid - .as_ref() - .map(|c| c.to_ipld().expect("valid cid")) - .map(StoredData::Ptr) + (!only_index_links).then(|| { + op.cid + .as_ref() + .map(|c| c.to_ipld().expect("valid cid")) + .map(StoredData::Ptr) + })? }) .unwrap_or(StoredData::Nothing), }; diff --git a/src/state.rs b/src/state.rs index 5c07e9e..d340b7d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -34,6 +34,7 @@ pub struct AppState { #[cfg(feature = "indexer")] pub backfill_enabled: watch::Sender, pub ephemeral_ttl: Duration, + pub only_index_links: bool, pub throttler: Throttler, } @@ -107,6 +108,7 @@ impl AppState { #[cfg(feature = "indexer")] backfill_enabled, ephemeral_ttl: config.ephemeral_ttl.clone(), + only_index_links: config.only_index_links, throttler: Throttler::new(), }) }