Skip to content

Commit 49e7df6

Browse files
committed
wip
1 parent 478875d commit 49e7df6

20 files changed

+196
-818
lines changed

adapters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var ErrInvalidCommand = errors.New("invalid command type")
1717
// ErrInvalidPool is returned when the pool type is not supported.
1818
var ErrInvalidPool = errors.New("invalid pool type")
1919

20-
// NewClientAdapter creates a new client adapter for regular Redis clients.
21-
func NewClientAdapter(client *baseClient) interfaces.ClientInterface {
20+
// newClientAdapter creates a new client adapter for regular Redis clients.
21+
func newClientAdapter(client *baseClient) interfaces.ClientInterface {
2222
return &clientAdapter{client: client}
2323
}
2424

async_handoff_integration_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
4141
}
4242

4343
// Create processor with event-driven handoff support
44-
processor := hitless.NewPoolHook(3, baseDialer, nil, nil)
44+
processor := hitless.NewPoolHook(baseDialer, nil, nil)
4545
defer processor.Shutdown(context.Background())
4646

4747
// Create a test pool with hooks
@@ -52,10 +52,12 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
5252
Dialer: func(ctx context.Context) (net.Conn, error) {
5353
return &mockNetConn{addr: "original:6379"}, nil
5454
},
55-
PoolHooks: hookManager,
56-
PoolSize: 5,
57-
PoolTimeout: time.Second,
55+
PoolSize: 5,
56+
PoolTimeout: time.Second,
5857
})
58+
59+
// Add the hook to the pool after creation
60+
testPool.AddPoolHook(processor)
5961
defer testPool.Close()
6062

6163
// Set the pool reference in the processor for connection removal on handoff failure
@@ -131,7 +133,7 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
131133
return &mockNetConn{addr: addr}, nil
132134
}
133135

134-
processor := hitless.NewPoolHook(3, baseDialer, nil, nil)
136+
processor := hitless.NewPoolHook(baseDialer, nil, nil)
135137
defer processor.Shutdown(context.Background())
136138

137139
// Create hooks manager and add processor as hook
@@ -142,12 +144,15 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
142144
Dialer: func(ctx context.Context) (net.Conn, error) {
143145
return &mockNetConn{addr: "original:6379"}, nil
144146
},
145-
PoolHooks: hookManager,
147+
146148
PoolSize: 10,
147149
PoolTimeout: time.Second,
148150
})
149151
defer testPool.Close()
150152

153+
// Add the hook to the pool after creation
154+
testPool.AddPoolHook(processor)
155+
151156
// Set the pool reference in the processor
152157
processor.SetPool(testPool)
153158

@@ -200,7 +205,7 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
200205
return nil, &net.OpError{Op: "dial", Err: &net.DNSError{Name: addr}}
201206
}
202207

203-
processor := hitless.NewPoolHook(3, failingDialer, nil, nil)
208+
processor := hitless.NewPoolHook(failingDialer, nil, nil)
204209
defer processor.Shutdown(context.Background())
205210

206211
// Create hooks manager and add processor as hook
@@ -211,12 +216,15 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
211216
Dialer: func(ctx context.Context) (net.Conn, error) {
212217
return &mockNetConn{addr: "original:6379"}, nil
213218
},
214-
PoolHooks: hookManager,
219+
215220
PoolSize: 3,
216221
PoolTimeout: time.Second,
217222
})
218223
defer testPool.Close()
219224

225+
// Add the hook to the pool after creation
226+
testPool.AddPoolHook(processor)
227+
220228
// Set the pool reference in the processor
221229
processor.SetPool(testPool)
222230

@@ -260,7 +268,7 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
260268
return &mockNetConn{addr: addr}, nil
261269
}
262270

263-
processor := hitless.NewPoolHook(3, slowDialer, nil, nil)
271+
processor := hitless.NewPoolHook(slowDialer, nil, nil)
264272

265273
// Create hooks manager and add processor as hook
266274
hookManager := pool.NewPoolHookManager()
@@ -270,12 +278,15 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
270278
Dialer: func(ctx context.Context) (net.Conn, error) {
271279
return &mockNetConn{addr: "original:6379"}, nil
272280
},
273-
PoolHooks: hookManager,
281+
274282
PoolSize: 2,
275283
PoolTimeout: time.Second,
276284
})
277285
defer testPool.Close()
278286

