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
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build fmt clippy test clean check help install-hooks lint
.PHONY: build build-debug fmt fmt-check clippy test unit test-unit check check-all check-safe clean help install-hooks install-tools setup lint run-metadata run-gateway run-scheduler run-cache run-tape

.DEFAULT_GOAL := help

Expand All @@ -18,10 +18,14 @@ fmt-check:
clippy:
@cargo clippy --all-targets --all-features -- -D warnings
test:
@cargo test --all-features
@cargo test --workspace --all-features
unit test-unit:
@cargo test --workspace --lib --bins
check:
@cargo check --all-targets --all-features
check-all: fmt-check clippy test
check-safe: fmt-check clippy unit build-debug
@echo "Safe verification passed (fmt/clippy/unit/build only)."
clean:
@cargo clean

Expand All @@ -36,8 +40,8 @@ run-cache:
run-tape:
@cargo run -p coldstore-tape

lint: fmt-check clippy check test
@echo "All lint checks passed."
lint: fmt-check clippy check unit
@echo "All lint checks passed (unit-only)."

install-hooks:
@cp scripts/pre-commit .git/hooks/pre-commit
Expand All @@ -55,6 +59,6 @@ help:
@echo "ColdStore Workspace Makefile"
@echo ""
@echo "Build: build build-debug clean"
@echo "Quality: fmt fmt-check clippy test check check-all lint"
@echo "Quality: fmt fmt-check clippy test unit check check-all check-safe lint"
@echo "Run: run-metadata run-gateway run-scheduler run-cache run-tape"
@echo "Setup: setup install-tools install-hooks"
1 change: 1 addition & 0 deletions crates/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coldstore-common = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
anyhow = { workspace = true }
Expand Down
26 changes: 24 additions & 2 deletions crates/cache/src/hdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ impl HddBackend {
fs::create_dir_all(base.join("staging")).await?;
fs::create_dir_all(base.join("restored")).await?;
fs::create_dir_all(base.join("meta")).await?;
let next_id = discover_next_id(&base).await?;
Ok(Self {
base_path: base,
max_size_bytes: max_size_gb * 1024 * 1024 * 1024,
next_id: AtomicU64::new(1),
next_id: AtomicU64::new(next_id),
})
}

Expand Down Expand Up @@ -134,6 +135,27 @@ impl CacheBackend for HddBackend {
}

async fn available_bytes(&self) -> Result<u64> {
Ok(self.max_size_bytes)
let used_bytes: u64 = self
.list_all()
.await?
.into_iter()
.map(|(_, x)| x.size)
.sum();
Ok(self.max_size_bytes.saturating_sub(used_bytes))
}
}

async fn discover_next_id(base: &std::path::Path) -> Result<u64> {
let mut max_id = 0_u64;
let mut rd = fs::read_dir(base.join("meta")).await?;
while let Some(entry) = rd.next_entry().await? {
let name = entry.file_name();
let name = name.to_string_lossy();
if let Some(raw) = name.strip_suffix(".json") {
if let Ok(id) = raw.parse::<u64>() {
max_id = max_id.max(id);
}
}
}
Ok(max_id + 1)
}
Loading
Loading