Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void stop() {
shutdown();
}

@Override
public void clearUserCache(String userName) {
// do nothing
}

public void startup() {
IoTDBConfig iotDBConfig = IoTDBDescriptor.getInstance().getConfig();
IConfig config = createBrokerConfig(iotDBConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
import org.apache.iotdb.externalservice.api.IExternalService;
import org.apache.iotdb.rest.protocol.filter.ApiOriginFilter;
import org.apache.iotdb.rest.protocol.filter.UserCache;

import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.HttpConfiguration;
Expand Down Expand Up @@ -141,4 +142,9 @@ public void stop() {
server.destroy();
}
}

@Override
public void clearUserCache(String userName) {
UserCache.getInstance().clearUserCache(userName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class UserCache {
Expand Down Expand Up @@ -51,6 +52,15 @@ public void setUser(String key, User user) {
cache.put(key, user);
}

public void clearUserCache(String userName) {
for (Map.Entry<String, User> mapValue : cache.asMap().entrySet()) {
if (mapValue.getValue().getUsername().equals(userName)) {
cache.invalidate(mapValue.getKey());
return;
}
}
}

private static class UserCacheHolder {
private static final UserCache INSTANCE = new UserCache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public interface IExternalService {
* guarantee to putBack thread or thread pool.
*/
void stop();

/** Clear user cache of current service. */
void clearUserCache(String userName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RelationalAuthorStatement;
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.AuthorStatement;
import org.apache.iotdb.db.service.externalservice.ExternalServiceManagementService;
import org.apache.iotdb.rpc.TSStatusCode;

import com.google.common.util.concurrent.SettableFuture;
Expand Down Expand Up @@ -130,6 +131,7 @@ public static IAuthorityFetcher getAuthorityFetcher() {

public static boolean invalidateCache(String username, String roleName) {
PipeInsertionDataNodeListener.getInstance().invalidateAllCache();
ExternalServiceManagementService.getInstance().clearServiceUserCache(username);
return authorityFetcher.get().getAuthorCache().invalidateCache(username, roleName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,25 @@ public static ExternalServiceManagementService getInstance() {
return ExternalServiceManagementServiceHolder.INSTANCE;
}

public void clearServiceUserCache(String userName) {
serviceInfos
.values()
.forEach(
serviceInfo -> {
// clear user cache of service with RUNNING state
if (serviceInfo.getState() == RUNNING) {
IExternalService serviceInstance = serviceInfo.getServiceInstance();
// serviceInstance maybe null when an exception occurs during the start of certain
// service in restoreRunningServiceInstance method
if (serviceInstance != null) {
// only clear user cache of the instance successfully started and running
runWithServiceClassLoader(
serviceInfo, () -> serviceInstance.clearUserCache(userName));
}
}
});
}

private static class ExternalServiceManagementServiceHolder {

private static final ExternalServiceManagementService INSTANCE =
Expand Down