-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(s3stream): merge small data blocks during compaction
Signed-off-by: Shichao Nie <[email protected]>
- Loading branch information
Showing
12 changed files
with
370 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
s3stream/src/main/java/com/automq/stream/s3/compact/utils/GroupByLimitPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.automq.stream.s3.compact.utils; | ||
|
||
import com.automq.stream.s3.StreamDataBlock; | ||
import java.util.function.Predicate; | ||
|
||
public class GroupByLimitPredicate implements Predicate<StreamDataBlock> { | ||
private final long blockSizeThreshold; | ||
private long streamId = -1; | ||
private long startOffset = 0; | ||
private long nextStartOffset = 0; | ||
private int blockSize = 0; | ||
private int recordCnt = 0; | ||
|
||
public GroupByLimitPredicate(long blockSizeThreshold) { | ||
this.blockSizeThreshold = blockSizeThreshold; | ||
} | ||
|
||
@Override | ||
public boolean test(StreamDataBlock block) { | ||
boolean flag = true; | ||
if (streamId == -1 // first block | ||
|| block.getStreamId() != streamId // iterate to next stream | ||
|| block.getStartOffset() != nextStartOffset // block start offset is not continuous for same stream (unlikely to happen) | ||
|| (long) blockSize + block.getBlockSize() >= blockSizeThreshold // group size exceeds threshold | ||
|| (long) recordCnt + block.dataBlockIndex().recordCount() > Integer.MAX_VALUE // group record count exceeds int32 | ||
|| (block.getEndOffset() - startOffset) > Integer.MAX_VALUE) { // group delta offset exceeds int32 | ||
|
||
if (streamId != -1) { | ||
flag = false; | ||
} | ||
|
||
streamId = block.getStreamId(); | ||
startOffset = block.getStartOffset(); | ||
blockSize = 0; | ||
recordCnt = 0; | ||
} | ||
|
||
nextStartOffset = block.getEndOffset(); | ||
blockSize += block.getBlockSize(); | ||
recordCnt += block.dataBlockIndex().recordCount(); | ||
return flag; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
s3stream/src/main/java/com/automq/stream/s3/compact/utils/GroupByOffsetPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.automq.stream.s3.compact.utils; | ||
|
||
import com.automq.stream.s3.StreamDataBlock; | ||
import java.util.function.Predicate; | ||
|
||
public class GroupByOffsetPredicate implements Predicate<StreamDataBlock> { | ||
|
||
private long currStreamId = -1; | ||
private long nextStartOffset = 0; | ||
|
||
@Override | ||
public boolean test(StreamDataBlock block) { | ||
if (currStreamId == -1) { | ||
currStreamId = block.getStreamId(); | ||
nextStartOffset = block.getEndOffset(); | ||
return true; | ||
} else { | ||
if (currStreamId == block.getStreamId() && nextStartOffset == block.getStartOffset()) { | ||
nextStartOffset = block.getEndOffset(); | ||
return true; | ||
} else { | ||
currStreamId = block.getStreamId(); | ||
nextStartOffset = block.getEndOffset(); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.