Skip to content

Commit f09c188

Browse files
author
Nagaraj G
committed
Fix partial cache update post snapshot restore
Signed-off-by: Nagaraj G <narajg@amazon.com>
1 parent 5384cf3 commit f09c188

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
* Provide SecureHttpTransportParameters to complement SecureTransportParameters counterpart ([#5432](https://github.com/opensearch-project/security/pull/5432))
2727
* Use isClusterPerm instead of requestedResolved.isLocalAll() to determine if action is a cluster action ([#5445](https://github.com/opensearch-project/security/pull/5445))
2828
* Fix config update with deprecated config types failing in mixed clusters ([#5456](https://github.com/opensearch-project/security/pull/5456))
29+
* Fix partial cache update post snapshot restore[#5478](https://github.com/opensearch-project/security/pull/5478)
2930

3031
### Refactoring
3132

src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,10 @@ public void afterIndexShardStarted(IndexShard indexShard) {
681681

682682
// Check if this is a security index shard
683683
if (securityIndex.equals(index.getName())) {
684-
// Only trigger on primary shard to avoid multiple reloads
685-
if (indexShard.routingEntry() != null && indexShard.routingEntry().primary()) {
684+
if (indexShard.routingEntry() != null) {
686685
threadPool.generic().execute(() -> {
687686
if (isSecurityIndexRestoredFromSnapshot(clusterService, index, securityIndex)) {
688-
LOGGER.info("Security index primary shard {} started - config reloading for snapshot restore", shardId);
687+
LOGGER.info("Security index shard {} started - config reloading for snapshot restore", shardId);
689688
reloadConfiguration(CType.values());
690689
}
691690
});

src/test/java/org/opensearch/security/configuration/ConfigurationRepositoryTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,7 @@ public void afterIndexShardStarted_whenSecurityIndexUpdated() throws Interrupted
616616
when(mockClusterState.custom(RestoreInProgress.TYPE)).thenReturn(mockRestore);
617617
when(threadPool.generic()).thenReturn(executorService);
618618

619-
// when replica shard updated
620-
when(shardRouting.primary()).thenReturn(false);
621-
configurationRepository.afterIndexShardStarted(indexShard);
622-
verify(executorService, never()).execute(any());
623-
verify(configurationRepository, never()).reloadConfiguration(any());
624-
625-
// when primary shard updated
626619
doReturn(true).when(configurationRepository).reloadConfiguration(any());
627-
when(shardRouting.primary()).thenReturn(true);
628620
when(mockRestore.iterator()).thenReturn(Collections.singletonList(mockEntry).iterator());
629621
when(mockEntry.indices()).thenReturn(Collections.singletonList(ConfigConstants.OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX));
630622
ArgumentCaptor<Runnable> successRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
@@ -637,7 +629,6 @@ public void afterIndexShardStarted_whenSecurityIndexUpdated() throws Interrupted
637629
Mockito.reset(configurationRepository, executorService);
638630
ArgumentCaptor<Runnable> errorRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
639631
when(clusterService.state()).thenThrow(new RuntimeException("ClusterState exception"));
640-
when(shardRouting.primary()).thenReturn(true);
641632
configurationRepository.afterIndexShardStarted(indexShard);
642633
verify(executorService).execute(errorRunnableCaptor.capture());
643634
errorRunnableCaptor.getValue().run();

0 commit comments

Comments
 (0)