Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
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,15 @@ 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";
// TODO: Adjust timeout as needed.
// One concern would be that snapdiff can take a long time.
// If snapdiff wait time is included in the timeout it can make it indeterministic.
// -- So don't wait? Trigger and check later?
Comment thread
smengcl marked this conversation as resolved.

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 @@ -517,6 +517,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_DEFRAGGED_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 @@ -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 @@ -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 @@ -609,7 +609,7 @@ public List<LiveFileMetaData> getLiveFilesMetaData() throws RocksDatabaseExcepti
}
}

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

Expand Down Expand Up @@ -660,7 +660,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
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,22 @@ 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;

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 =
Comment thread
smengcl marked this conversation as resolved.
"ozone.snapshot.defrag.service.interval";
public static final String
OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL_DEFAULT = "-1";
// TODO: Disabled by default. Do not enable by default until upgrade handling is complete.
Comment thread
smengcl marked this conversation as resolved.

public static final String
OZONE_SNAPSHOT_CHECKPOINT_DIR_CREATION_POLL_TIMEOUT =
"ozone.om.snapshot.checkpoint.dir.creation.poll.timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ DeleteKeysResult getPendingDeletionSubFiles(long volumeId,
*/
SstFilteringService getSnapshotSstFilteringService();

/**
* Returns the instance of Snapshot Defrag service.
* @return Background service.
*/
SnapshotDefragService getSnapshotDefragService();

/**
* Returns the instance of Snapshot Deleting service.
* @return Background service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_TIMEOUT_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_TIMEOUT;
Expand Down Expand Up @@ -58,6 +60,8 @@
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_OPEN_KEY_CLEANUP_SERVICE_TIMEOUT_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_DEEP_CLEANING_ENABLED;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_DEEP_CLEANING_ENABLED_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_THREAD_NUMBER_DIR_DELETION;
Expand Down Expand Up @@ -200,6 +204,7 @@ public class KeyManagerImpl implements KeyManager {
private KeyDeletingService keyDeletingService;

private SstFilteringService snapshotSstFilteringService;
private SnapshotDefragService snapshotDefragService;
private SnapshotDeletingService snapshotDeletingService;

private final KeyProviderCryptoExtension kmsProvider;
Expand Down Expand Up @@ -308,6 +313,11 @@ public void start(OzoneConfiguration configuration) {
startSnapshotSstFilteringService(configuration);
}

if (snapshotDefragService == null &&
ozoneManager.isFilesystemSnapshotEnabled()) {
startSnapshotDefragService(configuration);
}

if (snapshotDeletingService == null &&
ozoneManager.isFilesystemSnapshotEnabled()) {

Expand Down Expand Up @@ -391,6 +401,42 @@ public void stopSnapshotSstFilteringService() {
}
}

/**
* Start the snapshot defrag service if interval is not set to disabled value.
* @param conf
*/
public void startSnapshotDefragService(OzoneConfiguration conf) {
if (isDefragSvcEnabled()) {
long serviceInterval = conf.getTimeDuration(
OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL,
OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL_DEFAULT,
TimeUnit.MILLISECONDS);
long serviceTimeout = conf.getTimeDuration(
OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT,
OZONE_SNAPSHOT_DEFRAG_SERVICE_TIMEOUT_DEFAULT,
TimeUnit.MILLISECONDS);

snapshotDefragService =
new SnapshotDefragService(serviceInterval, TimeUnit.MILLISECONDS,
serviceTimeout, ozoneManager, conf);
snapshotDefragService.start();
} else {
LOG.info("SnapshotDefragService is disabled. Snapshot defragmentation will not run periodically.");
}
}

/**
* Stop the snapshot defrag service if it is running.
*/
public void stopSnapshotDefragService() {
if (snapshotDefragService != null) {
snapshotDefragService.shutdown();
snapshotDefragService = null;
} else {
LOG.info("SnapshotDefragService is already stopped or not started.");
}
}

private void startCompactionService(OzoneConfiguration configuration,
boolean isCompactionServiceEnabled) {
if (compactionService == null && isCompactionServiceEnabled) {
Expand All @@ -417,7 +463,7 @@ KeyProviderCryptoExtension getKMSProvider() {
}

@Override
public void stop() throws IOException {
public void stop() {
if (keyDeletingService != null) {
keyDeletingService.shutdown();
keyDeletingService = null;
Expand All @@ -434,6 +480,10 @@ public void stop() throws IOException {
snapshotSstFilteringService.shutdown();
snapshotSstFilteringService = null;
}
if (snapshotDefragService != null) {
snapshotDefragService.shutdown();
snapshotDefragService = null;
}
if (snapshotDeletingService != null) {
snapshotDeletingService.shutdown();
snapshotDeletingService = null;
Expand All @@ -448,6 +498,15 @@ public void stop() throws IOException {
}
}

/**
* Get the SnapshotDefragService instance.
*
* @return SnapshotDefragService instance, or null if not initialized
*/
public SnapshotDefragService getSnapshotDefragService() {
return snapshotDefragService;
}

private OmBucketInfo getBucketInfo(String volumeName, String bucketName)
throws IOException {
String bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
Expand Down Expand Up @@ -968,7 +1027,16 @@ public boolean isSstFilteringSvcEnabled() {
// any interval <= 0 causes IllegalArgumentException from scheduleWithFixedDelay
return serviceInterval > 0;
}


public boolean isDefragSvcEnabled() {
long serviceInterval = ozoneManager.getConfiguration()
.getTimeDuration(OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL,
OZONE_SNAPSHOT_DEFRAG_SERVICE_INTERVAL_DEFAULT,
TimeUnit.MILLISECONDS);
// any interval <= 0 causes IllegalArgumentException from scheduleWithFixedDelay
Comment thread
smengcl marked this conversation as resolved.
return serviceInterval > 0;
}

@Override
public OmMultipartUploadList listMultipartUploads(String volumeName,
String bucketName,
Expand Down
Loading