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