<commit_before>package raft

import (
	"fmt"

	"golang.org/x/net/context"
)

// ErrNotLeader is returned by Raft when a method is invoked requiring the
// server to be the leader, and it's not. A hint about the actual leader is
// provided.
type ErrNotLeader struct {
	Leader uint64
}

func (e *ErrNotLeader) Error() string {
	return fmt.Sprintf("not leader, %d is", e.Leader)
}

// Raft represents the interface a Raft node needs expose to the application
// layer.
type Raft interface {
	// ProposeCmd proposes a command. Blocks until Raft handles the message
	// or the context is canceled, i.e., server is busy. Immediately returns
	// an ErrNotLeader error if server isn't the leader.
	ProposeCmd(ctx context.Context, cmd []byte) error

	// Read blocks until Raft has had a successful round of heartbeats in
	// its current term, and the read index is read from Committed, i.e.,
	// Read must not block reads on Committed. If the context is canceled,
	// i.e., server is busy, and error is returned and Read must be retired.
	// Immediately returns an ErrNotLeader error if server isn't the leader.<commit_msg>raft.go: Update Read comment<commit_after>package raft

import (
	"fmt"

	"golang.org/x/net/context"
)

// ErrNotLeader is returned by Raft when a method is invoked requiring the
// server to be the leader, and it's not. A hint about the actual leader is
// provided.
type ErrNotLeader struct {
	Leader uint64
}

func (e *ErrNotLeader) Error() string {
	return fmt.Sprintf("not leader, %d is", e.Leader)
}

// Raft represents the interface a Raft node needs expose to the application
// layer.
type Raft interface {
	// ProposeCmd proposes a command. Blocks until Raft handles the message
	// or the context is canceled, i.e., server is busy. Immediately returns
	// an ErrNotLeader error if server isn't the leader.
	ProposeCmd(ctx context.Context, cmd []byte) error

	// Read blocks until Raft has had a successful round of heartbeats in
	// its current term, and the read index is read from Committed, i.e.,
	// Read must not block reads on Committed. A successful call to Read
	// allows read-only queries accumulated up to the point where Read was
	// called, to be safely executed on the state machine. If the context is
	// canceled, i.e., server is busy, and error is returned and Read must
	// be retried. Immediately returns an ErrNotLeader error if server isn't
	// the leader.
{'fraction_non_alphanumeric': 0.08031627132750728, 'fraction_numerical': 0.0016645859342488557, 'mean_word_length': 3.518796992481203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5050687', 'n_tokens_mistral': 720, 'n_tokens_neox': 686, 'n_words': 343}