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