diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java new file mode 100644 index 0000000000000000000000000000000000000000..d1a6f063a6db9a0bea9326d8c3bcc16425b3b909 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IKindCache.java @@ -0,0 +1,6 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.ICache; + +public interface IKindCache extends ICache<String, String> { +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelatedObjectsSpecsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelatedObjectsSpecsCache.java new file mode 100644 index 0000000000000000000000000000000000000000..34f9bae78323ceed8c8226ae5c5ddc73e83ae5da --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IParentChildRelatedObjectsSpecsCache.java @@ -0,0 +1,9 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelatedObjectsSpec; + +import java.util.List; + +public interface IParentChildRelatedObjectsSpecsCache extends ICache<String, List<ParentChildRelatedObjectsSpec>> { +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java new file mode 100644 index 0000000000000000000000000000000000000000..6a0d866b455628346b0372c77aff1344513fdabd --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IPropertyConfigurationsCache.java @@ -0,0 +1,7 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; + +public interface IPropertyConfigurationsCache extends ICache<String, PropertyConfigurations> { +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCache.java deleted file mode 100644 index 6845961e5ea7110fe298b7a9bbb08fee1b1f517d..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCache.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © Schlumberger - * - * Licensed 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 - * - * https://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.opengroup.osdu.indexer.cache; - -import org.opengroup.osdu.core.common.cache.VmCache; -import org.springframework.stereotype.Component; - -@Component -public class KindCache extends VmCache<String, String> { - public KindCache() { - super(600, 1000); - } - - public boolean containsKey(final String key) { - return this.get(key) != null; - } -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..10909fed434254677864c732f0e03b8cc401a474 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/KindCacheVmImpl.java @@ -0,0 +1,35 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.model.Constants; +import org.springframework.stereotype.Component; + +@Component +public class KindCacheVmImpl implements IKindCache { + + private VmCache<String, String> cache; + + public KindCacheVmImpl() { + cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); + } + + @Override + public void put(String s, String o) { + this.cache.put(s, o); + } + + @Override + public String get(String s) { + return this.cache.get(s); + } + + @Override + public void delete(String s) { + this.cache.delete(s); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCache.java deleted file mode 100644 index 1776a24bbfdb290380b4812ed48bcb68376a13a8..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCache.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © Schlumberger - * - * Licensed 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 - * - * https://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.opengroup.osdu.indexer.cache; - -import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelatedObjectsSpec; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class ParentChildRelatedObjectsSpecsCache extends VmCache<String, List<ParentChildRelatedObjectsSpec>> { - public ParentChildRelatedObjectsSpecsCache() { - super(600, 1000); - } -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCacheVmImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b5ae956c61e2d4a8ec77e0907abe116e62488ed3 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ParentChildRelatedObjectsSpecsCacheVmImpl.java @@ -0,0 +1,37 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.model.Constants; +import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelatedObjectsSpec; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class ParentChildRelatedObjectsSpecsCacheVmImpl implements IParentChildRelatedObjectsSpecsCache { + private VmCache<String, List<ParentChildRelatedObjectsSpec>> cache; + + public ParentChildRelatedObjectsSpecsCacheVmImpl() { + cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); + } + + @Override + public void put(String s, List<ParentChildRelatedObjectsSpec> o) { + this.cache.put(s, o); + } + + @Override + public List<ParentChildRelatedObjectsSpec> get(String s) { + return this.cache.get(s); + } + + @Override + public void delete(String s) { + this.cache.delete(s); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java new file mode 100644 index 0000000000000000000000000000000000000000..c9c8d340850187f12b4ca74195e4f116ce6c1a6a --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeKindCache.java @@ -0,0 +1,52 @@ +/* + * Copyright © Schlumberger + * + * Licensed 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 + * + * https://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.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; + +@Component +@RequestScope +public class PartitionSafeKindCache { + @Inject + private IKindCache cache; + @Autowired + private IRequestInfo requestInfo; + + public void put(String s, String o) { + this.cache.put(cacheKey(s), o); + } + + public String get(String s) { + return this.cache.get(cacheKey(s)); + } + + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + public void clearAll() { + this.cache.clearAll(); + } + + private String cacheKey(String s) { + return this.requestInfo.getPartitionId() + "-" + s; + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelatedObjectsSpecsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelatedObjectsSpecsCache.java new file mode 100644 index 0000000000000000000000000000000000000000..a257f5e87affa5b92eccbdfbfb230139611dfb85 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeParentChildRelatedObjectsSpecsCache.java @@ -0,0 +1,54 @@ +/* + * Copyright © Schlumberger + * + * Licensed 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 + * + * https://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.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.model.indexproperty.ParentChildRelatedObjectsSpec; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; +import java.util.List; + +@Component +@RequestScope +public class PartitionSafeParentChildRelatedObjectsSpecsCache { + @Inject + private IParentChildRelatedObjectsSpecsCache cache; + @Autowired + private IRequestInfo requestInfo; + + public void put(String s, List<ParentChildRelatedObjectsSpec> o) { + this.cache.put(cacheKey(s), o); + } + + public List<ParentChildRelatedObjectsSpec> get(String s) { + return this.cache.get(cacheKey(s)); + } + + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + public void clearAll() { + this.cache.clearAll(); + } + + private String cacheKey(String s) { + return this.requestInfo.getPartitionId() + "-" + s; + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java new file mode 100644 index 0000000000000000000000000000000000000000..dbb64c0192c8a63d60c4fc3887779333a4283ac1 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafePropertyConfigurationsCache.java @@ -0,0 +1,53 @@ +/* + * Copyright © Schlumberger + * + * Licensed 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 + * + * https://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.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; + +@Component +@RequestScope +public class PartitionSafePropertyConfigurationsCache { + @Inject + private IPropertyConfigurationsCache cache; + @Autowired + private IRequestInfo requestInfo; + + public void put(String s, PropertyConfigurations o) { + this.cache.put(cacheKey(s), o); + } + + public PropertyConfigurations get(String s) { + return this.cache.get(cacheKey(s)); + } + + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + public void clearAll() { + this.cache.clearAll(); + } + + private String cacheKey(String s) { + return this.requestInfo.getPartitionId() + "-" + s; + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java new file mode 100644 index 0000000000000000000000000000000000000000..800a197bebdabfa2ef8c5b2db2cd6437768eec5f --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeSchemaCache.java @@ -0,0 +1,59 @@ +package org.opengroup.osdu.indexer.cache; + +import com.google.common.base.Strings; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; + +@Component +@RequestScope +public class PartitionSafeSchemaCache { + private static final String FLATTENED_SCHEMA = "_flattened"; + + @Inject + private ISchemaCache schemaCache; + @Autowired + private IRequestInfo requestInfo; + + public void putSchema(String s, String o) { + this.schemaCache.put(cacheKey(s), o); + } + + public String getSchema(String s) { + return (String) this.schemaCache.get(cacheKey(s)); + } + + public void putFlattenedSchema(String s, String o) { + this.schemaCache.put(flattenedCacheKey(s), o); + } + + public String getFlattenedSchema(String s) { + return (String) this.schemaCache.get(flattenedCacheKey(s)); + } + + public void delete(String s) { + if (!Strings.isNullOrEmpty(this.getSchema(s))) { + this.schemaCache.delete(cacheKey(s)); + } + + if (!Strings.isNullOrEmpty(this.getFlattenedSchema(s))) { + this.schemaCache.delete(flattenedCacheKey(s)); + } + } + + public void clearAll() { + this.schemaCache.clearAll(); + } + + private String cacheKey(String s) { + return this.requestInfo.getPartitionId() + "-" + s; + } + + private String flattenedCacheKey(String s) { + return this.requestInfo.getPartitionId() + "-" + s + FLATTENED_SCHEMA; + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCache.java deleted file mode 100644 index 89fab66d5efaef350f6d0a802efde683cedae1f8..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCache.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © Schlumberger - * - * Licensed 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 - * - * https://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.opengroup.osdu.indexer.cache; - -import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; -import org.springframework.stereotype.Component; - -@Component -public class PropertyConfigurationsCache extends VmCache<String, PropertyConfigurations> { - public PropertyConfigurationsCache() { - super(600, 1000); - } -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2fd1eb88c6412b2d2138a5dfba8c9d3f297ff95f --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java @@ -0,0 +1,35 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.model.Constants; +import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.springframework.stereotype.Component; + +@Component +public class PropertyConfigurationsCacheVmImpl implements IPropertyConfigurationsCache { + private VmCache<String, PropertyConfigurations> cache; + + public PropertyConfigurationsCacheVmImpl() { + cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); + } + + @Override + public void put(String s, PropertyConfigurations o) { + this.cache.put(s, o); + } + + @Override + public PropertyConfigurations get(String s) { + return this.cache.get(s); + } + + @Override + public void delete(String s) { + this.cache.delete(s); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCache.java index 67aa01f36c1c9d84c1b47ea44819ca074efaee08..67e9e0b8250712bdebc632fbada8063aab90d207 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RecordChangeInfoCache.java @@ -16,12 +16,13 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.model.Constants; import org.opengroup.osdu.indexer.model.RecordChangeInfo; import org.springframework.stereotype.Component; @Component public class RecordChangeInfoCache extends VmCache<String, RecordChangeInfo> { public RecordChangeInfoCache() { - super(300, 1000); + super(Constants.DATA_CACHE_EXPIRATION, Constants.DATA_MAX_CACHE_SIZE); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCache.java index 75f058b4e07fdb4398d9fb5d8c80a6471051f50e..8d0ba094c621552f75f1894b04364fabc4c50f88 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCache.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.indexer.model.SearchRecord; +import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; import java.util.Map; @@ -24,6 +24,6 @@ import java.util.Map; @Component public class RelatedObjectCache extends VmCache<String, Map<String, Object>> { public RelatedObjectCache() { - super(60, 1000); + super(Constants.DATA_CACHE_EXPIRATION, Constants.DATA_MAX_CACHE_SIZE); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java index 4cd9682ddb91a63b1cde558441082664656405cb..ca3f537c75eeefb6d29bcae655a56d5856489ca3 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java @@ -3,4 +3,12 @@ package org.opengroup.osdu.indexer.model; public class Constants { // It should be moved to core common later public static final String ANCESTRY_KINDS = "ancestry_kinds"; + + // Specifications using kind as key is not partition safe if the specifications are per data partition + public static final int SPEC_CACHE_EXPIRATION = 600; + public static final int SPEC_MAX_CACHE_SIZE = 2000; + + // Data id itself is partition safe + public static final int DATA_CACHE_EXPIRATION = 120; + public static final int DATA_MAX_CACHE_SIZE = 1000; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index 4d2d73e3a1f7fb5c12b25f7cc8077f000f61df65..27ff6965cd1c91dd803effd84b703b5937000305 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -30,9 +30,9 @@ import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.indexer.cache.PartitionSafeSchemaCache; import org.opengroup.osdu.indexer.model.Kind; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; -import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -48,8 +48,6 @@ import java.util.*; @Service public class IndexSchemaServiceImpl implements IndexSchemaService { - private static final String FLATTENED_SCHEMA = "_flattened"; - private final Gson gson = new Gson(); @Inject @@ -65,7 +63,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { @Inject private IndicesService indicesService; @Inject - private ISchemaCache schemaCache; + private PartitionSafeSchemaCache schemaCache; @Inject private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Inject @@ -155,7 +153,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { this.invalidateCache(kind); } - String schema = (String) this.schemaCache.get(kind); + String schema = this.schemaCache.getSchema(kind); if (Strings.isNullOrEmpty(schema)) { // get from storage schema = this.schemaProvider.getSchema(kind); @@ -173,7 +171,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } } else { // search flattened schema in memcache - String flattenedSchema = (String) this.schemaCache.get(kind + FLATTENED_SCHEMA); + String flattenedSchema = this.schemaCache.getFlattenedSchema(kind); if (Strings.isNullOrEmpty(flattenedSchema)) { return this.getEmptySchema(kind); } @@ -183,11 +181,11 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { private IndexSchema cacheAndNormalizeSchema(String kind, String schema) { // cache the schema - this.schemaCache.put(kind, schema); + this.schemaCache.putSchema(kind, schema); // get flatten schema and cache it IndexSchema flatSchemaObj = normalizeSchema(schema); if (flatSchemaObj != null) { - this.schemaCache.put(kind + FLATTENED_SCHEMA, gson.toJson(flatSchemaObj)); + this.schemaCache.putFlattenedSchema(kind, gson.toJson(flatSchemaObj)); } return flatSchemaObj; } @@ -216,7 +214,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { if (Strings.isNullOrEmpty(concreteRelatedObjectKind)) continue; - String relatedObjectKindSchema = (String) this.schemaCache.get(concreteRelatedObjectKind); + String relatedObjectKindSchema = this.schemaCache.getSchema(concreteRelatedObjectKind); if (Strings.isNullOrEmpty(relatedObjectKindSchema)) { relatedObjectKindSchema = this.schemaProvider.getSchema(concreteRelatedObjectKind); if (!Strings.isNullOrEmpty(relatedObjectKindSchema)) { @@ -258,13 +256,8 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } private void invalidateCache(String kind) { - String schema = (String) this.schemaCache.get(kind); - if (!Strings.isNullOrEmpty(schema)) this.schemaCache.delete(kind); - - String flattenSchema = (String) this.schemaCache.get(kind + FLATTENED_SCHEMA); - if (!Strings.isNullOrEmpty(flattenSchema)) this.schemaCache.delete(kind + FLATTENED_SCHEMA); - - virtualPropertiesSchemaCache.delete(kind); + this.schemaCache.delete(kind); + this.virtualPropertiesSchemaCache.delete(kind); } private IndexSchema normalizeSchema(String schemaStr) throws AppException { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java index a60198446e64941cfb97ee5f8902cfde24c37cdf..1a58edeccbcc229692c46061cdfc220203e0006a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java @@ -69,11 +69,11 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations @Inject private IndexerConfigurationProperties configurationProperties; @Inject - private PropertyConfigurationsCache propertyConfigurationCache; + private PartitionSafePropertyConfigurationsCache propertyConfigurationCache; @Inject - private ParentChildRelatedObjectsSpecsCache parentChildRelatedObjectsSpecsCache; + private PartitionSafeParentChildRelatedObjectsSpecsCache parentChildRelatedObjectsSpecsCache; @Inject - private KindCache kindCache; + private PartitionSafeKindCache kindCache; @Inject private RelatedObjectCache relatedObjectCache; @Inject @@ -93,19 +93,17 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations public PropertyConfigurations getPropertyConfiguration(String kind) { if (Strings.isNullOrEmpty(kind)) return null; - String dataPartitionId = requestInfo.getHeaders().getPartitionId(); kind = PropertyUtil.getKindWithMajor(kind); - String key = dataPartitionId + " | " + kind; - PropertyConfigurations configuration = propertyConfigurationCache.get(key); + PropertyConfigurations configuration = propertyConfigurationCache.get(kind); if (configuration == null) { configuration = searchConfigurations(kind); if (configuration != null) { - propertyConfigurationCache.put(key, configuration); + propertyConfigurationCache.put(kind, configuration); } else { // It is common that a kind does not have extended property. So we need to cache an empty configuration // to avoid unnecessary search - propertyConfigurationCache.put(key, EMPTY_CONFIGURATIONS); + propertyConfigurationCache.put(kind, EMPTY_CONFIGURATIONS); } } @@ -240,7 +238,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return kind; } - if (kindCache.containsKey(kind)) { + if (kindCache.get(kind) != null) { return kindCache.get(kind); } else { String concreteKind = getLatestVersionOfKind(kind); @@ -295,7 +293,6 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } /******************************************************** Private methods **************************************************************/ - private SchemaItem createAssociatedIdentitiesSchemaItem() { SchemaItem extendedSchemaItem = new SchemaItem(); extendedSchemaItem.setPath(ASSOCIATED_IDENTITIES_PROPERTY); @@ -577,11 +574,9 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } private List<ParentChildRelatedObjectsSpec> getParentChildRelatedObjectsSpecs(String childKind) { - String dataPartitionId = requestInfo.getHeaders().getPartitionId(); final String kindWithMajor = PropertyUtil.getKindWithMajor(childKind); - String key = dataPartitionId + " | " + kindWithMajor; - List<ParentChildRelatedObjectsSpec> specsList = parentChildRelatedObjectsSpecsCache.get(key); + List<ParentChildRelatedObjectsSpec> specsList = parentChildRelatedObjectsSpecsCache.get(kindWithMajor); if (specsList == null) { Map<Integer, ParentChildRelatedObjectsSpec> specs = new HashMap<>(); List<PropertyConfigurations> configurationsList = searchParentKindConfigurations((kindWithMajor)); @@ -612,7 +607,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } specsList = new ArrayList<>(specs.values()); - parentChildRelatedObjectsSpecsCache.put(key, specsList); + parentChildRelatedObjectsSpecsCache.put(kindWithMajor, specsList); } return specsList;