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