Skip to content

Commit 7698d07

Browse files
committed
CMR-10569: Fixing search index cache issue.
1 parent 60c89e4 commit 7698d07

7 files changed

Lines changed: 359 additions & 303 deletions

File tree

elastic-utils-lib/src/cmr/elastic_utils/search/es_index_name_cache.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@
5656
{:index-names index-names-map
5757
:rebalancing-collections moving-to-separate-index}))
5858

59+
(comment
60+
(println context3)
61+
(fetch-concept-type-index-names context3)
62+
(indexer/get-index-set context3 index-set-id)
63+
)
5964
(defn refresh-index-names-cache
6065
"Refresh the search index-names cache."
6166
[context]
67+
(def context3 context)
6268
(info "Refreshing search index-names cache.")
6369
(let [index-names-map (fetch-concept-type-index-names context)
6470
index-names (:index-names index-names-map)

indexer-app/src/cmr/indexer/data/index_set.clj

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
[cmr.common.concepts :as cs]
88
[cmr.common.config :as cfg :refer [defconfig]]
99
[cmr.common.generics :as common-generic]
10+
[cmr.common.hash-cache :as hcache]
1011
[cmr.common.log :as log :refer (info error)]
1112
[cmr.common.util :as util]
1213
[cmr.common.services.errors :as errors]
1314
[cmr.elastic-utils.index-util :as m :refer [defmapping defnestedmapping]]
15+
[cmr.elastic-utils.search.es-index-name-cache :as elastic-search-index-names-cache]
1416
[cmr.indexer.data.index-set-generics :as index-set-gen]
1517
[cmr.indexer.data.index-set-elasticsearch :as index-set-es]
1618
[cmr.indexer.services.index-set-service :as index-set-service]
@@ -1103,8 +1105,15 @@
11031105
:indexer-index-set-cache)
11041106

11051107
(comment
1108+
(let [cache (cache/context->cache context1 index-set-cache-key)]
1109+
(cache/get-keys cache))
1110+
(let [cache (cache/context->cache context1 index-set-cache-key)]
1111+
(cache/get-value cache :concept-mapping-types))
1112+
(let [cache (cache/context->cache context1 index-set-cache-key)]
1113+
(cache/get-value cache :concept-indices))
11061114
(let [cache (cache/context->cache context index-set-cache-key)]
11071115
(cache/get-keys cache))
1116+
11081117
(let [cache (cache/context->cache context index-set-cache-key)]
11091118
(cache/get-value cache :concept-mapping-types))
11101119

@@ -1122,9 +1131,9 @@
11221131
(cache/get-value cache :concept-indices (partial fetch-concept-type-index-names context))))
11231132

11241133
(defn set-concept-type-index-names
1125-
"Fetch index names associated with concepts."
1134+
"Set index names associated with concepts."
11261135
[context value]
1127-
(def context1 context)
1136+
(def context2 context)
11281137
(let [cache (cache/context->cache context index-set-cache-key)]
11291138
(cache/set-value cache :concept-indices value)))
11301139

@@ -1167,23 +1176,26 @@
11671176

11681177
; (index-requested-index-set context index-set)))
11691178

