server: classic GetMinTS ignores GenerateTSO error and returns zero timestamp

Open Beginner friendly
#11,752 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, grpc
Domain
api, backend

Research direction

Read the non-independent TSO branch in server/grpc_service.go around GetMinTS and check how its error is handled before the response header is built. Follow nearby GetMinTS tests or add coverage for GenerateTSO failure; done means the endpoint returns the error in its response header instead of a successful header with a zero timestamp.

Written by the indexing model from the issue text.

Description

needs-type

Bug Report

What did you do?

Called the GetMinTS gRPC endpoint on a PD server running in classic (non-independent TSO service) mode when s.tsoAllocator.GenerateTSO(ctx, 1) fails (for example, while the TSO allocator is uninitialized or resetting during leadership transition).

What did you expect to see?

GrpcServer.GetMinTS should propagate the error from s.tsoAllocator.GenerateTSO into the response error header instead of returning a zero timestamp as valid.

What did you see instead?

In server/grpc_service.go, the non-independent TSO branch assigns the error to internalErr and only uses it to guard tsoHandleDuration.Observe(...), leaving the outer err variable nil:

	if s.IsServiceIndependent(constant.TSOServiceName) {
		minTS, err = s.GetMinTSFromTSOService()
	} else {
		start := time.Now()
		ts, internalErr := s.tsoAllocator.GenerateTSO(ctx, 1)
		if internalErr == nil {
			tsoHandleDuration.Observe(time.Since(start).Seconds())
		}
		minTS = &ts
	}
	if err != nil {

As a result, GetMinTS returns a success header (grpcutil.WrapHeader()) with a zero (0, 0) timestamp whenever GenerateTSO fails.

What version of PD are you using (pd-server -V)?

master (4be269d9ea33)

Dominant language
Go
Stars
1.2k
Forks
794
Avg merge
5d 32m
Merged PRs (30d)
81

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tikv/pd

All issues in tikv/pd

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.