mito2/
error.rs

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