forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PIP-146] ManagedCursorInfo compression (apache#14542)
Fixes apache#14529 ### Motivation The cursor data is managed by ZooKeeper/etcd metadata store. When cursor data becomes more and more, the data size will increase and will take a lot of time to pull the data. Therefore, it is necessary to add compression for the cursor, which can reduce the size of data and reduce the time of pulling data. ### Modifications - Add a named `ManagedCursorInfoMetadata` message to `MLDataFormats.proto` for as compression metadata - Add the `managedCursorInfoCompressionType` to `org.apache.pulsar.broker.ServiceConfiguration` and `org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig` - This feature is the same as the implementation of ManagedLedgerInfo compression, so the code is optimized to avoid duplication
- Loading branch information
Showing
8 changed files
with
236 additions
and
77 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
96 changes: 96 additions & 0 deletions
96
...edger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorInfoMetadataTest.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,96 @@ | ||
/** | ||
* 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 org.apache.bookkeeper.mledger.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.testng.Assert.expectThrows; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.bookkeeper.mledger.proto.MLDataFormats; | ||
import org.apache.pulsar.common.api.proto.CompressionType; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* ManagedCursorInfo metadata test. | ||
*/ | ||
@Slf4j | ||
public class ManagedCursorInfoMetadataTest { | ||
private final String INVALID_TYPE = "INVALID_TYPE"; | ||
|
||
@DataProvider(name = "compressionTypeProvider") | ||
private Object[][] compressionTypeProvider() { | ||
return new Object[][]{ | ||
{null}, | ||
{INVALID_TYPE}, | ||
{CompressionType.NONE.name()}, | ||
{CompressionType.LZ4.name()}, | ||
{CompressionType.ZLIB.name()}, | ||
{CompressionType.ZSTD.name()}, | ||
{CompressionType.SNAPPY.name()} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "compressionTypeProvider") | ||
public void testEncodeAndDecode(String compressionType) throws IOException { | ||
long ledgerId = 10000; | ||
MLDataFormats.ManagedCursorInfo.Builder builder = MLDataFormats.ManagedCursorInfo.newBuilder(); | ||
|
||
builder.setCursorsLedgerId(ledgerId); | ||
builder.setMarkDeleteLedgerId(ledgerId); | ||
|
||
List<MLDataFormats.BatchedEntryDeletionIndexInfo> batchedEntryDeletionIndexInfos = new ArrayList<>(); | ||
for (int i = 0; i < 1000; i++) { | ||
MLDataFormats.NestedPositionInfo nestedPositionInfo = MLDataFormats.NestedPositionInfo.newBuilder() | ||
.setEntryId(i).setLedgerId(i).build(); | ||
MLDataFormats.BatchedEntryDeletionIndexInfo batchedEntryDeletionIndexInfo = MLDataFormats | ||
.BatchedEntryDeletionIndexInfo.newBuilder().setPosition(nestedPositionInfo).build(); | ||
batchedEntryDeletionIndexInfos.add(batchedEntryDeletionIndexInfo); | ||
} | ||
builder.addAllBatchedEntryDeletionIndexInfo(batchedEntryDeletionIndexInfos); | ||
|
||
MetaStoreImpl metaStore; | ||
if (INVALID_TYPE.equals(compressionType)) { | ||
IllegalArgumentException compressionTypeEx = expectThrows(IllegalArgumentException.class, () -> { | ||
new MetaStoreImpl(null, null, null, compressionType); | ||
}); | ||
assertEquals("No enum constant org.apache.bookkeeper.mledger.proto.MLDataFormats.CompressionType." | ||
+ compressionType, compressionTypeEx.getMessage()); | ||
return; | ||
} else { | ||
metaStore = new MetaStoreImpl(null, null, null, compressionType); | ||
} | ||
|
||
MLDataFormats.ManagedCursorInfo managedCursorInfo = builder.build(); | ||
byte[] compressionBytes = metaStore.compressCursorInfo(managedCursorInfo); | ||
log.info("[{}] Uncompressed data size: {}, compressed data size: {}", | ||
compressionType, managedCursorInfo.getSerializedSize(), compressionBytes.length); | ||
if (compressionType == null || compressionType.equals(CompressionType.NONE.name())) { | ||
Assert.assertEquals(compressionBytes.length, managedCursorInfo.getSerializedSize()); | ||
} | ||
|
||
// parse compression data and unCompression data, check their results. | ||
MLDataFormats.ManagedCursorInfo info1 = metaStore.parseManagedCursorInfo(compressionBytes); | ||
MLDataFormats.ManagedCursorInfo info2 = metaStore.parseManagedCursorInfo(managedCursorInfo.toByteArray()); | ||
Assert.assertEquals(info1, info2); | ||
} | ||
} |
Oops, something went wrong.