Repository: etcd-io/etcd
File: tests/robustness/report/wal.go (Go)

Code before:
		}
	}
	return PersistedRequests(lg, dataDirs)
}

func PersistedRequestsCluster(lg *zap.Logger, cluster *e2e.EtcdProcessCluster) ([]model.EtcdRequest, error) {
	dataDirs := []string{}
	for _, proc := range cluster.Procs {
		dataDirs = append(dataDirs, memberDataDir(proc))
	}
	return PersistedRequests(lg, dataDirs)
}

func PersistedRequests(lg *zap.Logger, dataDirs []string) ([]model.EtcdRequest, error) {
	if len(dataDirs) == 0 {
		return nil, errors.New("no data dirs")
	}
	entriesPersistedInWAL := make([][]raftpb.Entry, len(dataDirs))
	var minCommitIndex uint64 = math.MaxUint64
	for i, dir := range dataDirs {
		state, entries, err := ReadWAL(lg, dir)
		if err != nil {
			lg.Error("Failed to read WAL", zap.Error(err), zap.String("data-dir", dir))
		}
		minCommitIndex = min(minCommitIndex, state.Commit)
		entriesPersistedInWAL[i] = entries
	}
	entries, err := mergeMembersEntries(minCommitIndex, entriesPersistedInWAL)
	if err != nil {
		return nil, err
	}
	persistedRequests := make([]model.EtcdRequest, 0, len(entries))
	for _, e := range entries {
		if e.Type != raftpb.EntryNormal {
			continue
		}
		request, err := parseEntryNormal(e)
		if err != nil {
			return nil, err
		}
		if request != nil {
			persistedRequests = append(persistedRequests, *request)
		}
	}
	return persistedRequests, nil
}

func mergeMembersEntries(minCommitIndex uint64, memberEntries [][]raftpb.Entry) ([]raftpb.Entry, error) {
	for _, entries := range memberEntries {
		var lastIndex uint64
		for _, e := range entries {

Review comment (suggestion):
I think we should _not_ execute this line when the error above is returned.  if I understand correctly, `state.Commit` will be 0 when reading WAL returns an error, hence can interfere the actual min commit index.

Code after:
		}
	}
	return PersistedRequests(lg, dataDirs)
}

func PersistedRequestsCluster(lg *zap.Logger, cluster *e2e.EtcdProcessCluster) ([]model.EtcdRequest, error) {
	dataDirs := []string{}
	for _, proc := range cluster.Procs {
		dataDirs = append(dataDirs, memberDataDir(proc))
	}
	return PersistedRequests(lg, dataDirs)
}

func PersistedRequests(lg *zap.Logger, dataDirs []string) ([]model.EtcdRequest, error) {
	if len(dataDirs) == 0 {
		return nil, errors.New("no data dirs")
	}
	entriesPersistedInWAL := make([][]raftpb.Entry, len(dataDirs))
	var minCommitIndex uint64 = math.MaxUint64
	for i, dir := range dataDirs {
		state, entries, err := ReadWAL(lg, dir)
		if err != nil {
			lg.Error("Failed to read WAL", zap.Error(err), zap.String("data-dir", dir))
			continue
		}
		minCommitIndex = min(minCommitIndex, state.Commit)
		entriesPersistedInWAL[i] = entries
	}
	entries, err := mergeMembersEntries(minCommitIndex, entriesPersistedInWAL)
	if err != nil {
		return nil, err
	}
	persistedRequests := make([]model.EtcdRequest, 0, len(entries))
	for _, e := range entries {
		if e.Type != raftpb.EntryNormal {
			continue
		}
		request, err := parseEntryNormal(e)
		if err != nil {
			return nil, err
		}
		if request != nil {
			persistedRequests = append(persistedRequests, *request)
		}
	}
	return persistedRequests, nil
}

func mergeMembersEntries(minCommitIndex uint64, memberEntries [][]raftpb.Entry) ([]raftpb.Entry, error) {
	for _, entries := range memberEntries {
		var lastIndex uint64