287+
// Add the hook to the pool after creation
288+
testPool.AddPoolHook(processor)
289+
279290
// Set the pool reference in the processor
280291
processor.SetPool(testPool)
281292

commands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ func (c cmdable) ClientInfo(ctx context.Context) *ClientInfoCmd {
524524
func (c cmdable) ClientMaintNotifications(ctx context.Context, enabled bool, endpointType string) *StatusCmd {
525525
args := []interface{}{"client", "maint_notifications"}
526526
if enabled {
527+
if endpointType == "" {
528+
endpointType = "none"
529+
}
527530
args = append(args, "on", "moving-endpoint-type", endpointType)
528531
} else {
529532
args = append(args, "off")

hitless/config.go

Lines changed: 22 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,26 @@ func DefaultConfig() *Config {
206206
LogLevel: 1,
207207

208208
// Connection Handoff Configuration
209-
MaxHandoffRetries: 3,
210-
HandoffQueueTimeout: 5 * time.Second,
211-
HandoffRetryDelay: 1 * time.Second,
209+
MaxHandoffRetries: 3,
210+
HandoffQueueTimeout: 5 * time.Second,
211+
HandoffRetryDelay: 1 * time.Second,
212212

213213
// Worker Scaling Configuration
214-
WorkerScaleDownDelay: 30 * time.Second,
215-
WorkerScaleUpDelay: 5 * time.Second,
216-
WorkerIdleTimeout: 60 * time.Second,
214+
WorkerScaleDownDelay: 30 * time.Second,
215+
WorkerScaleUpDelay: 5 * time.Second,
216+
WorkerIdleTimeout: 60 * time.Second,
217217

218218
// Connection Validation Configuration
219-
ConnectionValidationTimeout: 2 * time.Second,
220-
ConnectionHealthCheckInterval: 10 * time.Second,
219+
ConnectionValidationTimeout: 2 * time.Second,
220+
ConnectionHealthCheckInterval: 10 * time.Second,
221221

222222
// Operation Tracking Configuration
223223
OperationCleanupInterval: 5 * time.Minute,
224224
MaxActiveOperations: 10000,
225225

226226
// Notification Processing Configuration
227-
NotificationBufferSize: 1000,
228-
NotificationTimeout: 1 * time.Second,
227+
NotificationBufferSize: 1000,
228+
NotificationTimeout: 1 * time.Second,
229229
}
230230
}
231231

@@ -318,90 +318,6 @@ func (c *Config) Validate() error {
318318
return nil
319319
}
320320

321-
// ProductionConfig returns a Config optimized for production environments.
322-
// This configuration is tuned for high-load scenarios with enhanced reliability.
323-
func ProductionConfig() *Config {
324-
return &Config{
325-
// Basic settings
326-
Enabled: MaintNotificationsEnabled,
327-
EndpointType: EndpointTypeAuto,
328-
RelaxedTimeout: 45 * time.Second,
329-
HandoffTimeout: 20 * time.Second,
330-
PostHandoffRelaxedDuration: 15 * time.Second,
331-
332-
// Enhanced performance settings for production
333-
MaxHandoffRetries: 5,
334-
HandoffQueueTimeout: 10 * time.Second,
335-
HandoffRetryDelay: 2 * time.Second,
336-
337-
// Worker scaling for high load
338-
MinWorkers: 8,
339-
MaxWorkers: 64,
340-
HandoffQueueSize: 2000,
341-
WorkerScaleDownDelay: 60 * time.Second,
342-
WorkerScaleUpDelay: 3 * time.Second,
343-
WorkerIdleTimeout: 120 * time.Second,
344-
345-
// Connection management
346-
ConnectionValidationTimeout: 3 * time.Second,
347-
ConnectionHealthCheckInterval: 30 * time.Second,
348-
349-
// Operation management for high throughput
350-
OperationCleanupInterval: 2 * time.Minute,
351-
MaxActiveOperations: 50000,
352-
353-
// Monitoring and observability
354-
LogLevel: 1, // Warnings and errors
355-
NotificationBufferSize: 5000,
356-
NotificationTimeout: 2 * time.Second,
357-
358-
// Existing fields
359-
ScaleDownDelay: 2 * time.Second,
360-
}
361-
}
362-
363-
// DevelopmentConfig returns a Config optimized for development environments.
364-
// This configuration prioritizes debugging and has conservative resource usage.
365-
func DevelopmentConfig() *Config {
366-
return &Config{
367-
// Basic settings
368-
Enabled: MaintNotificationsAuto,
369-
EndpointType: EndpointTypeAuto,
370-
RelaxedTimeout: 10 * time.Second,
371-
HandoffTimeout: 5 * time.Second,
372-
PostHandoffRelaxedDuration: 3 * time.Second,
373-
374-
// Conservative performance settings
375-
MaxHandoffRetries: 3,
376-
HandoffQueueTimeout: 5 * time.Second,
377-
HandoffRetryDelay: 1 * time.Second,
378-
379-
// Minimal worker scaling
380-
MinWorkers: 2,
381-
MaxWorkers: 8,
382-
HandoffQueueSize: 100,
383-
WorkerScaleDownDelay: 30 * time.Second,
384-
WorkerScaleUpDelay: 5 * time.Second,
385-
WorkerIdleTimeout: 60 * time.Second,
386-
387-
// Connection management
388-
ConnectionValidationTimeout: 2 * time.Second,
389-
ConnectionHealthCheckInterval: 10 * time.Second,
390-
391-
// Frequent cleanup for testing
392-
OperationCleanupInterval: 30 * time.Second,
393-
MaxActiveOperations: 1000,
394-
395-
// Verbose logging for debugging
396-
LogLevel: 3, // Debug level
397-
NotificationBufferSize: 100,
398-
NotificationTimeout: 1 * time.Second,
399-
400-
// Existing fields
401-
ScaleDownDelay: 2 * time.Second,
402-
}
403-
}
404-
405321
// ApplyDefaults applies default values to any zero-value fields in the configuration.
406322
// This ensures that partially configured structs get sensible defaults for missing fields.
407323
func (c *Config) ApplyDefaults() *Config {
@@ -579,18 +495,18 @@ func (c *Config) Clone() *Config {
579495
LogLevel: c.LogLevel,
580496

581497
// New configuration fields
582-
MaxHandoffRetries: c.MaxHandoffRetries,
583-
HandoffQueueTimeout: c.HandoffQueueTimeout,
584-
HandoffRetryDelay: c.HandoffRetryDelay,
585-
WorkerScaleDownDelay: c.WorkerScaleDownDelay,
586-
WorkerScaleUpDelay: c.WorkerScaleUpDelay,
587-
WorkerIdleTimeout: c.WorkerIdleTimeout,
588-
ConnectionValidationTimeout: c.ConnectionValidationTimeout,
589-
ConnectionHealthCheckInterval: c.ConnectionHealthCheckInterval,
590-
OperationCleanupInterval: c.OperationCleanupInterval,
591-
MaxActiveOperations: c.MaxActiveOperations,
592-
NotificationBufferSize: c.NotificationBufferSize,
593-
NotificationTimeout: c.NotificationTimeout,
498+
MaxHandoffRetries: c.MaxHandoffRetries,
499+
HandoffQueueTimeout: c.HandoffQueueTimeout,
500+
HandoffRetryDelay: c.HandoffRetryDelay,
501+
WorkerScaleDownDelay: c.WorkerScaleDownDelay,
502+
WorkerScaleUpDelay: c.WorkerScaleUpDelay,
503+
WorkerIdleTimeout: c.WorkerIdleTimeout,
504+
ConnectionValidationTimeout: c.ConnectionValidationTimeout,
505+
ConnectionHealthCheckInterval: c.ConnectionHealthCheckInterval,
506+
OperationCleanupInterval: c.OperationCleanupInterval,
507+
MaxActiveOperations: c.MaxActiveOperations,
508+
NotificationBufferSize: c.NotificationBufferSize,
509+
NotificationTimeout: c.NotificationTimeout,
594510
}
595511
}
596512

hitless/config_test.go

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func TestProcessorWithConfig(t *testing.T) {
249249
return &mockNetConn{addr: addr}, nil
250250
}
251251

252-
processor := NewPoolHook(3, baseDialer, config, nil)
252+
processor := NewPoolHook(baseDialer, config, nil)
253253
defer processor.Shutdown(context.Background())
254254

255255
// The processor should be created successfully with custom config
@@ -269,7 +269,7 @@ func TestProcessorWithConfig(t *testing.T) {
269269
return &mockNetConn{addr: addr}, nil
270270
}
271271

272-
processor := NewPoolHook(3, baseDialer, config, nil)
272+
processor := NewPoolHook(baseDialer, config, nil)
273273
defer processor.Shutdown(context.Background())
274274

275275
// Should work with partial config (defaults applied)
@@ -283,7 +283,7 @@ func TestProcessorWithConfig(t *testing.T) {
283283
return &mockNetConn{addr: addr}, nil
284284
}
285285

286-
processor := NewPoolHook(3, baseDialer, nil, nil)
286+
processor := NewPoolHook(baseDialer, nil, nil)
287287
defer processor.Shutdown(context.Background())
288288

289289
// Should use default config when nil is passed
@@ -308,7 +308,7 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
308308
}
309309

310310
// Create processor - should apply defaults to missing fields
311-
processor := NewPoolHook(3, baseDialer, partialConfig, nil)
311+
processor := NewPoolHook(baseDialer, partialConfig, nil)
312312
defer processor.Shutdown(context.Background())
313313

314314
// Processor should be created successfully
@@ -406,53 +406,8 @@ func TestEnhancedConfigValidation(t *testing.T) {
406406
})
407407
}
408408

