@@ -58,8 +58,10 @@ public boolean apply(
5858 errors = null ;
5959
6060 List <ParsedConfigKey > configBeenUsedByProduct = new ArrayList <>();
61+ List <ParsedConfigKey > changedKeys = new ArrayList <>();
6162 boolean changesDetected = false ;
6263
64+ // Step 1: Detect all changes
6365 for (ParsedConfigKey configKey : relevantKeys ) {
6466 try {
6567 RemoteConfigResponse .Targets .ConfigTarget target =
@@ -68,14 +70,26 @@ public boolean apply(
6870
6971 if (isTargetChanged (configKey , target )) {
7072 changesDetected = true ;
71- byte [] content = getTargetFileContent (fleetResponse , configKey );
72- callListenerApplyTarget (fleetResponse , hinter , configKey , content );
73+ changedKeys .add (configKey );
7374 }
7475 } catch (ReportableException e ) {
7576 recordError (e );
7677 }
7778 }
7879
80+ // Step 2: For products other than ASM_DD, apply changes immediately
81+ if (product != Product .ASM_DD ) {
82+ for (ParsedConfigKey configKey : changedKeys ) {
83+ try {
84+ byte [] content = getTargetFileContent (fleetResponse , configKey );
85+ callListenerApplyTarget (fleetResponse , hinter , configKey , content );
86+ } catch (ReportableException e ) {
87+ recordError (e );
88+ }
89+ }
90+ }
91+
92+ // Step 3: Remove obsolete configurations (for all products)
7993 List <ParsedConfigKey > keysToRemove =
8094 cachedTargetFiles .keySet ().stream ()
8195 .filter (configKey -> !configBeenUsedByProduct .contains (configKey ))
@@ -86,6 +100,19 @@ public boolean apply(
86100 callListenerRemoveTarget (hinter , configKey );
87101 }
88102
103+ // Step 4: For ASM_DD, apply changes AFTER removes
104+ if (product == Product .ASM_DD ) {
105+ for (ParsedConfigKey configKey : changedKeys ) {
106+ try {
107+ byte [] content = getTargetFileContent (fleetResponse , configKey );
108+ callListenerApplyTarget (fleetResponse , hinter , configKey , content );
109+ } catch (ReportableException e ) {
110+ recordError (e );
111+ }
112+ }
113+ }
114+
115+ // Step 5: Commit if there were changes
89116 if (changesDetected ) {
90117 try {
91118 callListenerCommit (hinter );
0 commit comments