pithecuse527 commented on code in PR #14381:
URL: https://github.com/apache/gravitino/pull/14381#discussion_r4414991927
##########
core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java:
##########
@@ -359,6 +363,36 @@ private void invalidateDescendants(String keyPrefix) {
}
}
+ /**
+ * Returns the prefix-index key of a cache key: the escaped identifier text,
{@code ":"}, and the
+ * entity type.
+ */
+ private static String indexKey(EntityCacheKey key) {
+ return indexText(key.identifier()) + ":" + key.entityType();
+ }
+
+ /**
+ * Joins the levels of an identifier into prefix-index text.
+ *
+ * <p>{@link NameIdentifier#toString()} is not one-to-one when a level
contains {@code "."}: table
+ * {@code a.b} in schema {@code sch} and table {@code b} in schema {@code
sch.a} both render as
+ * {@code sch.a.b}. Escaping {@code "."} and the escape character inside
each level makes the text
+ * unique, while every real level boundary stays a bare {@code "."}, so both
prefix scans in
+ * {@link #invalidateHierarchy(EntityCacheKey)} still match exactly the
descendants. The schema
+ * separator can be neither {@code "."} nor the escape character, so it is
kept as is.
+ */
+ private static String indexText(NameIdentifier ident) {
+ List<String> levels = Lists.newArrayList(ident.namespace().levels());
+ levels.add(ident.name());
+ return levels.stream()
+ .map(
+ level ->
+ level
+ .replace(INDEX_ESCAPE, INDEX_ESCAPE + INDEX_ESCAPE)
+ .replace(NAME_LEVEL_BOUNDARY, INDEX_ESCAPE +
NAME_LEVEL_BOUNDARY))
+ .collect(Collectors.joining(NAME_LEVEL_BOUNDARY));
+ }
+
Review Comment:
i do not agree this would cause a heavy GC... (since this part runs only on
a cache put or invalidate)
but it is good practice to use a `StringBuilder` when addressing strings,
and it's a cheap improvement here, so i'm taking it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]