Skip to content

Commit

Permalink
Fix fail to create three hops of ref pages (#5612) (#5674)
Browse files Browse the repository at this point in the history
close #5570
  • Loading branch information
ti-chi-bot authored Aug 22, 2022
1 parent f8dae94 commit dd8e5fa
Show file tree
Hide file tree
Showing 14 changed files with 944 additions and 254 deletions.
94 changes: 49 additions & 45 deletions dbms/src/Common/FailPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,55 @@ namespace DB
{
std::unordered_map<String, std::shared_ptr<FailPointChannel>> FailPointHelper::fail_point_wait_channels;

#define APPLY_FOR_FAILPOINTS_ONCE(M) \
M(exception_between_drop_meta_and_data) \
M(exception_between_alter_data_and_meta) \
M(exception_drop_table_during_remove_meta) \
M(exception_between_rename_table_data_and_metadata) \
M(exception_between_create_database_meta_and_directory) \
M(exception_before_rename_table_old_meta_removed) \
M(exception_after_step_1_in_exchange_partition) \
M(exception_before_step_2_rename_in_exchange_partition) \
M(exception_after_step_2_in_exchange_partition) \
M(exception_before_step_3_rename_in_exchange_partition) \
M(exception_after_step_3_in_exchange_partition) \
M(region_exception_after_read_from_storage_some_error) \
M(region_exception_after_read_from_storage_all_error) \
M(exception_before_dmfile_remove_encryption) \
M(exception_before_dmfile_remove_from_disk) \
M(force_enable_region_persister_compatible_mode) \
M(force_disable_region_persister_compatible_mode) \
M(force_triggle_background_merge_delta) \
M(force_triggle_foreground_flush) \
M(exception_before_mpp_register_non_root_mpp_task) \
M(exception_before_mpp_register_tunnel_for_non_root_mpp_task) \
M(exception_during_mpp_register_tunnel_for_non_root_mpp_task) \
M(exception_before_mpp_non_root_task_run) \
M(exception_during_mpp_non_root_task_run) \
M(exception_before_mpp_register_root_mpp_task) \
M(exception_before_mpp_register_tunnel_for_root_mpp_task) \
M(exception_before_mpp_root_task_run) \
M(exception_during_mpp_root_task_run) \
M(exception_during_mpp_write_err_to_tunnel) \
M(exception_during_mpp_close_tunnel) \
M(exception_during_write_to_storage) \
M(force_set_sst_to_dtfile_block_size) \
M(force_set_sst_decode_rand) \
M(exception_before_page_file_write_sync) \
M(force_set_segment_ingest_packs_fail) \
M(segment_merge_after_ingest_packs) \
M(force_formal_page_file_not_exists) \
M(force_legacy_or_checkpoint_page_file_exists) \
M(exception_in_creating_set_input_stream) \
M(exception_when_read_from_log) \
M(exception_mpp_hash_build) \
M(exception_before_drop_segment) \
M(exception_after_drop_segment) \
M(exception_between_schema_change_in_the_same_diff)
#define APPLY_FOR_FAILPOINTS_ONCE(M) \
M(exception_between_drop_meta_and_data) \
M(exception_between_alter_data_and_meta) \
M(exception_drop_table_during_remove_meta) \
M(exception_between_rename_table_data_and_metadata) \
M(exception_between_create_database_meta_and_directory) \
M(exception_before_rename_table_old_meta_removed) \
M(exception_after_step_1_in_exchange_partition) \
M(exception_before_step_2_rename_in_exchange_partition) \
M(exception_after_step_2_in_exchange_partition) \
M(exception_before_step_3_rename_in_exchange_partition) \
M(exception_after_step_3_in_exchange_partition) \
M(region_exception_after_read_from_storage_some_error) \
M(region_exception_after_read_from_storage_all_error) \
M(exception_before_dmfile_remove_encryption) \
M(exception_before_dmfile_remove_from_disk) \
M(force_enable_region_persister_compatible_mode) \
M(force_disable_region_persister_compatible_mode) \
M(force_triggle_background_merge_delta) \
M(force_triggle_foreground_flush) \
M(exception_before_mpp_register_non_root_mpp_task) \
M(exception_before_mpp_register_tunnel_for_non_root_mpp_task) \
M(exception_during_mpp_register_tunnel_for_non_root_mpp_task) \
M(exception_before_mpp_non_root_task_run) \
M(exception_during_mpp_non_root_task_run) \
M(exception_before_mpp_register_root_mpp_task) \
M(exception_before_mpp_register_tunnel_for_root_mpp_task) \
M(exception_before_mpp_root_task_run) \
M(exception_during_mpp_root_task_run) \
M(exception_during_mpp_write_err_to_tunnel) \
M(exception_during_mpp_close_tunnel) \
M(exception_during_write_to_storage) \
M(force_set_sst_to_dtfile_block_size) \
M(force_set_sst_decode_rand) \
M(exception_before_page_file_write_sync) \
M(force_set_segment_ingest_packs_fail) \
M(segment_merge_after_ingest_packs) \
M(force_formal_page_file_not_exists) \
M(force_legacy_or_checkpoint_page_file_exists) \
M(exception_in_creating_set_input_stream) \
M(exception_when_read_from_log) \
M(exception_mpp_hash_build) \
M(exception_before_drop_segment) \
M(exception_after_drop_segment) \
M(exception_between_schema_change_in_the_same_diff) \
/* try to use logical split, could fall back to physical split */ \
M(try_segment_logical_split) \
/* must perform logical split, otherwise throw exception */ \
M(force_segment_logical_split)

#define APPLY_FOR_FAILPOINTS(M) \
M(skip_check_segment_update) \
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Management/tests/gtest_manual_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BasicManualCompactTest
storage = StorageDeltaMerge::create("TiFlash",
"default" /* db_name */,
"test_table" /* table_name */,
std::ref(table_info),
table_info,
ColumnsDescription{columns},
astptr,
0,
Expand Down
26 changes: 23 additions & 3 deletions dbms/src/Storages/DeltaMerge/Segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Exception.h>
#include <Common/SyncPoint/SyncPoint.h>
#include <Common/TiFlashMetrics.h>
#include <DataStreams/ConcatBlockInputStream.h>
Expand All @@ -37,6 +38,7 @@
#include <Storages/DeltaMerge/WriteBatches.h>
#include <Storages/PathPool.h>
#include <common/logger_useful.h>
#include <fiu.h>
#include <fmt/core.h>

#include <ext/scope_guard.h>
Expand Down Expand Up @@ -92,6 +94,12 @@ extern const int LOGICAL_ERROR;
extern const int UNKNOWN_FORMAT_VERSION;
} // namespace ErrorCodes

namespace FailPoints
{
extern const char try_segment_logical_split[];
extern const char force_segment_logical_split[];
} // namespace FailPoints

namespace DM
{
const static size_t SEGMENT_BUFFER_SIZE = 128; // More than enough.
Expand Down Expand Up @@ -868,9 +876,16 @@ std::optional<Segment::SplitInfo> Segment::prepareSplit(DMContext & dm_context,
{
SYNC_FOR("before_Segment::prepareSplit");

if (!dm_context.enable_logical_split //
|| segment_snap->stable->getPacks() <= 3 //
|| segment_snap->delta->getRows() > segment_snap->stable->getRows())
bool try_logical_split = dm_context.enable_logical_split //
&& segment_snap->stable->getPacks() > 3 //
&& segment_snap->delta->getRows() <= segment_snap->stable->getRows();
#ifdef FIU_ENABLE
bool force_logical_split = false;
fiu_do_on(FailPoints::try_segment_logical_split, { try_logical_split = true; });
fiu_do_on(FailPoints::force_segment_logical_split, { try_logical_split = true; force_logical_split = true; });
#endif

if (!try_logical_split)
{
return prepareSplitPhysical(dm_context, schema_snap, segment_snap, wbs);
}
Expand All @@ -887,6 +902,9 @@ std::optional<Segment::SplitInfo> Segment::prepareSplit(DMContext & dm_context,
"Got bad split point [{}] for segment {}, fall back to split physical.",
(split_point_opt.has_value() ? split_point_opt->toRowKeyValueRef().toDebugString() : "no value"),
info());
#ifdef FIU_ENABLE
RUNTIME_CHECK(!force_logical_split, Exception, "Can not perform logical split while failpoint `force_segment_logical_split` is true");
#endif
return prepareSplitPhysical(dm_context, schema_snap, segment_snap, wbs);
}
else
Expand Down Expand Up @@ -1173,6 +1191,8 @@ SegmentPtr Segment::merge(DMContext & dm_context, const ColumnDefinesPtr & schem
wbs.writeLogAndData();
merged_stable->enableDMFilesGC();

SYNC_FOR("before_Segment::applyMerge"); // pause without holding the lock on segments to be merged

auto left_lock = left->mustGetUpdateLock();
auto right_lock = right->mustGetUpdateLock();

Expand Down
6 changes: 6 additions & 0 deletions dbms/src/Storages/DeltaMerge/StoragePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Interpreters/Settings.h>
#include <Storages/DeltaMerge/StoragePool.h>
#include <Storages/Page/ConfigSettings.h>
#include <Storages/Page/FileUsage.h>
#include <Storages/Page/Page.h>
#include <Storages/Page/PageStorage.h>
#include <Storages/Page/Snapshot.h>
Expand Down Expand Up @@ -127,6 +128,11 @@ void GlobalStoragePool::restore()
false);
}

FileUsageStatistics GlobalStoragePool::getLogFileUsage() const
{
return log_storage->getFileUsageStatistics();
}

bool GlobalStoragePool::gc()
{
return gc(global_context.getSettingsRef(), true, DELTA_MERGE_GC_PERIOD);
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Storages/DeltaMerge/StoragePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <Poco/Logger.h>
#include <Storages/BackgroundProcessingPool.h>
#include <Storages/Page/FileUsage.h>
#include <Storages/Page/PageStorage.h>
#include <Storages/PathPool.h>

Expand Down Expand Up @@ -57,6 +58,8 @@ class GlobalStoragePool : private boost::noncopyable
// Only used on dbgFuncMisc
bool gc();

FileUsageStatistics getLogFileUsage() const;

private:
bool gc(const Settings & settings, bool immediately = false, const Seconds & try_gc_period = DELTA_MERGE_GC_PERIOD);

Expand Down
Loading

0 comments on commit dd8e5fa

Please sign in to comment.