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-10206. Expose jmx metrics for snapshot cache size on the ozone manager. #6138

Merged
merged 15 commits into from
Apr 5, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hadoop.metrics2.annotation.Metric;
import org.apache.hadoop.metrics2.annotation.Metrics;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.lib.MutableCounterInt;
import org.apache.hadoop.metrics2.lib.MutableCounterLong;

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ public class OMMetrics implements OmMetadataReaderMetrics {
private @Metric MutableCounterLong numSnapshotLists;
private @Metric MutableCounterLong numSnapshotDiffJobs;
private @Metric MutableCounterLong numSnapshotInfos;

private @Metric MutableCounterInt numSnapshotCacheSize;
private @Metric MutableCounterLong numGetFileStatus;
private @Metric MutableCounterLong numCreateDirectory;
private @Metric MutableCounterLong numCreateFile;
Expand Down Expand Up @@ -520,6 +521,19 @@ public void decNumSnapshotDeleted() {
numSnapshotDeleted.incr(-1);
}

public void setNumSnapshotCacheSize(int num) {
int curVal = numSnapshotCacheSize.value();
numSnapshotCacheSize.incr(num - curVal);
ceekay47 marked this conversation as resolved.
Show resolved Hide resolved
}

public void incNumSnapshotCacheSize() {
numSnapshotCacheSize.incr();
ceekay47 marked this conversation as resolved.
Show resolved Hide resolved
}

public void decNumSnapshotCacheSize() {
numSnapshotCacheSize.incr(-1);
ceekay47 marked this conversation as resolved.
Show resolved Hide resolved
}

public void incNumCompleteMultipartUploadFails() {
numCompleteMultipartUploadFails.incr();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ public int getSnapshotCacheSize() {
public void invalidateCache() {
if (snapshotCache != null) {
snapshotCache.invalidateAll();
updateSnapshotCacheSizeMetric();
}
}

Expand All @@ -429,6 +430,7 @@ public void invalidateCache() {
public void invalidateCacheEntry(UUID key) throws IOException {
if (snapshotCache != null) {
snapshotCache.invalidate(key);
updateSnapshotCacheSizeMetric();
}
}

Expand Down Expand Up @@ -679,7 +681,9 @@ private ReferenceCounted<OmSnapshot> getSnapshot(String snapshotTableKey, boolea
}

// retrieve the snapshot from the cache
return snapshotCache.get(snapshotInfo.getSnapshotId());
ReferenceCounted<OmSnapshot> snapshot = snapshotCache.get(snapshotInfo.getSnapshotId());
updateSnapshotCacheSizeMetric();
return snapshot;
}

/**
Expand Down Expand Up @@ -977,4 +981,11 @@ public void close() {
public long getDiffCleanupServiceInterval() {
return diffCleanupServiceInterval;
}

/**
* Updates the SnapshotCache size jmx metric.
*/
public void updateSnapshotCacheSizeMetric() {
this.ozoneManager.getMetrics().setNumSnapshotCacheSize(getSnapshotCacheSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ private void instantiateServices(boolean withNewSnapshot) throws IOException {
omSnapshotManager = new OmSnapshotManager(this);

// Snapshot metrics
metrics.setNumSnapshotCacheSize(omSnapshotManager.getSnapshotCacheSize());
ceekay47 marked this conversation as resolved.
Show resolved Hide resolved
updateActiveSnapshotMetrics();

if (withNewSnapshot) {
Expand Down Expand Up @@ -1801,7 +1802,6 @@ private void updateActiveSnapshotMetrics()
}
}
}

ceekay47 marked this conversation as resolved.
Show resolved Hide resolved
metrics.setNumSnapshotActive(activeGauge);
metrics.setNumSnapshotDeleted(deletedGauge);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public ReferenceCounted<OmSnapshot> get(UUID key) throws IOException {
}
return v;
});

if (rcOmSnapshot == null) {
// The only exception that would fall through the loader logic above
// is OMException with FILE_NOT_FOUND.
Expand Down