-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stateful auto compaction #8489
Comments
just trying to wrap my head around compaction, I have few questions, it has evolved alot :)
or else auto/minor compaction would produce exactly same result because it doesn't change segmentGranularity... right ? |
@himanshug thank you for taking a look!
For now, auto compaction doesn't support minor compaction. You can do minor compaction with the compaction task by setting The future plan I'm thinking of is supporting both minor and major compaction in auto compaction. Like, it will do minor compaction for recent segments while doing major compaction for old ones. There are a couple reasons why we still need major compaction. One reason could be, we can do secondary partitioning with major compaction which could accelerate query performance by further pruning segments.
Good question. It is the major compaction if 1)
You mean if the compaction task has the exactly same tuningConfig? Then I think yes. |
I see, but then why segment is not candidate for compaction when it has same partitionSpec .. if tuningConfig is different then it could still produce different result, no ? Thanks for clarifications around major/minor compaction. I think confusion arises because there is no trace of major/minor compaction in the code. Do you think it makes sense to create two new classes , I totally recognize the need for major compaction as ,I think, minor compaction is limited to compact segments in same partition set (i.e. segments with same dataSource, interval and version) only. |
That's a good point! I just checked
Hmm, yes it sounds good to me. For now,
That's also correct. Minor compaction can compact only the segments in the same time chunk. |
Motivation
In auto compaction, the coordinator searches for segments to compact based on their byte size. This algorithm is currently a stateless algorithm. At each coordinator run, it traverses all segments of all datasources from the latest one to the oldest one, compares their size against
targetCompactionSizeBytes
(this is currently missing which causes #8481), and issues a compaction task if it finds some segments smaller thantargetCompactionSizeBytes
.However, only comparing the segment size against
targetCompactionSizeBytes
is not enough to tell that a given segment requires a further compaction or not because the segment could be created with various types ofpartitionsSpec
and later compacted with one of them. (As of now, auto compaction supports onlymaxRowsPerSegment
,maxTotalRows
, andtargetCompactionSizeBytes
, but it should support all partitionsSpec types in the future.)As of now, we have 3
partitionsSpec
, i.e.,DynamicPartitionsSpec
,HashedPartitionsSpec
, andSingleDimensionPartitionsSpec
.DynamicPartitionsSpec
hasmaxRowsPerSegment
, andmaxTotalRows
.HashedPartitionsSpec
hastargetPartitionSize
(target number of rows per segment),numShards
, andpartitionDimensions
.SingleDimensionPartitionsSpec
hastargetPartitionSize
(target number of rows per segment),maxPartitionSize
(max number of rows per segment),partitionDimensions
.In the coordinator, most of these configurations are not easy to use to search for segments which need compaction because the number of rows in each segment is not available in the coordinator. And even if we had that in the coordinator, hash or range partitioned segments could have totally different number of rows from
targetPartitionSize
, which makes hard to tell a given segment needs compaction or not. Note that a segment doesn't need further compaction if it's already compacted with the samepartitionsSpec
. Auto compaction based on parallel indexing can also make things complicated. In parallel indexing withDynamicPartitionsSpec
, the last segment created by each task can have rows less thanmaxRowsPerSegment
.Proposed changes
To address this issue, I propose to store the state of auto compaction in the metadata store, so that auto compaction can search for compaction candidates from the segments which are not compacted yet.
DataSegment change
A new
compactionPartitionsSpec
will be added toDataSegment
.compactionPartitionsSpec
will be filled in only the coordinator.Changes in publishing segments
When a compaction task creates segments, it can add its
partitionsSpec
to them (Appenderator.add()
). Other task types don't add it.Changes in the coordinator
SQLMetadataSegmentManager
loadsDataSegment
and keeps them in memory same as now. SincePartitionsSpec
is not very diverse in general, interning would be useful to reduce memory usage.DruidCoordinatorSegmentCompactor
checks that thecompactionPartitionsSpec
is available for a given segment. If it's missing, that segment should be a new segment created by a non-compaction task, which means it will be a compaction candidate. If it exists, the coordinator compares thecompactionPartitionsSpec
with thepartitionsSpec
in auto compaction configuration. The segment will be a compaction candidate if it has a differentpartitionsSpec
.Rationale
Dropped alternative
The coordinator can get the number of rows of each segment from the system schema to find the compaction candidates. However, as mentioned in the motivation section, number of rows is not enough to determine that a given segment needs a compaction or not.
Operational impact
There should be no operational impact.
Test plan
Future work
In
DataSegment
, similar tocompactionPartitionsSpec
, there are a couple of fields which are loaded only in some particular places; they are null or some default value elsewhere. But, even when they are null or default, they will still use 8 more bytes per segment. I think it would probably be worth to splitDataSegment
into several classes, so that only necessary fields are loaded to reduce memory usage.The text was updated successfully, but these errors were encountered: