Skip to content

Commit

Permalink
add stats for rocksdb getLastEntryInLedger (#4529)
Browse files Browse the repository at this point in the history
Co-authored-by: fanjianye <[email protected]>
  • Loading branch information
TakaHiR07 and fanjianye authored Feb 14, 2025
1 parent a3e3668 commit b71446f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,16 @@ public long getLastEntryInLedger(long ledgerId) throws IOException {
private long getLastEntryInLedgerInternal(long ledgerId) throws IOException {
LongPairWrapper maxEntryId = LongPairWrapper.get(ledgerId, Long.MAX_VALUE);

long startTimeNanos = MathUtils.nowInNano();
// Search the last entry in storage
Entry<byte[], byte[]> entry = locationsDb.getFloor(maxEntryId.array);
if (entry != null) {
stats.getGetLastEntryInLedgerStats()
.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
} else {
stats.getGetLastEntryInLedgerStats()
.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
}
maxEntryId.recycle();

if (entry == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class EntryLocationIndexStats {

private static final String ENTRIES_COUNT = "entries-count";
private static final String LOOKUP_ENTRY_LOCATION = "lookup-entry-location";
private static final String GET_LAST_ENTRY_IN_LEDGER = "get-last-entry-in-ledger";

@StatsDoc(
name = ENTRIES_COUNT,
Expand All @@ -55,6 +56,12 @@ class EntryLocationIndexStats {
)
private final OpStatsLogger lookupEntryLocationStats;

@StatsDoc(
name = GET_LAST_ENTRY_IN_LEDGER,
help = "operation stats of get last entry in ledger"
)
private final OpStatsLogger getLastEntryInLedgerStats;

EntryLocationIndexStats(StatsLogger statsLogger,
Supplier<Long> entriesCountSupplier) {
entriesCountGauge = new Gauge<Long>() {
Expand All @@ -70,6 +77,7 @@ public Long getSample() {
};
statsLogger.registerGauge(ENTRIES_COUNT, entriesCountGauge);
lookupEntryLocationStats = statsLogger.getOpStatsLogger(LOOKUP_ENTRY_LOCATION);
getLastEntryInLedgerStats = statsLogger.getOpStatsLogger(GET_LAST_ENTRY_IN_LEDGER);
}

}

0 comments on commit b71446f

Please sign in to comment.