Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#4246] improvement(core): Remove role local cache (#4901)

lwyang252b911bedb6
diff --git a/core/src/main/java/org/apache/gravitino/Configs.java b/core/src/main/java/org/apache/gravitino/Configs.java
index fa65d399a3..587d85adae 100644
--- a/core/src/main/java/org/apache/gravitino/Configs.java
+++ b/core/src/main/java/org/apache/gravitino/Configs.java
@@ -327,13 +327,6 @@ public class Configs {
ConfigConstants.NOT_BLANK_ERROR_MSG)
.create();
- public static final ConfigEntry<Long> ROLE_CACHE_EVICTION_INTERVAL_MS =
- new ConfigBuilder("gravitino.authorization.roleCacheEvictionIntervalMs")
- .doc("The interval in milliseconds to evict the role cache")
- .version(ConfigConstants.VERSION_0_5_0)
- .longConf()
- .createWithDefault(60 * 60 * 1000L);
-
public static final int DEFAULT_METRICS_TIME_SLIDING_WINDOW_SECONDS = 60;
public static final ConfigEntry<Integer> METRICS_TIME_SLIDING_WINDOW_SECONDS =
new ConfigBuilder("gravitino.metrics.timeSlidingWindowSecs")
diff --git a/core/src/main/java/org/apache/gravitino/authorization/AccessControlManager.java b/core/src/main/java/org/apache/gravitino/authorization/AccessControlManager.java
index 8c6a73346d..aa890667dd 100644
--- a/core/src/main/java/org/apache/gravitino/authorization/AccessControlManager.java
+++ b/core/src/main/java/org/apache/gravitino/authorization/AccessControlManager.java
@@ -45,7 +45,7 @@ public class AccessControlManager implements AccessControlDispatcher {
private final List<String> serviceAdmins;
public AccessControlManager(EntityStore store, IdGenerator idGenerator, Config config) {
- this.roleManager = new RoleManager(store, idGenerator, config);
+ this.roleManager = new RoleManager(store, idGenerator);
this.userGroupManager = new UserGroupManager(store, idGenerator);
this.permissionManager = new PermissionManager(store, roleManager);
this.serviceAdmins = config.get(Configs.SERVICE_ADMINS);
diff --git a/core/src/main/java/org/apache/gravitino/authorization/RoleManager.java b/core/src/main/java/org/apache/gravitino/authorization/RoleManager.java
index 3edcfaa573..457a7f5ffe 100644
--- a/core/src/main/java/org/apache/gravitino/authorization/RoleManager.java
+++ b/core/src/main/java/org/apache/gravitino/authorization/RoleManager.java
@@ -19,19 +19,10 @@
package org.apache.gravitino.authorization;
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
-import com.github.benmanes.caffeine.cache.Scheduler;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import org.apache.gravitino.Config;
-import org.apache.gravitino.Configs;
import org.apache.gravitino.Entity;
import org.apache.gravitino.EntityAlreadyExistsException;
import org.apache.gravitino.EntityStore;
@@ -57,32 +48,10 @@ class RoleManager {
private static final Logger LOG = LoggerFactory.getLogger(RoleManager.class);
private final EntityStore store;
private final IdGenerator idGenerator;
- private final Cache<NameIdentifier, RoleEntity> cache;
- RoleManager(EntityStore store, IdGenerator idGenerator, Config config) {
+ RoleManager(EntityStore store, IdGenerator idGenerator) {
this.store = store;
this.idGenerator = idGenerator;
-
- long cacheEvictionIntervalInMs = config.get(Configs.ROLE_CACHE_EVICTION_INTERVAL_MS);
- // One role entity is about 40 bytes using jol estimate, there are usually about 100w+
- // roles in the production environment, this won't bring too much memory cost, but it
- // can improve the performance significantly.
- this.cache =
- Caffeine.newBuilder()
- .expireAfterAccess(cacheEvictionIntervalInMs, TimeUnit.MILLISECONDS)
- .removalListener(
- (k, v, c) -> {
- LOG.info("Remove role {} from the cache.", k);
- })
- .scheduler(
- Scheduler.forScheduledExecutorService(
- new ScheduledThreadPoolExecutor(
- 1,
- new ThreadFactoryBuilder()
- .setDaemon(true)
- .setNameFormat("role-cleaner-%d")
- .build())))
- .build();
}
RoleEntity createRole(
@@ -107,7 +76,6 @@ class RoleManager {
.build();
try {
store.put(roleEntity, false /* overwritten */);
- cache.put(roleEntity.nameIdentifier(), roleEntity);
AuthorizationUtils.callAuthorizationPluginForSecurableObjects(
metalake,
@@ -141,7 +109,6 @@ class RoleManager {
try {
AuthorizationUtils.checkMetalakeExists(metalake);
NameIdentifier ident = AuthorizationUtils.ofRole(metalake, role);
- cache.invalidate(ident);
try {
RoleEntity roleEntity = store.get(ident, Entity.EntityType.ROLE, RoleEntity.class);
@@ -163,20 +130,11 @@ class RoleManager {
}
private RoleEntity getRoleEntity(NameIdentifier identifier) {
- return cache.get(
- identifier,
- id -> {
- try {
- return store.get(identifier, Entity.EntityType.ROLE, RoleEntity.class);
- } catch (IOException ioe) {
- LOG.error("Failed to get roles {} due to storage issues", identifier, ioe);
- throw new RuntimeException(ioe);
- }
- });
- }
-
- @VisibleForTesting
- Cache<NameIdentifier, RoleEntity> getCache() {
- return cache;
+ try {
+ return store.get(identifier, Entity.EntityType.ROLE, RoleEntity.class);
+ } catch (IOException ioe) {
+ LOG.error("Failed to get roles {} due to storage issues", identifier, ioe);
+ throw new RuntimeException(ioe);
+ }
}
}
diff --git a/core/src/test/java/org/apache/gravitino/authorization/TestAccessControlManager.java b/core/src/test/java/org/apache/gravitino/authorization/TestAccessControlManager.java
index 27e5e667c3..fd27771a08 100644
--- a/core/src/test/java/org/apache/gravitino/authorization/TestAccessControlManager.java
+++ b/core/src/test/java/org/apache/gravitino/authorization/TestAccessControlManager.java
@@ -268,13 +268,8 @@ public class TestAccessControlManager {
SecurableObjects.ofCatalog(
"catalog", Lists.newArrayList(Privileges.UseCatalog.allow()))));
- Role cachedRole = accessControlManager.getRole("metalake", "loadRole");
- accessControlManager.getRoleManager().getCache().invalidateAll();
Role role = accessControlManager.getRole("metalake", "loadRole");
- // Verify the cached roleEntity is correct
- Assertions.assertEquals(role, cachedRole);
-
Assertions.assertEquals("loadRole", role.name());
testProperties(props, role.properties());