Repository: etcd-io/etcd
File: server/etcdserver/server.go (Go)

Code before:
		AuthStore:                    s.authStore,
		Lessor:                       s.lessor,
		Cluster:                      s.cluster,
		RaftStatus:                   s,
		SnapshotServer:               s,
		ConsistentIndex:              s.consistIndex,
		TxnModeWriteWithSharedBuffer: s.Cfg.ServerFeatureGate.Enabled(features.TxnModeWriteWithSharedBuffer),
		Backend:                      s.be,
		QuotaBackendBytesCfg:         s.Cfg.QuotaBackendBytes,
		WarningApplyDuration:         s.Cfg.WarningApplyDuration,
	}
	return apply.NewUberApplier(opts)
}

func verifySnapshotIndex(snapshot raftpb.Snapshot, cindex uint64) {
	verify.Verify("consistent_index isn't equal to snapshot index", func() (bool, map[string]any) {
		return cindex != snapshot.Metadata.Index,
			map[string]any{
				"consistent_index": cindex,
				"snapshot_index":   snapshot.Metadata.Index,
			}
	})
}

func verifyConsistentIndexIsLatest(lg *zap.Logger, snapshot raftpb.Snapshot, cindex uint64) {
	verify.Verify("consistent_index is older than snapshot_index", func() (bool, map[string]any) {
		return cindex < snapshot.Metadata.Index,
			map[string]any{
				"consistent_index": cindex,
				"snapshot_index":   snapshot.Metadata.Index,
			}
	})
}

func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *toApply) {
	if len(apply.entries) == 0 {
		return
	}
	firsti := apply.entries[0].Index
	if firsti > ep.appliedi+1 {
		lg := s.Logger()
		lg.Panic(
			"unexpected committed entry index",
			zap.Uint64("current-applied-index", ep.appliedi),
			zap.Uint64("first-committed-entry-index", firsti),
		)
	}
	var ents []raftpb.Entry
	if ep.appliedi+1-firsti < uint64(len(apply.entries)) {
		ents = apply.entries[ep.appliedi+1-firsti:]
	}

Review comment (bug):
Looks like this is strictly required by robustness test.  Removing this is causing the test failure.  

Should we find a way to add this back or adjust the robustness test @serathius?

Code after:
		AuthStore:                    s.authStore,
		Lessor:                       s.lessor,
		Cluster:                      s.cluster,
		RaftStatus:                   s,
		SnapshotServer:               s,
		ConsistentIndex:              s.consistIndex,
		TxnModeWriteWithSharedBuffer: s.Cfg.ServerFeatureGate.Enabled(features.TxnModeWriteWithSharedBuffer),
		Backend:                      s.be,
		QuotaBackendBytesCfg:         s.Cfg.QuotaBackendBytes,
		WarningApplyDuration:         s.Cfg.WarningApplyDuration,
	}
	return apply.NewUberApplier(opts)
}

func verifySnapshotIndex(snapshot raftpb.Snapshot, cindex uint64) {
	verify.Verify("consistent_index isn't equal to snapshot index", func() (bool, map[string]any) {
		return cindex == snapshot.Metadata.Index,
			map[string]any{
				"consistent_index": cindex,
				"snapshot_index":   snapshot.Metadata.Index,
			}
	})
}

func verifyConsistentIndexIsLatest(snapshot raftpb.Snapshot, cindex uint64) {
	verify.Verify("consistent_index is older than snapshot_index", func() (bool, map[string]any) {
		return cindex >= snapshot.Metadata.Index,
			map[string]any{
				"consistent_index": cindex,
				"snapshot_index":   snapshot.Metadata.Index,
			}
	})
}

func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *toApply) {
	if len(apply.entries) == 0 {
		return
	}
	firsti := apply.entries[0].Index
	if firsti > ep.appliedi+1 {
		lg := s.Logger()
		lg.Panic(
			"unexpected committed entry index",
			zap.Uint64("current-applied-index", ep.appliedi),
			zap.Uint64("first-committed-entry-index", firsti),
		)
	}
	var ents []raftpb.Entry
	if ep.appliedi+1-firsti < uint64(len(apply.entries)) {
		ents = apply.entries[ep.appliedi+1-firsti:]
	}