diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java index ec68f6cccbdc88ea0f8a605c90f301fba53e56bc..bd3a90009edc62e105323b2586678083cc094267 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java @@ -62,7 +62,7 @@ public class IndicesServiceImpl implements IndicesService { @Autowired private ElasticIndexNameResolver elasticIndexNameResolver; @Autowired - private IIndexCache indicesExistCache; + private IIndexCache indexCache; @Autowired private JaxRsDpsLog log; @@ -99,14 +99,14 @@ public class IndicesServiceImpl implements IndicesService { CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); // cache the index status boolean indexStatus = response.isAcknowledged() && response.isShardsAcknowledged(); - if (indexStatus) this.indicesExistCache.put(index, true); + if (indexStatus) this.indexCache.put(index, true); return indexStatus; } catch (ElasticsearchStatusException e) { if (e.status() == RestStatus.BAD_REQUEST && (e.getMessage().contains("resource_already_exists_exception"))) { log.info("Index already exists. Ignoring error..."); // cache the index status - this.indicesExistCache.put(index, true); + this.indexCache.put(index, true); return true; } throw e; @@ -123,15 +123,15 @@ public class IndicesServiceImpl implements IndicesService { public boolean isIndexExist(RestHighLevelClient client, String index) throws IOException { try { try { - Boolean isIndexExist = (Boolean) this.indicesExistCache.get(index); + Boolean isIndexExist = (Boolean) this.indexCache.get(index); if (isIndexExist != null && isIndexExist) return true; } catch (RedisException ex) { //In case the format of cache changes then clean the cache - this.indicesExistCache.delete(index); + this.indexCache.delete(index); } GetIndexRequest request = new GetIndexRequest(index); boolean exists = client.indices().exists(request, RequestOptions.DEFAULT); - if (exists) this.indicesExistCache.put(index, true); + if (exists) this.indexCache.put(index, true); return exists; } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) return false; @@ -152,7 +152,7 @@ public class IndicesServiceImpl implements IndicesService { public boolean deleteIndex(RestHighLevelClient client, String index) throws ElasticsearchException, IOException, AppException { boolean responseStatus = removeIndexInElasticsearch(client, index); if (responseStatus) { - this.indicesExistCache.delete(index); + this.clearCacheOnIndexDeletion(index); } return responseStatus; } @@ -225,4 +225,10 @@ public class IndicesServiceImpl implements IndicesService { final Type typeOf = new TypeToken<List<IndexInfo>>() {}.getType(); return new Gson().fromJson(str, typeOf); } + + private void clearCacheOnIndexDeletion(String index) { + final String syncCacheKey = String.format("metaAttributeMappingSynced-%s", index); + this.indexCache.delete(index); + this.indexCache.delete(syncCacheKey); + } } \ No newline at end of file diff --git a/testing/indexer-test-core/src/main/resources/features/indexrecord/indexRecord-schema-service.feature b/testing/indexer-test-core/src/main/resources/features/indexrecord/indexRecord-schema-service.feature index a6d40a7e8d42567e608a8859b7dbaa41a3d290dd..c7b17f6bb6f01f1c3ff732ed6ead34f943e178ba 100644 --- a/testing/indexer-test-core/src/main/resources/features/indexrecord/indexRecord-schema-service.feature +++ b/testing/indexer-test-core/src/main/resources/features/indexrecord/indexRecord-schema-service.feature @@ -63,5 +63,5 @@ Feature: Indexing of the documents Then I can validate indexed meta attributes for the <index> and given <kind> Examples: - | kind | index | recordFile | mappingFile | acl | + | kind | index | recordFile | mappingFile | acl | | "tenant1:indexer:test-mapping--Sync:1.0.0" | "tenant1-indexer-test-mapping--sync-1.0.0" | "index_record_sync_mapping" | "index_record_sync_mapping" | "data.default.viewers@tenant1" | \ No newline at end of file