1use std::any::Any;
16use std::sync::Arc;
17
18use common_datasource::compression::CompressionType;
19use common_error::ext::{BoxedError, ErrorExt, RetryHint};
20use common_error::status_code::StatusCode;
21use common_macro::stack_trace_debug;
22use common_memory_manager;
23use common_runtime::JoinError;
24use common_time::Timestamp;
25use common_time::timestamp::TimeUnit;
26use datatypes::arrow::error::ArrowError;
27use datatypes::prelude::ConcreteDataType;
28use object_store::ErrorKind;
29use object_store::error::retry_hint_from_opendal_error;
30use partition::error::Error as PartitionError;
31use prost::DecodeError;
32use snafu::{Location, Snafu};
33use store_api::ManifestVersion;
34use store_api::logstore::provider::Provider;
35use store_api::storage::{FileId, RegionId};
36use tokio::time::error::Elapsed;
37
38use crate::cache::file_cache::FileType;
39use crate::region::RegionRoleState;
40use crate::schedule::remote_job_scheduler::JobId;
41use crate::worker::WorkerId;
42
43#[derive(Snafu)]
44#[snafu(visibility(pub))]
45#[stack_trace_debug]
46pub enum Error {
47 #[snafu(display("Unexpected data type"))]
48 DataTypeMismatch {
49 source: datatypes::error::Error,
50 #[snafu(implicit)]
51 location: Location,
52 },
53
54 #[snafu(display("External error, context: {}", context))]
55 External {
56 source: BoxedError,
57 context: String,
58 #[snafu(implicit)]
59 location: Location,
60 },
61
62 #[snafu(display("OpenDAL operator failed"))]
63 OpenDal {
64 #[snafu(implicit)]
65 location: Location,
66 #[snafu(source)]
67 error: object_store::Error,
68 },
69
70 #[snafu(display("Fail to compress object by {}, path: {}", compress_type, path))]
71 CompressObject {
72 compress_type: CompressionType,
73 path: String,
74 #[snafu(source)]
75 error: std::io::Error,
76 },
77
78 #[snafu(display("Fail to decompress object by {}, path: {}", compress_type, path))]
79 DecompressObject {
80 compress_type: CompressionType,
81 path: String,
82 #[snafu(source)]
83 error: std::io::Error,
84 },
85
86 #[snafu(display("Failed to ser/de json object"))]
87 SerdeJson {
88 #[snafu(implicit)]
89 location: Location,
90 #[snafu(source)]
91 error: serde_json::Error,
92 },
93
94 #[snafu(display("Failed to serialize column metadata"))]
95 SerializeColumnMetadata {
96 #[snafu(source)]
97 error: serde_json::Error,
98 #[snafu(implicit)]
99 location: Location,
100 },
101
102 #[snafu(display("Failed to serialize manifest, region_id: {}", region_id))]
103 SerializeManifest {
104 region_id: RegionId,
105 #[snafu(source)]
106 error: serde_json::Error,
107 #[snafu(implicit)]
108 location: Location,
109 },
110
111 #[snafu(display("Invalid scan index, start: {}, end: {}", start, end))]
112 InvalidScanIndex {
113 start: ManifestVersion,
114 end: ManifestVersion,
115 #[snafu(implicit)]
116 location: Location,
117 },
118
119 #[snafu(display("Invalid UTF-8 content"))]
120 Utf8 {
121 #[snafu(implicit)]
122 location: Location,
123 #[snafu(source)]
124 error: std::str::Utf8Error,
125 },
126
127 #[snafu(display("Cannot find RegionMetadata"))]
128 RegionMetadataNotFound {
129 #[snafu(implicit)]
130 location: Location,
131 },
132
133 #[snafu(display("Failed to join handle"))]
134 Join {
135 #[snafu(source)]
136 error: common_runtime::JoinError,
137 #[snafu(implicit)]
138 location: Location,
139 },
140
141 #[snafu(display("Worker {} is stopped", id))]
142 WorkerStopped {
143 id: WorkerId,
144 #[snafu(implicit)]
145 location: Location,
146 },
147
148 #[snafu(display("Failed to recv result"))]
149 Recv {
150 #[snafu(source)]
151 error: tokio::sync::oneshot::error::RecvError,
152 #[snafu(implicit)]
153 location: Location,
154 },
155
156 #[snafu(display("Invalid metadata, {}", reason))]
157 InvalidMeta {
158 reason: String,
159 #[snafu(implicit)]
160 location: Location,
161 },
162
163 #[snafu(display("Invalid region metadata"))]
164 InvalidMetadata {
165 source: store_api::metadata::MetadataError,
166 #[snafu(implicit)]
167 location: Location,
168 },
169
170 #[snafu(display("Failed to create RecordBatch from vectors"))]
171 NewRecordBatch {
172 #[snafu(implicit)]
173 location: Location,
174 #[snafu(source)]
175 error: ArrowError,
176 },
177
178 #[snafu(display("Failed to read parquet file, path: {}", path))]
179 ReadParquet {
180 path: String,
181 #[snafu(source)]
182 error: parquet::errors::ParquetError,
183 #[snafu(implicit)]
184 location: Location,
185 },
186
187 #[snafu(display("Failed to write parquet file"))]
188 WriteParquet {
189 #[snafu(source)]
190 error: parquet::errors::ParquetError,
191 #[snafu(implicit)]
192 location: Location,
193 },
194
195 #[snafu(display(
196 "Cannot assign a stable field id to native histogram sub-field '{}' of column id {} (unknown sub-field name or derived id overflows i32)",
197 field_name,
198 column_id
199 ))]
200 InvalidNativeHistogramSubfield {
201 column_id: i32,
202 field_name: String,
203 #[snafu(implicit)]
204 location: Location,
205 },
206
207 #[snafu(display(
208 "Native histogram column '{}' has no usable PARQUET:field_id to namespace its sub-field ids (missing, malformed, or exceeds i32::MAX)",
209 field_name
210 ))]
211 InvalidNativeHistogramFieldId {
212 field_name: String,
213 #[snafu(implicit)]
214 location: Location,
215 },
216
217 #[snafu(display("Region {} not found", region_id))]
218 RegionNotFound {
219 region_id: RegionId,
220 #[snafu(implicit)]
221 location: Location,
222 },
223
224 #[snafu(display("Object store not found: {}", object_store))]
225 ObjectStoreNotFound {
226 object_store: String,
227 #[snafu(implicit)]
228 location: Location,
229 },
230
231 #[snafu(display("Region {} is corrupted, reason: {}", region_id, reason))]
232 RegionCorrupted {
233 region_id: RegionId,
234 reason: String,
235 #[snafu(implicit)]
236 location: Location,
237 },
238
239 #[snafu(display("Invalid request to region {}, reason: {}", region_id, reason))]
240 InvalidRequest {
241 region_id: RegionId,
242 reason: String,
243 #[snafu(implicit)]
244 location: Location,
245 },
246
247 #[snafu(display(
248 "STALE_CURSOR: incremental query stale, region: {}, given_seq: {}, min_readable_seq: {}, retry_hint: FALLBACK_FULL_RECOMPUTE",
249 region_id,
250 given_seq,
251 min_readable_seq
252 ))]
253 IncrementalQueryStale {
254 region_id: RegionId,
255 given_seq: u64,
256 min_readable_seq: u64,
257 #[snafu(implicit)]
258 location: Location,
259 },
260
261 #[snafu(display(
262 "STALE_SNAPSHOT_FENCE: snapshot upper bound stale, region: {}, given_seq: {}, min_enforceable_seq: {}, retry_hint: REBIND_SNAPSHOT_FENCE",
263 region_id,
264 given_seq,
265 min_enforceable_seq
266 ))]
267 SnapshotFenceStale {
268 region_id: RegionId,
269 given_seq: u64,
270 min_enforceable_seq: u64,
271 #[snafu(implicit)]
272 location: Location,
273 },
274
275 #[snafu(display("Old manifest missing for region {}", region_id))]
276 MissingOldManifest {
277 region_id: RegionId,
278 #[snafu(implicit)]
279 location: Location,
280 },
281
282 #[snafu(display("New manifest missing for region {}", region_id))]
283 MissingNewManifest {
284 region_id: RegionId,
285 #[snafu(implicit)]
286 location: Location,
287 },
288
289 #[snafu(display("Manifest missing for region {}", region_id))]
290 MissingManifest {
291 region_id: RegionId,
292 #[snafu(implicit)]
293 location: Location,
294 },
295
296 #[snafu(display("File consistency check failed for file {}: {}", file_id, reason))]
297 InconsistentFile {
298 file_id: FileId,
299 reason: String,
300 #[snafu(implicit)]
301 location: Location,
302 },
303
304 #[snafu(display("Files lost during remapping: old={}, new={}", old_count, new_count))]
305 FilesLost {
306 old_count: usize,
307 new_count: usize,
308 #[snafu(implicit)]
309 location: Location,
310 },
311
312 #[snafu(display("No old manifests provided (need at least one for template)"))]
313 NoOldManifests {
314 #[snafu(implicit)]
315 location: Location,
316 },
317
318 #[snafu(display("Failed to fetch manifests"))]
319 FetchManifests {
320 #[snafu(implicit)]
321 location: Location,
322 source: BoxedError,
323 },
324
325 #[snafu(display("Partition expression missing for region {}", region_id))]
326 MissingPartitionExpr {
327 region_id: RegionId,
328 #[snafu(implicit)]
329 location: Location,
330 },
331
332 #[snafu(display("Failed to serialize partition expression: {}", source))]
333 SerializePartitionExpr {
334 #[snafu(source)]
335 source: PartitionError,
336 #[snafu(implicit)]
337 location: Location,
338 },
339
340 #[snafu(display(
341 "Failed to convert ConcreteDataType to ColumnDataType, reason: {}",
342 reason
343 ))]
344 ConvertColumnDataType {
345 reason: String,
346 source: api::error::Error,
347 #[snafu(implicit)]
348 location: Location,
349 },
350
351 #[snafu(display("Need to fill default value for region {}", region_id))]
354 FillDefault {
355 region_id: RegionId,
356 },
358
359 #[snafu(display(
360 "Failed to create default value for column {} of region {}",
361 column,
362 region_id
363 ))]
364 CreateDefault {
365 region_id: RegionId,
366 column: String,
367 source: datatypes::Error,
368 #[snafu(implicit)]
369 location: Location,
370 },
371
372 #[snafu(display("Failed to build entry, region_id: {}", region_id))]
373 BuildEntry {
374 region_id: RegionId,
375 #[snafu(implicit)]
376 location: Location,
377 source: BoxedError,
378 },
379
380 #[snafu(display("Failed to write WAL"))]
381 WriteWal {
382 #[snafu(implicit)]
383 location: Location,
384 source: BoxedError,
385 },
386
387 #[snafu(display("Failed to read WAL, provider: {}", provider))]
388 ReadWal {
389 provider: Provider,
390 #[snafu(implicit)]
391 location: Location,
392 source: BoxedError,
393 },
394
395 #[snafu(display("Failed to decode WAL entry, region_id: {}", region_id))]
396 DecodeWal {
397 region_id: RegionId,
398 #[snafu(implicit)]
399 location: Location,
400 #[snafu(source)]
401 error: DecodeError,
402 },
403
404 #[snafu(display("Failed to delete WAL, region_id: {}", region_id))]
405 DeleteWal {
406 region_id: RegionId,
407 #[snafu(implicit)]
408 location: Location,
409 source: BoxedError,
410 },
411
412 #[snafu(display("Failed to write region"))]
414 WriteGroup { source: Arc<Error> },
415
416 #[snafu(display("Invalid parquet SST file {}, reason: {}", file, reason))]
417 InvalidParquet {
418 file: String,
419 reason: String,
420 #[snafu(implicit)]
421 location: Location,
422 },
423
424 #[snafu(display("Invalid batch, {}", reason))]
425 InvalidBatch {
426 reason: String,
427 #[snafu(implicit)]
428 location: Location,
429 },
430
431 #[snafu(display("Invalid arrow record batch, {}", reason))]
432 InvalidRecordBatch {
433 reason: String,
434 #[snafu(implicit)]
435 location: Location,
436 },
437
438 #[snafu(display("Invalid wal read request, {}", reason))]
439 InvalidWalReadRequest {
440 reason: String,
441 #[snafu(implicit)]
442 location: Location,
443 },
444
445 #[snafu(display("Failed to convert array to vector"))]
446 ConvertVector {
447 #[snafu(implicit)]
448 location: Location,
449 source: datatypes::error::Error,
450 },
451
452 #[snafu(display("Failed to compute arrow arrays"))]
453 ComputeArrow {
454 #[snafu(implicit)]
455 location: Location,
456 #[snafu(source)]
457 error: datatypes::arrow::error::ArrowError,
458 },
459
460 #[snafu(display("Failed to evaluate partition filter"))]
461 EvalPartitionFilter {
462 #[snafu(implicit)]
463 location: Location,
464 #[snafu(source)]
465 error: datafusion::error::DataFusionError,
466 },
467
468 #[snafu(display("Failed to compute vector"))]
469 ComputeVector {
470 #[snafu(implicit)]
471 location: Location,
472 source: datatypes::error::Error,
473 },
474
475 #[snafu(display("Primary key length mismatch, expect: {}, actual: {}", expect, actual))]
476 PrimaryKeyLengthMismatch {
477 expect: usize,
478 actual: usize,
479 #[snafu(implicit)]
480 location: Location,
481 },
482
483 #[snafu(display("Invalid sender",))]
484 InvalidSender {
485 #[snafu(implicit)]
486 location: Location,
487 },
488
489 #[snafu(display("Invalid scheduler state"))]
490 InvalidSchedulerState {
491 #[snafu(implicit)]
492 location: Location,
493 },
494
495 #[snafu(display("Failed to stop scheduler"))]
496 StopScheduler {
497 #[snafu(source)]
498 error: JoinError,
499 #[snafu(implicit)]
500 location: Location,
501 },
502
503 #[snafu(display(
504 "Failed to batch delete SST files, region id: {}, file ids: {:?}",
505 region_id,
506 file_ids
507 ))]
508 DeleteSsts {
509 region_id: RegionId,
510 file_ids: Vec<FileId>,
511 #[snafu(source)]
512 error: object_store::Error,
513 #[snafu(implicit)]
514 location: Location,
515 },
516
517 #[snafu(display("Failed to delete index file, file id: {}", file_id))]
518 DeleteIndex {
519 file_id: FileId,
520 #[snafu(source)]
521 error: object_store::Error,
522 #[snafu(implicit)]
523 location: Location,
524 },
525
526 #[snafu(display("Failed to batch delete index files, file ids: {:?}", file_ids))]
527 DeleteIndexes {
528 file_ids: Vec<FileId>,
529 #[snafu(source)]
530 error: object_store::Error,
531 #[snafu(implicit)]
532 location: Location,
533 },
534
535 #[snafu(display("Failed to flush region {}", region_id))]
536 FlushRegion {
537 region_id: RegionId,
538 source: Arc<Error>,
539 #[snafu(implicit)]
540 location: Location,
541 },
542
543 #[snafu(display("Region {} is dropped", region_id))]
544 RegionDropped {
545 region_id: RegionId,
546 #[snafu(implicit)]
547 location: Location,
548 },
549
550 #[snafu(display("Region {} is closed", region_id))]
551 RegionClosed {
552 region_id: RegionId,
553 #[snafu(implicit)]
554 location: Location,
555 },
556
557 #[snafu(display("Region {} is truncated", region_id))]
558 RegionTruncated {
559 region_id: RegionId,
560 #[snafu(implicit)]
561 location: Location,
562 },
563
564 #[snafu(display(
565 "Engine write buffer is full, rejecting write requests of region {}",
566 region_id,
567 ))]
568 RejectWrite {
569 region_id: RegionId,
570 #[snafu(implicit)]
571 location: Location,
572 },
573
574 #[snafu(display("Failed to compact region {}", region_id))]
575 CompactRegion {
576 region_id: RegionId,
577 source: Arc<Error>,
578 #[snafu(implicit)]
579 location: Location,
580 },
581
582 #[snafu(display("Failed to edit region {}", region_id))]
583 EditRegion {
584 region_id: RegionId,
585 source: Arc<Error>,
586 #[snafu(implicit)]
587 location: Location,
588 },
589
590 #[snafu(display(
591 "Failed to compat readers for region {}, reason: {}",
592 region_id,
593 reason,
594 ))]
595 CompatReader {
596 region_id: RegionId,
597 reason: String,
598 #[snafu(implicit)]
599 location: Location,
600 },
601
602 #[snafu(display("Invalue region req"))]
603 InvalidRegionRequest {
604 source: store_api::metadata::MetadataError,
605 #[snafu(implicit)]
606 location: Location,
607 },
608
609 #[snafu(display(
610 "Region {} is in {:?} state, which does not permit manifest updates.",
611 region_id,
612 state
613 ))]
614 UpdateManifest {
615 region_id: RegionId,
616 state: RegionRoleState,
617 #[snafu(implicit)]
618 location: Location,
619 },
620
621 #[snafu(display("Region {} is in {:?} state, expect: {:?}", region_id, state, expect))]
622 RegionState {
623 region_id: RegionId,
624 state: RegionRoleState,
625 expect: RegionRoleState,
626 #[snafu(implicit)]
627 location: Location,
628 },
629
630 #[snafu(display(
631 "Partition expr version mismatch for region {}: request {}, expected {}",
632 region_id,
633 request_version,
634 expected_version
635 ))]
636 PartitionExprVersionMismatch {
637 region_id: RegionId,
638 request_version: u64,
639 expected_version: u64,
640 #[snafu(implicit)]
641 location: Location,
642 },
643
644 #[snafu(display("Invalid options"))]
645 JsonOptions {
646 #[snafu(source)]
647 error: serde_json::Error,
648 #[snafu(implicit)]
649 location: Location,
650 },
651
652 #[snafu(display(
653 "Empty region directory, region_id: {}, region_dir: {}",
654 region_id,
655 region_dir,
656 ))]
657 EmptyRegionDir {
658 region_id: RegionId,
659 region_dir: String,
660 #[snafu(implicit)]
661 location: Location,
662 },
663
664 #[snafu(display("Empty manifest directory, manifest_dir: {}", manifest_dir,))]
665 EmptyManifestDir {
666 manifest_dir: String,
667 #[snafu(implicit)]
668 location: Location,
669 },
670
671 #[snafu(display("Column not found, column: {column}"))]
672 ColumnNotFound {
673 column: String,
674 #[snafu(implicit)]
675 location: Location,
676 },
677
678 #[snafu(display("Failed to build index applier"))]
679 BuildIndexApplier {
680 source: index::inverted_index::error::Error,
681 #[snafu(implicit)]
682 location: Location,
683 },
684
685 #[snafu(display("Failed to build index asynchronously in region {}", region_id))]
686 BuildIndexAsync {
687 region_id: RegionId,
688 source: Arc<Error>,
689 #[snafu(implicit)]
690 location: Location,
691 },
692
693 #[snafu(display("Failed to convert value"))]
694 ConvertValue {
695 source: datatypes::error::Error,
696 #[snafu(implicit)]
697 location: Location,
698 },
699
700 #[snafu(display("Failed to apply inverted index"))]
701 ApplyInvertedIndex {
702 source: index::inverted_index::error::Error,
703 #[snafu(implicit)]
704 location: Location,
705 },
706
707 #[snafu(display("Failed to apply bloom filter index"))]
708 ApplyBloomFilterIndex {
709 source: index::bloom_filter::error::Error,
710 #[snafu(implicit)]
711 location: Location,
712 },
713
714 #[cfg(feature = "vector_index")]
715 #[snafu(display("Failed to apply vector index: {}", reason))]
716 ApplyVectorIndex {
717 reason: String,
718 #[snafu(implicit)]
719 location: Location,
720 },
721
722 #[snafu(display("Failed to push index value"))]
723 PushIndexValue {
724 source: index::inverted_index::error::Error,
725 #[snafu(implicit)]
726 location: Location,
727 },
728
729 #[snafu(display("Failed to write index completely"))]
730 IndexFinish {
731 source: index::inverted_index::error::Error,
732 #[snafu(implicit)]
733 location: Location,
734 },
735
736 #[snafu(display("Operate on aborted index"))]
737 OperateAbortedIndex {
738 #[snafu(implicit)]
739 location: Location,
740 },
741
742 #[snafu(display("Failed to read puffin blob"))]
743 PuffinReadBlob {
744 source: puffin::error::Error,
745 #[snafu(implicit)]
746 location: Location,
747 },
748
749 #[snafu(display("Failed to add blob to puffin file"))]
750 PuffinAddBlob {
751 source: puffin::error::Error,
752 #[snafu(implicit)]
753 location: Location,
754 },
755
756 #[snafu(display("Failed to clean dir {dir}"))]
757 CleanDir {
758 dir: String,
759 #[snafu(source)]
760 error: std::io::Error,
761 #[snafu(implicit)]
762 location: Location,
763 },
764
765 #[snafu(display("Invalid config, {reason}"))]
766 InvalidConfig {
767 reason: String,
768 #[snafu(implicit)]
769 location: Location,
770 },
771
772 #[snafu(display(
773 "Stale log entry found during replay, region: {}, flushed: {}, replayed: {}",
774 region_id,
775 flushed_entry_id,
776 unexpected_entry_id
777 ))]
778 StaleLogEntry {
779 region_id: RegionId,
780 flushed_entry_id: u64,
781 unexpected_entry_id: u64,
782 },
783
784 #[snafu(display(
785 "Failed to download file, region_id: {}, file_id: {}, file_type: {:?}",
786 region_id,
787 file_id,
788 file_type,
789 ))]
790 Download {
791 region_id: RegionId,
792 file_id: FileId,
793 file_type: FileType,
794 #[snafu(source)]
795 error: std::io::Error,
796 #[snafu(implicit)]
797 location: Location,
798 },
799
800 #[snafu(display(
801 "Failed to upload file, region_id: {}, file_id: {}, file_type: {:?}",
802 region_id,
803 file_id,
804 file_type,
805 ))]
806 Upload {
807 region_id: RegionId,
808 file_id: FileId,
809 file_type: FileType,
810 #[snafu(source)]
811 error: std::io::Error,
812 #[snafu(implicit)]
813 location: Location,
814 },
815
816 #[snafu(display("Failed to create directory {}", dir))]
817 CreateDir {
818 dir: String,
819 #[snafu(source)]
820 error: std::io::Error,
821 },
822
823 #[snafu(display("Record batch error"))]
824 RecordBatch {
825 source: common_recordbatch::error::Error,
826 #[snafu(implicit)]
827 location: Location,
828 },
829
830 #[snafu(display("BiErrors, first: {first}, second: {second}"))]
831 BiErrors {
832 first: Box<Error>,
833 second: Box<Error>,
834 #[snafu(implicit)]
835 location: Location,
836 },
837
838 #[snafu(display("Encode null value"))]
839 IndexEncodeNull {
840 #[snafu(implicit)]
841 location: Location,
842 },
843
844 #[snafu(display("Failed to encode memtable to Parquet bytes"))]
845 EncodeMemtable {
846 #[snafu(source)]
847 error: parquet::errors::ParquetError,
848 #[snafu(implicit)]
849 location: Location,
850 },
851
852 #[snafu(display("Partition {} out of range, {} in total", given, all))]
853 PartitionOutOfRange {
854 given: usize,
855 all: usize,
856 #[snafu(implicit)]
857 location: Location,
858 },
859
860 #[snafu(display("Failed to iter data part"))]
861 ReadDataPart {
862 #[snafu(implicit)]
863 location: Location,
864 #[snafu(source)]
865 error: parquet::errors::ParquetError,
866 },
867
868 #[snafu(display("Failed to read row group in memtable"))]
869 DecodeArrowRowGroup {
870 #[snafu(source)]
871 error: ArrowError,
872 #[snafu(implicit)]
873 location: Location,
874 },
875
876 #[snafu(display("Invalid region options, {}", reason))]
877 InvalidRegionOptions {
878 reason: String,
879 #[snafu(implicit)]
880 location: Location,
881 },
882
883 #[snafu(display("checksum mismatch (actual: {}, expected: {})", actual, expected))]
884 ChecksumMismatch { actual: u32, expected: u32 },
885
886 #[snafu(display(
887 "No checkpoint found, region: {}, last_version: {}",
888 region_id,
889 last_version
890 ))]
891 NoCheckpoint {
892 region_id: RegionId,
893 last_version: ManifestVersion,
894 #[snafu(implicit)]
895 location: Location,
896 },
897
898 #[snafu(display(
899 "No manifests found in range: [{}..{}), region: {}, last_version: {}",
900 start_version,
901 end_version,
902 region_id,
903 last_version
904 ))]
905 NoManifests {
906 region_id: RegionId,
907 start_version: ManifestVersion,
908 end_version: ManifestVersion,
909 last_version: ManifestVersion,
910 #[snafu(implicit)]
911 location: Location,
912 },
913
914 #[snafu(display(
915 "Failed to install manifest to {}, region: {}, available manifest version: {}, last version: {}",
916 target_version,
917 region_id,
918 available_version,
919 last_version
920 ))]
921 InstallManifestTo {
922 region_id: RegionId,
923 target_version: ManifestVersion,
924 available_version: ManifestVersion,
925 #[snafu(implicit)]
926 location: Location,
927 last_version: ManifestVersion,
928 },
929
930 #[snafu(display("Region {} is stopped", region_id))]
931 RegionStopped {
932 region_id: RegionId,
933 #[snafu(implicit)]
934 location: Location,
935 },
936
937 #[snafu(display(
938 "Time range predicate overflows, timestamp: {:?}, target unit: {}",
939 timestamp,
940 unit
941 ))]
942 TimeRangePredicateOverflow {
943 timestamp: Timestamp,
944 unit: TimeUnit,
945 #[snafu(implicit)]
946 location: Location,
947 },
948
949 #[snafu(display("Failed to open region"))]
950 OpenRegion {
951 #[snafu(implicit)]
952 location: Location,
953 source: Arc<Error>,
954 },
955
956 #[snafu(display(
957 "Region {} does not satisfy requirement '{}': {}",
958 region_id,
959 requirement,
960 reason
961 ))]
962 RegionRequirement {
963 region_id: RegionId,
964 requirement: &'static str,
965 reason: &'static str,
966 #[snafu(implicit)]
967 location: Location,
968 },
969
970 #[snafu(display("Failed to parse job id"))]
971 ParseJobId {
972 #[snafu(implicit)]
973 location: Location,
974 #[snafu(source)]
975 error: uuid::Error,
976 },
977
978 #[snafu(display("Operation is not supported: {}", err_msg))]
979 UnsupportedOperation {
980 err_msg: String,
981 #[snafu(implicit)]
982 location: Location,
983 },
984
985 #[snafu(display(
986 "Failed to remotely compact region {} by job {:?} due to {}",
987 region_id,
988 job_id,
989 reason
990 ))]
991 RemoteCompaction {
992 region_id: RegionId,
993 job_id: Option<JobId>,
994 reason: String,
995 #[snafu(implicit)]
996 location: Location,
997 },
998
999 #[snafu(display("Failed to initialize puffin stager"))]
1000 PuffinInitStager {
1001 source: puffin::error::Error,
1002 #[snafu(implicit)]
1003 location: Location,
1004 },
1005
1006 #[snafu(display("Failed to purge puffin stager"))]
1007 PuffinPurgeStager {
1008 source: puffin::error::Error,
1009 #[snafu(implicit)]
1010 location: Location,
1011 },
1012
1013 #[snafu(display("Failed to build puffin reader"))]
1014 PuffinBuildReader {
1015 source: puffin::error::Error,
1016 #[snafu(implicit)]
1017 location: Location,
1018 },
1019
1020 #[snafu(display("Failed to retrieve index options from column metadata"))]
1021 IndexOptions {
1022 #[snafu(implicit)]
1023 location: Location,
1024 source: datatypes::error::Error,
1025 column_name: String,
1026 },
1027
1028 #[snafu(display("Failed to create fulltext index creator"))]
1029 CreateFulltextCreator {
1030 source: index::fulltext_index::error::Error,
1031 #[snafu(implicit)]
1032 location: Location,
1033 },
1034
1035 #[snafu(display("Failed to cast vector of {from} to {to}"))]
1036 CastVector {
1037 #[snafu(implicit)]
1038 location: Location,
1039 from: ConcreteDataType,
1040 to: ConcreteDataType,
1041 source: datatypes::error::Error,
1042 },
1043
1044 #[snafu(display("Failed to push text to fulltext index"))]
1045 FulltextPushText {
1046 source: index::fulltext_index::error::Error,
1047 #[snafu(implicit)]
1048 location: Location,
1049 },
1050
1051 #[snafu(display("Failed to finalize fulltext index creator"))]
1052 FulltextFinish {
1053 source: index::fulltext_index::error::Error,
1054 #[snafu(implicit)]
1055 location: Location,
1056 },
1057
1058 #[snafu(display("Failed to apply fulltext index"))]
1059 ApplyFulltextIndex {
1060 source: index::fulltext_index::error::Error,
1061 #[snafu(implicit)]
1062 location: Location,
1063 },
1064
1065 #[snafu(display("SST file {} does not contain valid stats info", file_path))]
1066 StatsNotPresent {
1067 file_path: String,
1068 #[snafu(implicit)]
1069 location: Location,
1070 },
1071
1072 #[snafu(display("Failed to decode stats of file {}", file_path))]
1073 DecodeStats {
1074 file_path: String,
1075 #[snafu(implicit)]
1076 location: Location,
1077 },
1078
1079 #[snafu(display("Region {} is busy", region_id))]
1080 RegionBusy {
1081 region_id: RegionId,
1082 #[snafu(implicit)]
1083 location: Location,
1084 },
1085
1086 #[snafu(display("Failed to get schema metadata"))]
1087 GetSchemaMetadata {
1088 source: common_meta::error::Error,
1089 #[snafu(implicit)]
1090 location: Location,
1091 },
1092
1093 #[snafu(display("Timeout"))]
1094 Timeout {
1095 #[snafu(source)]
1096 error: Elapsed,
1097 #[snafu(implicit)]
1098 location: Location,
1099 },
1100
1101 #[snafu(display("Failed to read file metadata"))]
1102 Metadata {
1103 #[snafu(source)]
1104 error: std::io::Error,
1105 #[snafu(implicit)]
1106 location: Location,
1107 },
1108
1109 #[snafu(display("Failed to push value to bloom filter"))]
1110 PushBloomFilterValue {
1111 source: index::bloom_filter::error::Error,
1112 #[snafu(implicit)]
1113 location: Location,
1114 },
1115
1116 #[snafu(display("Failed to finish bloom filter"))]
1117 BloomFilterFinish {
1118 source: index::bloom_filter::error::Error,
1119 #[snafu(implicit)]
1120 location: Location,
1121 },
1122
1123 #[cfg(feature = "vector_index")]
1124 #[snafu(display("Failed to build vector index: {}", reason))]
1125 VectorIndexBuild {
1126 reason: String,
1127 #[snafu(implicit)]
1128 location: Location,
1129 },
1130
1131 #[cfg(feature = "vector_index")]
1132 #[snafu(display("Failed to finish vector index: {}", reason))]
1133 VectorIndexFinish {
1134 reason: String,
1135 #[snafu(implicit)]
1136 location: Location,
1137 },
1138
1139 #[snafu(display("Manual compaction is override by following operations."))]
1140 ManualCompactionOverride {},
1141
1142 #[snafu(display("Compaction is cancelled."))]
1143 CompactionCancelled {},
1144
1145 #[snafu(display("Compaction memory exhausted for region {region_id} (policy: {policy})",))]
1146 CompactionMemoryExhausted {
1147 region_id: RegionId,
1148 policy: String,
1149 #[snafu(source)]
1150 source: common_memory_manager::Error,
1151 #[snafu(implicit)]
1152 location: Location,
1153 },
1154
1155 #[snafu(display(
1156 "Incompatible WAL provider change. This is typically caused by changing WAL provider in database config file without completely cleaning existing files. Global provider: {}, region provider: {}",
1157 global,
1158 region
1159 ))]
1160 IncompatibleWalProviderChange { global: String, region: String },
1161
1162 #[snafu(display("Expected mito manifest info"))]
1163 MitoManifestInfo {
1164 #[snafu(implicit)]
1165 location: Location,
1166 },
1167
1168 #[snafu(display("Failed to scan series"))]
1169 ScanSeries {
1170 #[snafu(implicit)]
1171 location: Location,
1172 source: Arc<Error>,
1173 },
1174
1175 #[snafu(display("Partition {} scan multiple times", partition))]
1176 ScanMultiTimes {
1177 partition: usize,
1178 #[snafu(implicit)]
1179 location: Location,
1180 },
1181
1182 #[snafu(display("Invalid partition expression: {}", expr))]
1183 InvalidPartitionExpr {
1184 expr: String,
1185 #[snafu(implicit)]
1186 location: Location,
1187 source: partition::error::Error,
1188 },
1189
1190 #[snafu(display("Failed to decode bulk wal entry"))]
1191 ConvertBulkWalEntry {
1192 #[snafu(implicit)]
1193 location: Location,
1194 source: common_grpc::Error,
1195 },
1196
1197 #[snafu(display("Failed to encode"))]
1198 Encode {
1199 #[snafu(implicit)]
1200 location: Location,
1201 source: mito_codec::error::Error,
1202 },
1203
1204 #[snafu(display("Failed to decode"))]
1205 Decode {
1206 #[snafu(implicit)]
1207 location: Location,
1208 source: mito_codec::error::Error,
1209 },
1210
1211 #[snafu(display("Unexpected: {reason}"))]
1212 Unexpected {
1213 reason: String,
1214 #[snafu(implicit)]
1215 location: Location,
1216 },
1217
1218 #[cfg(feature = "enterprise")]
1219 #[snafu(display("Failed to scan external range"))]
1220 ScanExternalRange {
1221 source: BoxedError,
1222 #[snafu(implicit)]
1223 location: Location,
1224 },
1225
1226 #[snafu(display(
1227 "Inconsistent timestamp column length, expect: {}, actual: {}",
1228 expected,
1229 actual
1230 ))]
1231 InconsistentTimestampLength {
1232 expected: usize,
1233 actual: usize,
1234 #[snafu(implicit)]
1235 location: Location,
1236 },
1237
1238 #[snafu(display(
1239 "Too many files to read concurrently: {}, max allowed: {}",
1240 actual,
1241 max
1242 ))]
1243 TooManyFilesToRead {
1244 actual: usize,
1245 max: usize,
1246 #[snafu(implicit)]
1247 location: Location,
1248 },
1249
1250 #[snafu(display("Duration out of range: {input:?}"))]
1251 DurationOutOfRange {
1252 input: std::time::Duration,
1253 #[snafu(source)]
1254 error: chrono::OutOfRangeError,
1255 #[snafu(implicit)]
1256 location: Location,
1257 },
1258
1259 #[snafu(display("GC job permit exhausted"))]
1260 TooManyGcJobs {
1261 #[snafu(implicit)]
1262 location: Location,
1263 },
1264
1265 #[snafu(display(
1266 "Staging partition expr mismatch, manifest: {:?}, request: {}",
1267 manifest_expr,
1268 request_expr
1269 ))]
1270 StagingPartitionExprMismatch {
1271 manifest_expr: Option<String>,
1272 request_expr: String,
1273 #[snafu(implicit)]
1274 location: Location,
1275 },
1276
1277 #[snafu(display(
1278 "Invalid source and target region, source: {}, target: {}",
1279 source_region_id,
1280 target_region_id
1281 ))]
1282 InvalidSourceAndTargetRegion {
1283 source_region_id: RegionId,
1284 target_region_id: RegionId,
1285 #[snafu(implicit)]
1286 location: Location,
1287 },
1288
1289 #[snafu(display("Failed to prune file"))]
1290 PruneFile {
1291 source: Arc<Error>,
1292 #[snafu(implicit)]
1293 location: Location,
1294 },
1295
1296 #[snafu(display("Failed to cast column"))]
1297 CastColumn {
1298 #[snafu(source)]
1299 error: datafusion::error::DataFusionError,
1300 #[snafu(implicit)]
1301 location: Location,
1302 },
1303
1304 #[snafu(display("Failed to generate Arrow schema from Parquet file: {}", file))]
1305 ParquetToArrowSchema {
1306 file: String,
1307 #[snafu(source)]
1308 error: parquet::errors::ParquetError,
1309 #[snafu(implicit)]
1310 location: Location,
1311 },
1312
1313 #[snafu(display(
1314 "Region {} is in {:?} state, expect: Writable, Staging or Downgrading",
1315 region_id,
1316 state
1317 ))]
1318 FlushableRegionState {
1319 region_id: RegionId,
1320 state: RegionRoleState,
1321 #[snafu(implicit)]
1322 location: Location,
1323 },
1324}
1325
1326pub type Result<T, E = Error> = std::result::Result<T, E>;
1327
1328impl Error {
1329 pub(crate) fn is_fill_default(&self) -> bool {
1331 matches!(self, Error::FillDefault { .. })
1332 }
1333
1334 pub(crate) fn is_object_not_found(&self) -> bool {
1336 match self {
1337 Error::OpenDal { error, .. } => error.kind() == ErrorKind::NotFound,
1338 _ => false,
1339 }
1340 }
1341}
1342
1343impl ErrorExt for Error {
1344 fn status_code(&self) -> StatusCode {
1345 use Error::*;
1346
1347 match self {
1348 DataTypeMismatch { source, .. } => source.status_code(),
1349 OpenDal { .. } | ReadParquet { .. } => StatusCode::StorageUnavailable,
1350 WriteWal { source, .. } | ReadWal { source, .. } | DeleteWal { source, .. } => {
1351 source.status_code()
1352 }
1353 CompressObject { .. }
1354 | DecompressObject { .. }
1355 | SerdeJson { .. }
1356 | Utf8 { .. }
1357 | NewRecordBatch { .. }
1358 | RegionCorrupted { .. }
1359 | InconsistentFile { .. }
1360 | CreateDefault { .. }
1361 | InvalidParquet { .. }
1362 | OperateAbortedIndex { .. }
1363 | IndexEncodeNull { .. }
1364 | NoCheckpoint { .. }
1365 | NoManifests { .. }
1366 | FilesLost { .. }
1367 | InstallManifestTo { .. }
1368 | Unexpected { .. }
1369 | SerializeColumnMetadata { .. }
1370 | SerializeManifest { .. }
1371 | StagingPartitionExprMismatch { .. } => StatusCode::Unexpected,
1372
1373 RegionNotFound { .. } => StatusCode::RegionNotFound,
1374 ObjectStoreNotFound { .. }
1375 | InvalidScanIndex { .. }
1376 | InvalidMeta { .. }
1377 | InvalidRequest { .. }
1378 | PartitionExprVersionMismatch { .. }
1379 | FillDefault { .. }
1380 | ConvertColumnDataType { .. }
1381 | ColumnNotFound { .. }
1382 | InvalidMetadata { .. }
1383 | InvalidRegionOptions { .. }
1384 | InvalidWalReadRequest { .. }
1385 | PartitionOutOfRange { .. }
1386 | ParseJobId { .. }
1387 | DurationOutOfRange { .. }
1388 | MissingOldManifest { .. }
1389 | MissingNewManifest { .. }
1390 | MissingManifest { .. }
1391 | NoOldManifests { .. }
1392 | MissingPartitionExpr { .. }
1393 | SerializePartitionExpr { .. }
1394 | InvalidSourceAndTargetRegion { .. } => StatusCode::InvalidArguments,
1395
1396 IncrementalQueryStale { .. } | SnapshotFenceStale { .. } => StatusCode::RequestOutdated,
1397
1398 RegionMetadataNotFound { .. }
1399 | Join { .. }
1400 | WorkerStopped { .. }
1401 | Recv { .. }
1402 | DecodeWal { .. }
1403 | ComputeArrow { .. }
1404 | EvalPartitionFilter { .. }
1405 | BiErrors { .. }
1406 | StopScheduler { .. }
1407 | ComputeVector { .. }
1408 | EncodeMemtable { .. }
1409 | CreateDir { .. }
1410 | ReadDataPart { .. }
1411 | BuildEntry { .. }
1412 | Metadata { .. }
1413 | CastColumn { .. }
1414 | MitoManifestInfo { .. }
1415 | ParquetToArrowSchema { .. } => StatusCode::Internal,
1416
1417 FetchManifests { source, .. } => source.status_code(),
1418
1419 OpenRegion { source, .. } => source.status_code(),
1420
1421 WriteParquet { .. } => StatusCode::StorageUnavailable,
1422 WriteGroup { source, .. } => source.status_code(),
1423 InvalidBatch { .. } => StatusCode::InvalidArguments,
1424 InvalidRecordBatch { .. } => StatusCode::InvalidArguments,
1425 ConvertVector { source, .. } => source.status_code(),
1426
1427 PrimaryKeyLengthMismatch { .. } => StatusCode::InvalidArguments,
1428 InvalidSender { .. } => StatusCode::InvalidArguments,
1429 InvalidSchedulerState { .. } => StatusCode::InvalidArguments,
1430 RegionRequirement { .. } => StatusCode::InvalidArguments,
1431 DeleteSsts { .. } | DeleteIndex { .. } | DeleteIndexes { .. } => {
1432 StatusCode::StorageUnavailable
1433 }
1434 FlushRegion { source, .. } | BuildIndexAsync { source, .. } => source.status_code(),
1435 RegionDropped { .. } => StatusCode::Cancelled,
1436 RegionClosed { .. } => StatusCode::Cancelled,
1437 RegionTruncated { .. } => StatusCode::Cancelled,
1438 RejectWrite { .. } => StatusCode::StorageUnavailable,
1439 CompactRegion { source, .. } => source.status_code(),
1440 EditRegion { source, .. } => source.status_code(),
1441 CompatReader { .. } => StatusCode::Unexpected,
1442 InvalidRegionRequest { source, .. } => source.status_code(),
1443 RegionState { .. } | UpdateManifest { .. } => StatusCode::RegionNotReady,
1444 JsonOptions { .. } => StatusCode::InvalidArguments,
1445 EmptyRegionDir { .. } | EmptyManifestDir { .. } => StatusCode::RegionNotFound,
1446 ConvertValue { source, .. } => source.status_code(),
1447 ApplyBloomFilterIndex { source, .. } => source.status_code(),
1448 InvalidPartitionExpr { source, .. } => source.status_code(),
1449 BuildIndexApplier { source, .. }
1450 | PushIndexValue { source, .. }
1451 | ApplyInvertedIndex { source, .. }
1452 | IndexFinish { source, .. } => source.status_code(),
1453 #[cfg(feature = "vector_index")]
1454 ApplyVectorIndex { .. } => StatusCode::Internal,
1455 PuffinReadBlob { source, .. }
1456 | PuffinAddBlob { source, .. }
1457 | PuffinInitStager { source, .. }
1458 | PuffinBuildReader { source, .. }
1459 | PuffinPurgeStager { source, .. } => source.status_code(),
1460 CleanDir { .. } => StatusCode::Unexpected,
1461 InvalidConfig { .. } => StatusCode::InvalidArguments,
1462 StaleLogEntry { .. }
1463 | InvalidNativeHistogramSubfield { .. }
1464 | InvalidNativeHistogramFieldId { .. } => StatusCode::Unexpected,
1465
1466 External { source, .. } => source.status_code(),
1467
1468 RecordBatch { source, .. } => source.status_code(),
1469
1470 Download { .. } | Upload { .. } => StatusCode::StorageUnavailable,
1471 ChecksumMismatch { .. } => StatusCode::Unexpected,
1472 RegionStopped { .. } => StatusCode::RegionNotReady,
1473 TimeRangePredicateOverflow { .. } => StatusCode::InvalidArguments,
1474 UnsupportedOperation { .. } => StatusCode::Unsupported,
1475 RemoteCompaction { .. } => StatusCode::Unexpected,
1476
1477 IndexOptions { source, .. } => source.status_code(),
1478 CreateFulltextCreator { source, .. } => source.status_code(),
1479 CastVector { source, .. } => source.status_code(),
1480 FulltextPushText { source, .. }
1481 | FulltextFinish { source, .. }
1482 | ApplyFulltextIndex { source, .. } => source.status_code(),
1483 DecodeStats { .. } | StatsNotPresent { .. } => StatusCode::Internal,
1484 RegionBusy { .. } => StatusCode::RegionBusy,
1485 GetSchemaMetadata { source, .. } => source.status_code(),
1486 Timeout { .. } => StatusCode::Cancelled,
1487
1488 DecodeArrowRowGroup { .. } => StatusCode::Internal,
1489
1490 PushBloomFilterValue { source, .. } | BloomFilterFinish { source, .. } => {
1491 source.status_code()
1492 }
1493
1494 #[cfg(feature = "vector_index")]
1495 VectorIndexBuild { .. } | VectorIndexFinish { .. } => StatusCode::Internal,
1496
1497 ManualCompactionOverride {} | CompactionCancelled {} => StatusCode::Cancelled,
1498
1499 CompactionMemoryExhausted { source, .. } => source.status_code(),
1500
1501 IncompatibleWalProviderChange { .. } => StatusCode::InvalidArguments,
1502
1503 ScanSeries { source, .. } => source.status_code(),
1504
1505 ScanMultiTimes { .. } => StatusCode::InvalidArguments,
1506 ConvertBulkWalEntry { source, .. } => source.status_code(),
1507
1508 Encode { source, .. } | Decode { source, .. } => source.status_code(),
1509
1510 #[cfg(feature = "enterprise")]
1511 ScanExternalRange { source, .. } => source.status_code(),
1512
1513 InconsistentTimestampLength { .. } => StatusCode::InvalidArguments,
1514
1515 TooManyFilesToRead { .. } | TooManyGcJobs { .. } => StatusCode::RateLimited,
1516
1517 PruneFile { source, .. } => source.status_code(),
1518
1519 FlushableRegionState { .. } => StatusCode::RegionNotReady,
1520 }
1521 }
1522
1523 fn as_any(&self) -> &dyn Any {
1524 self
1525 }
1526
1527 fn retry_hint(&self) -> RetryHint {
1528 use Error::*;
1529
1530 match self {
1531 ReadParquet { .. }
1532 | WriteParquet { .. }
1533 | RejectWrite { .. }
1534 | Download { .. }
1535 | Upload { .. }
1536 | RegionState { .. }
1537 | UpdateManifest { .. }
1538 | RegionStopped { .. }
1539 | RegionBusy { .. }
1540 | FlushableRegionState { .. } => RetryHint::Retryable,
1541
1542 OpenDal { error, .. }
1543 | DeleteSsts { error, .. }
1544 | DeleteIndex { error, .. }
1545 | DeleteIndexes { error, .. } => retry_hint_from_opendal_error(error),
1546
1547 WriteWal { source, .. }
1548 | ReadWal { source, .. }
1549 | DeleteWal { source, .. }
1550 | FetchManifests { source, .. }
1551 | External { source, .. } => source.retry_hint(),
1552
1553 OpenRegion { source, .. }
1554 | WriteGroup { source, .. }
1555 | FlushRegion { source, .. }
1556 | BuildIndexAsync { source, .. }
1557 | CompactRegion { source, .. }
1558 | EditRegion { source, .. }
1559 | ScanSeries { source, .. }
1560 | PruneFile { source, .. } => source.retry_hint(),
1561
1562 DataTypeMismatch { source, .. }
1563 | ConvertVector { source, .. }
1564 | ConvertValue { source, .. }
1565 | IndexOptions { source, .. }
1566 | CastVector { source, .. } => source.retry_hint(),
1567
1568 BuildIndexApplier { source, .. }
1569 | PushIndexValue { source, .. }
1570 | ApplyInvertedIndex { source, .. }
1571 | IndexFinish { source, .. } => source.retry_hint(),
1572
1573 ApplyBloomFilterIndex { source, .. }
1574 | PushBloomFilterValue { source, .. }
1575 | BloomFilterFinish { source, .. } => source.retry_hint(),
1576
1577 PuffinReadBlob { source, .. }
1578 | PuffinAddBlob { source, .. }
1579 | PuffinInitStager { source, .. }
1580 | PuffinBuildReader { source, .. }
1581 | PuffinPurgeStager { source, .. } => source.retry_hint(),
1582
1583 CreateFulltextCreator { source, .. }
1584 | FulltextPushText { source, .. }
1585 | FulltextFinish { source, .. }
1586 | ApplyFulltextIndex { source, .. } => source.retry_hint(),
1587
1588 InvalidRegionRequest { source, .. } => source.retry_hint(),
1589 InvalidPartitionExpr { source, .. } => source.retry_hint(),
1590 RecordBatch { source, .. } => source.retry_hint(),
1591 GetSchemaMetadata { source, .. } => source.retry_hint(),
1592 CompactionMemoryExhausted { source, .. } => source.retry_hint(),
1593 ConvertBulkWalEntry { source, .. } => source.retry_hint(),
1594 Encode { source, .. } | Decode { source, .. } => source.retry_hint(),
1595
1596 #[cfg(feature = "enterprise")]
1597 ScanExternalRange { source, .. } => source.retry_hint(),
1598
1599 _ => RetryHint::NonRetryable,
1600 }
1601 }
1602}