Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TenantControl - creating cache records must use tenant #17121

Merged
merged 4 commits into from Jun 24, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -94,6 +94,7 @@
import static com.hazelcast.cache.impl.operation.MutableOperation.IGNORE_COMPLETION;
import static com.hazelcast.cache.impl.record.CacheRecord.TIME_NOT_AVAILABLE;
import static com.hazelcast.cache.impl.record.CacheRecordFactory.isExpiredAt;
import com.hazelcast.config.CacheConfigAccessor;
import static com.hazelcast.config.CacheConfigAccessor.getTenantControl;
import static com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig;
import static com.hazelcast.nio.IOUtil.closeResource;
Expand All @@ -102,6 +103,7 @@
import static com.hazelcast.util.MapUtil.createHashMap;
import static com.hazelcast.util.SetUtil.createHashSet;
import static com.hazelcast.util.ThreadUtil.assertRunningOnPartitionThread;
import java.io.IOException;
import static java.util.Collections.emptySet;

@SuppressWarnings({"checkstyle:methodcount", "checkstyle:classfanoutcomplexity"})
Expand Down Expand Up @@ -162,53 +164,62 @@ public AbstractCacheRecordStore(String cacheNameWithPrefix, int partitionId, Nod
throw new CacheNotExistsException("Cache " + cacheNameWithPrefix + " is already destroyed or not created yet, on "
+ nodeEngine.getLocalMember());
}
this.eventJournalConfig = nodeEngine.getConfig().findCacheEventJournalConfig(cacheConfig.getName());
this.evictionConfig = cacheConfig.getEvictionConfig();
if (evictionConfig == null) {
throw new IllegalStateException("Eviction config cannot be null!");
}
this.wanReplicationEnabled = cacheService.isWanReplicationEnabled(cacheNameWithPrefix);
this.disablePerEntryInvalidationEvents = cacheConfig.isDisablePerEntryInvalidationEvents();
if (cacheConfig.isStatisticsEnabled()) {
statistics = cacheService.createCacheStatIfAbsent(cacheNameWithPrefix);
}
if (cacheConfig.getCacheLoaderFactory() != null) {
Factory<CacheLoader> cacheLoaderFactory = cacheConfig.getCacheLoaderFactory();
injectDependencies(cacheLoaderFactory);
cacheLoader = cacheLoaderFactory.create();
injectDependencies(cacheLoader);
}
if (cacheConfig.getCacheWriterFactory() != null) {
Factory<CacheWriter> cacheWriterFactory = cacheConfig.getCacheWriterFactory();
injectDependencies(cacheWriterFactory);
cacheWriter = cacheWriterFactory.create();
injectDependencies(cacheWriter);
}
if (cacheConfig.getExpiryPolicyFactory() != null) {
Factory<ExpiryPolicy> expiryPolicyFactory = cacheConfig.getExpiryPolicyFactory();
injectDependencies(expiryPolicyFactory);
defaultExpiryPolicy = expiryPolicyFactory.create();
injectDependencies(defaultExpiryPolicy);
} else {
throw new IllegalStateException("Expiry policy factory cannot be null!");
}

this.cacheContext = cacheService.getOrCreateCacheContext(cacheNameWithPrefix);
this.records = createRecordCacheMap();
this.evictionChecker = createCacheEvictionChecker(evictionConfig.getSize(), evictionConfig.getMaximumSizePolicy());
this.evictionPolicyEvaluator = createEvictionPolicyEvaluator(evictionConfig);
this.evictionStrategy = createEvictionStrategy(evictionConfig);
this.objectNamespace = CacheService.getObjectNamespace(cacheNameWithPrefix);
this.persistWanReplicatedData = canPersistWanReplicatedData(cacheConfig, nodeEngine);
this.cacheRecordFactory = new CacheRecordFactory(cacheConfig.getInMemoryFormat(), ss);
this.valueComparator = getValueComparatorOf(cacheConfig.getInMemoryFormat());
this.clearExpiredRecordsTask = cacheService.getExpirationManager().getTask();

injectDependencies(evictionPolicyEvaluator.getEvictionPolicyComparator());
registerResourceIfItIsClosable(cacheWriter);
registerResourceIfItIsClosable(cacheLoader);
registerResourceIfItIsClosable(defaultExpiryPolicy);
init();
Closeable tenantContext = CacheConfigAccessor.getTenantControl(cacheConfig).setTenant(true);
try {
this.eventJournalConfig = nodeEngine.getConfig().findCacheEventJournalConfig(cacheConfig.getName());
this.evictionConfig = cacheConfig.getEvictionConfig();
if (evictionConfig == null) {
throw new IllegalStateException("Eviction config cannot be null!");
}
this.wanReplicationEnabled = cacheService.isWanReplicationEnabled(cacheNameWithPrefix);
this.disablePerEntryInvalidationEvents = cacheConfig.isDisablePerEntryInvalidationEvents();
if (cacheConfig.isStatisticsEnabled()) {
statistics = cacheService.createCacheStatIfAbsent(cacheNameWithPrefix);
}
if (cacheConfig.getCacheLoaderFactory() != null) {
Factory<CacheLoader> cacheLoaderFactory = cacheConfig.getCacheLoaderFactory();
injectDependencies(cacheLoaderFactory);
cacheLoader = cacheLoaderFactory.create();
injectDependencies(cacheLoader);
}
if (cacheConfig.getCacheWriterFactory() != null) {
Factory<CacheWriter> cacheWriterFactory = cacheConfig.getCacheWriterFactory();
injectDependencies(cacheWriterFactory);
cacheWriter = cacheWriterFactory.create();
injectDependencies(cacheWriter);
}
if (cacheConfig.getExpiryPolicyFactory() != null) {
Factory<ExpiryPolicy> expiryPolicyFactory = cacheConfig.getExpiryPolicyFactory();
injectDependencies(expiryPolicyFactory);
defaultExpiryPolicy = expiryPolicyFactory.create();
injectDependencies(defaultExpiryPolicy);
} else {
throw new IllegalStateException("Expiry policy factory cannot be null!");
}

this.cacheContext = cacheService.getOrCreateCacheContext(cacheNameWithPrefix);
this.records = createRecordCacheMap();
this.evictionChecker = createCacheEvictionChecker(evictionConfig.getSize(), evictionConfig.getMaximumSizePolicy());
this.evictionPolicyEvaluator = createEvictionPolicyEvaluator(evictionConfig);
this.evictionStrategy = createEvictionStrategy(evictionConfig);
this.objectNamespace = CacheService.getObjectNamespace(cacheNameWithPrefix);
this.persistWanReplicatedData = canPersistWanReplicatedData(cacheConfig, nodeEngine);
this.cacheRecordFactory = new CacheRecordFactory(cacheConfig.getInMemoryFormat(), ss);
this.valueComparator = getValueComparatorOf(cacheConfig.getInMemoryFormat());
this.clearExpiredRecordsTask = cacheService.getExpirationManager().getTask();

injectDependencies(evictionPolicyEvaluator.getEvictionPolicyComparator());
registerResourceIfItIsClosable(cacheWriter);
registerResourceIfItIsClosable(cacheLoader);
registerResourceIfItIsClosable(defaultExpiryPolicy);
init();
} finally {
try {
tenantContext.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
lprimak marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// Overridden in EE
Expand Down