Skip to content

Commit c158290

Browse files
hemantk-12xichen01
authored andcommitted
HDDS-11084. Read SstFilteringService config only once in SnapshotDeletingService (apache#6885)
(cherry picked from commit 950a4b5)
1 parent d889984 commit c158290

3 files changed

Lines changed: 107 additions & 51 deletions

File tree

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDeletingService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class SnapshotDeletingService extends AbstractKeyDeletingService {
100100
private final long snapshotDeletionPerTask;
101101
private final int keyLimitPerSnapshot;
102102
private final int ratisByteLimit;
103+
private final boolean isSstFilteringServiceEnabled;
103104

104105
public SnapshotDeletingService(long interval, long serviceTimeout,
105106
OzoneManager ozoneManager, ScmBlockLocationProtocol scmClient)
@@ -127,6 +128,8 @@ public SnapshotDeletingService(long interval, long serviceTimeout,
127128
this.keyLimitPerSnapshot = conf.getInt(
128129
OZONE_SNAPSHOT_KEY_DELETING_LIMIT_PER_TASK,
129130
OZONE_SNAPSHOT_KEY_DELETING_LIMIT_PER_TASK_DEFAULT);
131+
132+
this.isSstFilteringServiceEnabled = ((KeyManagerImpl) ozoneManager.getKeyManager()).isSstFilteringSvcEnabled();
130133
}
131134

132135
private class SnapshotDeletingTask implements BackgroundTask {
@@ -153,12 +156,9 @@ public BackgroundTaskResult call() throws InterruptedException {
153156

154157
while (iterator.hasNext() && snapshotLimit > 0) {
155158
SnapshotInfo snapInfo = iterator.next().getValue();
156-
boolean isSstFilteringServiceEnabled =
157-
((KeyManagerImpl) ozoneManager.getKeyManager())
158-
.isSstFilteringSvcEnabled();
159159

160160
// Only Iterate in deleted snapshot
161-
if (shouldIgnoreSnapshot(snapInfo, isSstFilteringServiceEnabled)) {
161+
if (shouldIgnoreSnapshot(snapInfo)) {
162162
continue;
163163
}
164164

@@ -590,10 +590,10 @@ public void submitRequest(OMRequest omRequest) {
590590
}
591591
}
592592

593-
public static boolean shouldIgnoreSnapshot(SnapshotInfo snapInfo,
594-
boolean isSstFilteringServiceEnabled) {
593+
@VisibleForTesting
594+
boolean shouldIgnoreSnapshot(SnapshotInfo snapInfo) {
595595
SnapshotInfo.SnapshotStatus snapshotStatus = snapInfo.getSnapshotStatus();
596-
return !(snapshotStatus == SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED)
596+
return snapshotStatus != SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED
597597
|| (isSstFilteringServiceEnabled && !snapInfo.isSstFiltered());
598598
}
599599

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package org.apache.hadoop.ozone.om.service;
20+
21+
22+
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
23+
import org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol;
24+
import org.apache.hadoop.ozone.om.KeyManagerImpl;
25+
import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
26+
import org.apache.hadoop.ozone.om.OmSnapshotManager;
27+
import org.apache.hadoop.ozone.om.OzoneManager;
28+
import org.apache.hadoop.ozone.om.SnapshotChainManager;
29+
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
30+
import org.junit.jupiter.api.extension.ExtendWith;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.Arguments;
33+
import org.junit.jupiter.params.provider.MethodSource;
34+
import org.mockito.Mock;
35+
import org.mockito.Mockito;
36+
import org.mockito.junit.jupiter.MockitoExtension;
37+
38+
import java.io.IOException;
39+
import java.time.Duration;
40+
import java.util.stream.Stream;
41+
42+
import static org.junit.jupiter.api.Assertions.assertEquals;
43+
44+
/**
45+
* Class to unit test SnapshotDeletingService.
46+
*/
47+
@ExtendWith(MockitoExtension.class)
48+
public class TestSnapshotDeletingService {
49+
@Mock
50+
private OzoneManager ozoneManager;
51+
@Mock
52+
private KeyManagerImpl keyManager;
53+
@Mock
54+
private OmSnapshotManager omSnapshotManager;
55+
@Mock
56+
private SnapshotChainManager chainManager;
57+
@Mock
58+
private OmMetadataManagerImpl omMetadataManager;
59+
@Mock
60+
private ScmBlockLocationProtocol scmClient;
61+
private final OzoneConfiguration conf = new OzoneConfiguration();;
62+
private final long sdsRunInterval = Duration.ofMillis(1000).toMillis();
63+
private final long sdsServiceTimeout = Duration.ofSeconds(10).toMillis();
64+
65+
66+
private static Stream<Arguments> testCasesForIgnoreSnapshotGc() {
67+
SnapshotInfo filteredSnapshot = SnapshotInfo.newBuilder().setSstFiltered(true).setName("snap1").build();
68+
SnapshotInfo unFilteredSnapshot = SnapshotInfo.newBuilder().setSstFiltered(false).setName("snap1").build();
69+
return Stream.of(
70+
Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, false),
71+
Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true),
72+
Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, true),
73+
Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true),
74+
Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false),
75+
Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false),
76+
Arguments.of(unFilteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true),
77+
Arguments.of(filteredSnapshot, SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true));
78+
}
79+
80+
@ParameterizedTest
81+
@MethodSource("testCasesForIgnoreSnapshotGc")
82+
public void testProcessSnapshotLogicInSDS(SnapshotInfo snapshotInfo,
83+
SnapshotInfo.SnapshotStatus status,
84+
boolean sstFilteringServiceEnabled,
85+
boolean expectedOutcome)
86+
throws IOException {
87+
Mockito.when(keyManager.isSstFilteringSvcEnabled()).thenReturn(sstFilteringServiceEnabled);
88+
Mockito.when(omMetadataManager.getSnapshotChainManager()).thenReturn(chainManager);
89+
Mockito.when(ozoneManager.getKeyManager()).thenReturn(keyManager);
90+
Mockito.when(ozoneManager.getOmSnapshotManager()).thenReturn(omSnapshotManager);
91+
Mockito.when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
92+
Mockito.when(ozoneManager.getConfiguration()).thenReturn(conf);
93+
94+
SnapshotDeletingService snapshotDeletingService =
95+
new SnapshotDeletingService(sdsRunInterval, sdsServiceTimeout, ozoneManager, scmClient);
96+
97+
snapshotInfo.setSnapshotStatus(status);
98+
assertEquals(expectedOutcome, snapshotDeletingService.shouldIgnoreSnapshot(snapshotInfo));
99+
}
100+
}

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOmSnapshotUtils.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,15 @@
1818

