Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8f1b164
HDDS-13003. [POC] Snapshot Defragmentation to reduce storage footprint
smengcl Aug 19, 2025
ad3ed61
[split] Add new OM layout feature SNAPSHOT_DEFRAGMENTATION (doesn't d…
smengcl Aug 19, 2025
f81e5b7
Make `RDBSstFileWriter` public to be used in defrag service.
smengcl Aug 19, 2025
e15a62d
Implement `delete(key)` in `RDBSstFileWriter`.
smengcl Aug 19, 2025
c04d67a
Add config `ozone.snapshot.defrag.service.timeout`, `ozone.snapshot.d…
smengcl Aug 19, 2025
160434b
Rename term: compact -> defrag
smengcl Aug 19, 2025
ac58394
[split] HDDS-13009. Implement SnapshotDefragService POC.
smengcl Aug 19, 2025
3de45ba
[split] Implement manual trigger of snapshot defrag. e.g. `ozone admi…
smengcl Aug 19, 2025
ab9d67e
Add tests (for debugging)
smengcl Aug 19, 2025
5bf6646
[split] yaml: TODO: Add OM_SLD_DB_CHECKPOINT_DIR field
smengcl Aug 19, 2025
d9ace6b
[drop][dev] Disable WAL archival
smengcl Aug 19, 2025
1270359
SDS: Write diff to defragged DB directly instead of writing to SST fi…
smengcl Aug 18, 2025
410ba6e
[dev] Disable WAL in write options for testing
smengcl Aug 19, 2025
41241fe
[dev] Update native library handling in Ozone build and shell
smengcl Aug 19, 2025
41abbc1
[dev] Add debug log for failed System.loadLibrary call
smengcl Aug 19, 2025
61a7fac
Update default values in OmSnapshotLocalData constructor
smengcl Aug 19, 2025
fb700d0
[dev] testUpdateYaml to set fields in .yaml before triggering defrag
smengcl Aug 19, 2025
2f1cb67
Remove TestSnapshotDefragService test class
smengcl Aug 19, 2025
737416b
Reorder constant definition in OMConfigKeys
smengcl Aug 19, 2025
e301d7c
[dev] Update compose/ozone volumes/profiles and config defaults for l…
smengcl Aug 19, 2025
173ea8e
om: Use triggerSnapshotDefragOnce for snapshot defrag manual triggering
smengcl Aug 19, 2025
f1e5def
SDS: Do not fall back to full defrag on inc defrag error
smengcl Aug 19, 2025
8124405
SDS: Clean up, add TODOs
smengcl Aug 19, 2025
026f74f
SDS: Fix extractKeyFromPath for FSO (hack).
smengcl Aug 19, 2025
af7dc32
Rename CHECKPOINT_STATE_DEFRAGED_DIR -> CHECKPOINT_STATE_DEFRAGGED_DIR
smengcl Aug 19, 2025
f08ebe9
Update TestSnapshotDefragService2 for FSO buckets and config tuning
smengcl Aug 19, 2025
6cb7420
[split] freon RandomKeyGenerator to handle existing volumes and buckets
smengcl Aug 19, 2025
420323f
[dev] Update key comparison logic in SnapshotDiffManager to count mod…
smengcl Aug 19, 2025
bcab08c
Make RocksCheckpoint and related methods public
smengcl Aug 19, 2025
60fbe52
[split] Handle STAND_ALONE replication type in QuotaUtil (was printin…
smengcl Aug 19, 2025
fb5fa37
[split] TODO that we should disable db.snapshots creation for scm and…
smengcl Aug 19, 2025
09a381a
Remove TestOmSnapshotDefrag integration test
smengcl Aug 19, 2025
a527b67
Update docker-compose.yaml
smengcl Aug 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ public final class OzoneConfigKeys {
OZONE_SNAPSHOT_SST_FILTERING_SERVICE_TIMEOUT_DEFAULT = "300s";
// 300s for default

public static final String OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT =
"ozone.snapshot.defrag.service.timeout";
public static final String
OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT_DEFAULT = "300s";
// 300s for default

public static final String OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL =
"ozone.snapshot.deleting.service.interval";
public static final String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ public final class OzoneConsts {
public static final String OM_SLD_VERSION = "version";
public static final String OM_SLD_CHECKSUM = "checksum";
public static final String OM_SLD_IS_SST_FILTERED = "isSSTFiltered";
public static final String OM_SLD_UNCOMPACTED_SST_FILE_LIST = "uncompactedSSTFileList";
public static final String OM_SLD_LAST_COMPACTION_TIME = "lastCompactionTime";
public static final String OM_SLD_NEEDS_COMPACTION = "needsCompaction";
public static final String OM_SLD_COMPACTED_SST_FILE_LIST = "compactedSSTFileList";
public static final String OM_SLD_NOT_DEFRAGGED_SST_FILE_LIST = "notDefraggedSSTFileList";
public static final String OM_SLD_LAST_DEFRAG_TIME = "lastDefragTime";
public static final String OM_SLD_NEEDS_DEFRAGMENTATION = "needsDefragmentation";
public static final String OM_SLD_DEFRAGGED_SST_FILE_LIST = "defraggedSSTFileList";
public static final String OM_SLD_DB_CHECKPOINT_DIR = "dbCheckpointDir";

// YAML fields for .container files
public static final String CONTAINER_ID = "containerID";
Expand Down Expand Up @@ -509,6 +510,7 @@ public final class OzoneConsts {
public static final String OM_SNAPSHOT_DIR = "db.snapshots";
public static final String OM_SNAPSHOT_CHECKPOINT_DIR = OM_SNAPSHOT_DIR
+ OM_KEY_PREFIX + "checkpointState";
public static final String OM_SNAPSHOT_CHECKPOINT_DEFRAGED_DIR = "checkpointStateDefragged";
public static final String OM_SNAPSHOT_DIFF_DIR = OM_SNAPSHOT_DIR
+ OM_KEY_PREFIX + "diffState";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public RDBStore build() throws RocksDatabaseException {
ManagedWriteOptions writeOptions = new ManagedWriteOptions();
writeOptions.setSync(rocksDBConfiguration.getSyncOption());

// Disable WAL to reduce disk write, for testing only
writeOptions.setDisableWAL(true);

File dbFile = getDBFile();
if (!dbFile.getParentFile().exists()) {
throw new RocksDatabaseException("The DB destination directory should exist.");
Expand Down Expand Up @@ -399,6 +402,9 @@ private ManagedDBOptions getDefaultDBOptions(
// RocksDB log settings.
dbOptions.setMaxLogFileSize(rocksDBConfiguration.getMaxLogFileSize());
dbOptions.setKeepLogFileNum(rocksDBConfiguration.getKeepLogFileNum());
// Disable WAL archival (for more accurate RocksDB size measurements when there aren't too many keys)
rocksDBConfiguration.setWalTTL(0);
rocksDBConfiguration.setWalSizeLimit(0);

// Apply WAL settings.
dbOptions.setWalTtlSeconds(rocksDBConfiguration.getWalTTL());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
/**
* DumpFileWriter using rocksdb sst files.
*/
class RDBSstFileWriter implements Closeable {
public class RDBSstFileWriter implements Closeable {

private ManagedSstFileWriter sstFileWriter;
private File sstFile;
private AtomicLong keyCounter;
private ManagedOptions emptyOption = new ManagedOptions();
private final ManagedEnvOptions emptyEnvOptions = new ManagedEnvOptions();

RDBSstFileWriter(File externalFile) throws RocksDatabaseException {
public RDBSstFileWriter(File externalFile) throws RocksDatabaseException {
this.sstFileWriter = new ManagedSstFileWriter(emptyEnvOptions, emptyOption);
this.keyCounter = new AtomicLong(0);
this.sstFile = externalFile;
Expand All @@ -60,6 +60,17 @@ public void put(byte[] key, byte[] value) throws RocksDatabaseException {
}
}

public void delete(byte[] key) throws RocksDatabaseException {
try {
sstFileWriter.delete(key);
keyCounter.incrementAndGet();
} catch (RocksDBException e) {
closeOnFailure();
throw new RocksDatabaseException("Failed to delete key (length=" + key.length
+ "), sstFile=" + sstFile.getAbsolutePath(), e);
}
}

@Override
public void close() throws RocksDatabaseException {
if (sstFileWriter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public class RDBStore implements DBStore {
checkpointsParentDir = checkpointsParentDirPath.toString();
Files.createDirectories(checkpointsParentDirPath);

// TODO: scm, dn, etc. don't need this. Only om does
Path snapshotsParentDirPath =
Paths.get(dbLocation.getParent(), OM_SNAPSHOT_CHECKPOINT_DIR);
snapshotsParentDir = snapshotsParentDirPath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public boolean isClosed() {
*
* @see ManagedCheckpoint
*/
final class RocksCheckpoint implements Closeable {
public final class RocksCheckpoint implements Closeable {
private final ManagedCheckpoint checkpoint;

private RocksCheckpoint() {
Expand Down Expand Up @@ -599,7 +599,7 @@ public List<LiveFileMetaData> getLiveFilesMetaData() throws RocksDatabaseExcepti
}
}

RocksCheckpoint createCheckpoint() {
public RocksCheckpoint createCheckpoint() {
return new RocksCheckpoint();
}

Expand Down Expand Up @@ -650,7 +650,7 @@ public Collection<ColumnFamily> getExtraColumnFamilies() {
return Collections.unmodifiableCollection(columnFamilies.values());
}

byte[] get(ColumnFamily family, byte[] key) throws RocksDatabaseException {
public byte[] get(ColumnFamily family, byte[] key) throws RocksDatabaseException {
try (UncheckedAutoCloseable ignored = acquire()) {
return db.get().get(family.getHandle(), key);
} catch (RocksDBException e) {
Expand Down
4 changes: 0 additions & 4 deletions hadoop-hdds/rocks-native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,6 @@
<configuration>
<includes>
<include>**/*.class</include>
<include>**/lib*.dylib</include>
<include>**/lib*.so</include>
<include>**/lib*.jnilib</include>
<include>**/lib*.dll</include>
</includes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public synchronized boolean loadLibrary(final String libraryName, final List<Str
System.loadLibrary(libraryName);
loaded = true;
} catch (Throwable e) {

LOG.debug("Failed to load library {} using System.loadLibrary, " +
"trying to load from jar", libraryName, e);
}
if (!loaded) {
Pair<Optional<File>, List<File>> files = copyResourceFromJarToTemp(libraryName, dependentFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
UpdateRangerSubcommand.class,
TransferOmLeaderSubCommand.class,
FetchKeySubCommand.class,
LeaseSubCommand.class
LeaseSubCommand.class,
TriggerSnapshotDefragSubCommand.class
})
@MetaInfServices(AdminSubcommand.class)
public class OMAdmin implements AdminSubcommand {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.admin.om;

import java.util.concurrent.Callable;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import picocli.CommandLine;

/**
* Handler of ozone admin om triggerSnapshotDefrag command.
*/
@CommandLine.Command(
name = "triggerSnapshotDefrag",
description = "Triggers the Snapshot Defragmentation Service to run " +
"immediately. This command manually initiates the snapshot " +
"defragmentation process which compacts snapshot data and removes " +
"fragmentation to improve storage efficiency.",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class
)
public class TriggerSnapshotDefragSubCommand implements Callable<Void> {

@CommandLine.ParentCommand
private OMAdmin parent;

@CommandLine.Option(
names = {"-id", "--service-id"},
description = "Ozone Manager Service ID"
)
private String omServiceId;

@CommandLine.Option(
names = {"-host", "--service-host"},
description = "Ozone Manager Host"
)
private String omHost;

@CommandLine.Option(
names = {"--no-wait"},
description = "Do not wait for the defragmentation task to complete. " +
"The command will return immediately after triggering the task.",
defaultValue = "false"
)
private boolean noWait;

@Override
public Void call() throws Exception {
boolean forceHA = false;

try (OzoneManagerProtocol client = parent.createOmClient(omServiceId, omHost, forceHA)) {
System.out.println("Triggering Snapshot Defragmentation Service...");
boolean result = client.triggerSnapshotDefrag(noWait);

if (noWait) {
System.out.println("Snapshot defragmentation task has been triggered " +
"successfully and is running in the background.");
} else {
if (result) {
System.out.println("Snapshot defragmentation completed successfully.");
} else {
System.out.println("Snapshot defragmentation task failed or was " +
"interrupted.");
}
}
} catch (Exception e) {
System.err.println("Failed to trigger snapshot defragmentation: " +
e.getMessage());
throw e;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public static boolean isReadOnly(
// write to OM DB. And therefore it doesn't need a OMClientRequest.
// Although indirectly the Ranger sync service task could invoke write
// operation SetRangerServiceVersion.
case SnapshotDefrag:
case GetKeyInfo:
case SnapshotDiff:
case CancelSnapshotDiff:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,21 @@ public final class OMConfigKeys {
"ozone.snapshot.deleting.limit.per.task";
public static final int SNAPSHOT_DELETING_LIMIT_PER_TASK_DEFAULT = 10;

// Snapshot defragmentation service configuration
public static final String SNAPSHOT_DEFRAG_LIMIT_PER_TASK =
"ozone.snapshot.defrag.limit.per.task";
public static final int SNAPSHOT_DEFRAG_LIMIT_PER_TASK_DEFAULT = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: the interval can be set to 2 or 3 later


public static final String OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL =
"ozone.snapshot.filtering.service.interval";
public static final String
OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL_DEFAULT = "60s";

public static final String OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL =
"ozone.snapshot.defrag.service.interval";
public static final String
OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL_DEFAULT = "60s";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: May need to increase this interval if snapshotDiff is taking long.

Does interval countdown start only after the service run ends? I vaguely remember that is the case. Need to double check


public static final String
OZONE_SNAPSHOT_CHECKPOINT_DIR_CREATION_POLL_TIMEOUT =
"ozone.om.snapshot.checkpoint.dir.creation.poll.timeout";
Expand Down Expand Up @@ -558,13 +568,12 @@ public final class OMConfigKeys {

public static final String OZONE_OM_SNAPSHOT_DIFF_REPORT_MAX_PAGE_SIZE
= "ozone.om.snapshot.diff.max.page.size";
public static final int OZONE_OM_SNAPSHOT_DIFF_REPORT_MAX_PAGE_SIZE_DEFAULT = 1000;

public static final String OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES
= "ozone.om.snapshot.db.max.open.files";
public static final int OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES_DEFAULT
= 100;
public static final int OZONE_OM_SNAPSHOT_DIFF_REPORT_MAX_PAGE_SIZE_DEFAULT
= 1000;

public static final String OZONE_OM_SNAPSHOT_DIFF_THREAD_POOL_SIZE
= "ozone.om.snapshot.diff.thread.pool.size";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType.EC;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType.RATIS;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType.STAND_ALONE;

import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
Expand Down Expand Up @@ -59,6 +60,9 @@ public static long getReplicatedSize(
fullStripes * rc.getParity() * rc.getEcChunkSize()
+ partialFirstChunk * rc.getParity();
return dataSize + replicationOverhead;
} else if (repConfig.getReplicationType() == STAND_ALONE) {
// For replication type STAND_ALONE, the replicated size is the same as data size.
return dataSize;
} else {
LOG.warn("Unknown replication type '{}'. Returning original data size.",
repConfig.getReplicationType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,18 @@ ListOpenFilesResult listOpenFiles(String path, int maxKeys, String contToken)
*/
boolean triggerRangerBGSync(boolean noWait) throws IOException;

/**
* Triggers Snapshot Defragmentation Service immediately.
*
* Requires Ozone administrator privilege.
*
* @param noWait set to true if client won't wait for the result.
* @return true if noWait is true or when task completed successfully,
* false otherwise.
* @throws IOException OMException (e.g. PERMISSION_DENIED)
*/
boolean triggerSnapshotDefrag(boolean noWait) throws IOException;

/**
* Initiate metadata upgrade finalization.
* This method when called, initiates finalization of Ozone Manager metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetTimesRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotDefragRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotDefragResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotInfoRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.TenantAssignAdminRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.TenantAssignUserAccessIdRequest;
Expand Down Expand Up @@ -1926,6 +1928,22 @@ public boolean triggerRangerBGSync(boolean noWait) throws IOException {
return resp.getRunSuccess();
}

@Override
public boolean triggerSnapshotDefrag(boolean noWait) throws IOException {
SnapshotDefragRequest req = SnapshotDefragRequest.newBuilder()
.setNoWait(noWait)
.build();

OMRequest omRequest = createOMRequest(Type.SnapshotDefrag)
.setSnapshotDefragRequest(req)
.build();

SnapshotDefragResponse resp = handleError(submitRequest(omRequest))
.getSnapshotDefragResponse();

return resp.getRunSuccess();
}

@Override
public StatusAndMessages finalizeUpgrade(String upgradeClientID)
throws IOException {
Expand Down
19 changes: 19 additions & 0 deletions hadoop-ozone/dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<target>
<copy toDir="${project.build.directory}/ozone-${ozone.version}/share/ozone/lib">
<fileset dir="${project.basedir}/../../hadoop-hdds/rocks-native/target/classes" includes="**/lib*.*" />
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
Expand Down
Loading