Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-12134. Implement Snapshot Cache lock for OM Bootstrap #7745

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,16 @@
</description>
</property>

<property>
<name>ozone.om.snapshot.cache.lock.timeout</name>
<value>5s</value>
<tag>OZONE, OM</tag>
<description>
Wait Timeout for snapshot cache lock.
Uses milliseconds by default when no time unit is specified.
</description>
</property>

<property>
<name>ozone.om.snapshot.load.native.lib</name>
<value>true</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ private OMConfigKeys() {
public static final long
OZONE_OM_SNAPSHOT_DIFF_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT
= TimeUnit.MINUTES.toMillis(1);
public static final String
OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT
= "ozone.om.snapshot.cache.lock.timeout";
public static final long
OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT_DEFAULT
= TimeUnit.SECONDS.toMillis(5);
public static final long
OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT
= TimeUnit.MINUTES.toMillis(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES;
Expand Down Expand Up @@ -282,8 +284,12 @@ public OmSnapshotManager(OzoneManager ozoneManager) {
.getTimeDuration(OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL,
OZONE_OM_SNAPSHOT_CACHE_CLEANUP_SERVICE_RUN_INTERVAL_DEFAULT,
TimeUnit.MILLISECONDS);
long cacheLockTimeout = ozoneManager.getConfiguration()
.getTimeDuration(OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT,
OZONE_OM_SNAPSHOT_CACHE_LOCK_TIMEOUT_DEFAULT,
TimeUnit.MILLISECONDS);
this.snapshotCache = new SnapshotCache(loader, softCacheSize, ozoneManager.getMetrics(),
cacheCleanupServiceInterval);
cacheCleanupServiceInterval, cacheLockTimeout);

this.snapshotDiffManager = new SnapshotDiffManager(snapshotDiffDb, differ,
ozoneManager, snapDiffJobCf, snapDiffReportCf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.apache.hadoop.ozone.om.snapshot;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -51,10 +53,10 @@ public class ReferenceCounted<T>
/**
* Parent instance whose callback will be triggered upon this RC closure.
*/
private final ReferenceCountedCallback parentWithCallback;
private final ReferenceCountedCallback<T> parentWithCallback;

public ReferenceCounted(T obj, boolean disableCounter,
ReferenceCountedCallback parentWithCallback) {
ReferenceCountedCallback<T> parentWithCallback) {
// A param to allow disabling ref counting to reduce active DB
// access penalties due to AtomicLong operations.
this.obj = obj;
Expand Down Expand Up @@ -126,9 +128,7 @@ public long decrementRefCount() {
Preconditions.checkState(newValTotal >= 0L,
"Total reference count underflow");
}
if (refCount.get() == 0) {
this.parentWithCallback.callback(this);
}
this.parentWithCallback.callback(this);
return refCount.get();
}

Expand Down Expand Up @@ -161,4 +161,8 @@ public void close() {
// so it is eligible to be used with try-with-resources.
decrementRefCount();
}

public Map<Long, Long> getThreadCntMap() {
return ImmutableMap.copyOf(threadMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
/**
* Callback interface for ReferenceCounted.
*/
public interface ReferenceCountedCallback {
void callback(ReferenceCounted referenceCounted);
public interface ReferenceCountedCallback<T> {
void callback(ReferenceCounted<T> referenceCounted);
}
Loading
Loading