Repository: etcd-io/etcd
File: server/storage/mvcc/kvstore.go (Go)

Code before:
			}

			rev := BytesToRev(rkv.key)
			verify.Verify(func() {
				if rev.Main < currentRev {
					panic(fmt.Errorf("revision %d shouldn't be less than the previous revision %d", rev.Main, currentRev))
				}
			})
			currentRev = rev.Main

			if ok {
				if isTombstone(rkv.key) {
					if err := ki.tombstone(lg, rev.Main, rev.Sub); err != nil {
						lg.Warn("tombstone encountered error", zap.Error(err))
					}
					continue
				}
				ki.put(lg, rev.Main, rev.Sub)
			} else if !isTombstone(rkv.key) {
				ki.restore(lg, Revision{Main: rkv.kv.CreateRevision}, rev, rkv.kv.Version)
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			} else {
				ki.restoreTombstone(lg, rev.Main, rev.Sub)
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			}
		}
	}()
	return rkvc, revc
}

func restoreChunk(lg *zap.Logger, kvc chan<- revKeyValue, keys, vals [][]byte, keyToLease map[string]lease.LeaseID) {
	for i, key := range keys {
		rkv := revKeyValue{key: key}
		if err := rkv.kv.Unmarshal(vals[i]); err != nil {
			lg.Fatal("failed to unmarshal mvccpb.KeyValue", zap.Error(err))
		}
		rkv.kstr = string(rkv.kv.Key)
		if isTombstone(key) {
			delete(keyToLease, rkv.kstr)
		} else if lid := lease.LeaseID(rkv.kv.Lease); lid != lease.NoLease {
			keyToLease[rkv.kstr] = lid
		} else {
			delete(keyToLease, rkv.kstr)
		}
		kvc <- rkv
	}
}

func (s *store) Close() error {

Review comment (performance):
Minor comment, you can combine them 

```
			} else if !isTombstone(rkv.key) {
				ki.restore(lg, Revision{Main: rkv.kv.CreateRevision}, rev, rkv.kv.Version)
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			} else {
				ki.restoreTombstone(lg, rev.Main, rev.Sub)
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			}
```

into something like below,

```
			} else {
				if isTombstone(rkv.key) {
					ki.restoreTombstone(lg, rev.Main, rev.Sub)
				} else {
					ki.restore(lg, Revision{Main: rkv.kv.CreateRevision}, rev, rkv.kv.Version)
				}
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			}
```

Code after:
			}

			rev := BytesToRev(rkv.key)
			verify.Verify(func() {
				if rev.Main < currentRev {
					panic(fmt.Errorf("revision %d shouldn't be less than the previous revision %d", rev.Main, currentRev))
				}
			})
			currentRev = rev.Main

			if ok {
				if isTombstone(rkv.key) {
					if err := ki.tombstone(lg, rev.Main, rev.Sub); err != nil {
						lg.Warn("tombstone encountered error", zap.Error(err))
					}
					continue
				}
				ki.put(lg, rev.Main, rev.Sub)
			} else {
				if isTombstone(rkv.key) {
					ki.restoreTombstone(lg, rev.Main, rev.Sub)
				} else {
					ki.restore(lg, Revision{Main: rkv.kv.CreateRevision}, rev, rkv.kv.Version)
				}
				idx.Insert(ki)
				kiCache[rkv.kstr] = ki
			}
		}
	}()
	return rkvc, revc
}

func restoreChunk(lg *zap.Logger, kvc chan<- revKeyValue, keys, vals [][]byte, keyToLease map[string]lease.LeaseID) {
	for i, key := range keys {
		rkv := revKeyValue{key: key}
		if err := rkv.kv.Unmarshal(vals[i]); err != nil {
			lg.Fatal("failed to unmarshal mvccpb.KeyValue", zap.Error(err))
		}
		rkv.kstr = string(rkv.kv.Key)
		if isTombstone(key) {
			delete(keyToLease, rkv.kstr)
		} else if lid := lease.LeaseID(rkv.kv.Lease); lid != lease.NoLease {
			keyToLease[rkv.kstr] = lid
		} else {
			delete(keyToLease, rkv.kstr)
		}
		kvc <- rkv
	}
}

func (s *store) Close() error {