Skip to content

Commit 04c89da

Browse files
committed
[metrics] Fix pendingRecords metric to return actual row count for primary key tables when lake tiering hasn't started
1 parent 0fccd3c commit 04c89da

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

fluss-common/src/main/java/org/apache/fluss/metrics/MetricNames.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ public class MetricNames {
222222
// metrics for table bucket
223223
// --------------------------------------------------------------------------------------------
224224

225+
// for tablet
226+
public static final String LAKE_PENDING_RECORDS = "pendingRecords";
227+
225228
// for log tablet
226229
public static final String LOG_NUM_SEGMENTS = "numSegments";
227230
public static final String LOG_END_OFFSET = "endOffset";
228231
public static final String REMOTE_LOG_SIZE = "size";
229-
public static final String LOG_LAKE_PENDING_RECORDS = "pendingRecords";
230232
public static final String LOG_LAKE_TIMESTAMP_LAG = "timestampLag";
231233

232234
// for logic storage

fluss-server/src/main/java/org/apache/fluss/server/replica/Replica.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.fluss.config.TableConfig;
2424
import org.apache.fluss.exception.FencedLeaderEpochException;
2525
import org.apache.fluss.exception.InvalidColumnProjectionException;
26+
import org.apache.fluss.exception.InvalidTableException;
2627
import org.apache.fluss.exception.InvalidTimestampException;
2728
import org.apache.fluss.exception.InvalidUpdateVersionException;
2829
import org.apache.fluss.exception.KvStorageException;
@@ -549,11 +550,20 @@ private void onBecomeNewLeader() {
549550
private void registerLakeTieringMetrics() {
550551
lakeTieringMetricGroup = bucketMetricGroup.addGroup("lakeTiering");
551552
lakeTieringMetricGroup.gauge(
552-
MetricNames.LOG_LAKE_PENDING_RECORDS,
553-
() ->
554-
getLakeLogEndOffset() < 0L
555-
? getLogHighWatermark() - getLogStartOffset()
556-
: getLogHighWatermark() - getLakeLogEndOffset());
553+
MetricNames.LAKE_PENDING_RECORDS,
554+
() -> {
555+
long lakeLogEndOffset = getLakeLogEndOffset();
556+
if (lakeLogEndOffset < 0L) {
557+
try {
558+
return getRowCount();
559+
} catch (InvalidTableException e) {
560+
// WAL mode or v0.9 old table: row count disabled,
561+
// fall back to log-level pending count
562+
return getLogHighWatermark() - getLogStartOffset();
563+
}
564+
}
565+
return getLogHighWatermark() - lakeLogEndOffset;
566+
});
557567
lakeTieringMetricGroup.gauge(
558568
MetricNames.LOG_LAKE_TIMESTAMP_LAG,
559569
() ->

website/docs/maintenance/observability/monitor-metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ Some metrics might not be exposed when using other JVM implementations (e.g. IBM
855855
</tr>
856856
<tr>
857857
<td>timestampLag</td>
858-
<td>The timestamp lag between local log and remote log for this table bucket in milliseconds.</td>
858+
<td>The timestamp lag between the latest log record and the latest record already tiered to the lake for this table bucket, in milliseconds.</td>
859859
<td>Gauge</td>
860860
</tr>
861861
<tr>

0 commit comments

Comments
 (0)