88using System ;
99using System . Collections . Concurrent ;
1010using System . Linq ;
11- using System . Reflection ;
1211using System . Threading ;
1312using Akka . Actor ;
1413using Akka . Annotations ;
@@ -21,18 +20,21 @@ namespace Akka.Persistence
2120{
2221 internal struct PluginHolder
2322 {
24- public PluginHolder ( IActorRef @ref , EventAdapters adapters , Config config )
23+ public PluginHolder ( IActorRef @ref , EventAdapters adapters , Config config , IActorRef recoveryPermitter )
2524 {
2625 Ref = @ref ;
2726 Adapters = adapters ;
2827 Config = config ;
28+ RecoveryPermitter = recoveryPermitter ;
2929 }
3030
3131 public IActorRef Ref { get ; }
3232
3333 public EventAdapters Adapters { get ; }
3434
3535 public Config Config { get ; }
36+
37+ public IActorRef RecoveryPermitter { get ; }
3638 }
3739
3840 /// <summary>
@@ -50,7 +52,6 @@ public class PersistenceExtension : IExtension
5052 private readonly Lazy < string > _defaultJournalPluginId ;
5153 private readonly Lazy < string > _defaultSnapshotPluginId ;
5254 private readonly Lazy < IStashOverflowStrategy > _defaultInternalStashOverflowStrategy ;
53- private readonly Lazy < IActorRef > _recoveryPermitter ;
5455
5556 private readonly ConcurrentDictionary < string , Lazy < PluginHolder > > _pluginExtensionIds = new ( ) ;
5657
@@ -120,12 +121,6 @@ public PersistenceExtension(ExtendedActorSystem system)
120121 _log . Info ( "Auto-starting snapshot store `{0}`" , id ) ;
121122 SnapshotStoreFor ( id ) ;
122123 } ) ;
123-
124- _recoveryPermitter = new Lazy < IActorRef > ( ( ) =>
125- {
126- var maxPermits = _config . GetInt ( "max-concurrent-recoveries" , 0 ) ;
127- return _system . SystemActorOf ( Akka . Persistence . RecoveryPermitter . Props ( maxPermits ) , "recoveryPermitter" ) ;
128- } ) ;
129124 }
130125
131126 /// <summary>
@@ -152,9 +147,10 @@ public string PersistenceId(IActorRef actor)
152147 /// INTERNAL API: When starting many persistent actors at the same time the journal its data store is protected
153148 /// from being overloaded by limiting number of recoveries that can be in progress at the same time.
154149 /// </summary>
155- internal IActorRef RecoveryPermitter ( )
150+ internal IActorRef RecoveryPermitterFor ( string journalPluginId )
156151 {
157- return _recoveryPermitter . Value ;
152+ var configPath = string . IsNullOrEmpty ( journalPluginId ) ? _defaultJournalPluginId . Value : journalPluginId ;
153+ return PluginHolderFor ( configPath , JournalFallbackConfigPath ) . RecoveryPermitter ;
158154 }
159155
160156 /// <summary>
@@ -270,6 +266,17 @@ private PluginHolder PluginHolderFor(string configPath, string fallbackPath)
270266 return pluginContainer . Value ;
271267 }
272268
269+ private static IActorRef CreateRecoveryPermitter ( ExtendedActorSystem system , string configPath , Config pluginConfig )
270+ {
271+ // backward compatibility
272+ // get the setting from the plugin path, if not found, default to the one defined in "akka.persistence"
273+ var maxPermits = pluginConfig . HasPath ( "max-concurrent-recoveries" )
274+ ? pluginConfig . GetInt ( "max-concurrent-recoveries" )
275+ : system . Settings . Config . GetInt ( "akka.persistence.max-concurrent-recoveries" ) ;
276+
277+ return system . SystemActorOf ( RecoveryPermitter . Props ( maxPermits ) , $ "recoveryPermitter-{ configPath } ") ;
278+ }
279+
273280 private static IActorRef CreatePlugin ( ExtendedActorSystem system , string configPath , Config pluginConfig )
274281 {
275282 var pluginActorName = configPath ;
@@ -303,8 +310,9 @@ private static PluginHolder NewPluginHolder(ExtendedActorSystem system, string c
303310 var config = system . Settings . Config . GetConfig ( configPath ) . WithFallback ( system . Settings . Config . GetConfig ( fallbackPath ) ) ;
304311 var plugin = CreatePlugin ( system , configPath , config ) ;
305312 var adapters = CreateAdapters ( system , configPath ) ;
313+ var recoveryPermitter = CreateRecoveryPermitter ( system , configPath , config ) ;
306314
307- return new PluginHolder ( plugin , adapters , config ) ;
315+ return new PluginHolder ( plugin , adapters , config , recoveryPermitter ) ;
308316 }
309317 }
310318
0 commit comments