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