# TSO Assignment: Process

![`smart`](TSOAssignmentProcess_aa_002_20220509.png)

------------------------------------------------------------------------------
The PD Client thread in the TiDB server handles all communication with the PD (Placement Driver) service. This module is responsible for retrieving TSO (Timestamp Oracle) in batches from PD. The process works as follows:

1. When a transaction (TSO requester) needs to request a TSO, it sends the request to the PD Client module, which immediately returns a tsFuture object to the requester.
2. The requester then caches the tsFuture object and begins executing SQL parsing and compilation. Once this is complete, the requester calls the wait method on the tsFuture object to wait for the TSO to be returned.
3. Meanwhile, the PD Client asynchronously retrieves the TSO from the PD (Placement Driver) service through gRPC. Note that this request is not sent only once for each TSO request, but rather a batch request is sent if a large number of requests arrive concurrently within a very short time frame. If TSO requests are received over a longer period of time, requests will be sent to the PD one by one.
4. Once the PD Client receives the TSO from the PD, it attempts to return the TSO to the corresponding requester. If the requester happens to be calling the wait method at this time, it will receive the TSO, otherwise it will wait until the tsFuture object is signaled.

In summary, the allocation of the TSO is an asynchronous process within the TiDB cluster.
