Skip to content

Commit 9fc80a3

Browse files
swamirishixichen01
authored andcommitted
HDDS-10156. Optimize Snapshot Cache get and eviction (apache#6024)
(cherry picked from commit 3e97d8f)
1 parent bb4f066 commit 9fc80a3

10 files changed

Lines changed: 160 additions & 85 deletions

File tree

hadoop-hdds/common/src/main/resources/ozone-default.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4205,7 +4205,7 @@
42054205
</property>
42064206

42074207
<property>
4208-
<name>ozone.om.snapshot.diff.cleanup.service.run.internal</name>
4208+
<name>ozone.om.snapshot.diff.cleanup.service.run.interval</name>
42094209
<value>1m</value>
42104210
<tag>OZONE, OM</tag>
42114211
<description>
@@ -4224,6 +4224,16 @@
42244224
</description>
42254225
</property>
42264226

4227+
<property>
4228+
<name>ozone.om.snapshot.cache.cleanup.service.run.interval</name>
4229+
<value>1m</value>
4230+
<tag>OZONE, OM</tag>
4231+
<description>
4232+
Interval at which snapshot cache clean up will run.
4233+
Uses millisecond by default when no time unit is specified.
4234+
</description>
4235+
</property>
4236+
42274237
<property>
42284238
<name>ozone.om.snapshot.sst_dumptool.pool.size</name>
42294239
<value>1</value>

hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private void createSstBackUpDir() {
301301
}
302302

303303
@Override
304-
public void close() throws Exception {
304+
public void close() {
305305
if (!closed) {
306306
synchronized (this) {
307307
if (!closed) {

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,20 @@ private OMConfigKeys() {
579579
= TimeUnit.DAYS.toMillis(7);
580580

581581
public static final String OZONE_OM_SNAPSHOT_DIFF_CLEANUP_SERVICE_RUN_INTERVAL
582-
= "ozone.om.snapshot.diff.cleanup.service.run.internal";
582+
= "ozone.om.snapshot.diff.cleanup.service.run.interval";
583+
public static final String
584+
OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL
585+
= "ozone.om.snapshot.cache.cleanup.service.run.interval";
583586
public static final long
584587
OZONE_OM_SNAPSHOT_DIFF_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT
585588
= TimeUnit.MINUTES.toMillis(1);
589+
public static final long
590+
OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT
591+
= TimeUnit.MINUTES.toMillis(1);
586592

587593
public static final String OZONE_OM_SNAPSHOT_DIFF_CLEANUP_SERVICE_TIMEOUT
588594
= "ozone.om.snapshot.diff.cleanup.service.timeout";
595+
589596
public static final long
590597
OZONE_OM_SNAPSHOT_DIFF_CLEANUP_SERVICE_TIMEOUT_DEFAULT
591598
= TimeUnit.MINUTES.toMillis(5);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Arrays;
4848
import java.util.Collections;
4949
import java.util.List;
50+
import java.util.UUID;
5051
import java.util.stream.Collectors;
5152

5253
/**
@@ -74,6 +75,7 @@ public class OmSnapshot implements IOmMetadataReader, Closeable {
7475
private final String volumeName;
7576
private final String bucketName;
7677
private final String snapshotName;
78+
private final UUID snapshotID;
7779
// To access snapshot checkpoint DB metadata
7880
private final OMMetadataManager omMetadataManager;
7981
private final KeyManager keyManager;
@@ -83,7 +85,8 @@ public OmSnapshot(KeyManager keyManager,
8385
OzoneManager ozoneManager,
8486
String volumeName,
8587
String bucketName,
86-
String snapshotName) {
88+
String snapshotName,
89+
UUID snapshotID) {
8790
IAccessAuthorizer accessAuthorizer =
8891
OzoneAuthorizerFactory.forSnapshot(ozoneManager,
8992
keyManager, prefixManager);
@@ -93,6 +96,7 @@ public OmSnapshot(KeyManager keyManager,
9396
this.snapshotName = snapshotName;
9497
this.bucketName = bucketName;
9598
this.volumeName = volumeName;
99+
this.snapshotID = snapshotID;
96100
this.keyManager = keyManager;
97101
this.omMetadataManager = keyManager.getMetadataManager();
98102
}
@@ -295,6 +299,10 @@ public String getName() {
295299
return snapshotName;
296300
}
297301

302+
public UUID getSnapshotID() {
303+
return snapshotID;
304+
}
305+
298306
@Override
299307
public void close() throws IOException {
300308
// Close DB

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_CHECKPOINT_DIR;
8484
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_DIFF_DB_NAME;
8585
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
86+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL;
87+
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT;
8688
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE;
8789
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE_DEFAULT;
8890
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES;
@@ -272,7 +274,12 @@ public OmSnapshotManager(OzoneManager ozoneManager) {
272274
};
273275

274276
// Init snapshot cache
275-
this.snapshotCache = new SnapshotCache(loader, softCacheSize, ozoneManager.getMetrics());
277+
long cacheCleanupServiceInterval = ozoneManager.getConfiguration()
278+
.getTimeDuration(OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL,
279+
OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT,
280+
TimeUnit.MILLISECONDS);
281+
this.snapshotCache = new SnapshotCache(loader, softCacheSize, ozoneManager.getMetrics(),
282+
cacheCleanupServiceInterval);
276283

277284
this.snapshotDiffManager = new SnapshotDiffManager(snapshotDiffDb, differ,
278285
ozoneManager, snapDiffJobCf, snapDiffReportCf,
@@ -382,7 +389,8 @@ public OmSnapshot load(@Nonnull UUID snapshotId) throws IOException {
382389
return new OmSnapshot(km, pm, ozoneManager,
383390
snapshotInfo.getVolumeName(),
384391
snapshotInfo.getBucketName(),
385-
snapshotInfo.getName());
392+
snapshotInfo.getName(),
393+
snapshotInfo.getSnapshotId());
386394
} catch (Exception e) {
387395
// Close RocksDB if there is any failure.
388396
if (!snapshotMetadataManager.getStore().isClosed()) {
@@ -426,7 +434,7 @@ public void invalidateCache() {
426434
*
427435
* @param key SnapshotId.
428436
*/
429-
public void invalidateCacheEntry(UUID key) throws IOException {
437+
public void invalidateCacheEntry(UUID key) {
430438
if (snapshotCache != null) {
431439
snapshotCache.invalidate(key);
432440
}
@@ -949,7 +957,9 @@ public void close() {
949957
snapshotDiffManager.close();
950958
}
951959

952-
invalidateCache();
960+
if (snapshotCache != null) {
961+
snapshotCache.close();
962+
}
953963

954964
if (snapshotDiffCleanupService != null) {
955965
snapshotDiffCleanupService.shutdown();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public class ReferenceCounted<T>
5151
/**
5252
* Parent instance whose callback will be triggered upon this RC closure.
5353
*/
54-
private final Object parentWithCallback;
54+
private final ReferenceCountedCallback parentWithCallback;
5555

5656
public ReferenceCounted(T obj, boolean disableCounter,
57-
Object parentWithCallback) {
57+
ReferenceCountedCallback parentWithCallback) {
5858
// A param to allow disabling ref counting to reduce active DB
5959
// access penalties due to AtomicLong operations.
6060
this.obj = obj;
@@ -126,7 +126,9 @@ public long decrementRefCount() {
126126
Preconditions.checkState(newValTotal >= 0L,
127127
"Total reference count underflow");
128128
}
129-
129+
if (refCount.get() == 0) {
130+
this.parentWithCallback.callback(this);
131+
}
130132
return refCount.get();
131133
}
132134

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
package org.apache.hadoop.ozone.om.snapshot;
19+
20+
/**
21+
* Callback interface for ReferenceCounted.
22+
*/
23+
public interface ReferenceCountedCallback {
24+
void callback(ReferenceCounted referenceCounted);
25+
}

0 commit comments

Comments
 (0)