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