File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
core/src/main/scala/app/softnetwork/elastic/client Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -18,29 +18,31 @@ package app.softnetwork.elastic.client
1818
1919import app .softnetwork .elastic .client .result .{ElasticFailure , ElasticResult , ElasticSuccess }
2020
21+ import java .util .concurrent .atomic .AtomicReference
22+
2123trait VersionApi extends ElasticClientHelpers { _ : SerializationApi =>
2224
2325 // ========================================================================
2426 // PUBLIC METHODS
2527 // ========================================================================
2628
2729 // Cache ES version (avoids calling it every time)
28- @ volatile private var cachedVersion : Option [String ] = None
30+ private val cachedVersion = new AtomicReference [ Option [String ]]( None )
2931
3032 /** Get Elasticsearch version.
3133 * @return
3234 * the Elasticsearch version
3335 */
3436 def version : ElasticResult [String ] = {
35- cachedVersion match {
37+ cachedVersion.get match {
3638 case Some (version) =>
3739 ElasticSuccess (version)
3840 case None =>
3941 executeVersion() match {
40- case success @ ElasticSuccess (version) =>
42+ case ElasticSuccess (version) =>
4143 logger.info(s " ✅ Elasticsearch version: $version" )
42- cachedVersion = Some (version)
43- success
44+ cachedVersion.compareAndSet( None , Some (version) )
45+ ElasticSuccess (cachedVersion.get.getOrElse(version))
4446 case failure @ ElasticFailure (error) =>
4547 logger.error(s " ❌ Failed to get Elasticsearch version: ${error.message}" )
4648 failure
You can’t perform that action at this time.
0 commit comments