101101import java .util .concurrent .Executor ;
102102import java .util .function .BiConsumer ;
103103import java .util .function .Consumer ;
104+ import java .util .stream .StreamSupport ;
104105
105106import static org .elasticsearch .core .Strings .format ;
106107import static org .elasticsearch .indices .cluster .IndexRemovalReason .CLOSED ;
@@ -709,7 +710,8 @@ private void createOrUpdateShard(ClusterState state, ShardRouting shardRouting,
709710
710711 @ SuppressForbidden (reason = "usage of unbatched task" ) // TODO add support for batching here
711712 private void renameIndices (ClusterChangedEvent event ) {
712- if (event .metadataChanged () == false ) {
713+ // No need to check any renamed indices if the no metadata has changed or the node is not the master node
714+ if (event .metadataChanged () == false || event .localNodeMaster () == false ) {
713715 return ;
714716 }
715717 final ClusterState state = event .state ();
@@ -815,7 +817,16 @@ private void updateIndices(ClusterChangedEvent event) {
815817 final Index index = indexService .getIndexSettings ().getIndex ();
816818 final Optional <ProjectMetadata > project = state .metadata ().lookupProject (index );
817819 final IndexMetadata newIndexMetadata = project .map (proj -> proj .index (index )).orElse (null );
818- if (newIndexMetadata == null && isBeingRenamed (previousState .metadata ().findIndex (index ).orElse (null ))) {
820+ if (newIndexMetadata == null ) {
821+ logger .info (
822+ "--> Updating. I have {}" ,
823+ StreamSupport .stream (previousState .metadata ().indicesAllProjects ().spliterator (), false )
824+ .map (IndexMetadata ::getIndex )
825+ .toList ()
826+ );
827+ }
828+ if (newIndexMetadata == null ) {
829+ // if (newIndexMetadata == null && isBeingRenamed(previousState.metadata().findIndex(index).orElse(null))) {
819830 logger .info ("--> skipping update for rename-in-progress for [{}]" , index .getName ());
820831 continue ;
821832 }
@@ -834,6 +845,7 @@ private void updateIndices(ClusterChangedEvent event) {
834845 reason = "mapping update failed" ;
835846 indexService .updateMapping (currentIndexMetadata , newIndexMetadata );
836847 } catch (Exception e ) {
848+ logger .info ("##> caught an error" , e );
837849 indicesService .removeIndex (
838850 index ,
839851 FAILURE ,
0 commit comments