You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: leader_elector.go
    path of file: ./repos/kuma/pkg/plugins/leader/postgres
    
    the code of the file until where you have to start completion: package postgres

import (
	"context"
	"fmt"
	"sync/atomic"
	"time"

	"cirello.io/pglock"

	"github.com/kumahq/kuma/pkg/core"
	"github.com/kumahq/kuma/pkg/cor
    
func (p *postgresLeaderElector) Start(stop <-chan struct{}) {
	log.Info("starting Leader Elector")
	ctx, cancelFn := context.WithCancel(context.Background())
	go func() {
		<-stop
		log.Info("stopping Leader Elector")
		cancelFn()
	}()

	retries := 0
	for {
		log.Info("waiting for lock")
		err := p.lockClient.Do(ctx, kumaLockName, func(ctx context.Context, lock *pglock.Lock) error {
			p.leaderAcquired()
			<-ctx.Done()
			p.leaderLost()
			return nil
		})
		// in case of error (ex. connection to postgres is dropped) we want to retry the lock with some backoff
		// returning error here would shut down the CP
		// according to https://github.com/cirello-io/pglock/blob/d0d1ce72df710b5da6bdc27f9c44d9ae7bf1d3a2/errors.go#L86
		// ErrNotAcquired could be normal lock contestation
		if err != nil {
			if retries >= 3 {
				log.Error(err, "error waiting for lock", "retries", retries)
			} else {
				log.V(1).Info("error waiting for lock", "err", err, "retries", retries)
			}
			retries += 1
		} else {
			retries = 0
		}

		if util_channels.IsClosed(stop) {
			break
		}
		time.Sleep(backoffTime)
	}
	log.Info("Leader Elector stopped")
}