1170-
(comment
1171-
(let [index-set (index-set-es/get-index-set context index-set-id)]
1172-
(get-in index-set [:index-set :granule])
1173-
;(cmr.indexer.services.index-set-service/update-index-set context index-set)
1179+
(defn set-search-index-names-cache
1180+
""
1181+
[context index-kw index-name]
1182+
(let [cache (hcache/context->cache context elastic-search-index-names-cache/index-names-cache-key)
1183+
granule (hcache/get-value cache elastic-search-index-names-cache/index-names-cache-key "granule")
1184+
new-granule (assoc granule index-kw index-name)]
1185+
(hcache/set-value cache elastic-search-index-names-cache/index-names-cache-key "granule" new-granule)))
1186+
1187+
(comment
1188+
(println coll-concept-id)
1189+
(let [coll-concept-id "C12323-PROV2"
1190+
{:keys [index-names rebalancing-collections]} (get-concept-type-index-names context)
1191+
indexes (:granule index-names)
1192+
provider (util/safe-lowercase (cs/concept-id->provider-id coll-concept-id))
1193+
idx-name (str "granules_" provider)
1194+
idx (get indexes (keyword idx-name))]
1195+
idx
11741196
)
1175-
1176-
(println target-index-key)
1177-
update-index-set
1178-
(get-granule-index-names-for-collection context "C1200000001-PROV2" nil)
1179-
(let [index-names (get-concept-type-index-names context)]
1180-
(get-in index-names [:index-names :granule]))
1181-
(let [{:keys [index-names rebalancing-collections]} (get-concept-type-index-names context)
1182-
indexes (:granule index-names)]
1183-
indexes)
1184-
; (get indexes :small_collections))
1185-
(get-granule-index-names-for-provider context "prov6")
1186-
)
1197+
1198+
)
11871199
(defn get-granule-index-names-for-collection
11881200
"Return the granule index names for the input collection concept id. Optionally a
11891201
target-index-key can be specified which indicates that a specific index should be returned"
@@ -1200,26 +1212,34 @@
12001212
(let [provider (util/safe-lowercase (cs/concept-id->provider-id coll-concept-id))
12011213
idx-name (str "granules_" provider)
12021214
idx (get indexes (keyword idx-name))]
1203-
;(println "idx:" idx)
12041215
(if idx
12051216
idx
1206-
(let [index-set (index-set-es/get-index-set context index-set-id)
1217+
(let [_ (println "idx-name:" idx-name)
1218+
_ (println "indexes:" indexes)
1219+
_ (println "coll-concept-id:" coll-concept-id)
1220+
index-set (index-set-es/get-index-set context index-set-id)
12071221
;; This sets the index names in ES index.
1208-
new-index-set (try
1209-
(let [new-idx-set (add-new-granule-provider-index index-set idx-name)]
1210-
(index-set-service/update-index-set context new-idx-set))
1211-
(catch Exception e
1212-
(println (format "index %s already exists." idx-name))
1213-
index-set))
1222+
new-index-set (let [new-idx-set (add-new-granule-provider-index index-set idx-name)]
1223+
(try
1224+
(index-set-service/update-index-set context new-idx-set)
1225+
(catch Exception _e
1226+
(println (format "index %s already exists." idx-name))
1227+
new-idx-set)))
12141228
_ (println "new-index-set" new-index-set)
1229+
_ (when (nil? new-index-set)
1230+
(println "index-set is:" index-set)
1231+
(println "index-set is:" (:index-set index-set))
1232+
(println "index-set is granule:" (:granule (:index-set index-set)))
1233+
(println "index-set is:" (:indexes (:granule (:index-set index-set)))))
12151234
new-index-name (str index-set-id "_" idx-name)
12161235
new-index-names (update-in (get-concept-type-index-names context) [:index-names :granule] #(assoc % (keyword idx-name) new-index-name))
12171236
;; This needs to set the in memory cache
1218-
_ (set-concept-type-index-names context new-index-names)]
1219-
new-index-name)))
1220-
(get indexes :small_collections))
1221-
]
1237+
_ (set-concept-type-index-names context new-index-names)
1238+
;; this needs to set the search redis cache - this cache and the one above need to be combined into redis
12221239

1240+
_ (set-search-index-names-cache context (keyword idx-name) new-index-name)]
1241+
new-index-name)))
1242+
(get indexes :small_collections))]
12231243
(cond
12241244
target-index-key
12251245
[(get indexes target-index-key)]

indexer-app/src/cmr/indexer/services/index_set_service.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@
210210
es-store (indexer-util/context->es-store context)]
211211

212212
(doseq [idx indices-w-config]
213-
(es/update-index es-store idx))
213+
(try
214+
(es/update-index es-store idx)
215+
(catch Exception e
216+
(println "Caught exeption updating or creating" e))))
214217

215218
(index-requested-index-set context index-set)))
216219

