-
Notifications
You must be signed in to change notification settings - Fork 597
HDDS-14996. Add metrics to track Snapshot backup SST file stats. #10065
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
Draft
jojochuang
wants to merge
4
commits into
apache:master
Choose a base branch
from
jojochuang:HDDS-14996
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−44
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
74ca832
HDDS-14996. Add metrics to track Snapshot backup SST file stats.
jojochuang e0a1c6d
HDDS-14996. Fix checkstyle issues in TestOMSnapshotDirectoryMetrics.
jojochuang fc9354f
HDDS-14996. Fix PMD SingularField warnings in TestOMSnapshotDirectory…
jojochuang f3239c6
review commens
jojochuang 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
129 changes: 129 additions & 0 deletions
129
...ger/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOMSnapshotDirectoryMetrics.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,129 @@ | ||
| /* | ||
| * 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.hadoop.ozone.om.snapshot; | ||
|
|
||
| import static org.apache.hadoop.ozone.OzoneConsts.ROCKSDB_SST_SUFFIX; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.UUID; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.utils.db.RDBStore; | ||
| import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
| import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import org.mockito.Mockito; | ||
|
|
||
| /** | ||
| * Tests for OMSnapshotDirectoryMetrics. | ||
| */ | ||
| public class TestOMSnapshotDirectoryMetrics { | ||
|
|
||
| @TempDir | ||
| private Path tempDir; | ||
|
|
||
| private OMMetadataManager metadataManager; | ||
| private OMSnapshotDirectoryMetrics metrics; | ||
|
|
||
| @BeforeEach | ||
| public void setup() throws IOException { | ||
| metadataManager = Mockito.mock(OMMetadataManager.class); | ||
| RDBStore store = Mockito.mock(RDBStore.class); | ||
| RocksDBCheckpointDiffer differ = Mockito.mock(RocksDBCheckpointDiffer.class); | ||
|
|
||
| when(metadataManager.getStore()).thenReturn(store); | ||
| when(store.getRocksDBCheckpointDiffer()).thenReturn(differ); | ||
|
|
||
| Path snapshotsDir = tempDir.resolve("snapshots"); | ||
| Files.createDirectories(snapshotsDir); | ||
| when(store.getSnapshotsParentDir()).thenReturn(snapshotsDir.toString()); | ||
|
|
||
| Path backupDir = tempDir.resolve("backup"); | ||
| Files.createDirectories(backupDir); | ||
| when(differ.getSSTBackupDir()).thenReturn(backupDir.toString()); | ||
|
|
||
| OzoneConfiguration conf = new OzoneConfiguration(); | ||
| metrics = new OMSnapshotDirectoryMetrics(conf, metadataManager); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMetrics() throws IOException { | ||
| Path snapshotsDir = Paths.get(metadataManager.getStore().getSnapshotsParentDir()); | ||
| Path backupDir = Paths.get(metadataManager.getStore().getRocksDBCheckpointDiffer().getSSTBackupDir()); | ||
|
|
||
| // Create a snapshot directory with some files | ||
| Path snap1 = snapshotsDir.resolve(UUID.randomUUID().toString()); | ||
| Files.createDirectories(snap1); | ||
| Path file1 = snap1.resolve("file1" + ROCKSDB_SST_SUFFIX); | ||
| Files.write(file1, "data1".getBytes(StandardCharsets.UTF_8)); | ||
| long size1 = Files.size(file1); | ||
|
|
||
| // Create backup directory with some files | ||
| Path backupFile1 = backupDir.resolve("backup1" + ROCKSDB_SST_SUFFIX); | ||
| Files.write(backupFile1, "backupData1".getBytes(StandardCharsets.UTF_8)); | ||
| long backupSize1 = Files.size(backupFile1); | ||
|
|
||
| Path backupFile2 = backupDir.resolve("backup2" + ROCKSDB_SST_SUFFIX); | ||
| Files.write(backupFile2, "backupData22".getBytes(StandardCharsets.UTF_8)); | ||
| long backupSize2 = Files.size(backupFile2); | ||
|
|
||
| metrics.updateMetrics(); | ||
|
|
||
| assertEquals(1, metrics.getNumSnapshots()); | ||
| assertEquals(1, metrics.getTotalSstFilesCount()); | ||
| assertEquals(size1, metrics.getDbSnapshotsDirSize()); | ||
| assertEquals(2, metrics.getSstBackupSstFilesCount()); | ||
| assertEquals(backupSize1 + backupSize2, metrics.getSstBackupDirSize()); | ||
|
|
||
| // Add another snapshot with a hardlink | ||
| Path snap2 = snapshotsDir.resolve(UUID.randomUUID().toString()); | ||
| Files.createDirectories(snap2); | ||
| Path file2 = snap2.resolve("file1" + ROCKSDB_SST_SUFFIX); | ||
| try { | ||
| Files.createLink(file2, file1); | ||
| } catch (UnsupportedOperationException e) { | ||
| // Fallback for systems that don't support hardlinks in temp dir | ||
| Files.write(file2, "data1".getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
|
|
||
| metrics.updateMetrics(); | ||
|
|
||
| assertEquals(2, metrics.getNumSnapshots()); | ||
| // Total SST count should still be 1 if hardlink is counted once, | ||
| // but the implementation uses visitedInodes per snapshot directory? | ||
| // Wait, let's check the implementation again. | ||
|
||
| // calculateAndUpdateMetrics: visitedSnapshotsInodes is used for ALL snapshots. | ||
| assertEquals(1, metrics.getTotalSstFilesCount()); | ||
| assertEquals(size1, metrics.getDbSnapshotsDirSize()); | ||
|
|
||
| // Test backup dir update | ||
| Path backupFile3 = backupDir.resolve("notSst.txt"); | ||
| Files.write(backupFile3, "notSstData".getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| metrics.updateMetrics(); | ||
| assertEquals(2, metrics.getSstBackupSstFilesCount()); | ||
| assertEquals(backupSize1 + backupSize2 + Files.size(backupFile3), metrics.getSstBackupDirSize()); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.