Пример #1
0
// Initialize initializes an election object.
func (this *Election) Initialize(opts *Options, namespace, uid string,
	msn msg.Messenger, wal wal.WriteAheadLog) (status error) {

	re := regexp.MustCompile(uid)
	if err := wal.ConfigureRecoverer(re, this); err != nil {
		this.Errorf("could not configure wal recoverer: %v", err)
		return err
	}
	defer func() {
		if status != nil {
			if err := wal.ConfigureRecoverer(re, nil); err != nil {
				this.Errorf("could not unconfigure wal recoverer: %v", err)
				status = errs.MergeErrors(status, err)
			}
		}
	}()

	this.uid = uid
	this.namespace = namespace
	this.opts = *opts
	this.msn = msn
	this.wal = wal
	this.majoritySize = -1
	this.currentRound = -1
	this.classicPaxosMap = make(map[int64]*classic.Paxos)
	this.electionHistoryMap = make(map[int64]string)

	this.Logger = this.NewLogger("election-%s-%s", this.msn.UID(), this.uid)
	this.ctlr.Initialize(this)
	return nil
}
Пример #2
0
// Initialize initializes a classic paxos instance.
func (this *Paxos) Initialize(opts *Options, namespace, uid string,
	msn msg.Messenger, wal wal.WriteAheadLog) (status error) {

	if err := opts.Validate(); err != nil {
		this.Errorf("invalid user options: %v", err)
		return err
	}

	re := regexp.MustCompile(uid)
	if err := wal.ConfigureRecoverer(re, this); err != nil {
		this.Errorf("could not configure wal recoverer: %v", err)
		return err
	}
	defer func() {
		if status != nil {
			if err := wal.ConfigureRecoverer(re, nil); err != nil {
				this.Errorf("could not unconfigure wal recoverer: %v", err)
				status = errs.MergeErrors(status, err)
			}
		}
	}()

	this.wal = wal
	this.opts = *opts
	this.msn = msn
	this.uid = uid
	this.namespace = namespace
	this.proposerIndex = -1
	this.promisedBallot = -1
	this.votedBallot = -1
	this.majoritySize = -1
	this.proposalBallot = -1
	this.doneLearnerSet = make(map[string]struct{})
	this.votedValueMap = make(map[int64][]byte)
	this.ballotValueMap = make(map[int64][]byte)
	this.ballotAcceptorsMap = make(map[int64]map[string]struct{})
	this.learnerAckMap = make(map[int64]map[string]struct{})

	this.Logger = this.NewLogger("classic-paxos:%s-%s", this.msn.UID(), uid)
	this.ctlr.Initialize(this)
	this.alarm.Initialize()
	return nil
}