Skip to content

Commit 04fc9e7

Browse files
committed
fix: stale is_deleting self-heal didn't clear the "already exists" check
The stale-flag self-heal added in the previous commit cleared is_deleting()/removed the flag but left stream_in_memory_dont_update untouched, so create_update_stream still fell through to the "Logstream already exists" 400 right after self-healing -- exactly the Quest delete-then-recreate pattern that broke both the standalone and distributed CI runs (TestSmokeIngestEventsToStream: expected 200, got 400). Now the stale entry is dropped from the in-memory map (not just its flag cleared) so get_or_create doesn't hand back the same stale Arc<Stream>, and stream_in_memory_dont_update is corrected so the "already exists" check no longer trips. Also extracted the deletion/tombstone checks in create_update_stream into reject_if_stream_deleting to bring its cyclomatic complexity back down (DeepSource flagged RS-R1000 after the previous commit pushed it to "very-high" risk).
1 parent b0b0f65 commit 04fc9e7

1 file changed

Lines changed: 77 additions & 50 deletions

File tree

‎src/parseable/mod.rs‎

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -742,59 +742,17 @@ impl Parseable {
742742
Ok(())
743743
}
744744

745-
pub async fn create_update_stream(
745+
/// Rejects a create/update call blocked by an in-progress or stale
746+
/// deletion, self-healing a stale `is_deleting()` flag once its
747+
/// tombstone is confirmed gone. Returns the (possibly corrected) value
748+
/// of `stream_in_memory_dont_update` for the caller's subsequent
749+
/// "already exists" check.
750+
async fn reject_if_stream_deleting(
746751
&self,
747-
headers: &HeaderMap,
748-
body: &Bytes,
749752
stream_name: &str,
750753
tenant_id: &Option<String>,
751-
) -> Result<HeaderMap, StreamError> {
752-
let PutStreamHeaders {
753-
time_partition_limit,
754-
custom_partition,
755-
static_schema_flag,
756-
update_stream_flag,
757-
stream_type,
758-
log_source,
759-
mut telemetry_type,
760-
telemetry_type_set,
761-
dataset_tags,
762-
dataset_labels,
763-
infer_timestamp,
764-
infer_timestamp_set,
765-
} = headers.into();
766-
767-
// x-p-infer-timestamp can only be set during stream creation, not on update.
768-
// It is only valid for otel-metrics datasets.
769-
if infer_timestamp_set {
770-
if update_stream_flag {
771-
return Err(StreamError::Custom {
772-
msg: format!(
773-
"Header {} can only be set at stream creation, not on update",
774-
crate::handlers::INFER_TIMESTAMP_KEY
775-
),
776-
status: StatusCode::BAD_REQUEST,
777-
});
778-
}
779-
if log_source != LogSource::OtelMetrics {
780-
return Err(StreamError::Custom {
781-
msg: format!(
782-
"Header {} is only supported for otel-metrics datasets",
783-
crate::handlers::INFER_TIMESTAMP_KEY
784-
),
785-
status: StatusCode::BAD_REQUEST,
786-
});
787-
}
788-
}
789-
790-
// For OTel datasets the telemetry_type is implied by the log_source and
791-
// they must be consistent. Auto-derive it when not provided; reject any
792-
// mismatch when both x-p-log-source and x-p-telemetry-type are set.
793-
telemetry_type = resolve_telemetry_type(&log_source, telemetry_type, telemetry_type_set)?;
794-
795-
let stream_in_memory_dont_update =
796-
self.streams.contains(stream_name, tenant_id) && !update_stream_flag;
797-
754+
stream_in_memory_dont_update: bool,
755+
) -> Result<bool, StreamError> {
798756
// A stream still resident with is_deleting()=true is functionally
799757
// gone (reads/writes are already rejected elsewhere), but its entry
800758
// isn't removed from memory until the background deletion job
@@ -825,6 +783,16 @@ impl Parseable {
825783
});
826784
}
827785
stream.clear_deleting();
786+
787+
// The stale entry itself (data path, schema, old metadata) must
788+
// go too, not just the flag -- otherwise the "already exists"
789+
// check just below still trips on it, and get_or_create's
790+
// resident-entry short-circuit would hand back this same stale
791+
// Arc<Stream> instead of actually recreating it. Dropping it
792+
// here makes this indistinguishable from a stream that was
793+
// never resident in the first place.
794+
self.streams.delete(stream_name, tenant_id);
795+
return Ok(false);
828796
}
829797

830798
// A tombstoned-but-not-yet-purged stream must be rejected the same
@@ -851,6 +819,65 @@ impl Parseable {
851819
});
852820
}
853821

822+
Ok(stream_in_memory_dont_update)
823+
}
824+
825+
pub async fn create_update_stream(
826+
&self,
827+
headers: &HeaderMap,
828+
body: &Bytes,
829+
stream_name: &str,
830+
tenant_id: &Option<String>,
831+
) -> Result<HeaderMap, StreamError> {
832+
let PutStreamHeaders {
833+
time_partition_limit,
834+
custom_partition,
835+
static_schema_flag,
836+
update_stream_flag,
837+
stream_type,
838+
log_source,
839+
mut telemetry_type,
840+
telemetry_type_set,
841+
dataset_tags,
842+
dataset_labels,
843+
infer_timestamp,
844+
infer_timestamp_set,
845+
} = headers.into();
846+
847+
// x-p-infer-timestamp can only be set during stream creation, not on update.
848+
// It is only valid for otel-metrics datasets.
849+
if infer_timestamp_set {
850+
if update_stream_flag {
851+
return Err(StreamError::Custom {
852+
msg: format!(
853+
"Header {} can only be set at stream creation, not on update",
854+
crate::handlers::INFER_TIMESTAMP_KEY
855+
),
856+
status: StatusCode::BAD_REQUEST,
857+
});
858+
}
859+
if log_source != LogSource::OtelMetrics {
860+
return Err(StreamError::Custom {
861+
msg: format!(
862+
"Header {} is only supported for otel-metrics datasets",
863+
crate::handlers::INFER_TIMESTAMP_KEY
864+
),
865+
status: StatusCode::BAD_REQUEST,
866+
});
867+
}
868+
}
869+
870+
// For OTel datasets the telemetry_type is implied by the log_source and
871+
// they must be consistent. Auto-derive it when not provided; reject any
872+
// mismatch when both x-p-log-source and x-p-telemetry-type are set.
873+
telemetry_type = resolve_telemetry_type(&log_source, telemetry_type, telemetry_type_set)?;
874+
875+
let stream_in_memory_dont_update =
876+
self.streams.contains(stream_name, tenant_id) && !update_stream_flag;
877+
let stream_in_memory_dont_update = self
878+
.reject_if_stream_deleting(stream_name, tenant_id, stream_in_memory_dont_update)
879+
.await?;
880+
854881
// check if stream in storage only if not in memory
855882
// for Parseable OSS, create_update_stream is called only from query node
856883
// for Parseable Enterprise, create_update_stream is called from prism node

0 commit comments

Comments
 (0)