2017-04-01 09:19:00 +00:00
# include <Storages/StorageReplicatedMergeTree.h>
# include <Storages/MergeTree/ReplicatedMergeTreeQuorumEntry.h>
2021-07-26 16:48:25 +00:00
# include <Storages/MergeTree/ReplicatedMergeTreeSink.h>
2017-06-25 00:01:10 +00:00
# include <Interpreters/PartLog.h>
2023-01-31 14:01:12 +00:00
# include <Common/ProfileEventsScope.h>
2017-04-01 09:19:00 +00:00
# include <Common/SipHash.h>
2018-04-03 17:35:48 +00:00
# include <Common/ZooKeeper/KeeperException.h>
2022-11-16 16:59:08 +00:00
# include <Common/ThreadFuzzer.h>
2023-01-12 16:44:20 +00:00
# include <Storages/MergeTree/AsyncBlockIDsCache.h>
2022-05-06 14:44:00 +00:00
# include <DataTypes/ObjectUtils.h>
2021-10-14 10:25:43 +00:00
# include <Core/Block.h>
2017-04-01 09:19:00 +00:00
# include <IO/Operators.h>
2022-12-07 22:40:52 +00:00
# include <fmt/core.h>
2018-04-03 17:35:48 +00:00
2018-01-25 18:46:24 +00:00
namespace ProfileEvents
{
extern const Event DuplicatedInsertedBlocks ;
}
2016-01-17 05:22:22 +00:00
namespace DB
{
namespace ErrorCodes
{
2018-12-07 03:20:27 +00:00
extern const int TOO_FEW_LIVE_REPLICAS ;
2016-01-17 05:22:22 +00:00
extern const int UNSATISFIED_QUORUM_FOR_PREVIOUS_WRITE ;
extern const int UNEXPECTED_ZOOKEEPER_ERROR ;
extern const int NO_ZOOKEEPER ;
2016-01-24 05:00:24 +00:00
extern const int READONLY ;
extern const int UNKNOWN_STATUS_OF_INSERT ;
2018-01-23 22:56:46 +00:00
extern const int INSERT_WAS_DEDUPLICATED ;
2018-11-22 21:19:58 +00:00
extern const int TIMEOUT_EXCEEDED ;
extern const int NO_ACTIVE_REPLICAS ;
2020-06-15 18:57:38 +00:00
extern const int DUPLICATE_DATA_PART ;
2020-08-28 00:28:37 +00:00
extern const int PART_IS_TEMPORARILY_LOCKED ;
2020-06-16 01:13:45 +00:00
extern const int LOGICAL_ERROR ;
2022-11-10 12:14:04 +00:00
extern const int TABLE_IS_READ_ONLY ;
2022-11-02 15:24:18 +00:00
extern const int QUERY_WAS_CANCELLED ;
2016-01-17 05:22:22 +00:00
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
struct ReplicatedMergeTreeSinkImpl < async_insert > : : DelayedChunk
2022-02-01 10:36:51 +00:00
{
struct Partition
{
2022-12-28 16:25:36 +00:00
Poco : : Logger * log ;
2022-02-01 10:36:51 +00:00
MergeTreeDataWriter : : TemporaryPart temp_part ;
UInt64 elapsed_ns ;
2022-11-06 22:56:26 +00:00
BlockIDsType block_id ;
2022-11-18 16:22:05 +00:00
BlockWithPartition block_with_partition ;
2022-12-28 16:25:36 +00:00
std : : unordered_map < String , std : : vector < size_t > > block_id_to_offset_idx ;
2023-01-31 14:01:12 +00:00
ProfileEvents : : Counters part_counters ;
2022-11-06 22:56:26 +00:00
Partition ( ) = default ;
2023-01-31 14:01:12 +00:00
Partition ( Poco : : Logger * log_ ,
MergeTreeDataWriter : : TemporaryPart & & temp_part_ ,
UInt64 elapsed_ns_ ,
BlockIDsType & & block_id_ ,
BlockWithPartition & & block_ ,
ProfileEvents : : Counters & & part_counters_ )
2022-12-28 16:25:36 +00:00
: log ( log_ ) ,
temp_part ( std : : move ( temp_part_ ) ) ,
2022-11-06 22:56:26 +00:00
elapsed_ns ( elapsed_ns_ ) ,
block_id ( std : : move ( block_id_ ) ) ,
2023-01-31 14:01:12 +00:00
block_with_partition ( std : : move ( block_ ) ) ,
part_counters ( std : : move ( part_counters_ ) )
2022-11-06 22:56:26 +00:00
{
initBlockIDMap ( ) ;
}
void initBlockIDMap ( )
{
if constexpr ( async_insert )
{
block_id_to_offset_idx . clear ( ) ;
for ( size_t i = 0 ; i < block_id . size ( ) ; + + i )
{
2022-12-28 16:25:36 +00:00
block_id_to_offset_idx [ block_id [ i ] ] . push_back ( i ) ;
2022-11-06 22:56:26 +00:00
}
}
}
2023-01-15 21:51:10 +00:00
/// this function check if the block contains duplicate inserts.
/// if so, we keep only one insert for every duplicate ones.
bool filterSelfDuplicate ( )
2022-12-28 16:25:36 +00:00
{
if constexpr ( async_insert )
{
std : : vector < String > dup_block_ids ;
2023-01-15 18:46:16 +00:00
for ( const auto & [ hash_id , offset_indexes ] : block_id_to_offset_idx )
2022-12-28 16:25:36 +00:00
{
2023-01-15 21:51:10 +00:00
/// It means more than one inserts have the same hash id, in this case, we should keep only one of them.
if ( offset_indexes . size ( ) > 1 )
2022-12-28 16:25:36 +00:00
dup_block_ids . push_back ( hash_id ) ;
}
if ( dup_block_ids . empty ( ) )
return false ;
2023-01-15 21:51:10 +00:00
filterBlockDuplicate ( dup_block_ids , true ) ;
2022-12-28 16:25:36 +00:00
return true ;
}
return false ;
}
/// remove the conflict parts of block for rewriting again.
2023-01-15 21:51:10 +00:00
void filterBlockDuplicate ( const std : : vector < String > & block_paths , bool self_dedup )
2022-12-28 16:25:36 +00:00
{
if constexpr ( async_insert )
{
std : : vector < size_t > offset_idx ;
for ( const auto & raw_path : block_paths )
{
std : : filesystem : : path p ( raw_path ) ;
String conflict_block_id = p . filename ( ) ;
auto it = block_id_to_offset_idx . find ( conflict_block_id ) ;
if ( it = = block_id_to_offset_idx . end ( ) )
2023-01-16 13:07:36 +00:00
throw Exception ( ErrorCodes : : LOGICAL_ERROR , " Unknown conflict path {} " , conflict_block_id ) ;
2023-01-15 21:51:10 +00:00
/// if this filter is for self_dedup, that means the block paths is selected by `filterSelfDuplicate`, which is a self purge.
/// in this case, we don't know if zk has this insert, then we should keep one insert, to avoid missing this insert.
2022-12-28 16:25:36 +00:00
offset_idx . insert ( std : : end ( offset_idx ) , std : : begin ( it - > second ) + self_dedup , std : : end ( it - > second ) ) ;
}
std : : sort ( offset_idx . begin ( ) , offset_idx . end ( ) ) ;
2023-01-15 21:51:10 +00:00
auto & offsets = block_with_partition . offsets ;
2022-12-28 16:25:36 +00:00
size_t idx = 0 , remove_count = 0 ;
auto it = offset_idx . begin ( ) ;
std : : vector < size_t > new_offsets ;
std : : vector < String > new_block_ids ;
/// construct filter
size_t rows = block_with_partition . block . rows ( ) ;
auto filter_col = ColumnUInt8 : : create ( rows , 1u ) ;
ColumnUInt8 : : Container & vec = filter_col - > getData ( ) ;
UInt8 * pos = vec . data ( ) ;
for ( auto & offset : offsets )
{
if ( it ! = offset_idx . end ( ) & & * it = = idx )
{
size_t start_pos = idx > 0 ? offsets [ idx - 1 ] : 0 ;
size_t end_pos = offset ;
remove_count + = end_pos - start_pos ;
while ( start_pos < end_pos )
{
* ( pos + start_pos ) = 0 ;
2023-01-15 18:46:09 +00:00
start_pos + + ;
2022-12-28 16:25:36 +00:00
}
it + + ;
}
else
{
new_offsets . push_back ( offset - remove_count ) ;
new_block_ids . push_back ( block_id [ idx ] ) ;
}
idx + + ;
}
LOG_TRACE ( log , " New block IDs: {}, new offsets: {}, size: {} " , toString ( new_block_ids ) , toString ( new_offsets ) , new_offsets . size ( ) ) ;
2023-01-15 21:51:10 +00:00
block_with_partition . offsets = std : : move ( new_offsets ) ;
2022-12-28 16:25:36 +00:00
block_id = std : : move ( new_block_ids ) ;
auto cols = block_with_partition . block . getColumns ( ) ;
for ( auto & col : cols )
{
col = col - > filter ( vec , rows - remove_count ) ;
}
block_with_partition . block . setColumns ( cols ) ;
LOG_TRACE ( log , " New block rows {} " , block_with_partition . block . rows ( ) ) ;
initBlockIDMap ( ) ;
}
else
{
throw Exception ( ErrorCodes : : LOGICAL_ERROR , " sync insert should not call rewriteBlock " ) ;
}
}
2022-02-01 10:36:51 +00:00
} ;
2022-09-06 12:09:03 +00:00
DelayedChunk ( ) = default ;
explicit DelayedChunk ( size_t replicas_num_ ) : replicas_num ( replicas_num_ ) { }
size_t replicas_num = 0 ;
2022-02-01 10:36:51 +00:00
std : : vector < Partition > partitions ;
} ;
2016-01-17 05:22:22 +00:00
2022-12-28 16:25:36 +00:00
std : : vector < Int64 > testSelfDeduplicate ( std : : vector < Int64 > data , std : : vector < size_t > offsets , std : : vector < String > hashes )
{
MutableColumnPtr column = DataTypeInt64 ( ) . createColumn ( ) ;
for ( auto datum : data )
{
column - > insert ( datum ) ;
}
Block block ( { ColumnWithTypeAndName ( std : : move ( column ) , DataTypePtr ( new DataTypeInt64 ( ) ) , " a " ) } ) ;
2023-01-15 21:51:10 +00:00
BlockWithPartition block1 ( std : : move ( block ) , Row ( ) , std : : move ( offsets ) ) ;
2023-01-31 14:01:12 +00:00
ProfileEvents : : Counters profile_counters ;
2022-12-28 16:25:36 +00:00
ReplicatedMergeTreeSinkImpl < true > : : DelayedChunk : : Partition part (
2023-01-31 14:01:12 +00:00
& Poco : : Logger : : get ( " testSelfDeduplicate " ) , MergeTreeDataWriter : : TemporaryPart ( ) , 0 , std : : move ( hashes ) , std : : move ( block1 ) , std : : move ( profile_counters ) ) ;
2022-12-28 16:25:36 +00:00
2023-01-15 21:51:10 +00:00
part . filterSelfDuplicate ( ) ;
2022-12-28 16:25:36 +00:00
ColumnPtr col = part . block_with_partition . block . getColumns ( ) [ 0 ] ;
std : : vector < Int64 > result ;
for ( size_t i = 0 ; i < col - > size ( ) ; i + + )
{
result . push_back ( col - > getInt ( i ) ) ;
}
return result ;
}
2022-11-18 16:22:05 +00:00
namespace
2022-11-06 22:56:26 +00:00
{
2022-12-07 22:40:52 +00:00
/// Convert block id vector to string. Output at most 50 ids.
2022-11-18 16:22:05 +00:00
template < typename T >
inline String toString ( const std : : vector < T > & vec )
2022-11-06 22:56:26 +00:00
{
2022-11-23 20:07:59 +00:00
size_t size = vec . size ( ) ;
if ( size > 50 ) size = 50 ;
2022-12-07 22:40:52 +00:00
return fmt : : format ( " ({}) " , fmt : : join ( vec . begin ( ) , vec . begin ( ) + size , " , " ) ) ;
2022-11-06 22:56:26 +00:00
}
2022-11-18 16:22:05 +00:00
std : : vector < String > getHashesForBlocks ( BlockWithPartition & block , String partition_id )
{
size_t start = 0 ;
auto cols = block . block . getColumns ( ) ;
2022-12-08 08:57:33 +00:00
std : : vector < String > block_id_vec ;
2023-01-15 21:51:10 +00:00
for ( auto offset : block . offsets )
2022-11-18 16:22:05 +00:00
{
SipHash hash ;
for ( size_t i = start ; i < offset ; + + i )
for ( const auto & col : cols )
col - > updateHashWithValue ( i , hash ) ;
union
{
char bytes [ 16 ] ;
UInt64 words [ 2 ] ;
} hash_value ;
hash . get128 ( hash_value . bytes ) ;
block_id_vec . push_back ( partition_id + " _ " + DB : : toString ( hash_value . words [ 0 ] ) + " _ " + DB : : toString ( hash_value . words [ 1 ] ) ) ;
2022-11-06 22:56:26 +00:00
2022-11-18 16:22:05 +00:00
start = offset ;
}
return block_id_vec ;
}
2022-11-06 22:56:26 +00:00
}
template < bool async_insert >
2022-12-07 22:40:52 +00:00
ReplicatedMergeTreeSinkImpl < async_insert > : : ReplicatedMergeTreeSinkImpl (
2020-06-16 15:51:29 +00:00
StorageReplicatedMergeTree & storage_ ,
const StorageMetadataPtr & metadata_snapshot_ ,
2022-09-06 12:09:03 +00:00
size_t quorum_size ,
2020-06-16 15:51:29 +00:00
size_t quorum_timeout_ms_ ,
size_t max_parts_per_block_ ,
2020-09-30 23:16:27 +00:00
bool quorum_parallel_ ,
2020-11-13 07:54:05 +00:00
bool deduplicate_ ,
2022-09-06 12:09:03 +00:00
bool majority_quorum ,
2021-02-10 14:12:49 +00:00
ContextPtr context_ ,
2021-02-15 15:06:48 +00:00
bool is_attach_ )
2021-07-26 10:08:40 +00:00
: SinkToStorage ( metadata_snapshot_ - > getSampleBlock ( ) )
2021-07-23 19:33:59 +00:00
, storage ( storage_ )
2020-06-16 15:51:29 +00:00
, metadata_snapshot ( metadata_snapshot_ )
2022-09-06 12:09:03 +00:00
, required_quorum_size ( majority_quorum ? std : : nullopt : std : : make_optional < size_t > ( quorum_size ) )
2020-06-15 17:41:44 +00:00
, quorum_timeout_ms ( quorum_timeout_ms_ )
, max_parts_per_block ( max_parts_per_block_ )
2021-02-16 13:19:21 +00:00
, is_attach ( is_attach_ )
2020-09-30 23:16:27 +00:00
, quorum_parallel ( quorum_parallel_ )
2020-06-15 17:41:44 +00:00
, deduplicate ( deduplicate_ )
, log ( & Poco : : Logger : : get ( storage . getLogName ( ) + " (Replicated OutputStream) " ) )
2021-02-10 14:12:49 +00:00
, context ( context_ )
2022-12-15 23:54:46 +00:00
, storage_snapshot ( storage . getStorageSnapshotWithoutParts ( metadata_snapshot ) )
2016-01-17 05:22:22 +00:00
{
2017-03-13 18:01:46 +00:00
/// The quorum value `1` has the same meaning as if it is disabled.
2022-09-06 12:09:03 +00:00
if ( required_quorum_size = = 1 )
required_quorum_size = 0 ;
2016-01-17 05:22:22 +00:00
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
ReplicatedMergeTreeSinkImpl < async_insert > : : ~ ReplicatedMergeTreeSinkImpl ( ) = default ;
2022-02-01 10:36:51 +00:00
2017-03-12 19:18:07 +00:00
/// Allow to verify that the session in ZooKeeper is still alive.
2022-11-10 12:14:04 +00:00
static void assertSessionIsNotExpired ( const zkutil : : ZooKeeperPtr & zookeeper )
2016-01-17 05:22:22 +00:00
{
2016-01-17 08:12:48 +00:00
if ( ! zookeeper )
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : NO_ZOOKEEPER , " No ZooKeeper session. " ) ;
2016-01-17 08:12:48 +00:00
2016-01-17 05:22:22 +00:00
if ( zookeeper - > expired ( ) )
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : NO_ZOOKEEPER , " ZooKeeper session has been expired. " ) ;
2016-01-17 05:22:22 +00:00
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
size_t ReplicatedMergeTreeSinkImpl < async_insert > : : checkQuorumPrecondition ( const ZooKeeperWithFaultInjectionPtr & zookeeper )
2017-06-25 00:01:10 +00:00
{
2022-09-06 12:09:03 +00:00
if ( ! isQuorumEnabled ( ) )
return 0 ;
2017-06-25 00:01:10 +00:00
quorum_info . status_path = storage . zookeeper_path + " /quorum/status " ;
2021-12-02 17:51:55 +00:00
Strings replicas = zookeeper - > getChildren ( fs : : path ( storage . zookeeper_path ) / " replicas " ) ;
2022-10-11 09:27:46 +00:00
Strings exists_paths ;
2022-11-10 12:14:04 +00:00
exists_paths . reserve ( replicas . size ( ) ) ;
2021-12-02 17:51:55 +00:00
for ( const auto & replica : replicas )
if ( replica ! = storage . replica_name )
2022-10-11 09:27:46 +00:00
exists_paths . emplace_back ( fs : : path ( storage . zookeeper_path ) / " replicas " / replica / " is_active " ) ;
2021-12-02 17:51:55 +00:00
2022-10-11 09:27:46 +00:00
auto exists_result = zookeeper - > exists ( exists_paths ) ;
auto get_results = zookeeper - > get ( Strings { storage . replica_path + " /is_active " , storage . replica_path + " /host " } ) ;
2017-06-25 00:01:10 +00:00
2022-11-10 12:14:04 +00:00
Coordination : : Error keeper_error = Coordination : : Error : : ZOK ;
2021-12-02 17:51:55 +00:00
size_t active_replicas = 1 ; /// Assume current replica is active (will check below)
2022-10-11 09:27:46 +00:00
for ( size_t i = 0 ; i < exists_paths . size ( ) ; + + i )
{
2022-11-10 12:14:04 +00:00
auto error = exists_result [ i ] . error ;
if ( error = = Coordination : : Error : : ZOK )
2021-12-02 17:51:55 +00:00
+ + active_replicas ;
2022-11-10 12:14:04 +00:00
else if ( Coordination : : isHardwareError ( error ) )
keeper_error = error ;
2022-10-11 09:27:46 +00:00
}
2017-06-25 00:01:10 +00:00
2022-09-06 12:09:03 +00:00
size_t replicas_number = replicas . size ( ) ;
size_t quorum_size = getQuorumSize ( replicas_number ) ;
2022-08-08 05:23:49 +00:00
2022-09-06 12:09:03 +00:00
if ( active_replicas < quorum_size )
2022-11-10 12:14:04 +00:00
{
if ( Coordination : : isHardwareError ( keeper_error ) )
throw Coordination : : Exception ( " Failed to check number of alive replicas " , keeper_error ) ;
2022-09-06 12:09:03 +00:00
throw Exception ( ErrorCodes : : TOO_FEW_LIVE_REPLICAS , " Number of alive replicas ({}) is less than requested quorum ( { } / { } ) . " ,
active_replicas , quorum_size , replicas_number ) ;
2022-11-10 12:14:04 +00:00
}
2017-06-25 00:01:10 +00:00
/** Is there a quorum for the last part for which a quorum is needed?
* Write of all the parts with the included quorum is linearly ordered .
* This means that at any time there can be only one part ,
* for which you need , but not yet reach the quorum .
* Information about this part will be located in ` / quorum / status ` node .
* If the quorum is reached , then the node is deleted .
*/
2020-10-07 11:28:48 +00:00
String quorum_status ;
if ( ! quorum_parallel & & zookeeper - > tryGet ( quorum_info . status_path , quorum_status ) )
2023-01-17 16:39:07 +00:00
throw Exception ( ErrorCodes : : UNSATISFIED_QUORUM_FOR_PREVIOUS_WRITE ,
" Quorum for previous write has not been satisfied yet. Status: {} " , quorum_status ) ;
2017-06-25 00:01:10 +00:00
/// Both checks are implicitly made also later (otherwise there would be a race condition).
2022-10-11 09:27:46 +00:00
auto is_active = get_results [ 0 ] ;
auto host = get_results [ 1 ] ;
2017-06-25 00:01:10 +00:00
2020-06-12 15:09:12 +00:00
if ( is_active . error = = Coordination : : Error : : ZNONODE | | host . error = = Coordination : : Error : : ZNONODE )
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : READONLY , " Replica is not active right now " ) ;
2017-06-25 00:01:10 +00:00
quorum_info . is_active_node_version = is_active . stat . version ;
quorum_info . host_node_version = host . stat . version ;
2022-09-06 12:09:03 +00:00
return replicas_number ;
}
2017-06-25 00:01:10 +00:00
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < async_insert > : : consume ( Chunk chunk )
2016-01-17 05:22:22 +00:00
{
2021-09-03 17:29:36 +00:00
auto block = getHeader ( ) . cloneWithColumns ( chunk . detachColumns ( ) ) ;
2021-07-23 19:33:59 +00:00
2022-11-10 12:14:04 +00:00
const auto & settings = context - > getSettingsRef ( ) ;
zookeeper_retries_info = ZooKeeperRetriesInfo (
" ReplicatedMergeTreeSink::consume " ,
settings . insert_keeper_max_retries ? log : nullptr ,
settings . insert_keeper_max_retries ,
settings . insert_keeper_retry_initial_backoff_ms ,
settings . insert_keeper_retry_max_backoff_ms ) ;
ZooKeeperWithFaultInjectionPtr zookeeper = ZooKeeperWithFaultInjection : : createInstance (
settings . insert_keeper_fault_injection_probability ,
settings . insert_keeper_fault_injection_seed ,
storage . getZooKeeper ( ) ,
" ReplicatedMergeTreeSink::consume " ,
log ) ;
2017-04-01 07:20:54 +00:00
2017-03-13 18:01:46 +00:00
/** If write is with quorum, then we check that the required number of replicas is now live,
2017-06-25 00:01:10 +00:00
* and also that for all previous parts for which quorum is required , this quorum is reached .
2017-03-13 18:01:46 +00:00
* And also check that during the insertion , the replica was not reinitialized or disabled ( by the value of ` is_active ` node ) .
2017-03-12 19:18:07 +00:00
* TODO Too complex logic , you can do better .
2016-01-24 05:00:24 +00:00
*/
2022-11-10 12:14:04 +00:00
size_t replicas_num = 0 ;
ZooKeeperRetriesControl quorum_retries_ctl ( " checkQuorumPrecondition " , zookeeper_retries_info ) ;
quorum_retries_ctl . retryLoop (
[ & ] ( )
{
zookeeper - > setKeeper ( storage . getZooKeeper ( ) ) ;
replicas_num = checkQuorumPrecondition ( zookeeper ) ;
} ) ;
2017-04-01 07:20:54 +00:00
2022-05-06 14:44:00 +00:00
if ( ! storage_snapshot - > object_columns . empty ( ) )
convertDynamicColumnsToTuples ( block , storage_snapshot ) ;
2017-04-01 07:20:54 +00:00
2022-11-06 22:56:26 +00:00
ChunkOffsetsPtr chunk_offsets ;
2022-02-20 22:04:45 +00:00
2022-11-06 22:56:26 +00:00
if constexpr ( async_insert )
{
const auto & chunk_info = chunk . getChunkInfo ( ) ;
if ( const auto * chunk_offsets_ptr = typeid_cast < const ChunkOffsets * > ( chunk_info . get ( ) ) )
chunk_offsets = std : : make_shared < ChunkOffsets > ( chunk_offsets_ptr - > offsets ) ;
else
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : LOGICAL_ERROR , " No chunk info for async inserts " ) ;
2022-11-06 22:56:26 +00:00
}
auto part_blocks = storage . writer . splitBlockIntoParts ( block , max_parts_per_block , metadata_snapshot , context , chunk_offsets ) ;
2022-12-07 22:40:52 +00:00
using DelayedPartition = typename ReplicatedMergeTreeSinkImpl < async_insert > : : DelayedChunk : : Partition ;
using DelayedPartitions = std : : vector < DelayedPartition > ;
2022-02-20 22:04:45 +00:00
DelayedPartitions partitions ;
size_t streams = 0 ;
bool support_parallel_write = false ;
2017-04-01 07:20:54 +00:00
2016-01-17 05:22:22 +00:00
for ( auto & current_block : part_blocks )
{
2017-06-25 00:01:10 +00:00
Stopwatch watch ;
2017-04-01 07:20:54 +00:00
2023-01-31 14:01:12 +00:00
ProfileEvents : : Counters part_counters ;
auto profile_events_scope = std : : make_unique < ProfileEventsScope > ( & part_counters ) ;
2017-06-25 00:01:10 +00:00
/// Write part to the filesystem under temporary name. Calculate a checksum.
2017-04-01 07:20:54 +00:00
2022-02-01 10:36:51 +00:00
auto temp_part = storage . writer . writeTempPart ( current_block , metadata_snapshot , context ) ;
2017-04-01 07:20:54 +00:00
2021-02-12 14:02:04 +00:00
/// If optimize_on_insert setting is true, current_block could become empty after merge
/// and we didn't create part.
2022-02-01 10:36:51 +00:00
if ( ! temp_part . part )
2021-02-12 14:02:04 +00:00
continue ;
2022-11-06 22:56:26 +00:00
BlockIDsType block_id ;
2017-04-01 07:20:54 +00:00
2022-11-06 22:56:26 +00:00
if constexpr ( async_insert )
{
/// TODO consider insert_deduplication_token
2022-11-18 16:22:05 +00:00
block_id = getHashesForBlocks ( current_block , temp_part . part - > info . partition_id ) ;
2023-01-15 21:51:10 +00:00
LOG_TRACE ( log , " async insert part, part id {}, block id {}, offsets {}, size {} " , temp_part . part - > info . partition_id , toString ( block_id ) , toString ( current_block . offsets ) , current_block . offsets . size ( ) ) ;
2022-11-06 22:56:26 +00:00
}
else if ( deduplicate )
2017-10-24 19:32:23 +00:00
{
2022-02-20 22:04:45 +00:00
String block_dedup_token ;
2017-11-15 20:05:10 +00:00
/// We add the hash from the data and partition identifier to deduplication ID.
/// That is, do not insert the same data to the same partition twice.
2017-04-01 07:20:54 +00:00
2022-02-20 22:04:45 +00:00
const String & dedup_token = settings . insert_deduplication_token ;
2022-01-30 22:25:55 +00:00
if ( ! dedup_token . empty ( ) )
insert_deduplication_token setting for INSERT statement
The setting allows a user to provide own deduplication semantic in Replicated*MergeTree
If provided, it's used instead of data digest to generate block ID
So, for example, by providing a unique value for the setting in each INSERT statement,
user can avoid the same inserted data being deduplicated
Inserting data within the same INSERT statement are split into blocks
according to the *insert_block_size* settings
(max_insert_block_size, min_insert_block_size_rows, min_insert_block_size_bytes).
Each block with the same INSERT statement will get an ordinal number.
The ordinal number is added to insert_deduplication_token to get block dedup token
i.e. <token>_0, <token>_1, ... Deduplication is done per block
So, to guarantee deduplication for two same INSERT queries,
dedup token and number of blocks to have to be the same
Issue: #7461
2021-11-21 20:39:42 +00:00
{
/// multiple blocks can be inserted within the same insert query
/// an ordinal number is added to dedup token to generate a distinctive block id for each block
2022-01-30 22:25:55 +00:00
block_dedup_token = fmt : : format ( " {}_{} " , dedup_token , chunk_dedup_seqnum ) ;
insert_deduplication_token setting for INSERT statement
The setting allows a user to provide own deduplication semantic in Replicated*MergeTree
If provided, it's used instead of data digest to generate block ID
So, for example, by providing a unique value for the setting in each INSERT statement,
user can avoid the same inserted data being deduplicated
Inserting data within the same INSERT statement are split into blocks
according to the *insert_block_size* settings
(max_insert_block_size, min_insert_block_size_rows, min_insert_block_size_bytes).
Each block with the same INSERT statement will get an ordinal number.
The ordinal number is added to insert_deduplication_token to get block dedup token
i.e. <token>_0, <token>_1, ... Deduplication is done per block
So, to guarantee deduplication for two same INSERT queries,
dedup token and number of blocks to have to be the same
Issue: #7461
2021-11-21 20:39:42 +00:00
+ + chunk_dedup_seqnum ;
}
2022-02-20 22:04:45 +00:00
2022-02-01 10:36:51 +00:00
block_id = temp_part . part - > getZeroLevelPartBlockID ( block_dedup_token ) ;
2022-09-13 13:49:51 +00:00
LOG_DEBUG ( log , " Wrote block with ID '{}', {} rows{} " , block_id , current_block . block . rows ( ) , quorumLogMessage ( replicas_num ) ) ;
2017-10-24 19:32:23 +00:00
}
else
{
2022-09-13 13:49:51 +00:00
LOG_DEBUG ( log , " Wrote block with {} rows{} " , current_block . block . rows ( ) , quorumLogMessage ( replicas_num ) ) ;
2017-10-24 19:32:23 +00:00
}
2017-04-01 07:20:54 +00:00
2023-01-31 14:01:12 +00:00
profile_events_scope . reset ( ) ;
2022-02-01 10:36:51 +00:00
UInt64 elapsed_ns = watch . elapsed ( ) ;
2022-02-20 22:04:45 +00:00
size_t max_insert_delayed_streams_for_parallel_write = DEFAULT_DELAYED_STREAMS_FOR_PARALLEL_WRITE ;
if ( ! support_parallel_write | | settings . max_insert_delayed_streams_for_parallel_write . changed )
max_insert_delayed_streams_for_parallel_write = settings . max_insert_delayed_streams_for_parallel_write ;
/// In case of too much columns/parts in block, flush explicitly.
streams + = temp_part . streams . size ( ) ;
if ( streams > max_insert_delayed_streams_for_parallel_write )
{
finishDelayedChunk ( zookeeper ) ;
2022-12-07 22:40:52 +00:00
delayed_chunk = std : : make_unique < ReplicatedMergeTreeSinkImpl < async_insert > : : DelayedChunk > ( replicas_num ) ;
2022-02-20 22:04:45 +00:00
delayed_chunk - > partitions = std : : move ( partitions ) ;
finishDelayedChunk ( zookeeper ) ;
streams = 0 ;
support_parallel_write = false ;
partitions = DelayedPartitions { } ;
}
2023-01-31 14:01:12 +00:00
2022-12-07 22:40:52 +00:00
partitions . emplace_back ( DelayedPartition (
2022-12-28 16:25:36 +00:00
log ,
2022-11-06 22:56:26 +00:00
std : : move ( temp_part ) ,
elapsed_ns ,
std : : move ( block_id ) ,
2023-01-31 14:01:12 +00:00
std : : move ( current_block ) ,
std : : move ( part_counters ) /// profile_events_scope must be reset here.
2022-11-06 22:56:26 +00:00
) ) ;
2022-02-01 10:36:51 +00:00
}
finishDelayedChunk ( zookeeper ) ;
2022-12-07 22:40:52 +00:00
delayed_chunk = std : : make_unique < ReplicatedMergeTreeSinkImpl : : DelayedChunk > ( ) ;
2022-02-01 10:36:51 +00:00
delayed_chunk - > partitions = std : : move ( partitions ) ;
/// If deduplicated data should not be inserted into MV, we need to set proper
/// value for `last_block_is_duplicate`, which is possible only after the part is committed.
/// Othervide we can delay commit.
/// TODO: we can also delay commit if there is no MVs.
2022-02-20 22:04:45 +00:00
if ( ! settings . deduplicate_blocks_in_dependent_materialized_views )
2022-02-01 10:36:51 +00:00
finishDelayedChunk ( zookeeper ) ;
}
2022-11-06 22:56:26 +00:00
template < >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < false > : : finishDelayedChunk ( const ZooKeeperWithFaultInjectionPtr & zookeeper )
2022-02-01 10:36:51 +00:00
{
if ( ! delayed_chunk )
return ;
last_block_is_duplicate = false ;
for ( auto & partition : delayed_chunk - > partitions )
{
2023-01-31 14:01:12 +00:00
ProfileEventsScope scoped_attach ( & partition . part_counters ) ;
2022-02-01 10:36:51 +00:00
partition . temp_part . finalize ( ) ;
auto & part = partition . temp_part . part ;
2018-01-23 22:56:46 +00:00
try
{
2022-11-10 12:14:04 +00:00
commitPart ( zookeeper , part , partition . block_id , delayed_chunk - > replicas_num , false ) ;
2022-02-01 10:36:51 +00:00
last_block_is_duplicate = last_block_is_duplicate | | part - > is_duplicate ;
2022-01-24 14:43:36 +00:00
2018-01-23 22:56:46 +00:00
/// Set a special error code if the block is duplicate
2022-02-01 10:36:51 +00:00
int error = ( deduplicate & & part - > is_duplicate ) ? ErrorCodes : : INSERT_WAS_DEDUPLICATED : 0 ;
2023-01-31 14:01:12 +00:00
auto counters_snapshot = std : : make_shared < ProfileEvents : : Counters : : Snapshot > ( partition . part_counters . getPartiallyAtomicSnapshot ( ) ) ;
PartLog : : addNewPart ( storage . getContext ( ) , PartLog : : PartLogEntry ( part , partition . elapsed_ns , counters_snapshot ) , ExecutionStatus ( error ) ) ;
2022-05-25 14:54:49 +00:00
storage . incrementInsertedPartsProfileEvent ( part - > getType ( ) ) ;
2018-01-23 22:56:46 +00:00
}
catch ( . . . )
{
2023-01-31 14:01:12 +00:00
auto counters_snapshot = std : : make_shared < ProfileEvents : : Counters : : Snapshot > ( partition . part_counters . getPartiallyAtomicSnapshot ( ) ) ;
PartLog : : addNewPart ( storage . getContext ( ) , PartLog : : PartLogEntry ( part , partition . elapsed_ns , counters_snapshot ) , ExecutionStatus : : fromCurrentException ( " " , true ) ) ;
2018-01-23 22:56:46 +00:00
throw ;
}
2017-06-25 00:01:10 +00:00
}
2022-02-01 10:36:51 +00:00
delayed_chunk . reset ( ) ;
2017-06-25 00:01:10 +00:00
}
2017-04-01 07:20:54 +00:00
2022-11-06 22:56:26 +00:00
template < >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < true > : : finishDelayedChunk ( const ZooKeeperWithFaultInjectionPtr & zookeeper )
2022-11-06 22:56:26 +00:00
{
if ( ! delayed_chunk )
return ;
for ( auto & partition : delayed_chunk - > partitions )
{
2022-11-23 20:07:59 +00:00
int retry_times = 0 ;
2022-12-28 16:25:36 +00:00
/// users may have lots of same inserts. It will be helpful to deduplicate in advance.
2023-01-15 21:51:10 +00:00
if ( partition . filterSelfDuplicate ( ) )
2022-12-28 16:25:36 +00:00
{
LOG_TRACE ( log , " found duplicated inserts in the block " ) ;
partition . block_with_partition . partition = std : : move ( partition . temp_part . part - > partition . value ) ;
partition . temp_part = storage . writer . writeTempPart ( partition . block_with_partition , metadata_snapshot , context ) ;
}
2023-01-16 13:07:36 +00:00
/// reset the cache version to zero for every partition write.
2023-01-13 19:17:58 +00:00
cache_version = 0 ;
2022-11-06 22:56:26 +00:00
while ( true )
{
partition . temp_part . finalize ( ) ;
2022-11-14 18:01:40 +00:00
auto conflict_block_ids = commitPart ( zookeeper , partition . temp_part . part , partition . block_id , delayed_chunk - > replicas_num , false ) ;
2022-11-06 22:56:26 +00:00
if ( conflict_block_ids . empty ( ) )
break ;
2022-12-18 21:44:51 +00:00
+ + retry_times ;
2022-12-19 13:05:50 +00:00
LOG_DEBUG ( log , " Found duplicate block IDs: {}, retry times {} " , toString ( conflict_block_ids ) , retry_times ) ;
2022-11-06 22:56:26 +00:00
/// partition clean conflict
2023-01-15 21:51:10 +00:00
partition . filterBlockDuplicate ( conflict_block_ids , false ) ;
2022-11-06 22:56:26 +00:00
if ( partition . block_id . empty ( ) )
break ;
2022-11-18 16:22:05 +00:00
partition . block_with_partition . partition = std : : move ( partition . temp_part . part - > partition . value ) ;
partition . temp_part = storage . writer . writeTempPart ( partition . block_with_partition , metadata_snapshot , context ) ;
2022-11-06 22:56:26 +00:00
}
}
delayed_chunk . reset ( ) ;
}
template < bool async_insert >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < async_insert > : : writeExistingPart ( MergeTreeData : : MutableDataPartPtr & part )
2017-06-25 00:51:51 +00:00
{
2018-05-21 13:49:54 +00:00
/// NOTE: No delay in this case. That's Ok.
2017-06-25 00:51:51 +00:00
2022-11-10 12:14:04 +00:00
auto origin_zookeeper = storage . getZooKeeper ( ) ;
assertSessionIsNotExpired ( origin_zookeeper ) ;
auto zookeeper = std : : make_shared < ZooKeeperWithFaultInjection > ( origin_zookeeper ) ;
2017-06-25 00:51:51 +00:00
2022-09-06 12:09:03 +00:00
size_t replicas_num = checkQuorumPrecondition ( zookeeper ) ;
2017-06-25 00:51:51 +00:00
Stopwatch watch ;
2023-01-31 14:01:12 +00:00
ProfileEventsScope profile_events_scope ;
2017-06-25 00:51:51 +00:00
2018-01-23 22:56:46 +00:00
try
{
2022-02-15 15:00:45 +00:00
part - > version . setCreationTID ( Tx : : PrehistoricTID , nullptr ) ;
2022-11-14 18:01:40 +00:00
commitPart ( zookeeper , part , BlockIDsType ( ) , replicas_num , true ) ;
2023-01-31 14:01:12 +00:00
PartLog : : addNewPart ( storage . getContext ( ) , PartLog : : PartLogEntry ( part , watch . elapsed ( ) , profile_events_scope . getSnapshot ( ) ) ) ;
2018-01-23 22:56:46 +00:00
}
catch ( . . . )
{
2023-01-31 14:01:12 +00:00
PartLog : : addNewPart ( storage . getContext ( ) , PartLog : : PartLogEntry ( part , watch . elapsed ( ) , profile_events_scope . getSnapshot ( ) ) , ExecutionStatus : : fromCurrentException ( " " , true ) ) ;
2018-01-23 22:56:46 +00:00
throw ;
}
2017-06-25 00:51:51 +00:00
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
std : : vector < String > ReplicatedMergeTreeSinkImpl < async_insert > : : commitPart (
2022-11-10 12:14:04 +00:00
const ZooKeeperWithFaultInjectionPtr & zookeeper ,
2022-06-23 16:21:46 +00:00
MergeTreeData : : MutableDataPartPtr & part ,
2022-11-06 22:56:26 +00:00
const BlockIDsType & block_id ,
2022-11-10 12:14:04 +00:00
size_t replicas_num ,
bool writing_existing_part )
2017-06-25 00:01:10 +00:00
{
2022-10-14 14:52:26 +00:00
/// It is possible that we alter a part with different types of source columns.
/// In this case, if column was not altered, the result type will be different with what we have in metadata.
/// For now, consider it is ok. See 02461_alter_update_respect_part_column_type_bug for an example.
///
/// metadata_snapshot->check(part->getColumns());
2022-12-26 20:49:04 +00:00
const String temporary_part_relative_path = part - > getDataPartStorage ( ) . getPartDirectory ( ) ;
2018-01-19 22:37:50 +00:00
2020-08-27 23:22:00 +00:00
/// There is one case when we need to retry transaction in a loop.
/// But don't do it too many times - just as defensive measure.
size_t loop_counter = 0 ;
constexpr size_t max_iterations = 10 ;
2020-08-27 23:39:12 +00:00
bool is_already_existing_part = false ;
2022-11-10 12:14:04 +00:00
/// for retries due to keeper error
bool part_committed_locally_but_zookeeper = false ;
Coordination : : Error write_part_info_keeper_error = Coordination : : Error : : ZOK ;
2022-11-14 18:01:40 +00:00
std : : vector < String > conflict_block_ids ;
2022-11-10 12:14:04 +00:00
ZooKeeperRetriesControl retries_ctl ( " commitPart " , zookeeper_retries_info ) ;
retries_ctl . retryLoop ( [ & ] ( )
2018-01-19 22:37:50 +00:00
{
2022-11-10 12:14:04 +00:00
zookeeper - > setKeeper ( storage . getZooKeeper ( ) ) ;
if ( storage . is_readonly )
{
/// stop retries if in shutdown
if ( storage . shutdown_called )
throw Exception (
ErrorCodes : : TABLE_IS_READ_ONLY , " Table is in readonly mode due to shutdown: replica_path={} " , storage . replica_path ) ;
/// When we attach existing parts it's okay to be in read-only mode
/// For example during RESTORE REPLICA.
if ( ! writing_existing_part )
{
retries_ctl . setUserError ( ErrorCodes : : TABLE_IS_READ_ONLY , " Table is in readonly mode: replica_path={} " , storage . replica_path ) ;
return ;
}
}
if ( retries_ctl . isRetry ( ) )
{
/// If we are retrying, check if last iteration was actually successful,
/// we could get network error on committing part to zk
/// but the operation could be completed by zk server
/// If this flag is true, then part is in Active state, and we'll not retry anymore
/// we only check if part was committed to zk and return success or failure correspondingly
/// Note: if commit to zk failed then cleanup thread will mark the part as Outdated later
if ( part_committed_locally_but_zookeeper )
{
/// check that info about the part was actually written in zk
if ( zookeeper - > exists ( fs : : path ( storage . replica_path ) / " parts " / part - > name ) )
{
LOG_DEBUG ( log , " Part was successfully committed on previous iteration: part_id={} " , part - > name ) ;
}
else
{
retries_ctl . setUserError (
ErrorCodes : : UNEXPECTED_ZOOKEEPER_ERROR ,
" Insert failed due to zookeeper error. Please retry. Reason: {} " ,
Coordination : : errorMessage ( write_part_info_keeper_error ) ) ;
}
retries_ctl . stopRetries ( ) ;
return ;
}
}
2020-06-15 18:57:38 +00:00
/// Obtain incremental block number and lock it. The lock holds our intention to add the block to the filesystem.
/// We remove the lock just after renaming the part. In case of exception, block number will be marked as abandoned.
/// Also, make deduplication check. If a duplicate is detected, no nodes are created.
/// Allocate new block number and check for duplicates
bool deduplicate_block = ! block_id . empty ( ) ;
2022-11-06 22:56:26 +00:00
BlockIDsType block_id_path ;
if constexpr ( async_insert )
{
2023-01-10 12:19:12 +00:00
/// prefilter by cache
conflict_block_ids = storage . async_block_ids_cache . detectConflicts ( block_id , cache_version ) ;
if ( ! conflict_block_ids . empty ( ) )
2023-01-17 14:47:52 +00:00
{
cache_version = 0 ;
2023-01-10 12:19:12 +00:00
return ;
2023-01-17 14:47:52 +00:00
}
2022-11-06 22:56:26 +00:00
for ( const auto & single_block_id : block_id )
2022-11-22 14:12:00 +00:00
block_id_path . push_back ( storage . zookeeper_path + " /async_blocks/ " + single_block_id ) ;
2022-11-06 22:56:26 +00:00
}
2022-11-16 16:59:08 +00:00
else if ( deduplicate_block )
2022-11-06 22:56:26 +00:00
block_id_path = storage . zookeeper_path + " /blocks/ " + block_id ;
2020-06-15 18:57:38 +00:00
auto block_number_lock = storage . allocateBlockNumber ( part - > info . partition_id , zookeeper , block_id_path ) ;
2022-11-02 15:24:18 +00:00
ThreadFuzzer : : maybeInjectSleep ( ) ;
2020-06-15 18:57:38 +00:00
2020-08-27 23:22:00 +00:00
/// Prepare transaction to ZooKeeper
/// It will simultaneously add information about the part to all the necessary places in ZooKeeper and remove block_number_lock.
Coordination : : Requests ops ;
2020-06-16 01:17:02 +00:00
Int64 block_number = 0 ;
2022-11-02 15:24:18 +00:00
size_t block_unlock_op_idx = std : : numeric_limits < size_t > : : max ( ) ;
2020-06-15 18:57:38 +00:00
String existing_part_name ;
if ( block_number_lock )
{
2022-11-18 16:22:05 +00:00
if constexpr ( async_insert )
{
/// The truth is that we always get only one path from block_number_lock.
/// This is a restriction of Keeper. Here I would like to use vector because
/// I wanna keep extensibility for future optimization, for instance, using
/// cache to resolve conflicts in advance.
String conflict_path = block_number_lock - > getConflictPath ( ) ;
if ( ! conflict_path . empty ( ) )
{
LOG_TRACE ( log , " Cannot get lock, the conflict path is {} " , conflict_path ) ;
conflict_block_ids . push_back ( conflict_path ) ;
return ;
}
}
2020-08-27 23:39:12 +00:00
is_already_existing_part = false ;
2020-06-15 18:57:38 +00:00
block_number = block_number_lock - > getNumber ( ) ;
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
/// Set part attributes according to part_number. Prepare an entry for log.
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
part - > info . min_block = block_number ;
part - > info . max_block = block_number ;
part - > info . level = 0 ;
2021-01-11 13:26:43 +00:00
part - > info . mutation = 0 ;
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
part - > name = part - > getNewName ( part - > info ) ;
2020-08-27 23:22:00 +00:00
StorageReplicatedMergeTree : : LogEntry log_entry ;
2021-02-15 15:06:48 +00:00
if ( is_attach )
{
2021-02-16 12:40:00 +00:00
log_entry . type = StorageReplicatedMergeTree : : LogEntry : : ATTACH_PART ;
2021-06-20 08:24:43 +00:00
/// We don't need to involve ZooKeeper to obtain checksums as by the time we get
/// MutableDataPartPtr here, we already have the data thus being able to
2021-02-16 12:40:00 +00:00
/// calculate the checksums.
log_entry . part_checksum = part - > checksums . getTotalChecksumHex ( ) ;
2021-02-15 15:06:48 +00:00
}
else
log_entry . type = StorageReplicatedMergeTree : : LogEntry : : GET_PART ;
2020-08-27 23:22:00 +00:00
log_entry . create_time = time ( nullptr ) ;
log_entry . source_replica = storage . replica_name ;
log_entry . new_part_name = part - > name ;
2020-10-29 16:18:25 +00:00
/// TODO maybe add UUID here as well?
2022-09-06 12:09:03 +00:00
log_entry . quorum = getQuorumSize ( replicas_num ) ;
2023-01-25 17:34:09 +00:00
log_entry . new_part_format = part - > getFormat ( ) ;
2022-11-06 22:56:26 +00:00
if constexpr ( ! async_insert )
log_entry . block_id = block_id ;
2020-08-27 23:22:00 +00:00
ops . emplace_back ( zkutil : : makeCreateRequest (
storage . zookeeper_path + " /log/log- " ,
log_entry . toString ( ) ,
zkutil : : CreateMode : : PersistentSequential ) ) ;
/// Deletes the information that the block number is used for writing.
2022-11-02 15:24:18 +00:00
block_unlock_op_idx = ops . size ( ) ;
block_number_lock - > getUnlockOp ( ops ) ;
2020-08-27 23:30:07 +00:00
/** If we need a quorum - create a node in which the quorum is monitored.
* ( If such a node already exists , then someone has managed to make another quorum record at the same time ,
* but for it the quorum has not yet been reached .
* You can not do the next quorum record at this time . )
*/
2022-09-06 12:09:03 +00:00
if ( isQuorumEnabled ( ) )
2020-08-27 23:30:07 +00:00
{
2020-10-06 21:49:48 +00:00
ReplicatedMergeTreeQuorumEntry quorum_entry ;
quorum_entry . part_name = part - > name ;
2022-09-06 12:09:03 +00:00
quorum_entry . required_number_of_replicas = getQuorumSize ( replicas_num ) ;
2020-10-06 21:49:48 +00:00
quorum_entry . replicas . insert ( storage . replica_name ) ;
2020-08-27 23:30:07 +00:00
/** At this point, this node will contain information that the current replica received a part.
* When other replicas will receive this part ( in the usual way , processing the replication log ) ,
* they will add themselves to the contents of this node .
* When it contains information about ` quorum ` number of replicas , this node is deleted ,
* which indicates that the quorum has been reached .
*/
2020-10-06 21:49:48 +00:00
if ( quorum_parallel )
quorum_info . status_path = storage . zookeeper_path + " /quorum/parallel/ " + part - > name ;
ops . emplace_back (
zkutil : : makeCreateRequest (
quorum_info . status_path ,
quorum_entry . toString ( ) ,
zkutil : : CreateMode : : Persistent ) ) ;
2020-08-27 23:30:07 +00:00
/// Make sure that during the insertion time, the replica was not reinitialized or disabled (when the server is finished).
ops . emplace_back (
zkutil : : makeCheckRequest (
storage . replica_path + " /is_active " ,
quorum_info . is_active_node_version ) ) ;
2020-08-28 00:28:37 +00:00
/// Unfortunately, just checking the above is not enough, because `is_active`
/// node can be deleted and reappear with the same version.
2020-08-27 23:30:07 +00:00
/// But then the `host` value will change. We will check this.
/// It's great that these two nodes change in the same transaction (see MergeTreeRestartingThread).
ops . emplace_back (
zkutil : : makeCheckRequest (
storage . replica_path + " /host " ,
quorum_info . host_node_version ) ) ;
}
2020-06-15 18:57:38 +00:00
}
2022-11-18 16:22:05 +00:00
/// async_insert will never return null lock, because they need the conflict path.
else if constexpr ( ! async_insert )
2020-06-15 18:57:38 +00:00
{
2020-08-27 23:39:12 +00:00
is_already_existing_part = true ;
2020-06-15 18:57:38 +00:00
/// This block was already written to some replica. Get the part name for it.
/// Note: race condition with DROP PARTITION operation is possible. User will get "No node" exception and it is Ok.
existing_part_name = zookeeper - > get ( storage . zookeeper_path + " /blocks/ " + block_id ) ;
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
/// If it exists on our replica, ignore it.
2020-10-06 21:49:48 +00:00
if ( storage . getActiveContainingPart ( existing_part_name ) )
2020-06-15 18:57:38 +00:00
{
part - > is_duplicate = true ;
ProfileEvents : : increment ( ProfileEvents : : DuplicatedInsertedBlocks ) ;
2022-09-06 12:09:03 +00:00
if ( isQuorumEnabled ( ) )
2021-04-08 10:35:38 +00:00
{
LOG_INFO ( log , " Block with ID {} already exists locally as part {}; ignoring it, but checking quorum. " , block_id , existing_part_name ) ;
std : : string quorum_path ;
if ( quorum_parallel )
quorum_path = storage . zookeeper_path + " /quorum/parallel/ " + existing_part_name ;
else
quorum_path = storage . zookeeper_path + " /quorum/status " ;
2022-11-10 12:14:04 +00:00
if ( ! retries_ctl . callAndCatchAll (
[ & ] ( )
{
waitForQuorum (
zookeeper , existing_part_name , quorum_path , quorum_info . is_active_node_version , replicas_num ) ;
} ) )
return ;
2021-04-08 10:35:38 +00:00
}
else
{
LOG_INFO ( log , " Block with ID {} already exists locally as part {}; ignoring it. " , block_id , existing_part_name ) ;
}
2020-06-15 18:57:38 +00:00
return ;
}
2022-11-10 12:14:04 +00:00
2020-06-15 18:57:38 +00:00
LOG_INFO ( log , " Block with ID {} already exists on other replicas as part {}; will write it locally with that name. " ,
block_id , existing_part_name ) ;
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
/// If it does not exist, we will write a new part with existing name.
2021-12-30 14:27:22 +00:00
/// Note that it may also appear on filesystem right now in PreActive state due to concurrent inserts of the same data.
2020-06-15 18:57:38 +00:00
/// It will be checked when we will try to rename directory.
2017-06-25 00:01:10 +00:00
2020-06-15 18:57:38 +00:00
part - > name = existing_part_name ;
part - > info = MergeTreePartInfo : : fromPartName ( existing_part_name , storage . format_version ) ;
2020-08-27 23:22:00 +00:00
/// Used only for exception messages.
2020-06-16 01:17:02 +00:00
block_number = part - > info . min_block ;
2020-08-28 00:07:51 +00:00
/// Do not check for duplicate on commit to ZK.
block_id_path . clear ( ) ;
2020-06-15 18:57:38 +00:00
}
2022-11-18 16:22:05 +00:00
else
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : LOGICAL_ERROR ,
" Conflict block ids and block number lock should not "
" be empty at the same time for async inserts " ) ;
2020-06-15 18:57:38 +00:00
/// Information about the part.
2020-10-06 21:49:48 +00:00
storage . getCommitPartOps ( ops , part , block_id_path ) ;
2017-06-25 00:01:10 +00:00
2022-07-01 13:16:32 +00:00
/// It's important to create it outside of lock scope because
2022-07-01 13:26:27 +00:00
/// otherwise it can lock parts in destructor and deadlock is possible.
2022-03-16 19:16:26 +00:00
MergeTreeData : : Transaction transaction ( storage , NO_TRANSACTION_RAW ) ; /// If you can not add a part to ZK, we'll remove it back from the working set.
2020-06-15 18:57:38 +00:00
bool renamed = false ;
2021-06-20 08:24:43 +00:00
2020-06-15 18:57:38 +00:00
try
{
2022-06-24 15:19:59 +00:00
auto lock = storage . lockParts ( ) ;
2022-10-22 22:51:59 +00:00
renamed = storage . renameTempPartAndAdd ( part , transaction , lock ) ;
2020-06-15 18:57:38 +00:00
}
catch ( const Exception & e )
{
2022-11-10 12:14:04 +00:00
if ( e . code ( ) ! = ErrorCodes : : DUPLICATE_DATA_PART & & e . code ( ) ! = ErrorCodes : : PART_IS_TEMPORARILY_LOCKED )
2020-06-15 18:57:38 +00:00
throw ;
}
2021-06-20 08:24:43 +00:00
2020-06-15 18:57:38 +00:00
if ( ! renamed )
{
2020-08-28 00:07:51 +00:00
if ( is_already_existing_part )
2020-06-15 18:57:38 +00:00
{
2020-09-17 12:10:06 +00:00
LOG_INFO ( log , " Part {} is duplicate and it is already written by concurrent request or fetched; ignoring it. " , part - > name ) ;
2020-06-15 18:57:38 +00:00
return ;
}
else
2020-09-17 12:10:06 +00:00
throw Exception ( ErrorCodes : : LOGICAL_ERROR , " Part with name {} is already written by concurrent request. "
2020-08-28 00:28:37 +00:00
" It should not happen for non-duplicate data parts because unique names are assigned for them. It's a bug " ,
2020-09-17 12:10:06 +00:00
part - > name ) ;
2020-06-15 18:57:38 +00:00
}
2018-01-19 22:37:50 +00:00
2022-12-28 13:08:13 +00:00
auto rename_part_to_temporary = [ & temporary_part_relative_path , & transaction , & part ] ( )
2022-12-26 20:49:04 +00:00
{
transaction . rollbackPartsToTemporaryState ( ) ;
part - > is_temp = true ;
part - > renameTo ( temporary_part_relative_path , false ) ;
} ;
2022-11-10 12:14:04 +00:00
try
{
ThreadFuzzer : : maybeInjectSleep ( ) ;
storage . lockSharedData ( * part , zookeeper , false , { } ) ;
ThreadFuzzer : : maybeInjectSleep ( ) ;
}
catch ( const Exception & )
{
2022-12-28 13:08:13 +00:00
rename_part_to_temporary ( ) ;
2022-11-10 12:14:04 +00:00
throw ;
}
2022-04-15 14:24:38 +00:00
2022-11-02 15:24:18 +00:00
ThreadFuzzer : : maybeInjectSleep ( ) ;
2022-04-15 14:24:38 +00:00
2020-06-15 18:57:38 +00:00
Coordination : : Responses responses ;
Coordination : : Error multi_code = zookeeper - > tryMultiNoThrow ( ops , responses ) ; /// 1 RTT
if ( multi_code = = Coordination : : Error : : ZOK )
{
transaction . commit ( ) ;
storage . merge_selecting_task - > schedule ( ) ;
2018-01-19 22:37:50 +00:00
2020-06-15 18:57:38 +00:00
/// Lock nodes have been already deleted, do not delete them in destructor
if ( block_number_lock )
block_number_lock - > assumeUnlocked ( ) ;
}
2022-11-02 15:24:18 +00:00
else if ( multi_code = = Coordination : : Error : : ZNONODE & & zkutil : : getFailedOpIndex ( multi_code , responses ) = = block_unlock_op_idx )
{
throw Exception ( ErrorCodes : : QUERY_WAS_CANCELLED ,
" Insert query (for block {}) was cancelled by concurrent ALTER PARTITION " , block_number_lock - > getPath ( ) ) ;
}
2022-11-10 12:14:04 +00:00
else if ( Coordination : : isHardwareError ( multi_code ) )
2020-06-15 18:57:38 +00:00
{
2022-11-10 12:14:04 +00:00
write_part_info_keeper_error = multi_code ;
2020-06-15 18:57:38 +00:00
/** If the connection is lost, and we do not know if the changes were applied, we can not delete the local part
2022-11-10 12:14:04 +00:00
* if the changes were applied , the inserted block appeared in ` / blocks / ` , and it can not be inserted again .
*/
2020-06-15 18:57:38 +00:00
transaction . commit ( ) ;
2022-11-10 12:14:04 +00:00
/// Setting this flag is point of no return
/// On next retry, we'll just check if actually operation succeed or failed
/// and return ok or error correspondingly
part_committed_locally_but_zookeeper = true ;
/// if all retries will be exhausted by accessing zookeeper on fresh retry -> we'll add committed part to queue in the action
/// here lambda capture part name, it's ok since we'll not generate new one for this insert,
/// see comments around 'part_committed_locally_but_zookeeper' flag
retries_ctl . actionAfterLastFailedRetry (
[ & storage = storage , part_name = part - > name ] ( )
{ storage . enqueuePartForCheck ( part_name , MAX_AGE_OF_LOCAL_PART_THAT_WASNT_ADDED_TO_ZOOKEEPER ) ; } ) ;
2020-06-15 18:57:38 +00:00
/// We do not know whether or not data has been inserted.
2022-11-10 12:14:04 +00:00
retries_ctl . setUserError (
ErrorCodes : : UNKNOWN_STATUS_OF_INSERT ,
" Unknown status, client must retry. Reason: {} " ,
Coordination : : errorMessage ( multi_code ) ) ;
return ;
2020-06-15 18:57:38 +00:00
}
else if ( Coordination : : isUserError ( multi_code ) )
2016-01-17 05:22:22 +00:00
{
2023-02-24 11:36:29 +00:00
String failed_op_path = ops [ zkutil : : getFailedOpIndex ( multi_code , responses ) ] - > getPath ( ) ;
2018-01-19 22:37:50 +00:00
2022-11-06 22:56:26 +00:00
auto contains = [ ] ( const auto & block_ids , const String & path )
{
if constexpr ( async_insert )
{
for ( const auto & local_block_id : block_ids )
if ( local_block_id = = path )
return true ;
return false ;
}
else
return block_ids = = path ;
} ;
if ( multi_code = = Coordination : : Error : : ZNODEEXISTS & & deduplicate_block & & contains ( block_id_path , failed_op_path ) )
2020-06-15 18:57:38 +00:00
{
2023-02-24 11:36:29 +00:00
/// Block with the same id have just appeared in table (or other replica), rollback the insertion.
2020-06-15 18:57:38 +00:00
LOG_INFO ( log , " Block with ID {} already exists (it was just appeared). Renaming part {} back to {}. Will retry write. " ,
2022-11-06 22:56:26 +00:00
toString ( block_id ) , part - > name , temporary_part_relative_path ) ;
2020-06-15 18:57:38 +00:00
2020-09-17 19:30:45 +00:00
/// We will try to add this part again on the new iteration as it's just a new part.
/// So remove it from storage parts set immediately and transfer state to temporary.
2022-12-28 13:08:13 +00:00
rename_part_to_temporary ( ) ;
2020-06-15 18:57:38 +00:00
2022-11-06 22:56:26 +00:00
if constexpr ( async_insert )
2022-11-14 18:01:40 +00:00
{
conflict_block_ids = std : : vector < String > ( { failed_op_path } ) ;
LOG_TRACE ( log , " conflict when committing, the conflict block ids are {} " , toString ( conflict_block_ids ) ) ;
return ;
}
2020-06-15 18:57:38 +00:00
2020-09-17 12:01:03 +00:00
/// If this part appeared on other replica than it's better to try to write it locally one more time. If it's our part
2022-11-10 12:14:04 +00:00
/// than it will be ignored on the next iteration.
2020-08-27 23:22:00 +00:00
+ + loop_counter ;
if ( loop_counter = = max_iterations )
2020-09-17 14:01:17 +00:00
{
part - > is_duplicate = true ; /// Part is duplicate, just remove it from local FS
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : DUPLICATE_DATA_PART , " Too many transaction retries - it may indicate an error " ) ;
2020-09-17 14:01:17 +00:00
}
2022-11-10 12:14:04 +00:00
retries_ctl . requestUnconditionalRetry ( ) ; /// we want one more iteration w/o counting it as a try and timeout
return ;
2020-06-15 18:57:38 +00:00
}
2020-09-17 12:10:06 +00:00
else if ( multi_code = = Coordination : : Error : : ZNODEEXISTS & & failed_op_path = = quorum_info . status_path )
2020-06-15 18:57:38 +00:00
{
2022-12-26 20:49:04 +00:00
try
{
2022-12-27 15:15:23 +00:00
storage . unlockSharedData ( * part , zookeeper ) ;
2022-12-26 20:49:04 +00:00
}
catch ( const zkutil : : KeeperException & e )
{
/// suppress this exception since need to rename part to temporary next
2022-12-26 21:01:00 +00:00
LOG_DEBUG ( log , " Unlocking shared data failed during error handling: code={} message={} " , e . code , e . message ( ) ) ;
2022-12-26 20:49:04 +00:00
}
2022-10-19 20:26:16 +00:00
2022-12-26 20:49:04 +00:00
/// Part was not committed to keeper
/// So make it temporary to avoid its resurrection on restart
2022-12-28 13:08:13 +00:00
rename_part_to_temporary ( ) ;
2022-10-19 20:26:16 +00:00
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : UNSATISFIED_QUORUM_FOR_PREVIOUS_WRITE , " Another quorum insert has been already started " ) ;
2020-06-15 18:57:38 +00:00
}
else
{
2022-11-10 12:14:04 +00:00
storage . unlockSharedData ( * part , zookeeper ) ;
2020-06-15 18:57:38 +00:00
/// NOTE: We could be here if the node with the quorum existed, but was quickly removed.
transaction . rollback ( ) ;
2022-11-10 12:14:04 +00:00
throw Exception (
ErrorCodes : : UNEXPECTED_ZOOKEEPER_ERROR ,
" Unexpected logical error while adding block {} with ID '{}': {}, path {} " ,
block_number ,
2022-11-14 18:01:40 +00:00
toString ( block_id ) ,
2022-11-10 12:14:04 +00:00
Coordination : : errorMessage ( multi_code ) ,
failed_op_path ) ;
2020-06-15 18:57:38 +00:00
}
2016-01-17 05:22:22 +00:00
}
2017-06-25 00:01:10 +00:00
else
2016-01-17 05:22:22 +00:00
{
2022-11-10 12:14:04 +00:00
storage . unlockSharedData ( * part , zookeeper ) ;
2018-01-19 22:37:50 +00:00
transaction . rollback ( ) ;
2022-11-10 12:14:04 +00:00
throw Exception (
ErrorCodes : : UNEXPECTED_ZOOKEEPER_ERROR ,
" Unexpected ZooKeeper error while adding block {} with ID '{}': {} " ,
block_number ,
2022-11-14 18:01:40 +00:00
toString ( block_id ) ,
2022-11-10 12:14:04 +00:00
Coordination : : errorMessage ( multi_code ) ) ;
2017-06-25 00:01:10 +00:00
}
2022-11-10 12:14:04 +00:00
} ,
[ & zookeeper ] ( ) { zookeeper - > cleanupEphemeralNodes ( ) ; } ) ;
2022-11-14 18:01:40 +00:00
if ( ! conflict_block_ids . empty ( ) )
return conflict_block_ids ;
2022-09-06 12:09:03 +00:00
if ( isQuorumEnabled ( ) )
2017-06-25 00:01:10 +00:00
{
2022-11-10 12:14:04 +00:00
ZooKeeperRetriesControl quorum_retries_ctl ( " waitForQuorum " , zookeeper_retries_info ) ;
quorum_retries_ctl . retryLoop ( [ & ] ( )
2020-08-27 23:39:12 +00:00
{
2022-11-10 12:14:04 +00:00
zookeeper - > setKeeper ( storage . getZooKeeper ( ) ) ;
2020-08-27 23:39:12 +00:00
2022-11-10 12:14:04 +00:00
if ( is_already_existing_part )
{
/// We get duplicate part without fetch
/// Check if this quorum insert is parallel or not
if ( zookeeper - > exists ( storage . zookeeper_path + " /quorum/parallel/ " + part - > name ) )
storage . updateQuorum ( part - > name , true ) ;
else if ( zookeeper - > exists ( storage . zookeeper_path + " /quorum/status " ) )
storage . updateQuorum ( part - > name , false ) ;
}
2020-08-27 23:39:12 +00:00
2022-11-10 12:14:04 +00:00
if ( ! quorum_retries_ctl . callAndCatchAll (
[ & ] ( )
{ waitForQuorum ( zookeeper , part - > name , quorum_info . status_path , quorum_info . is_active_node_version , replicas_num ) ; } ) )
return ;
} ) ;
2021-04-08 10:35:38 +00:00
}
2022-11-06 22:56:26 +00:00
return { } ;
2021-04-08 10:35:38 +00:00
}
2017-06-25 00:01:10 +00:00
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < async_insert > : : onStart ( )
2021-04-08 10:35:38 +00:00
{
/// Only check "too many parts" before write,
/// because interrupting long-running INSERT query in the middle is not convenient for users.
2022-04-18 04:15:41 +00:00
storage . delayInsertOrThrowIfNeeded ( & storage . partial_shutdown_event , context ) ;
2021-04-08 10:35:38 +00:00
}
2017-06-25 00:01:10 +00:00
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < async_insert > : : onFinish ( )
2022-02-01 10:36:51 +00:00
{
auto zookeeper = storage . getZooKeeper ( ) ;
assertSessionIsNotExpired ( zookeeper ) ;
2022-11-10 12:14:04 +00:00
finishDelayedChunk ( std : : make_shared < ZooKeeperWithFaultInjection > ( zookeeper ) ) ;
2022-02-01 10:36:51 +00:00
}
2017-06-25 00:01:10 +00:00
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
void ReplicatedMergeTreeSinkImpl < async_insert > : : waitForQuorum (
2022-11-10 12:14:04 +00:00
const ZooKeeperWithFaultInjectionPtr & zookeeper ,
2021-04-08 10:35:38 +00:00
const std : : string & part_name ,
const std : : string & quorum_path ,
2022-11-07 19:27:18 +00:00
Int32 is_active_node_version ,
2022-09-06 12:09:03 +00:00
size_t replicas_num ) const
2021-04-08 10:35:38 +00:00
{
/// We are waiting for quorum to be satisfied.
2022-09-13 13:49:51 +00:00
LOG_TRACE ( log , " Waiting for quorum '{}' for part {}{} " , quorum_path , part_name , quorumLogMessage ( replicas_num ) ) ;
2020-12-17 16:13:01 +00:00
2021-04-08 10:35:38 +00:00
try
{
while ( true )
{
zkutil : : EventPtr event = std : : make_shared < Poco : : Event > ( ) ;
2020-10-06 21:49:48 +00:00
2021-04-08 10:35:38 +00:00
std : : string value ;
/// `get` instead of `exists` so that `watch` does not leak if the node is no longer there.
if ( ! zookeeper - > tryGet ( quorum_path , value , nullptr , event ) )
break ;
2017-06-25 00:01:10 +00:00
2021-04-08 10:35:38 +00:00
LOG_TRACE ( log , " Quorum node {} still exists, will wait for updates " , quorum_path ) ;
2020-12-17 16:13:01 +00:00
2021-04-08 10:35:38 +00:00
ReplicatedMergeTreeQuorumEntry quorum_entry ( value ) ;
2017-04-01 07:20:54 +00:00
2021-04-08 10:35:38 +00:00
/// If the node has time to disappear, and then appear again for the next insert.
if ( quorum_entry . part_name ! = part_name )
break ;
if ( ! event - > tryWait ( quorum_timeout_ms ) )
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : TIMEOUT_EXCEEDED , " Timeout while waiting for quorum " ) ;
2021-04-08 10:35:38 +00:00
2022-09-06 12:09:03 +00:00
LOG_TRACE ( log , " Quorum {} for part {} updated, will check quorum node still exists " , quorum_path , part_name ) ;
2017-06-25 00:01:10 +00:00
}
2021-04-08 10:35:38 +00:00
/// And what if it is possible that the current replica at this time has ceased to be active
/// and the quorum is marked as failed and deleted?
2022-11-07 19:27:18 +00:00
Coordination : : Stat stat ;
2021-04-08 10:35:38 +00:00
String value ;
2022-11-07 19:27:18 +00:00
if ( ! zookeeper - > tryGet ( storage . replica_path + " /is_active " , value , & stat )
| | stat . version ! = is_active_node_version )
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : NO_ACTIVE_REPLICAS , " Replica become inactive while waiting for quorum " ) ;
2021-04-08 10:35:38 +00:00
}
catch ( . . . )
{
/// We do not know whether or not data has been inserted
/// - whether other replicas have time to download the part and mark the quorum as done.
2023-01-23 21:13:58 +00:00
throw Exception ( ErrorCodes : : UNKNOWN_STATUS_OF_INSERT , " Unknown status, client must retry. Reason: {} " ,
getCurrentExceptionMessage ( false ) ) ;
2016-01-17 05:22:22 +00:00
}
2022-09-06 12:09:03 +00:00
LOG_TRACE ( log , " Quorum '{}' for part {} satisfied " , quorum_path , part_name ) ;
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
String ReplicatedMergeTreeSinkImpl < async_insert > : : quorumLogMessage ( size_t replicas_num ) const
2022-09-13 13:49:51 +00:00
{
if ( ! isQuorumEnabled ( ) )
return " " ;
return fmt : : format ( " (quorum {} of {} replicas) " , getQuorumSize ( replicas_num ) , replicas_num ) ;
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
size_t ReplicatedMergeTreeSinkImpl < async_insert > : : getQuorumSize ( size_t replicas_num ) const
2022-09-06 12:09:03 +00:00
{
if ( ! isQuorumEnabled ( ) )
return 0 ;
if ( required_quorum_size )
return required_quorum_size . value ( ) ;
return replicas_num / 2 + 1 ;
2018-05-21 23:17:57 +00:00
}
2022-11-06 22:56:26 +00:00
template < bool async_insert >
2022-12-07 22:40:52 +00:00
bool ReplicatedMergeTreeSinkImpl < async_insert > : : isQuorumEnabled ( ) const
2022-09-06 12:09:03 +00:00
{
return ! required_quorum_size . has_value ( ) | | required_quorum_size . value ( ) > 1 ;
}
2016-01-17 05:22:22 +00:00
2022-12-07 22:40:52 +00:00
template class ReplicatedMergeTreeSinkImpl < true > ;
template class ReplicatedMergeTreeSinkImpl < false > ;
2022-11-06 22:56:26 +00:00
2016-01-17 05:22:22 +00:00
}