@@ -342,49 +342,17 @@ func (n *Node) PostInit(ctx context.Context) error {
342
342
}
343
343
}
344
344
345
- totalMembers := len (standbys ) + 1
346
- totalActive := 1
347
- totalInactive := 0
348
- totalConflicts := 0
349
-
350
- conflictMap := map [string ]int {}
351
-
352
- for _ , standby := range standbys {
353
- // Check for connectivity
354
- mConn , err := repmgr .NewRemoteConnection (ctx , standby .Hostname )
355
- if err != nil {
356
- fmt .Printf ("failed to connect to %s" , standby .Hostname )
357
- totalInactive ++
358
- continue
359
- }
360
- defer mConn .Close (ctx )
361
-
362
- // Verify the primary
363
- primary , err := repmgr .PrimaryMember (ctx , mConn )
364
- if err != nil {
365
- fmt .Printf ("failed to resolve primary from standby %s" , standby .Hostname )
366
- totalInactive ++
367
- continue
368
- }
369
-
370
- totalActive ++
371
-
372
- // Record conflict when primary doesn't match.
373
- if primary .Hostname != n .PrivateIP {
374
- totalConflicts ++
375
- conflictMap [primary .Hostname ]++
376
- }
345
+ // Collect sample data from registered standbys
346
+ sample , err := ZombieDNASample (ctx , n , standbys )
347
+ if err != nil {
348
+ return fmt .Errorf ("failed to resolve cluster metrics: %s" , err )
377
349
}
378
350
379
- primary , err := ZombieDiagnosis (n .PrivateIP , totalMembers , totalInactive , totalActive , conflictMap )
351
+ printDNASample (sample )
352
+
353
+ primary , err := ZombieDiagnosis (sample )
380
354
if errors .Is (err , ErrZombieDiagnosisUndecided ) {
381
355
fmt .Println ("Unable to confirm that we are the true primary!" )
382
- fmt .Printf ("Registered members: %d, Active member(s): %d, Inactive member(s): %d, Conflicts detected: %d\n " ,
383
- totalMembers ,
384
- totalActive ,
385
- totalInactive ,
386
- totalConflicts ,
387
- )
388
356
389
357
fmt .Println ("Writing zombie.lock file." )
390
358
if err := writeZombieLock ("" ); err != nil {
0 commit comments