@@ -133,8 +133,9 @@ type Store struct {
133133 externalStore blob.Store
134134 utxoBatchSize int
135135 externalTxCache * util.ExpiringConcurrentCache [chainhash.Hash , * bt.Tx ]
136- indexMutex sync.Mutex // Mutex for index creation operations
137- indexOnce sync.Once // Ensures index creation/wait is only done once per process
136+ externalStoreSem chan struct {} // Semaphore to limit concurrent external storage operations
137+ indexMutex sync.Mutex // Mutex for index creation operations
138+ indexOnce sync.Once // Ensures index creation/wait is only done once per process
138139}
139140
140141// New creates a new Aerospike-based UTXO store.
@@ -191,6 +192,12 @@ func New(ctx context.Context, logger ulogger.Logger, tSettings *settings.Setting
191192 externalTxCache = util.NewExpiringConcurrentCache [chainhash.Hash , * bt.Tx ](10 * time .Second )
192193 }
193194
195+ // Initialize external store semaphore if concurrency limit is set
196+ var externalStoreSem chan struct {}
197+ if tSettings .UtxoStore .ExternalStoreConcurrency > 0 {
198+ externalStoreSem = make (chan struct {}, tSettings .UtxoStore .ExternalStoreConcurrency )
199+ }
200+
194201 s := & Store {
195202 ctx : ctx ,
196203 url : aerospikeURL ,
@@ -199,10 +206,11 @@ func New(ctx context.Context, logger ulogger.Logger, tSettings *settings.Setting
199206 setName : setName ,
200207 logger : logger ,
201208
202- settings : tSettings ,
203- externalStore : externalStore ,
204- utxoBatchSize : utxoBatchSize ,
205- externalTxCache : externalTxCache ,
209+ settings : tSettings ,
210+ externalStore : externalStore ,
211+ utxoBatchSize : utxoBatchSize ,
212+ externalTxCache : externalTxCache ,
213+ externalStoreSem : externalStoreSem ,
206214 }
207215
208216 // Ensure index creation/wait is only done once per process
0 commit comments