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