1919
package org.apache.hadoop.ozone.om.snapshot;
2020

21-
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
22-
import org.apache.hadoop.ozone.om.service.SnapshotDeletingService;
2321
import org.apache.ozone.test.GenericTestUtils;
2422
import org.junit.jupiter.api.Test;
2523
import org.junit.jupiter.api.io.TempDir;
26-
import org.junit.jupiter.params.ParameterizedTest;
27-
import org.junit.jupiter.params.provider.Arguments;
28-
import org.junit.jupiter.params.provider.MethodSource;
2924

3025
import java.io.File;
3126
import java.nio.file.Files;
3227
import java.nio.file.Path;
3328
import java.util.Set;
3429
import java.util.stream.Collectors;
35-
import java.util.stream.Stream;
3630

3731
import static java.nio.charset.StandardCharsets.UTF_8;
3832
import static org.apache.hadoop.ozone.om.snapshot.OmSnapshotUtils.getINode;
@@ -84,42 +78,4 @@ public void testLinkFiles(@TempDir File tempDir) throws Exception {
8478
assertEquals(tree1Files, tree2Files);
8579
GenericTestUtils.deleteDirectory(tempDir);
8680
}
87-
88-
89-
private static Stream<Arguments> testCasesForIgnoreSnapshotGc() {
90-
SnapshotInfo filteredSnapshot =
91-
SnapshotInfo.newBuilder().setSstFiltered(true).setName("snap1").build();
92-
SnapshotInfo unFilteredSnapshot =
93-
SnapshotInfo.newBuilder().setSstFiltered(false).setName("snap1")
94-
.build();
95-
// {IsSnapshotFiltered,isSnapshotDeleted,IsSstServiceEnabled = ShouldIgnore}
96-
return Stream.of(Arguments.of(filteredSnapshot,
97-
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, false),
98-
Arguments.of(filteredSnapshot,
99-
SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true),
100-
Arguments.of(unFilteredSnapshot,
101-
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, true, true),
102-
Arguments.of(unFilteredSnapshot,
103-
SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, true, true),
104-
Arguments.of(filteredSnapshot,
105-
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false),
106-
Arguments.of(unFilteredSnapshot,
107-
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED, false, false),
108-
Arguments.of(unFilteredSnapshot,
109-
SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true),
110-
Arguments.of(filteredSnapshot,
111-
SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE, false, true));
112-
}
113-
114-
@ParameterizedTest
115-
@MethodSource("testCasesForIgnoreSnapshotGc")
116-
public void testProcessSnapshotLogicInSDS(SnapshotInfo snapshotInfo,
117-
SnapshotInfo.SnapshotStatus status, boolean isSstFilteringSvcEnabled,
118-
boolean expectedOutcome) {
119-
snapshotInfo.setSnapshotStatus(status);
120-
assertEquals(expectedOutcome,
121-
SnapshotDeletingService.shouldIgnoreSnapshot(snapshotInfo,
122-
isSstFilteringSvcEnabled));
123-
}
124-
12581
}

0 commit comments

Comments
 (0)