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