From a5103416872e33ad3f8f62be374cad09c77f864b Mon Sep 17 00:00:00 2001
From: NThakur4 <nthakur4@slb.com>
Date: Fri, 10 Sep 2021 12:38:03 -0500
Subject: [PATCH] clear cache

---
 .../indexer/service/IndicesServiceImpl.java   | 20 ++++++++++++-------
 .../indexRecord-schema-service.feature        |  2 +-
 2 files changed, 14 insertions(+), 8 deletions(-)

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 ec68f6ccc..bd3a90009 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 a6d40a7e8..c7b17f6bb 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
-- 
GitLab