morrySnow commented on code in PR #37723: URL: https://github.com/apache/doris/pull/37723#discussion_r1682777001
########## fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/cache/RangerCache.java: ########## @@ -0,0 +1,103 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.catalog.authorizer.ranger.cache; + +import org.apache.doris.datasource.CacheException; +import org.apache.doris.mysql.privilege.CatalogAccessController; +import org.apache.doris.mysql.privilege.DataMaskPolicy; +import org.apache.doris.mysql.privilege.RowFilterPolicy; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +public class RangerCache { + private static final Logger LOG = LoggerFactory.getLogger(RangerCache.class); + public static final long MAX_CACHE_NUM = 1000; Review Comment: should be configable? ########## fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/cache/RangerCacheInvalidateListener.java: ########## @@ -0,0 +1,41 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.catalog.authorizer.ranger.cache; + +import org.apache.doris.catalog.authorizer.ranger.doris.RangerDorisAccessController; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.ranger.plugin.service.RangerAuthContextListener; + +public class RangerCacheInvalidateListener implements RangerAuthContextListener { + private static final Logger LOG = LogManager.getLogger(RangerDorisAccessController.class); + + private RangerCache cache; + + public RangerCacheInvalidateListener(RangerCache cache) { + this.cache = cache; + } + + @Override + public void contextChanged() { + LOG.info("ranget contextChanged"); Review Comment: ```suggestion LOG.info("ranger context changed"); ``` ########## fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/cache/RangerCache.java: ########## @@ -0,0 +1,103 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.catalog.authorizer.ranger.cache; + +import org.apache.doris.datasource.CacheException; +import org.apache.doris.mysql.privilege.CatalogAccessController; +import org.apache.doris.mysql.privilege.DataMaskPolicy; +import org.apache.doris.mysql.privilege.RowFilterPolicy; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +public class RangerCache { + private static final Logger LOG = LoggerFactory.getLogger(RangerCache.class); + public static final long MAX_CACHE_NUM = 1000; + + private CatalogAccessController controller; + private LoadingCache<DatamaskCacheKey, Optional<DataMaskPolicy>> datamaskCache = CacheBuilder.newBuilder() + .maximumSize(MAX_CACHE_NUM) + .build(new CacheLoader<DatamaskCacheKey, Optional<DataMaskPolicy>>() { + @Override + public Optional<DataMaskPolicy> load(DatamaskCacheKey key) { + return loadDatamask(key); + } + }); + + private LoadingCache<RowFilterCacheKey, List<? extends RowFilterPolicy>> rowFilterCache = CacheBuilder.newBuilder() + .maximumSize(MAX_CACHE_NUM) + .build(new CacheLoader<RowFilterCacheKey, List<? extends RowFilterPolicy>>() { + @Override + public List<? extends RowFilterPolicy> load(RowFilterCacheKey key) { + return loadRowFilter(key); + } + }); + + public RangerCache() { + } + + public void init(CatalogAccessController controller) { + this.controller = controller; + } + + private Optional<DataMaskPolicy> loadDatamask(DatamaskCacheKey key) { + Objects.requireNonNull(controller, "controller can not be null"); + LOG.info("load datamask: {}", key); Review Comment: debug? ########## fe/fe-core/src/main/java/org/apache/doris/catalog/authorizer/ranger/cache/RangerCache.java: ########## @@ -0,0 +1,103 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.catalog.authorizer.ranger.cache; + +import org.apache.doris.datasource.CacheException; +import org.apache.doris.mysql.privilege.CatalogAccessController; +import org.apache.doris.mysql.privilege.DataMaskPolicy; +import org.apache.doris.mysql.privilege.RowFilterPolicy; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +public class RangerCache { + private static final Logger LOG = LoggerFactory.getLogger(RangerCache.class); + public static final long MAX_CACHE_NUM = 1000; + + private CatalogAccessController controller; + private LoadingCache<DatamaskCacheKey, Optional<DataMaskPolicy>> datamaskCache = CacheBuilder.newBuilder() + .maximumSize(MAX_CACHE_NUM) + .build(new CacheLoader<DatamaskCacheKey, Optional<DataMaskPolicy>>() { + @Override + public Optional<DataMaskPolicy> load(DatamaskCacheKey key) { + return loadDatamask(key); + } + }); + + private LoadingCache<RowFilterCacheKey, List<? extends RowFilterPolicy>> rowFilterCache = CacheBuilder.newBuilder() + .maximumSize(MAX_CACHE_NUM) + .build(new CacheLoader<RowFilterCacheKey, List<? extends RowFilterPolicy>>() { + @Override + public List<? extends RowFilterPolicy> load(RowFilterCacheKey key) { + return loadRowFilter(key); + } + }); + + public RangerCache() { + } + + public void init(CatalogAccessController controller) { + this.controller = controller; + } + + private Optional<DataMaskPolicy> loadDatamask(DatamaskCacheKey key) { Review Comment: ```suggestion private Optional<DataMaskPolicy> loadDataMask(DatamaskCacheKey key) { ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org