Skip to content

Commit 1dda9ab

Browse files
authored
HDDS-14076. Disable SSTFilteringService when defrag feature is enabled (#9495)
1 parent e5a5565 commit 1dda9ab

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@ public void start(OzoneConfiguration configuration) {
376376
*/
377377
public void startSnapshotSstFilteringService(OzoneConfiguration conf) {
378378
if (isSstFilteringSvcEnabled()) {
379+
if (isDefragSvcEnabled()) {
380+
LOG.info("SstFilteringService is disabled (despite configuration intending to enable it) " +
381+
"because SnapshotDefragService is enabled. Defrag effectively performs filtering already.");
382+
return;
383+
}
384+
385+
LOG.info("SstFilteringService is enabled. Note SstFilteringService is " +
386+
"deprecated in favor of SnapshotDefragService and may be removed in a future release.");
387+
379388
long serviceInterval = conf.getTimeDuration(
380389
OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL,
381390
OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL_DEFAULT,

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
4949
import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
5050
import org.apache.hadoop.ozone.om.lock.OMLockDetails;
51+
import org.apache.hadoop.ozone.om.snapshot.OmSnapshotLocalDataManager;
5152
import org.apache.ratis.util.UncheckedAutoCloseable;
5253
import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier;
5354
import org.slf4j.Logger;
@@ -132,6 +133,32 @@ private boolean isSnapshotDeleted(SnapshotInfo snapshotInfo) {
132133
return snapshotInfo == null || snapshotInfo.getSnapshotStatus() == SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED;
133134
}
134135

136+
/**
137+
* Checks if the snapshot has been defragged.
138+
* @param snapshotInfo snapshotInfo
139+
* @return true if the snapshot has been defragged, false otherwise
140+
*/
141+
private boolean isSnapshotDefragged(SnapshotInfo snapshotInfo) {
142+
try {
143+
OmSnapshotManager omSnapshotManager = ozoneManager.getOmSnapshotManager();
144+
if (omSnapshotManager == null) {
145+
return false;
146+
}
147+
OmSnapshotLocalDataManager localDataManager = omSnapshotManager.getSnapshotLocalDataManager();
148+
if (localDataManager == null) {
149+
return false;
150+
}
151+
try (OmSnapshotLocalDataManager.ReadableOmSnapshotLocalDataProvider provider =
152+
localDataManager.getOmSnapshotLocalData(snapshotInfo)) {
153+
// If snapshot local data version is not 0, it means the snapshot has been defragged
154+
return provider.getVersion() > 0;
155+
}
156+
} catch (IOException e) {
157+
LOG.debug("Error checking if snapshot {} is defragged", snapshotInfo.getSnapshotId(), e);
158+
return false;
159+
}
160+
}
161+
135162
/**
136163
* Marks the snapshot as SSTFiltered by creating a file in snapshot directory.
137164
* @param snapshotInfo snapshotInfo
@@ -187,6 +214,12 @@ public BackgroundTaskResult call() throws Exception {
187214
continue;
188215
}
189216

217+
// Skip defragged snapshots as defrag already performs filtering
218+
if (isSnapshotDefragged(snapshotInfo)) {
219+
LOG.debug("Skipping SST filtering for defragged snapshot: {}", snapShotTableKey);
220+
continue;
221+
}
222+
190223
LOG.debug("Processing snapshot {} to filter relevant SST Files",
191224
snapShotTableKey);
192225
TablePrefixInfo bucketPrefixInfo =

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,14 @@ public boolean needsDefrag() {
788788
return false;
789789
}
790790

791+
/**
792+
* Returns the version of the snapshot local data.
793+
* @return Version of the snapshot local data
794+
*/
795+
public long getVersion() {
796+
return snapshotLocalData.getVersion();
797+
}
798+
791799
@Override
792800
public void close() throws IOException {
793801
if (previousLock != null) {

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DB_PROFILE;
2222
import static org.apache.hadoop.hdds.HddsConfigKeys.OZONE_METADATA_DIRS;
2323
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
24+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
25+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_GRPC_PORT_KEY;
26+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTPS_ADDRESS_KEY;
27+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY;
28+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_PORT_KEY;
29+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL;
2430
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL;
2531
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.KEY_TABLE;
2632
import static org.apache.ozone.test.LambdaTestUtils.await;
@@ -508,4 +514,48 @@ private void deleteSnapshot(String volumeName, String bucketName, String snapsho
508514
writeClient.deleteSnapshot(volumeName, bucketName, snapshotName);
509515
countTotalSnapshots--;
510516
}
517+
518+
/**
519+
* Test to verify that SSTFilteringService is disabled when defrag service is enabled.
520+
* This test creates a new OzoneManager instance with defrag service enabled and verifies
521+
* that the SST filtering service is not started.
522+
*/
523+
@Test
524+
public void testSstFilteringDisabledWhenDefragEnabled(@TempDir Path folder) throws Exception {
525+
OzoneConfiguration testConf = new OzoneConfiguration();
526+
testConf.set(OZONE_METADATA_DIRS, folder.toString());
527+
testConf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL, 200, TimeUnit.MILLISECONDS);
528+
// Enable SST filtering service
529+
testConf.setTimeDuration(OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL, 100, TimeUnit.MILLISECONDS);
530+
// Enable defrag service
531+
testConf.setTimeDuration(OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL, 100, TimeUnit.MILLISECONDS);
532+
testConf.setEnum(HDDS_DB_PROFILE, DBProfile.TEST);
533+
testConf.setQuietMode(false);
534+
// Configure dynamic ports to avoid conflicts with the OzoneManager instance from @BeforeAll
535+
testConf.set(OZONE_OM_ADDRESS_KEY, "127.0.0.1:0");
536+
testConf.set(OZONE_OM_HTTP_ADDRESS_KEY, "127.0.0.1:0");
537+
testConf.set(OZONE_OM_HTTPS_ADDRESS_KEY, "127.0.0.1:0");
538+
testConf.setInt(OZONE_OM_RATIS_PORT_KEY, 0);
539+
testConf.setInt(OZONE_OM_GRPC_PORT_KEY, 0);
540+
541+
OmTestManagers testManagers = new OmTestManagers(testConf);
542+
KeyManager testKeyManager = testManagers.getKeyManager();
543+
OzoneManager testOm = testManagers.getOzoneManager();
544+
545+
try {
546+
// Verify that SST filtering service is not started when defrag is enabled
547+
SstFilteringService sstFilteringService = testKeyManager.getSnapshotSstFilteringService();
548+
assertThat(sstFilteringService).as("SstFilteringService should be null when defrag is enabled").isNull();
549+
} finally {
550+
if (testKeyManager != null) {
551+
testKeyManager.stop();
552+
}
553+
if (testManagers.getWriteClient() != null) {
554+
testManagers.getWriteClient().close();
555+
}
556+
if (testOm != null) {
557+
testOm.stop();
558+
}
559+
}
560+
}
511561
}

0 commit comments

Comments
 (0)