@@ -143,8 +143,9 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
143143 })
144144
145145 var (
146- jobsdbPool * sql.DB
147- priorityPool * sql.DB
146+ jobsdbPool * sql.DB
147+ priorityPool * sql.DB
148+ maintenancePool * sql.DB
148149 )
149150 if config .GetBoolVar (true , "DB.embedded.Pool.enabled" , "DB.Pool.enabled" ) {
150151 jobsdbPool , err = misc .NewDatabaseConnectionPool (ctx , "embedded" , misc.DatabaseConnectionPoolConfig {
@@ -172,6 +173,19 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
172173 }
173174 defer priorityPool .Close ()
174175 }
176+ if config .GetBoolVar (true , "DB.embedded.MaintenancePool.enabled" , "DB.MaintenancePool.enabled" ) {
177+ maintenancePool , err = misc .NewDatabaseConnectionPool (ctx , "emp" , misc.DatabaseConnectionPoolConfig {
178+ MaxOpenConns : config .GetReloadableIntVar (20 , 1 , "DB.embedded.MaintenancePool.maxOpenConnections" , "DB.MaintenancePool.maxOpenConnections" ),
179+ MaxIdleConns : config .GetReloadableIntVar (2 , 1 , "DB.embedded.MaintenancePool.maxIdleConnections" , "DB.MaintenancePool.maxIdleConnections" ),
180+ ConnMaxIdleTime : config .GetReloadableDurationVar (15 , time .Minute , "DB.embedded.MaintenancePool.maxIdleTime" , "DB.MaintenancePool.maxIdleTime" ),
181+ ConnMaxLifetime : config .GetReloadableDurationVar (0 , time .Second , "DB.embedded.MaintenancePool.maxConnLifetime" , "DB.MaintenancePool.maxConnLifetime" ),
182+ UpdateInterval : config .GetDurationVar (60 , time .Second , "DB.embedded.MaintenancePool.updateInterval" , "DB.MaintenancePool.updateInterval" ),
183+ }, config , statsFactory )
184+ if err != nil {
185+ return err
186+ }
187+ defer maintenancePool .Close ()
188+ }
175189 partitionCount := config .GetIntVar (0 , 1 , "JobsDB.partitionCount" )
176190
177191 pendingEventsRegistry := rmetrics .NewPendingEventsRegistry ()
@@ -186,6 +200,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
186200 jobsdb .WithDBHandle (jobsdbPool ),
187201 jobsdb .WithNumPartitions (partitionCount ),
188202 jobsdb .WithPriorityPoolDB (priorityPool ),
203+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
189204 )
190205 defer gwWOHandle .Close ()
191206 if err = gwWOHandle .Start (); err != nil {
@@ -201,6 +216,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
201216 jobsdb .WithStats (statsFactory ),
202217 jobsdb .WithDBHandle (jobsdbPool ),
203218 jobsdb .WithPriorityPoolDB (priorityPool ),
219+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
204220 jobsdb .WithNumPartitions (partitionCount ),
205221 )
206222 defer gwROHandle .Close ()
@@ -214,6 +230,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
214230 jobsdb .WithStats (statsFactory ),
215231 jobsdb .WithDBHandle (jobsdbPool ),
216232 jobsdb .WithPriorityPoolDB (priorityPool ),
233+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
217234 jobsdb .WithNumPartitions (partitionCount ),
218235 )
219236 defer rtRWHandle .Close ()
@@ -227,6 +244,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
227244 jobsdb .WithStats (statsFactory ),
228245 jobsdb .WithDBHandle (jobsdbPool ),
229246 jobsdb .WithPriorityPoolDB (priorityPool ),
247+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
230248 jobsdb .WithNumPartitions (partitionCount ),
231249 )
232250 defer brtRWHandle .Close ()
@@ -239,6 +257,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
239257 jobsdb .WithSkipMaintenanceErr (config .GetBoolVar (false , "Processor.jobsDB.skipMaintenanceError" )),
240258 jobsdb .WithStats (statsFactory ),
241259 jobsdb .WithDBHandle (jobsdbPool ),
260+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
242261 )
243262 defer eschRWDB .Close ()
244263
@@ -250,6 +269,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
250269 jobsdb .WithStats (statsFactory ),
251270 jobsdb .WithJobMaxAge (config .GetReloadableDurationVar (24 , time .Hour , "archival.jobRetention" )),
252271 jobsdb .WithDBHandle (jobsdbPool ),
272+ jobsdb .WithMaintenancePoolDB (maintenancePool ),
253273 )
254274 defer arcRWDB .Close ()
255275
@@ -271,7 +291,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
271291 }
272292
273293 // setup partition migrator
274- ppmSetup , err := setupProcessorPartitionMigrator (ctx , shutdownFn , jobsdbPool , priorityPool ,
294+ ppmSetup , err := setupProcessorPartitionMigrator (ctx , shutdownFn , jobsdbPool , priorityPool , maintenancePool ,
275295 config , statsFactory ,
276296 gwRODB , gwWODB ,
277297 rtRWDB , brtRWDB ,
0 commit comments