Skip to content

Commit eef214d

Browse files
morningmanCalvinKirsclaude
committed
[improvement](fe) Add the branch-4.x weight budget columns to catalog_meta_cache_statistics
### What problem does this PR solve? Issue Number: None Related PR: #66717, #67726 Problem Summary: branch-4.x (#66717) shows ten memory-weight columns in information_schema.catalog_meta_cache_statistics. Master (#67726) has only MAX_WEIGHT, ESTIMATED_WEIGHT, WEIGHT_REJECT_COUNT and LAST_WEIGHT_REJECT_REASON, so monitoring queries written for 4.x, and the weight scenarios of 4.x's own regression suites, fail on master with unknown columns: WEIGHT_BOUNDED, EVICTION_WEIGHT, CATALOG_MAX_WEIGHT, CATALOG_ESTIMATED_WEIGHT, GLOBAL_MAX_WEIGHT and GLOBAL_ESTIMATED_WEIGHT. For an entry without a weight bound master also reports ESTIMATED_WEIGHT and WEIGHT_REJECT_COUNT as 0, where 4.x reports -1. The six columns are appended after LAST_WEIGHT_REJECT_REASON with the 4.x names, types and meanings: whether the entry is weight bounded; the bytes of the values removed by eviction, by Caffeine or to make room in the budget; the catalog limit the entry is admitted under (the smaller of the catalog and FE-global limits) and the bytes charged to its catalog; the FE-global limit and the bytes charged to it. A limit that does not exist is -1, and an entry without a weight bound reports -1 in every weight column, as on 4.x. The BE scanner asks an older FE that rejects the new columns for the leading 28, then 24 columns. SELECT * positions still differ from 4.x, whose base columns lack EVICTION_RATE; queries by column name now work on both. ### Release note information_schema.catalog_meta_cache_statistics adds the columns WEIGHT_BOUNDED, EVICTION_WEIGHT, CATALOG_MAX_WEIGHT, CATALOG_ESTIMATED_WEIGHT, GLOBAL_MAX_WEIGHT and GLOBAL_ESTIMATED_WEIGHT. A cache entry without a weight bound now reports -1 instead of 0 in ESTIMATED_WEIGHT and WEIGHT_REJECT_COUNT. ### Check List (For Author) - Test: Regression test / Unit Test - MetaCacheWeightGovernanceTest, FeMetaCacheEntryTest, HudiConnectorHmsCacheTest - test_paimon_table_meta_cache and test_remote_doris_meta_cache_weight, run against a local cluster; test_iceberg_table_meta_cache needs the hive3 environment and was not run locally - Manual: a new BE against an FE without the six columns falls back to the leading 28 - Behavior changed: Yes. A cache entry without a weight bound reports -1 instead of 0 in ESTIMATED_WEIGHT and WEIGHT_REJECT_COUNT. Upgrade BE before FE: an older BE cannot fill the six new columns. - Does this need documentation: Yes. The catalog_meta_cache_statistics page should list the six columns (doc PR to follow). Co-authored-by: Calvin Kirs <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1bb3537 commit eef214d

14 files changed

Lines changed: 471 additions & 10 deletions

File tree

‎be/src/information_schema/schema_catalog_meta_cache_stats_scanner.cpp‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "information_schema/schema_catalog_meta_cache_stats_scanner.h"
1919

