Skip to content
Merged
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
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ron = "0.12"
regex = "1.12"
rustls = "0.23.39"
rustls-native-certs = "0.8.3"
rusqlite = { version = "0.37", features = ["bundled"] }
Comment thread
vansour marked this conversation as resolved.
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha1 = "0.11"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ scripts/run-fuzz-coverage.sh --target certificate_inspect
## 文档

- [docs/README.md](docs/README.md) 汇总当前生效的仓库治理文档
- [docs/CACHE_ARCHITECTURE_GAPS.md](docs/CACHE_ARCHITECTURE_GAPS.md) 记录缓存当前长期架构差距与演进方向
- [docs/NEZHA_DASHBOARD.md](docs/NEZHA_DASHBOARD.md) 提供 Nezha Dashboard 反向代理完整示例
- [fuzz/README.md](fuzz/README.md) 说明 fuzz target、seed、smoke 和 coverage 流程

Expand Down
1 change: 1 addition & 0 deletions crates/rginx-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rasn-pkix = "0.28.13"
rginx-core = { path = "../rginx-core" }
rustls.workspace = true
rustls-native-certs.workspace = true
rusqlite.workspace = true
serde.workspace = true
serde_json.workspace = true
sha1.workspace = true
Expand Down
15 changes: 5 additions & 10 deletions crates/rginx-http/src/cache/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ impl CacheManager {
%error,
"failed to read cache metadata; removing entry"
);
remove_index_entry(zone, key);
remove_zone_index_entry(zone, key).await;
remove_cache_files_if_unindexed(zone, key, &entry.hash).await;
persist_zone_shared_index(zone).await;
return None;
}
};
Expand All @@ -133,9 +132,8 @@ impl CacheManager {
key_hash = %entry.hash,
"cache metadata key mismatch; removing entry"
);
remove_index_entry(zone, key);
remove_zone_index_entry(zone, key).await;
remove_cache_files_if_unindexed(zone, key, &entry.hash).await;
persist_zone_shared_index(zone).await;
return None;
}
let headers = match metadata.headers_map() {
Expand All @@ -147,9 +145,8 @@ impl CacheManager {
%error,
"failed to decode cached response headers; removing entry"
);
remove_index_entry(zone, key);
remove_zone_index_entry(zone, key).await;
remove_cache_files_if_unindexed(zone, key, &entry.hash).await;
persist_zone_shared_index(zone).await;
return None;
}
};
Expand Down Expand Up @@ -193,9 +190,8 @@ impl CacheManager {
%error,
"failed to build stale cached response; removing entry"
);
remove_index_entry(zone, key);
remove_zone_index_entry(zone, key).await;
remove_cache_files_if_unindexed(zone, key, &entry.hash).await;
persist_zone_shared_index(zone).await;
return None;
}
}
Expand All @@ -208,9 +204,8 @@ impl CacheManager {
key_hash = %entry.hash,
"cache metadata key mismatch while serving stale entry; removing entry"
);
remove_index_entry(zone, key);
remove_zone_index_entry(zone, key).await;
remove_cache_files_if_unindexed(zone, key, &entry.hash).await;
persist_zone_shared_index(zone).await;
return None;
}
if status == CacheStatus::Updating {
Expand Down
9 changes: 3 additions & 6 deletions crates/rginx-http/src/cache/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl CacheManager {
zone.path.display()
))
})?;
let (index, shared_index_generation, shared_index_last_modified_unix_ms) =
let (index, shared_index_store, shared_index_generation) =
bootstrap_shared_index(zone.as_ref()).map_err(|error| {
Error::Server(format!(
"failed to load cache zone `{name}` index from `{}`: {error}",
Expand All @@ -32,13 +32,11 @@ impl CacheManager {
index: Mutex::new(index),
io_lock: AsyncMutex::new(()),
shared_index_sync_lock: AsyncMutex::new(()),
shared_index_store,
fill_locks: Arc::new(Mutex::new(HashMap::new())),
fill_lock_generation: AtomicU64::new(0),
last_inactive_cleanup_unix_ms: AtomicU64::new(0),
shared_index_generation: AtomicU64::new(shared_index_generation),
shared_index_last_modified_unix_ms: AtomicU64::new(
shared_index_last_modified_unix_ms,
),
stats: CacheZoneStats::default(),
change_notifier: change_notifier.clone(),
}),
Expand Down Expand Up @@ -118,9 +116,8 @@ impl CacheManager {
%error,
"failed to read cached response; treating as miss"
);
remove_index_entry(&zone, &key);
remove_zone_index_entry(&zone, &key).await;
remove_cache_files_if_unindexed(&zone, &key, &entry.hash).await;
persist_zone_shared_index(&zone).await;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rginx-http/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ use request::{cache_request_bypass, render_cache_key};
use runtime::PurgeSelector;
pub(crate) use runtime::with_cache_status;
use runtime::{build_conditional_headers, remove_cache_files_if_unindexed};
use shared::{bootstrap_shared_index, persist_zone_shared_index, sync_zone_shared_index_if_needed};
use shared::{SharedIndexStore, bootstrap_shared_index, sync_zone_shared_index_if_needed};
use store::{
CacheStoreError, cleanup_inactive_entries_in_zone, lock_index, purge_zone_entries,
refresh_not_modified_response, remove_index_entry, store_response,
refresh_not_modified_response, remove_zone_index_entry, store_response,
};

const CACHE_STATUS_HEADER: &str = "x-cache";
Expand Down Expand Up @@ -150,11 +150,11 @@ struct CacheZoneRuntime {
index: Mutex<CacheIndex>,
io_lock: AsyncMutex<()>,
shared_index_sync_lock: AsyncMutex<()>,
shared_index_store: Option<Arc<SharedIndexStore>>,
fill_locks: Arc<Mutex<HashMap<String, CacheFillLockState>>>,
fill_lock_generation: AtomicU64,
last_inactive_cleanup_unix_ms: AtomicU64,
shared_index_generation: AtomicU64,
shared_index_last_modified_unix_ms: AtomicU64,
stats: CacheZoneStats,
change_notifier: Option<CacheChangeNotifier>,
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rginx-http/src/cache/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ impl CacheStoreContext {
%error,
"failed to serve stale cache entry"
);
remove_index_entry(&self.zone, &self.key);
remove_zone_index_entry(&self.zone, &self.key).await;
remove_cache_files_if_unindexed(&self.zone, &self.key, &entry.hash).await;
persist_zone_shared_index(&self.zone).await;
None
}
}
Expand Down
Loading