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