indexer-app/src/cmr/indexer/system.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
[cmr.common.nrepl :as nrepl]
1919
[cmr.common.system :as common-sys]
2020
[cmr.elastic-utils.config :as es-config]
21+
[cmr.elastic-utils.search.es-index-name-cache :as elastic-search-index-names-cache]
2122
[cmr.indexer.api.routes :as routes]
2223
[cmr.indexer.config :as config]
2324
[cmr.indexer.data.collection-granule-aggregation-cache :as cgac]
@@ -61,7 +62,9 @@
6162
:web (web/create-web-server (transmit-config/indexer-port) routes/make-api)
6263
:nrepl (nrepl/create-nrepl-if-configured (config/indexer-nrepl-port))
6364
:relative-root-url (transmit-config/indexer-relative-root-url)
64-
:caches {af/acl-cache-key (af/create-consistent-acl-cache
65+
:caches {;; first cache to set the search redis cache because the index set cache is different.
66+
elastic-search-index-names-cache/index-names-cache-key (elastic-search-index-names-cache/create-index-cache)
67+
af/acl-cache-key (af/create-consistent-acl-cache
6568
[:catalog-item :system-object :provider-object])
6669
index-set/index-set-cache-key (consistent-cache/create-consistent-cache
6770
{:hash-timeout-seconds (index-set-cache-consistent-timeout-seconds)

search-app/src/cmr/search/data/elastic_search_index.clj

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
(apply dissoc granule-index-names (map keyword rebalancing-collections))))
4343
(comment
4444
(println indexes)
45+
(let [cache (hcache/context->cache context1 cache-key)]
46+
(hcache/get-value cache cache-key :granule))
47+
(:granule (:index-names (index-names-cache/refresh-index-names-cache context1)))
48+
49+
; granule-index-names (or (hcache/get-value cache cache-key :granule)
50+
; (do
51+
; (index-names-cache/refresh-index-names-cache context)
52+
; (hcache/get-value cache cache-key :granule)))
53+
; rebalancing-collections (hcache/get-value cache cache-key :rebalancing-collections)]
54+
; (apply dissoc granule-index-names (map keyword rebalancing-collections)))
4555
)
4656
(defn- collection-concept-id->index-name
4757
"Return the granule index name for the input collection concept id"
@@ -57,10 +67,12 @@
5767
"Return the granule index names for the input collection concept ids"
5868
[context coll-concept-ids]
5969
(let [indexes (get-granule-index-names context)]
60-
(distinct (map #(collection-concept-id->index-name indexes %) coll-concept-ids))))
70+
(remove nil?
71+
(distinct (map #(collection-concept-id->index-name indexes %) coll-concept-ids)))))
6172

6273
(comment
63-
(println context)
74+
(println context1)
75+
(get-granule-index-names context1)
6476
)
6577
(defn- provider-ids->index-names
6678
"Return the granule index names for the input provider-ids"
@@ -97,9 +109,19 @@
97109
(format "%d_c*,%d_small_collections,-%d_collections*%s"
98110
index-set-id index-set-id index-set-id excluded-collections-str))))
99111

112+
(comment
113+
(println query1)
114+
(get-granule-indexes context1 query1)
115+
116+
(let [coll-concept-ids (seq (cex/extract-collection-concept-ids query1))]
117+
(collection-concept-ids->index-names context1 coll-concept-ids))
118+
)
119+
100120
(defn- get-granule-indexes
101121
"Returns the granule indexes that should be searched based on the input query"
102122
[context query]
123+
(def context1 context)
124+
(def query1 query)
103125
(let [coll-concept-ids (seq (cex/extract-collection-concept-ids query))
104126
provider-ids (seq (pex/extract-provider-ids query))]
105127
(cond

system-int-test/src/cmr/system_int_test/system.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[cmr.common.system :as common-sys]
1212
[cmr.common-app.services.kms-fetcher :as kf]
1313
[cmr.common-app.services.kms-lookup :as kl]
14+
[cmr.elastic-utils.search.es-index-name-cache :as elastic-search-index-names-cache]
1415
[cmr.metadata-db.services.util :as mdb-util]
1516
[cmr.oracle.connection :as oracle]
1617
[cmr.system-int-test.utils.url-helper :as url]
@@ -42,7 +43,8 @@
4243
kl/kms-short-name-cache-key (kl/create-kms-short-name-cache)
4344
kl/kms-umm-c-cache-key (kl/create-kms-umm-c-cache)
4445
kl/kms-location-cache-key (kl/create-kms-location-cache)
45-
kl/kms-measurement-cache-key (kl/create-kms-measurement-cache)})
46+
kl/kms-measurement-cache-key (kl/create-kms-measurement-cache)
47+
elastic-search-index-names-cache/index-names-cache-key (elastic-search-index-names-cache/create-index-cache)})
4648

4749
(defn create-system
4850
"Returns a new instance of the whole application."

0 commit comments

Comments
 (0)