Skip to content

Refresh the Ip2Geo cache and retry one more time when we run into an issue#766

Merged
heemin32 merged 1 commit intoopensearch-project:mainfrom
bzhangam:main
Jun 20, 2025
Merged

Refresh the Ip2Geo cache and retry one more time when we run into an issue#766
heemin32 merged 1 commit intoopensearch-project:mainfrom
bzhangam:main

Conversation

@bzhangam
Copy link
Copy Markdown
Contributor

@bzhangam bzhangam commented Jun 20, 2025

Description

Refresh the Ip2Geo cache and retry one more time when we run into an issue.

After we update the datasouce in the primary shard if we fail to send the request to the nodes with replica shard we will not update the cache. Even later the replica is recovered from the primary shard the cache update logic will not be triggered. So and this change to refresh the cache and retry when we run into an issue.

Related Issues

N/A

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@heemin32
Copy link
Copy Markdown
Collaborator

heemin32 commented Jun 20, 2025

I think we should just add retry in these four methods instead of handling each case outside of these methods. Otherwise, there will be case which we are missing to handle and also hard to maintain for future change.

    public boolean isExpired(final String datasourceName) {
        return getMetadata().getOrDefault(datasourceName, DatasourceMetadata.EMPTY_METADATA).getExpirationDate().isBefore(Instant.now());
    }

    public boolean has(final String datasourceName) {
        return getMetadata().containsKey(datasourceName);
    }

    public DatasourceState getState(final String datasourceName) {
        return getMetadata().getOrDefault(datasourceName, DatasourceMetadata.EMPTY_METADATA).getState();
    }

    public Map<String, Object> getGeoData(final String indexName, final String ip) {
        try {
            return geoDataCache.putIfAbsent(indexName, ip, addr -> geoIpDataDao.getGeoIpData(indexName, ip));
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

@heemin32 heemin32 closed this Jun 20, 2025
@heemin32 heemin32 reopened this Jun 20, 2025
@bzhangam bzhangam force-pushed the main branch 3 times, most recently from d0a2157 to bfff4d3 Compare June 20, 2025 19:28
Copy link
Copy Markdown
Collaborator

@heemin32 heemin32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

…issue.

Signed-off-by: Bo Zhang <bzhangam@amazon.com>
@heemin32 heemin32 merged commit 3e425b6 into opensearch-project:main Jun 20, 2025
18 of 20 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 20, 2025
…issue. (#766)

Signed-off-by: Bo Zhang <bzhangam@amazon.com>
(cherry picked from commit 3e425b6)
heemin32 pushed a commit that referenced this pull request Jun 20, 2025
…issue. (#766) (#767)

(cherry picked from commit 3e425b6)

Signed-off-by: Bo Zhang <bzhangam@amazon.com>
Co-authored-by: Bo Zhang <bzhangam@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants