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