@@ -1873,7 +1873,8 @@ bool TTableInfo::TryAddShardToMerge(const TSplitSettings& splitSettings,
1873
1873
const TForceShardSplitSettings& forceShardSplitSettings,
1874
1874
TShardIdx shardIdx, TVector<TShardIdx>& shardsToMerge,
1875
1875
THashSet<TTabletId>& partOwners, ui64& totalSize, float & totalLoad,
1876
- const TTableInfo* mainTableForIndex, TString& reason) const
1876
+ float cpuUsageThreshold, const TTableInfo* mainTableForIndex,
1877
+ TString& reason) const
1877
1878
{
1878
1879
if (ExpectedPartitionCount + 1 - shardsToMerge.size () <= GetMinPartitionsCount ()) {
1879
1880
return false ;
@@ -1907,9 +1908,7 @@ bool TTableInfo::TryAddShardToMerge(const TSplitSettings& splitSettings,
1907
1908
const auto sizeToMerge = GetSizeToMerge (forceShardSplitSettings);
1908
1909
if (IsMergeBySizeEnabled (forceShardSplitSettings) && stats->DataSize + totalSize <= sizeToMerge) {
1909
1910
reason = TStringBuilder () << " merge by size ("
1910
- << " dataSize: " << stats->DataSize << " , "
1911
- << " totalSize: " << stats->DataSize + totalSize << " , "
1912
- << " sizeToMerge: " << sizeToMerge << " )" ;
1911
+ << " shardSize: " << stats->DataSize << " )" ;
1913
1912
canMerge = true ;
1914
1913
}
1915
1914
@@ -1932,21 +1931,15 @@ bool TTableInfo::TryAddShardToMerge(const TSplitSettings& splitSettings,
1932
1931
// Check that total load doesn't exceed the limits
1933
1932
float shardLoad = stats->GetCurrentRawCpuUsage () * 0.000001 ;
1934
1933
if (IsMergeByLoadEnabled (mainTableForIndex)) {
1935
- const auto settings = GetEffectiveSplitByLoadSettings (mainTableForIndex);
1936
- i64 cpuPercentage = settings.GetCpuPercentageThreshold ();
1937
- float cpuUsageThreshold = 0.01 * (cpuPercentage ? cpuPercentage : (i64 )splitSettings.FastSplitCpuPercentageThreshold );
1938
-
1939
1934
// Calculate shard load based on historical data
1940
1935
TDuration loadDuration = TDuration::Seconds (splitSettings.MergeByLoadMinLowLoadDurationSec );
1941
1936
shardLoad = 0.01 * stats->GetLatestMaxCpuUsagePercent (now - loadDuration);
1942
1937
1943
- if (shardLoad + totalLoad > cpuUsageThreshold * 0.7 )
1938
+ if (shardLoad + totalLoad > cpuUsageThreshold)
1944
1939
return false ;
1945
1940
1946
1941
reason = TStringBuilder () << " merge by load ("
1947
- << " shardLoad: " << shardLoad << " , "
1948
- << " totalLoad: " << shardLoad + totalLoad << " , "
1949
- << " loadThreshold: " << cpuUsageThreshold * 0.7 << " )" ;
1942
+ << " shardLoad: " << shardLoad << " )" ;
1950
1943
}
1951
1944
1952
1945
// Merged shards must not have borrowed parts from the same original tablet
@@ -1966,8 +1959,9 @@ bool TTableInfo::TryAddShardToMerge(const TSplitSettings& splitSettings,
1966
1959
1967
1960
bool TTableInfo::CheckCanMergePartitions (const TSplitSettings& splitSettings,
1968
1961
const TForceShardSplitSettings& forceShardSplitSettings,
1969
- TShardIdx shardIdx, TVector<TShardIdx>& shardsToMerge,
1970
- const TTableInfo* mainTableForIndex, TString& reason) const
1962
+ TShardIdx shardIdx, const TTabletId& tabletId,
1963
+ TVector<TShardIdx>& shardsToMerge, const TTableInfo* mainTableForIndex,
1964
+ TString& reason) const
1971
1965
{
1972
1966
// Don't split/merge backup tables
1973
1967
if (IsBackup) {
@@ -1997,28 +1991,43 @@ bool TTableInfo::CheckCanMergePartitions(const TSplitSettings& splitSettings,
1997
1991
shardsToMerge.clear ();
1998
1992
ui64 totalSize = 0 ;
1999
1993
float totalLoad = 0 ;
1994
+ const auto settings = GetEffectiveSplitByLoadSettings (mainTableForIndex);
1995
+ const i64 cpuPercentageThreshold = settings.GetCpuPercentageThreshold ();
1996
+ const float cpuUsageThreshold = 0.01 * (cpuPercentageThreshold ? cpuPercentageThreshold : (i64 )splitSettings.FastSplitCpuPercentageThreshold );
1997
+ const float cpuMergeThreshold = 0.7 * cpuUsageThreshold;
1998
+
2000
1999
THashSet<TTabletId> partOwners;
2000
+ TString shardMergeReason;
2001
2001
2002
2002
// Make sure we can actually merge current shard first
2003
- if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, shardIdx, shardsToMerge, partOwners, totalSize, totalLoad, mainTableForIndex, reason )) {
2003
+ if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, shardIdx, shardsToMerge, partOwners, totalSize, totalLoad, cpuMergeThreshold, mainTableForIndex, shardMergeReason )) {
2004
2004
return false ;
2005
2005
}
2006
2006
2007
- TString mergeReason;
2007
+ reason = TStringBuilder () << " shard with tabletId: " << tabletId
2008
+ << " " << shardMergeReason;
2009
+
2008
2010
for (i64 pi = partitionIdx - 1 ; pi >= 0 ; --pi) {
2009
- if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, GetPartitions ()[pi].ShardIdx , shardsToMerge, partOwners, totalSize, totalLoad, mainTableForIndex, mergeReason )) {
2011
+ if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, GetPartitions ()[pi].ShardIdx , shardsToMerge, partOwners, totalSize, totalLoad, cpuMergeThreshold, mainTableForIndex, shardMergeReason )) {
2010
2012
break ;
2011
2013
}
2012
2014
}
2013
2015
// make shardsToMerge ordered by partition index
2014
2016
Reverse (shardsToMerge.begin (), shardsToMerge.end ());
2015
2017
2016
2018
for (ui64 pi = partitionIdx + 1 ; pi < GetPartitions ().size (); ++pi) {
2017
- if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, GetPartitions ()[pi].ShardIdx , shardsToMerge, partOwners, totalSize, totalLoad, mainTableForIndex, mergeReason )) {
2019
+ if (!TryAddShardToMerge (splitSettings, forceShardSplitSettings, GetPartitions ()[pi].ShardIdx , shardsToMerge, partOwners, totalSize, totalLoad, cpuMergeThreshold, mainTableForIndex, shardMergeReason )) {
2018
2020
break ;
2019
2021
}
2020
2022
}
2021
2023
2024
+ reason += TStringBuilder ()
2025
+ << " , shardToMergeCount: " << shardsToMerge.size ()
2026
+ << " , totalSize: " << totalSize
2027
+ << " , sizeToMerge: " << GetSizeToMerge (forceShardSplitSettings)
2028
+ << " , totalLoad: " << totalLoad
2029
+ << " , loadThreshold: " << cpuMergeThreshold;
2030
+
2022
2031
return shardsToMerge.size () > 1 ;
2023
2032
}
2024
2033
@@ -2082,8 +2091,8 @@ bool TTableInfo::CheckSplitByLoad(
2082
2091
reason = TStringBuilder () << " split by load ("
2083
2092
<< " rowCount: " << rowCount << " , "
2084
2093
<< " minRowCount: " << MIN_ROWS_FOR_SPLIT_BY_LOAD << " , "
2085
- << " dataSize : " << dataSize << " , "
2086
- << " minDataSize : " << MIN_SIZE_FOR_SPLIT_BY_LOAD << " , "
2094
+ << " shardSize : " << dataSize << " , "
2095
+ << " minShardSize : " << MIN_SIZE_FOR_SPLIT_BY_LOAD << " , "
2087
2096
<< " shardCount: " << Stats.PartitionStats .size () << " , "
2088
2097
<< " maxShardCount: " << maxShards << " , "
2089
2098
<< " cpuUsage: " << stats.GetCurrentRawCpuUsage () << " , "
0 commit comments