20+
#include <algorithm>
21+
#include <array>
22+
2023
#include "core/block/block.h"
2124
#include "core/data_type/data_type_factory.hpp"
2225
#include "core/string_ref.h"
@@ -57,9 +60,17 @@ std::vector<SchemaScanner::ColumnDesc> SchemaCatalogMetaCacheStatsScanner::_s_tb
5760
{"ESTIMATED_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
5861
{"WEIGHT_REJECT_COUNT", TYPE_BIGINT, sizeof(int64_t), true},
5962
{"LAST_WEIGHT_REJECT_REASON", TYPE_STRING, sizeof(StringRef), true},
63+
{"WEIGHT_BOUNDED", TYPE_BOOLEAN, sizeof(bool), true},
64+
{"EVICTION_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
65+
{"CATALOG_MAX_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
66+
{"CATALOG_ESTIMATED_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
67+
{"GLOBAL_MAX_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
68+
{"GLOBAL_ESTIMATED_WEIGHT", TYPE_BIGINT, sizeof(int64_t), true},
6069
};
6170

62-
static constexpr size_t kLegacyMetaCacheStatsColumnCount = 24;
71+
// The leading columns that older FE versions know, newest first: the first weight columns came before the
72+
// budget hierarchy columns, and the base columns before any weight column.
73+
static constexpr std::array<size_t, 2> kOlderFeMetaCacheStatsColumnCounts = {28, 24};
6374

6475
SchemaCatalogMetaCacheStatsScanner::SchemaCatalogMetaCacheStatsScanner()
6576
: SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_CATALOG_META_CACHE_STATISTICS) {}
@@ -111,8 +122,13 @@ Status SchemaCatalogMetaCacheStatsScanner::_get_meta_cache_from_fe() {
111122
return status;
112123
}
113124
Status first_status = status;
114-
result = TFetchSchemaTableDataResult();
115-
status = _fetch_from_fe(kLegacyMetaCacheStatsColumnCount, &result, &fe_rejected);
125+
for (size_t column_count : kOlderFeMetaCacheStatsColumnCounts) {
126+
result = TFetchSchemaTableDataResult();
127+
status = _fetch_from_fe(column_count, &result, &fe_rejected);
128+
if (status.ok() || !fe_rejected) {
129+
break;
130+
}
131+
}
116132
if (!status.ok()) {
117133
LOG(WARNING) << "fetch catalog meta cache stats from FE(" << _fe_addr.hostname
118134
<< ") failed, errmsg=" << first_status;
@@ -134,7 +150,10 @@ Status SchemaCatalogMetaCacheStatsScanner::_get_meta_cache_from_fe() {
134150
size_t col_size = _s_tbls_columns.size();
135151
if (!result_data.empty()) {
136152
col_size = result_data[0].column_value.size();
137-
if (col_size != _s_tbls_columns.size() && col_size != kLegacyMetaCacheStatsColumnCount) {
153+
if (col_size != _s_tbls_columns.size() &&
154+
std::find(kOlderFeMetaCacheStatsColumnCounts.begin(),
155+
kOlderFeMetaCacheStatsColumnCounts.end(),
156+
col_size) == kOlderFeMetaCacheStatsColumnCounts.end()) {
138157
return Status::InternalError<false>(
139158
"catalog meta cache stats schema is not match for FE and BE");
140159
}

‎fe/fe-connector/fe-connector-cache/src/main/java/org/apache/doris/connector/cache/MetaCacheBudgetManager.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,26 @@ public long getUsedWeight() {
530530
}
531531
}
532532

533+
/** The catalog limit this entry is admitted under: the smaller of the catalog and FE-global limits, or -1. */
534+
public long getCatalogMaxWeight() {
535+
return catalogBucket.maxWeight == Long.MAX_VALUE ? -1L : catalogBucket.maxWeight;
536+
}
537+
538+
public long getCatalogUsedWeight() {
539+
synchronized (manager.lock) {
540+
return catalogBucket.usedWeight;
541+
}
542+
}
543+
544+
/** The FE-global limit; -1 if none. */
545+
public long getGlobalMaxWeight() {
546+
return manager.globalMaxWeight.orElse(-1L);
547+
}
548+
549+
public long getGlobalUsedWeight() {
550+
return manager.getGlobalUsedWeight();
551+
}
552+
533553
@Override
534554
public void close() {
535555
manager.close(this);

‎fe/fe-connector/fe-connector-cache/src/main/java/org/apache/doris/connector/cache/ScopedMetaCache.java‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public final class ScopedMetaCache<K, V> implements AutoCloseable {
9191
private final LongAdder loadFailureCount = new LongAdder();
9292
private final LongAdder totalLoadTimeNanos = new LongAdder();
9393
private final LongAdder evictionCount = new LongAdder();
94+
private final AtomicLong evictionWeight = new AtomicLong();
9495
private final LongAdder invalidateCount = new LongAdder();
9596
private final AtomicReference<Long> lastLoadSuccessTimeMs = new AtomicReference<>(-1L);
9697
private final AtomicReference<Long> lastLoadFailureTimeMs = new AtomicReference<>(-1L);
@@ -576,8 +577,13 @@ public CacheMetrics metrics() {
576577
lastError.get(),
577578
weightBounded,
578579
entryBudget == null ? -1L : entryBudget.getEffectiveMaxWeight(),
579-
entryBudget == null ? 0L : entryBudget.getUsedWeight(),
580-
weightRejectCount.sum(),
580+
entryBudget == null ? -1L : entryBudget.getUsedWeight(),
581+
entryBudget == null ? -1L : evictionWeight.get(),
582+
entryBudget == null ? -1L : weightRejectCount.sum(),
583+
entryBudget == null ? -1L : entryBudget.getCatalogMaxWeight(),
584+
entryBudget == null ? -1L : entryBudget.getCatalogUsedWeight(),
585+
entryBudget == null ? -1L : entryBudget.getGlobalMaxWeight(),
586+
entryBudget == null ? -1L : entryBudget.getGlobalUsedWeight(),
581587
lastWeightRejectReason.get()));
582588
}
583589

@@ -1144,6 +1150,11 @@ private void completeRemoval(
11441150
VersionedValue<K, V> versioned, RemovalCause cause, boolean budgetEviction) {
11451151
if (cause.wasEvicted() || budgetEviction) {
11461152
evictionCount.increment();
1153+
if (weightBounded) {
1154+
// Every value of a bounded cache holds a reservation; it is released below.
1155+
evictionWeight.accumulateAndGet(
1156+
versioned.registration.reservation.getBytes(), JvmSizeUtils::saturatedAdd);
1157+
}
11471158
} else if (cause == RemovalCause.EXPLICIT) {
11481159
invalidateCount.increment();
11491160
}
@@ -1298,7 +1309,12 @@ public static final class CacheMetrics {
12981309
private final boolean weightBounded;
12991310
private final long maxWeight;
13001311
private final long estimatedWeight;
1312+
private final long evictionWeight;
13011313
private final long weightRejectCount;
1314+
private final long catalogMaxWeight;
1315+
private final long catalogEstimatedWeight;
1316+
private final long globalMaxWeight;
1317+
private final long globalEstimatedWeight;
13021318
private final String lastWeightRejectReason;
13031319

13041320
private CacheMetrics(
@@ -1322,7 +1338,12 @@ private CacheMetrics(
13221338
boolean weightBounded,
13231339
long maxWeight,
13241340
long estimatedWeight,
1341+
long evictionWeight,
13251342
long weightRejectCount,
1343+
long catalogMaxWeight,
1344+
long catalogEstimatedWeight,
1345+
long globalMaxWeight,
1346+
long globalEstimatedWeight,
13261347
String lastWeightRejectReason) {
13271348
this.physicalEntryCount = physicalEntryCount;
13281349
this.keyNodeCount = keyNodeCount;
@@ -1344,7 +1365,12 @@ private CacheMetrics(
13441365
this.weightBounded = weightBounded;
13451366
this.maxWeight = maxWeight;
13461367
this.estimatedWeight = estimatedWeight;
1368+
this.evictionWeight = evictionWeight;
13471369
this.weightRejectCount = weightRejectCount;
1370+
this.catalogMaxWeight = catalogMaxWeight;
1371+
this.catalogEstimatedWeight = catalogEstimatedWeight;
1372+
this.globalMaxWeight = globalMaxWeight;
1373+
this.globalEstimatedWeight = globalEstimatedWeight;
13481374
this.lastWeightRejectReason = lastWeightRejectReason;
13491375
}
13501376

@@ -1428,10 +1454,31 @@ public long getEstimatedWeight() {
14281454
return estimatedWeight;
14291455
}
14301456

1457+
/** Bytes of the values removed by eviction, by Caffeine or to make room in the budget; -1 if unbounded. */
1458+
public long getEvictionWeight() {
1459+
return evictionWeight;
1460+
}
1461+
14311462
public long getWeightRejectCount() {
14321463
return weightRejectCount;
14331464
}
14341465

1466+
public long getCatalogMaxWeight() {
1467+
return catalogMaxWeight;
1468+
}
1469+
1470+
public long getCatalogEstimatedWeight() {
1471+
return catalogEstimatedWeight;
1472+
}
1473+
1474+
public long getGlobalMaxWeight() {
1475+
return globalMaxWeight;
1476+
}
1477+
1478+
public long getGlobalEstimatedWeight() {
1479+
return globalEstimatedWeight;
1480+
}
1481+
14351482
public String getLastWeightRejectReason() {
14361483
return lastWeightRejectReason;
14371484
}

‎fe/fe-connector/fe-connector-cache/src/test/java/org/apache/doris/connector/cache/MetaCacheWeightGovernanceTest.java‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,76 @@ void budgetPressureReclaimsOneColdEntryBeforeTheNextAdmission() {
243243
Assertions.assertEquals(2048L, entry.metrics().getEstimatedWeight());
244244
Assertions.assertEquals(1L, entry.metrics().getWeightRejectCount());
245245
Assertions.assertEquals(1L, entry.metrics().getEvictionCount());
246+
// The value reclaimed for the budget counts with the reservation it held.
247+
Assertions.assertEquals(1024L, entry.metrics().getEvictionWeight());
248+
}
249+
}
250+
251+
@Test
252+
void capacityEvictionCountsTheEvictedReservationButInvalidationDoesNot() {
253+
MetaCacheBudgetManager manager = new MetaCacheBudgetManager(OptionalLong.of(4096L));
254+
try (CatalogMetaCache owner = new CatalogMetaCache(
255+
manager, 25L, "iceberg", Collections.emptyMap())) {
256+
MetaCache<String, String> entry = owner.create(MetaCacheDefinition
257+
.<String, String>builder("table", CacheSpec.of(true, -1L, 1L),
258+
ignored -> ScopePath.catalog())
259+
.sizeEstimator((key, value) -> MetaCacheSizeEstimate.complete(256L))
260+
.build());
261+
262+
entry.put("one", "value");
263+
entry.put("two", "value");
264+
awaitReclaimed(entry, 1L, ENTRY_OVERHEAD + 256L);
265+
Assertions.assertEquals(1L, entry.metrics().getEvictionCount());
266+
Assertions.assertEquals(ENTRY_OVERHEAD + 256L, entry.metrics().getEvictionWeight());
267+
268+
// Either key may be the one that was evicted; invalidating the survivor is not an eviction.
269+
entry.invalidateKey("one");
270+
entry.invalidateKey("two");
271+
Assertions.assertEquals(0L, entry.metrics().getEstimatedWeight());
272+
Assertions.assertEquals(ENTRY_OVERHEAD + 256L, entry.metrics().getEvictionWeight());
273+
}
274+
}
275+
276+
@Test
277+
void weightMetricsReportTheCatalogAndGlobalBudgetsOfTheEntry() {
278+
MetaCacheBudgetManager manager = new MetaCacheBudgetManager(OptionalLong.of(8192L));
279+
try (CatalogMetaCache owner = new CatalogMetaCache(manager, 26L, "paimon",
280+
Collections.singletonMap(MetaCacheBudgetManager.CATALOG_MAX_WEIGHT_PROPERTY, "4096"));
281+
CatalogMetaCache unlimitedCatalog = new CatalogMetaCache(
282+
manager, 27L, "paimon", Collections.emptyMap())) {
283+
MetaCache<String, String> table = weightedStringEntry(owner, "table", 512L);
284+
MetaCache<String, String> snapshot = weightedStringEntry(owner, "snapshot", 256L);
285+
MetaCache<String, String> other = weightedStringEntry(unlimitedCatalog, "table", 512L);
286+
table.put("t", "value");
287+
snapshot.put("s", "value");
288+
other.put("o", "value");
289+
290+
ScopedMetaCache.CacheMetrics metrics = table.metrics();
291+
Assertions.assertTrue(metrics.isWeightBounded());
292+
Assertions.assertEquals(4096L, metrics.getMaxWeight());
293+
Assertions.assertEquals(1024L, metrics.getEstimatedWeight());
294+
Assertions.assertEquals(0L, metrics.getEvictionWeight());
295+
Assertions.assertEquals(4096L, metrics.getCatalogMaxWeight());
296+
Assertions.assertEquals(1024L + 768L, metrics.getCatalogEstimatedWeight());
297+
Assertions.assertEquals(8192L, metrics.getGlobalMaxWeight());
298+
Assertions.assertEquals(1024L + 768L + 1024L, metrics.getGlobalEstimatedWeight());
299+
// Without a catalog limit, the catalog level is bounded by the FE-global one.
300+
Assertions.assertEquals(8192L, other.metrics().getCatalogMaxWeight());
301+
Assertions.assertEquals(1024L, other.metrics().getCatalogEstimatedWeight());
302+
}
303+
}
304+
305+
@Test
306+
void weightMetricsHaveNoGlobalMaximumWithoutAGlobalLimit() {
307+
MetaCacheBudgetManager manager = new MetaCacheBudgetManager(OptionalLong.empty());
308+
try (CatalogMetaCache owner = new CatalogMetaCache(manager, 28L, "iceberg",
309+
Collections.singletonMap(MetaCacheBudgetManager.CATALOG_MAX_WEIGHT_PROPERTY, "4096"))) {
310+
MetaCache<String, String> entry = weightedStringEntry(owner, "table", 512L);
311+
entry.put("key", "value");
312+
313+
Assertions.assertEquals(4096L, entry.metrics().getCatalogMaxWeight());
314+
Assertions.assertEquals(-1L, entry.metrics().getGlobalMaxWeight());
315+
Assertions.assertEquals(1024L, entry.metrics().getGlobalEstimatedWeight());
246316
}
247317
}
248318

@@ -329,6 +399,17 @@ void estimatorIsNotInvokedWhenNoWeightLimitIsConfigured() {
329399
Assertions.assertEquals("value", entry.getIfPresent("key"));
330400
Assertions.assertFalse(entry.isWeightBounded());
331401
Assertions.assertEquals(0, estimates.get());
402+
// An entry without a weight limit has no weight to report.
403+
ScopedMetaCache.CacheMetrics metrics = entry.metrics();
404+
Assertions.assertFalse(metrics.isWeightBounded());
405+
Assertions.assertEquals(-1L, metrics.getMaxWeight());
406+
Assertions.assertEquals(-1L, metrics.getEstimatedWeight());
407+
Assertions.assertEquals(-1L, metrics.getEvictionWeight());
408+
Assertions.assertEquals(-1L, metrics.getWeightRejectCount());
409+
Assertions.assertEquals(-1L, metrics.getCatalogMaxWeight());
410+
Assertions.assertEquals(-1L, metrics.getCatalogEstimatedWeight());
411+
Assertions.assertEquals(-1L, metrics.getGlobalMaxWeight());
412+
Assertions.assertEquals(-1L, metrics.getGlobalEstimatedWeight());
332413
}
333414
}
334415

‎fe/fe-connector/fe-connector-hudi/src/test/java/org/apache/doris/connector/hudi/HudiConnectorHmsCacheTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ void noWeightLimitPreservesCountBasedCaching() {
130130
cache.listPartitionNames("db", "t", -1);
131131
cache.listPartitionNames("db", "t", -1);
132132
Assertions.assertEquals(1, delegate.cachedCalls);
133-
Assertions.assertEquals(0L, entry.metrics().getEstimatedWeight());
133+
// An entry without a weight limit has no weight to report.
134+
Assertions.assertEquals(-1L, entry.metrics().getEstimatedWeight());
134135
}
135136

136137
// ── wrap ─────────────────────────────────────────────────────────────────────────────────────────────

‎fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,14 @@ public class SchemaTable extends Table {
660660
.column("ESTIMATED_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
661661
.column("WEIGHT_REJECT_COUNT", ScalarType.createType(PrimitiveType.BIGINT))
662662
.column("LAST_WEIGHT_REJECT_REASON", ScalarType.createStringType())
663+
// Appended last: the BE scanner falls back to asking an older FE for only the
664+
// leading columns.
665+
.column("WEIGHT_BOUNDED", ScalarType.createType(PrimitiveType.BOOLEAN))
666+
.column("EVICTION_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
667+
.column("CATALOG_MAX_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
668+
.column("CATALOG_ESTIMATED_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
669+
.column("GLOBAL_MAX_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
670+
.column("GLOBAL_ESTIMATED_WEIGHT", ScalarType.createType(PrimitiveType.BIGINT))
663671
.build())
664672
)
665673
.put("backend_kerberos_ticket_cache",

0 commit comments

Comments
 (0)