Deleting stream data by time range on local disk removes the whole UTC day, including hours outside the range
Bug Description
With local disk storage, the default for a single node (ZO_LOCAL_MODE=true, ZO_LOCAL_MODE_STORAGE=disk), DELETE /api/{org}/streams/{stream}/data_by_time_range deletes whole YYYY/MM/DD directories rather than the requested hours, so hours outside the range are removed too. The file list only drops the requested hours, so the other hours of that day stay listed while their files are gone: their data is gone, and queries over those hours return no rows, with is_partial: true and a "not found" error.
The API deliberately works in hours for hourly streams (logs, metrics, traces): "we need check the date is hour or day, user can't delete data with minute and second" (stream/src/lib.rs:934). It passes the bounds on as %Y-%m-%dT%H:00:00Z (:953-967). delete_by_date keeps the hour (retention.rs:470-489) and removes exactly those hours from the file list (:514). On local disk it first deletes the directories returned by generate_local_dirs (:491-503), which walks whole days (:696-705):
while date_start < date_end {
let date = date_start.format("%Y/%m/%d").to_string();
for stream_dir in &stream_dirs {
let day_path = stream_dir.join(&date);
if day_path.exists() {
dirs_to_delete.push(day_path);
}
}
date_start += Duration::days(1); // Move to the next day
}On local disk a file's key is its path under the data directory (format_key changes nothing there, storage/mod.rs:545-556), so files/{org}/logs/{stream}/YYYY/MM/DD/ holds every hour of that day. Because the loop steps a full day from the start hour, it also skips the last day when the end hour is not after the start hour. For example, 22:00 to 02:00 the next day deletes only the first day's directory, and the second day's 00:00–02:00 files stay on disk after the file list has dropped them. That case is from the code; I did not reproduce it.
Reproduced on a single node built from main (details below). One record per hour from 00:30 to 06:30 UTC, each hour persisted to files/default/logs/day_wipe_src/2026/09/29/HH/, then DELETE /api/default/streams/day_wipe_src/data_by_time_range?type=logs&start=<02:00>&end=<04:00>. The job reported Completed after 6 s, and the whole 2026/09/29 directory was gone. Querying each hour afterwards (use_cache=false):
hour asked to delete rows result
00 no 0 is_partial=true, .../2026/09/29/00/... not found
01 no 0 is_partial=true, .../2026/09/29/01/... not found
02 yes 0 ok
03 yes 0 ok
04 no 0 is_partial=true, .../2026/09/29/04/... not found
05 no 0 is_partial=true, .../2026/09/29/05/... not found
06 no 0 is_partial=true, .../2026/09/29/06/... not foundBefore the delete, each of the seven hours held one parquet file, and a single query over the whole day returned all seven rows. The tail of the hour-01 error, from function_error on an HTTP 200: …Object at location .../stream/files/default/logs/day_wipe_src/2026/09/29/01/751064741721826918590ae.parquet not found: No such file or directory (os error 2).
The scheduled retention path already avoids this: generate_deletion_dates only emits days the range fully covers (retention.rs:236-241), which test_generate_deletion_dates_less_than_a_day pins down. Only days the range fully covers can safely be removed by directory. The partial days at either end need either just their in-range HH directories removed, or the files the file list returns for the range.
Two related observations:
- From the code, not reproduced: pipeline backfill with
delete_before_backfillcreates the same job for logs streams (handlers.rs:6006-6036). Unlike the API, it does not reject non-zero minutes: it rounds both bounds down to the hour, so a backfill over 02:30–04:30 deletes 02:00–04:00. - Seen in the repro: with caching left at its default, a query identical to one that ran before the delete still returned all seven rows, including the deleted 02 and 03. The per-hour queries above used
use_cache=false. I did not isolate which cache. The API handler only queues the job (stream/src/lib.rs:915-994), anddelete_by_datedoes not invalidate cached query results.
Priority
P1 - High
Severity
Major
Related Story/Issue
Not Available
Is this a regression?
Unknown. I have not checked when the hour-level bounds were added.
Steps to Reproduce (Optional)
On a single node with local disk storage:
- Ingest a record per hour for several hours of one UTC day into
day_wipe_src(e.g. 00:30 to 06:30), and wait until each hour is written tofiles/default/logs/day_wipe_src/YYYY/MM/DD/HH/. DELETE /api/default/streams/day_wipe_src/data_by_time_range?type=logs&start=<02:00 in µs>&end=<04:00 in µs>, then pollGET /api/default/streams/day_wipe_src/data_by_time_range/status/{id}untilCompleted.- List
files/default/logs/day_wipe_src/YYYY/MM/DD/and query each hour withuse_cache=false.
Expected: only 02:00–04:00 is removed. The other hours stay on disk and are still returned by queries.
Actual: the whole day's directory is removed. Every hour outside the range returns no rows, with is_partial: true and a "not found" error for its file.
Environment Details
Version: main at 6ace69877 (Cargo.toml 0.93.0), debug build; retention.rs is unchanged on 97c0905ac, which the links point to
Deployment: single node, ZO_LOCAL_MODE=true, ZO_LOCAL_MODE_STORAGE=disk (defaults)
Only to shorten the repro: ZO_MAX_FILE_RETENTION_TIME=10 (persist within seconds) and ZO_INGEST_ALLOWED_UPTO=48 (accept records from earlier in the day)
Reproduced: against a running server, 2026-09-29Which OpenObserve Functionalities Are Affected?
- Home & Login
- Logs / Metrics / Traces
- Dashboards
- Alerts
- Streams, Pipelines & Functions
- Ingestion
- Real User Monitoring (RUM)
- Reports
- IAM & Management
- UI / Styling
- Unknown / Other
Source: openobserve/openobserve