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