409-
func TestProductionConfig(t *testing.T) {
410-
config := ProductionConfig()
411-
412-
// Test production-specific values
413-
if config.Enabled != MaintNotificationsEnabled {
414-
t.Errorf("Expected production config to have Enabled = MaintNotificationsEnabled, got %v", config.Enabled)
415-
}
416-
if config.MaxHandoffRetries != 5 {
417-
t.Errorf("Expected production config to have MaxHandoffRetries = 5, got %d", config.MaxHandoffRetries)
418-
}
419-
if config.HandoffQueueTimeout != 10*time.Second {
420-
t.Errorf("Expected production config to have HandoffQueueTimeout = 10s, got %v", config.HandoffQueueTimeout)
421-
}
422-
if config.MaxActiveOperations != 50000 {
423-
t.Errorf("Expected production config to have MaxActiveOperations = 50000, got %d", config.MaxActiveOperations)
424-
}
425-
426-
// Should be valid
427-
config.ApplyDefaultsWithPoolSize(100)
428-
if err := config.Validate(); err != nil {
429-
t.Errorf("Production config should be valid, got error: %v", err)
430-
}
431-
}
432-
433-
func TestDevelopmentConfig(t *testing.T) {
434-
config := DevelopmentConfig()
435-
436-
// Test development-specific values
437-
if config.Enabled != MaintNotificationsAuto {
438-
t.Errorf("Expected development config to have Enabled = MaintNotificationsAuto, got %v", config.Enabled)
439-
}
440-
if config.LogLevel != 3 {
441-
t.Errorf("Expected development config to have LogLevel = 3 (debug), got %d", config.LogLevel)
442-
}
443-
if config.MaxActiveOperations != 1000 {
444-
t.Errorf("Expected development config to have MaxActiveOperations = 1000, got %d", config.MaxActiveOperations)
445-
}
446-
447-
// Should be valid
448-
config.ApplyDefaultsWithPoolSize(100)
449-
if err := config.Validate(); err != nil {
450-
t.Errorf("Development config should be valid, got error: %v", err)
451-
}
452-
}
453-
454409
func TestConfigClone(t *testing.T) {
455-
original := ProductionConfig()
410+
original := DefaultConfig()
456411
original.MaxHandoffRetries = 7
457412
original.HandoffQueueTimeout = 8 * time.Second
458413

0 commit comments

Comments
 (0)