[indexes] extracted statistics access interface for BlobStorage

GitOrigin-RevId: c67e4d95318d0b9f7a0392d9b432da4240b2e57b
This commit is contained in:
Ruslan Cheremin
2024-05-26 10:17:05 +00:00
committed by intellij-monorepo-bot
parent be162e3010
commit 93ca4b74e2
2 changed files with 46 additions and 6 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.vfs.newvfs.persistent.dev.blobstorage;
import com.intellij.openapi.util.IntRef;
@@ -8,10 +8,7 @@ import com.intellij.platform.diagnostic.telemetry.TelemetryManager;
import com.intellij.util.io.ClosedStorageException;
import com.intellij.util.io.CorruptedException;
import com.intellij.util.io.IOUtil;
import com.intellij.util.io.blobstorage.ByteBufferReader;
import com.intellij.util.io.blobstorage.ByteBufferWriter;
import com.intellij.util.io.blobstorage.SpaceAllocationStrategy;
import com.intellij.util.io.blobstorage.StreamlinedBlobStorage;
import com.intellij.util.io.blobstorage.*;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.BatchCallback;
import io.opentelemetry.api.metrics.Meter;
@@ -39,7 +36,7 @@ import static com.intellij.platform.diagnostic.telemetry.PlatformScopesKt.Storag
* of responsibilities -- i.e. extracting all storage-specific functionality under common interface,
* and implement adapters for different storages.
*/
public abstract class StreamlinedBlobStorageHelper implements StreamlinedBlobStorage {
public abstract class StreamlinedBlobStorageHelper implements StreamlinedBlobStorage, BlobStorageStatistics {
/** First header int32, used to recognize this storage's file type */
protected static final int MAGIC_WORD = IOUtil.asciiToMagicWord("SBlS");
@@ -260,22 +257,27 @@ public abstract class StreamlinedBlobStorageHelper implements StreamlinedBlobSto
return recordsAllocated.get() - recordsDeleted.get() - recordsRelocated.get();
}
@Override
public int recordsAllocated() {
return recordsAllocated.get();
}
@Override
public int recordsRelocated() {
return recordsRelocated.get();
}
@Override
public int recordsDeleted() {
return recordsDeleted.get();
}
@Override
public long totalLiveRecordsPayloadBytes() {
return totalLiveRecordsPayloadBytes.get();
}
@Override
public long totalLiveRecordsCapacityBytes() {
return totalLiveRecordsCapacityBytes.get();
}
@@ -0,0 +1,38 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.io.blobstorage;
import org.jetbrains.annotations.ApiStatus;
/**
* Provides access to storage internal statistics.
* If storage provides access to such a statistics -- it must implement this interface
*/
@ApiStatus.Internal
public interface BlobStorageStatistics {
/** records currently alive (=allocated-relocated-deleted) */
int liveRecordsCount();
/** records allocated since storage creation (including deleted/relocated) */
int recordsAllocated();
/** records re-allocated -- i.e. recordId is accessible, but the access redirects to another (actual) record */
int recordsRelocated();
/** records deleted, i.e. un-accessible anymore */
int recordsDeleted();
/**
* Total size (bytes) occupied by storage data.
* Includes all the overhead of file/records header, alignment, etc.
* Could be <= file size, if e.g. file is expanded in advance.
*/
long sizeInBytes();
/** Total size of all alive records' payload, i.e. 'useful size', without any overhead */
long totalLiveRecordsPayloadBytes();
/** Total size of all alive records' capacity */
long totalLiveRecordsCapacityBytes();
}