We have following function which allows to delay inserts in case of TOO_MANY_PARTS:
https://github.com/ClickHouse/ClickHouse/blob/c09f83654dae58fd964e024f7842de64f59ab579/src/Storages/MergeTree/MergeTreeData.cpp#L3724-L3798.

Delay time formula looks really strange and can lead to enormous value of sleep time, like:
```
Delaying inserting block by 9223372036854775808 ms. because there are 199 parts and their average size is 1.85 GiB
```
This can lead to unexpected errors from `tryWait` function like:
```
0. Poco::EventImpl::waitImpl(long) @ 0x1730d6e6 in /usr/bin/clickhouse
1. DB::MergeTreeData::delayInsertOrThrowIfNeeded(Poco::Event*, std::__1::shared_ptr<DB::Context const>) const @ 0x13e9ca32 in /usr/bin/clickhouse
2. ? @ 0x145d9379 in /usr/bin/clickhouse
3. DB::ExceptionKeepingTransform::work() @ 0x145d8b54 in /usr/bin/clickhouse
4. DB::ExecutionThreadContext::executeTask() @ 0x14409026 in /usr/bin/clickhouse
5. DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic<bool>*) @ 0x143fdadc in /usr/bin/clickhouse
6. DB::PipelineExecutor::executeImpl(unsigned long) @ 0x143fc519 in /usr/bin/clickhouse
7. DB::PipelineExecutor::execute(unsigned long) @ 0x143fc31d in /usr/bin/clickhouse
8. DB::CompletedPipelineExecutor::execute() @ 0x143fad3d in /usr/bin/clickhouse
9. DB::AsynchronousInsertQueue::processData(DB::AsynchronousInsertQueue::InsertQuery, std::__1::unique_ptr<DB::AsynchronousInsertQueue::InsertData, std::__1::default_delete<DB::AsynchronousInsertQueue::InsertData>>, std::__1::shared_ptr<DB::Context const>) @ 0x1293f3f4 in /usr/bin/clickhouse
10. ? @ 0x12941ed0 in /usr/bin/clickhouse
11. ThreadPoolImpl<ThreadFromGlobalPoolImpl<false>>::worker(std::__1::__list_iterator<ThreadFromGlobalPoolImpl<false>, void*>) @ 0xda87576 in /usr/bin/clickhouse
12. void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<false>::ThreadFromGlobalPoolImpl<void ThreadPoolImpl<ThreadFromGlobalPoolImpl<false>>::scheduleImpl<void>(std::__1::function<void ()>, long, std::__1::optional<unsigned long>, bool)::'lambda0'()>(void&&)::'lambda'(), void ()>>(std::__1::__function::__policy_storage const*) @ 0xda89d37 in /usr/bin/clickhouse
13. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xda83b96 in /usr/bin/clickhouse
14. ? @ 0xda88d01 in /usr/bin/clickhouse
15. ? @ 0x7f636c46c609 in ?
16. clone @ 0x7f636c391133 in ?
```

Need to rethink the logic of delay time calculation and introduce better formula or some other thresholds.
M(Bool, compress_primary_key, false, "Primary key support compression, reduce primary key file size and speed up network transmission.", 0) \
    M(String, marks_compression_codec, "ZSTD(3)", "Compression encoding used by marks, marks are small enough and cached, so the default compression is ZSTD(3).", 0) \
    M(String, primary_key_compression_codec, "ZSTD(3)", "Compression encoding used by primary, primary key is small enough and cached, so the default compression is ZSTD(3).", 0) \
    M(UInt64, marks_compress_block_size, 65536, "Mark compress block size, the actual size of the block to compress.", 0) \
    M(UInt64, primary_key_compress_block_size, 65536, "Primary compress block size, the actual size of the block to compress.", 0) \
    \
    /** Obsolete settings. Kept for backward compatibility only. */ \
    M(UInt64, min_relative_delay_to_yield_leadership, 120, "Obsolete setting, does nothing.", 0) \
    M(UInt64, check_delay_period, 60, "Obsolete setting, does nothing.", 0) \
    M(Bool, allow_floating_point_partition_key, false, "Allow floating point as partition key", 0) \
    M(UInt64, replicated_max_parallel_sends, 0, "Obsolete setting, does nothing.", 0) \
    M(UInt64, replicated_max_parallel_sends_for_table, 0, "Obsolete setting, does nothing.", 0) \
    M(UInt64, replicated_max_parallel_fetches, 0, "Obsolete setting, does nothing.", 0) \
    M(UInt64, replicated_max_parallel_fetches_for_table, 0, "Obsolete setting, does nothing.", 0) \
    M(Bool, write_final_mark, true, "Obsolete setting, does nothing.", 0) \
    /// Settings that should not change after the creation of a table.
    
#define APPLY_FOR_IMMUTABLE_MERGE_TREE_SETTINGS(M) \
    M(index_granularity)
DECLARE_SETTINGS_TRAITS(MergeTreeSettingsTraits, LIST_OF_MERGE_TREE_SETTINGS)
/** Settings for the MergeTree family of engines.
  * Could be loaded from config or from a CREATE TABLE query (SETTINGS clause).
  */
struct MergeTreeSettings : public BaseSettings<MergeTreeSettingsTraits>
{
    void loadFromConfig(const String & config_elem, const Poco::Util::AbstractConfiguration & config);
    
    void loadFromQuery(ASTStorage & storage_def);
    
    static bool isReadonlySetting(const String & name)