-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-8477. Unit test for Snapdiff using tombstone entries #4678
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7daaec0
HDDS-8477. Unit test for Snapdiff using tombstone entries
swamirishi a51fb2b
HDDS-8477: Address review comments
swamirishi 607c185
HDDS-8477: Fix checkstyle
swamirishi 0611a6e
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi 964d5a6
HDDS-8477: Fix checkstyle
swamirishi ecd5d74
HDDS-8477: Address review comments
swamirishi 7a1d59e
HDDS-8477: Address review comments
swamirishi 7b79413
HDDS-8477. Fix testcase failure
swamirishi b1b22c0
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi 8150fe7
HDDS-8477. Fix test case
swamirishi 5dd6b1b
HDDS-8477. Initilialize counter to avoid null pointer
swamirishi c6ab89d
HDDS-8477. Fix testcase failure
swamirishi f2b74a8
HDDS-8477. Fix robot test for snapshot deletion check
swamirishi 0d57996
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi d0a955f
HDDS-8477. Fix snapshot delete robot test
swamirishi 8e9fc62
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi e6b9880
HDDS-8477. Address review comments to fix robot test
swamirishi 7d2c15b
HDDS-8477. Address review comments to fix ci
swamirishi 3fac5ab
HDDS-8477. Address review comments
swamirishi 39498aa
HDDS-8477. Add checks to add validation on page response
swamirishi 298e9ac
HDDS-8477. Fix checkstyle issue
swamirishi 10349f3
HDDS-8477. Fix checkstyle issue
swamirishi 746a238
HDDS-8477. Fix checkstyle issue
swamirishi 6d878d4
HDDS-8477. Address review comments
swamirishi 3be8689
HDDS-8477. Address review comments
swamirishi 4c55203
HDDS-8477. Remove loop from robot test
swamirishi c348853
HDDS-8477. Fix checkstyle for import
swamirishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
158 changes: 158 additions & 0 deletions
158
...eckpoint-differ/src/test/java/org/apache/ozone/rocksdb/util/TestManagedSstFileReader.java
This file contains hidden or 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,158 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.ozone.rocksdb.util; | ||
|
|
||
| import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.apache.hadoop.hdds.StringUtils; | ||
| import org.apache.hadoop.hdds.utils.NativeLibraryLoader; | ||
| import org.apache.hadoop.hdds.utils.NativeLibraryNotLoadedException; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedEnvOptions; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedOptions; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedSSTDumpTool; | ||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedSstFileWriter; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.rocksdb.RocksDBException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.TreeMap; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.SynchronousQueue; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME; | ||
|
|
||
| /** | ||
| * ManagedSstFileReader tests. | ||
| */ | ||
| public class TestManagedSstFileReader { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(TestManagedSstFileReader.class); | ||
|
|
||
| // Key prefix containing all characters, to check if all characters can be | ||
| // written & read from rocksdb through SSTDumptool | ||
| private static final String KEY_PREFIX = IntStream.range(0, 256).boxed() | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .map(i -> String.format("%c", i)) | ||
| .collect(Collectors.joining("")); | ||
|
|
||
| private String createRandomSSTFile(TreeMap<String, Integer> keys) | ||
| throws IOException, RocksDBException { | ||
| File file = File.createTempFile("tmp_sst_file", ".sst"); | ||
| file.deleteOnExit(); | ||
|
|
||
| try (ManagedOptions managedOptions = new ManagedOptions(); | ||
| ManagedEnvOptions managedEnvOptions = new ManagedEnvOptions(); | ||
| ManagedSstFileWriter sstFileWriter = new ManagedSstFileWriter( | ||
| managedEnvOptions, managedOptions)) { | ||
| sstFileWriter.open(file.getAbsolutePath()); | ||
| for (Map.Entry<String, Integer> entry : keys.entrySet()) { | ||
| byte[] keyByte = StringUtils.string2Bytes(entry.getKey()); | ||
| if (entry.getValue() == 0) { | ||
| sstFileWriter.delete(keyByte); | ||
| } else { | ||
| sstFileWriter.put(keyByte, keyByte); | ||
| } | ||
| } | ||
| sstFileWriter.finish(); | ||
| } | ||
| return file.getAbsolutePath(); | ||
| } | ||
|
|
||
| private Map<String, Integer> createKeys(int startRange, int endRange) { | ||
| return IntStream.range(startRange, endRange).boxed() | ||
| .collect(Collectors.toMap(i -> KEY_PREFIX + i, | ||
| i -> i % 2)); | ||
| } | ||
|
|
||
| private Pair<Map<String, Integer>, List<String>> createDummyData( | ||
| int numberOfFiles) throws RocksDBException, IOException { | ||
| List<String> files = new ArrayList<>(); | ||
| int numberOfKeysPerFile = 1000; | ||
| Map<String, Integer> keys = new HashMap<>(); | ||
| int cnt = 0; | ||
| for (int i = 0; i < numberOfFiles; i++) { | ||
| TreeMap<String, Integer> fileKeys = new TreeMap<>(createKeys(cnt, | ||
| cnt + numberOfKeysPerFile)); | ||
| cnt += fileKeys.size(); | ||
| String tmpSSTFile = createRandomSSTFile(fileKeys); | ||
| files.add(tmpSSTFile); | ||
| keys.putAll(fileKeys); | ||
| } | ||
| return Pair.of(keys, files); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(ints = {0, 1, 2, 3, 7, 10}) | ||
| public void testGetKeyStream(int numberOfFiles) | ||
| throws RocksDBException, IOException { | ||
| Pair<Map<String, Integer>, List<String>> data = | ||
| createDummyData(numberOfFiles); | ||
| List<String> files = data.getRight(); | ||
| Map<String, Integer> keys = data.getLeft(); | ||
| try (Stream<String> keyStream = | ||
| new ManagedSstFileReader(files).getKeyStream()) { | ||
| keyStream.forEach(key -> { | ||
| Assertions.assertEquals(keys.get(key), 1); | ||
| keys.remove(key); | ||
| }); | ||
| keys.values().forEach(val -> Assertions.assertEquals(0, val)); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(ints = {0, 1, 2, 3, 7, 10}) | ||
| public void testGetKeyStreamWithTombstone(int numberOfFiles) | ||
| throws RocksDBException, IOException, NativeLibraryNotLoadedException { | ||
| NativeLibraryLoader.getInstance() | ||
| .loadLibrary(ROCKS_TOOLS_NATIVE_LIBRARY_NAME); | ||
| Pair<Map<String, Integer>, List<String>> data = | ||
| createDummyData(numberOfFiles); | ||
| List<String> files = data.getRight(); | ||
| Map<String, Integer> keys = data.getLeft(); | ||
| ExecutorService executorService = new ThreadPoolExecutor(0, | ||
| 1, 60, TimeUnit.SECONDS, | ||
| new SynchronousQueue<>(), new ThreadFactoryBuilder() | ||
| .setNameFormat("snapshot-diff-manager-sst-dump-tool-TID-%d") | ||
| .build(), new ThreadPoolExecutor.DiscardPolicy()); | ||
| ManagedSSTDumpTool sstDumpTool = | ||
| new ManagedSSTDumpTool(executorService, 256); | ||
|
|
||
| try (Stream<String> keyStream = new ManagedSstFileReader(files) | ||
| .getKeyStreamWithTombstone(sstDumpTool)) { | ||
| keyStream.forEach(keys::remove); | ||
| Assertions.assertEquals(0, keys.size()); | ||
| } finally { | ||
| executorService.shutdown(); | ||
| } | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.