Skip to content

Commit 287317f

Browse files
authored
[to #773] implement UpdateServiceGCSafePoint (#723) (#732)
* implement UpdateServiceGCSafePoint Signed-off-by: shiyuhang <1136742008@qq.com>
1 parent d8f7a54 commit 287317f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main/java/org/tikv/common/PDClient.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import org.tikv.kvproto.Pdpb.Timestamp;
105105
import org.tikv.kvproto.Pdpb.TsoRequest;
106106
import org.tikv.kvproto.Pdpb.TsoResponse;
107+
import org.tikv.kvproto.Pdpb.UpdateServiceGCSafePointRequest;
107108

108109
public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDFutureStub>
109110
implements ReadOnlyPDClient {
@@ -383,6 +384,17 @@ private Supplier<GetAllStoresRequest> buildGetAllStoresReq() {
383384
return () -> GetAllStoresRequest.newBuilder().setHeader(header).build();
384385
}
385386

387+
private Supplier<UpdateServiceGCSafePointRequest> buildUpdateServiceGCSafePointRequest(
388+
ByteString serviceId, long ttl, long safePoint) {
389+
return () ->
390+
UpdateServiceGCSafePointRequest.newBuilder()
391+
.setHeader(header)
392+
.setSafePoint(safePoint)
393+
.setServiceId(serviceId)
394+
.setTTL(ttl)
395+
.build();
396+
}
397+
386398
private <T> PDErrorHandler<GetStoreResponse> buildPDErrorHandler() {
387399
return new PDErrorHandler<>(
388400
r -> r.getHeader().hasError() ? buildFromPdpbError(r.getHeader().getError()) : null, this);
@@ -419,6 +431,20 @@ public TiConfiguration.ReplicaRead getReplicaRead() {
419431
return conf.getReplicaRead();
420432
}
421433

434+
@Override
435+
public Long updateServiceGCSafePoint(
436+
String serviceId, long ttl, long safePoint, BackOffer backOffer) {
437+
return callWithRetry(
438+
backOffer,
439+
PDGrpc.getUpdateServiceGCSafePointMethod(),
440+
buildUpdateServiceGCSafePointRequest(
441+
ByteString.copyFromUtf8(serviceId), ttl, safePoint),
442+
new PDErrorHandler<>(
443+
r -> r.getHeader().hasError() ? buildFromPdpbError(r.getHeader().getError()) : null,
444+
this))
445+
.getMinSafePoint();
446+
}
447+
422448
@Override
423449
public void close() throws InterruptedException {
424450
etcdClient.close();

src/main/java/org/tikv/common/ReadOnlyPDClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,16 @@ List<Pdpb.Region> scanRegions(
7272
Long getClusterId();
7373

7474
RequestKeyCodec getCodec();
75+
76+
/**
77+
* Update ServiceGCSafePoint
78+
*
79+
* @param serviceId ServiceId
80+
* @param ttl TTL in seconds
81+
* @param safePoint The TiTimestamp you want to set. Set to start_ts.getPrevious() is a good
82+
* practice
83+
* @return the MinSafePoint of all services. If this value is greater than safePoint, it means
84+
* update failed
85+
*/
86+
Long updateServiceGCSafePoint(String serviceId, long ttl, long safePoint, BackOffer backOffer);
7587
}

0 commit comments

Comments
 (0)