36
36
37
37
#include < mutex>
38
38
39
-
40
39
namespace DB
41
40
{
41
+ namespace FailPoints
42
+ {
43
+ extern const char force_checkpoint_dump_throw_datafile[];
44
+ }
45
+
42
46
UniversalPageStoragePtr UniversalPageStorage::create (
43
47
const String & name,
44
48
PSDiskDelegatorPtr delegator,
@@ -495,7 +499,7 @@ bool UniversalPageStorage::canSkipCheckpoint() const
495
499
return snap->sequence == last_checkpoint_sequence;
496
500
}
497
501
498
- PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint (
502
+ std::optional< PS::V3::CPDataDumpStats> UniversalPageStorage::dumpIncrementalCheckpoint (
499
503
const UniversalPageStorage::DumpCheckpointOptions & options)
500
504
{
501
505
std::scoped_lock lock (checkpoint_mu);
@@ -504,7 +508,7 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(
504
508
auto snap = page_directory->createSnapshot (/* tracing_id*/ " dumpIncrementalCheckpoint" );
505
509
506
510
if (snap->sequence == last_checkpoint_sequence && !options.full_compact )
507
- return {.has_new_data = false };
511
+ return PS::V3::CPDataDumpStats {.has_new_data = false };
508
512
509
513
// As a checkpoint, we write both entries (in manifest) and its data.
510
514
// Some entries' data may be already written by a previous checkpoint. These data will not be written again.
@@ -542,23 +546,49 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(
542
546
.max_data_file_size = options.max_data_file_size ,
543
547
.max_edit_records_per_part = options.max_edit_records_per_part ,
544
548
});
545
-
546
- writer->writePrefix ({
547
- .writer = options.writer_info ,
548
- .sequence = snap->sequence ,
549
- .last_sequence = last_checkpoint_sequence,
550
- });
551
- PS::V3::CPFilesWriter::CompactOptions compact_opts = [&]() {
552
- if (options.full_compact )
553
- return PS::V3::CPFilesWriter::CompactOptions (true );
554
- if (options.compact_getter == nullptr )
555
- return PS::V3::CPFilesWriter::CompactOptions (false );
556
- return PS::V3::CPFilesWriter::CompactOptions (options.compact_getter ());
549
+ std::vector<String> data_file_paths;
550
+ const auto checkpoint_dump_stats = [&]() -> std::optional<PS::V3::CPDataDumpStats> {
551
+ try
552
+ {
553
+ writer->writePrefix ({
554
+ .writer = options.writer_info ,
555
+ .sequence = snap->sequence ,
556
+ .last_sequence = last_checkpoint_sequence,
557
+ });
558
+ const PS::V3::CPFilesWriter::CompactOptions compact_opts = [&]() {
559
+ if (options.full_compact )
560
+ return PS::V3::CPFilesWriter::CompactOptions (true );
561
+ if (options.compact_getter == nullptr )
562
+ return PS::V3::CPFilesWriter::CompactOptions (false );
563
+ return PS::V3::CPFilesWriter::CompactOptions (options.compact_getter ());
564
+ }();
565
+ // get the remote file ids that need to be compacted
566
+ const auto checkpoint_dump_stats_inner
567
+ = writer->writeEditsAndApplyCheckpointInfo (edit_from_mem, compact_opts, options.only_upload_manifest );
568
+ data_file_paths = writer->writeSuffix ();
569
+ fiu_do_on (FailPoints::force_checkpoint_dump_throw_datafile, {
570
+ throw Exception (ErrorCodes::LOGICAL_ERROR, " fake checkpoint write exception" );
571
+ });
572
+ return checkpoint_dump_stats_inner;
573
+ }
574
+ catch (...)
575
+ {
576
+ // Could be #9406, which is a soft error.
577
+ tryLogCurrentException (
578
+ __PRETTY_FUNCTION__,
579
+ fmt::format (
580
+ " Error dumping incremental snapshot sequence={} manifest_file_path={} data_file_path_pattern={}" ,
581
+ sequence,
582
+ manifest_file_path,
583
+ options.data_file_path_pattern ));
584
+ writer->abort ();
585
+ return std::nullopt;
586
+ }
557
587
}();
558
- // get the remote file ids that need to be compacted
559
- const auto checkpoint_dump_stats
560
- = writer-> writeEditsAndApplyCheckpointInfo (edit_from_mem, compact_opts, options. only_upload_manifest ) ;
561
- auto data_file_paths = writer-> writeSuffix ();
588
+
589
+ if (! checkpoint_dump_stats. has_value ())
590
+ return std::nullopt ;
591
+
562
592
writer.reset ();
563
593
auto dump_data_seconds = sw.elapsedMillisecondsFromLastTime () / 1000.0 ;
564
594
@@ -580,7 +610,7 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(
580
610
// TODO: Currently, even when has_new_data == false,
581
611
// something will be written to DataFile (i.e., the file prefix).
582
612
// This can be avoided, as its content is useless.
583
- if (checkpoint_dump_stats. has_new_data )
613
+ if (checkpoint_dump_stats-> has_new_data )
584
614
{
585
615
// Copy back the checkpoint info to the current PageStorage.
586
616
// New checkpoint infos are attached in `writeEditsAndApplyCheckpointInfo`.
@@ -607,8 +637,8 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(
607
637
copy_checkpoint_info_seconds,
608
638
sw.elapsedSeconds (),
609
639
sequence,
610
- checkpoint_dump_stats);
611
- SetMetrics (checkpoint_dump_stats);
640
+ * checkpoint_dump_stats);
641
+ SetMetrics (* checkpoint_dump_stats);
612
642
return checkpoint_dump_stats;
613
643
}
614
644
0 commit comments