-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
owner: check if the checkpoint ts is less then gc safe time when crea…
- Loading branch information
Showing
14 changed files
with
259 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package util | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/tidb/store/tikv" | ||
pd "github.com/tikv/pd/client" | ||
) | ||
|
||
const ( | ||
// cdcChangefeedCreatingServiceGCSafePointID is service GC safe point ID | ||
cdcChangefeedCreatingServiceGCSafePointID = "ticdc-changefeed-creating" | ||
// cdcChangefeedCreatingServiceGCSafePointTTL is service GC safe point TTL | ||
cdcChangefeedCreatingServiceGCSafePointTTL = 10 * 60 // 10 mins | ||
) | ||
|
||
// CheckSafetyOfStartTs checks if the startTs less than the minimum of Service-GC-Ts | ||
// and this function will update the service GC to startTs | ||
func CheckSafetyOfStartTs(ctx context.Context, pdCli pd.Client, startTs uint64) error { | ||
minServiceGCTs, err := pdCli.UpdateServiceGCSafePoint(ctx, cdcChangefeedCreatingServiceGCSafePointID, | ||
cdcChangefeedCreatingServiceGCSafePointTTL, startTs) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if startTs < minServiceGCTs { | ||
return errors.Wrap(tikv.ErrGCTooEarly.GenWithStackByArgs(startTs, minServiceGCTs), "startTs less than gcSafePoint") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package util | ||
|
||
import ( | ||
"context" | ||
"math" | ||
|
||
"github.com/pingcap/check" | ||
pd "github.com/tikv/pd/client" | ||
) | ||
|
||
type gcServiceSuite struct { | ||
pdCli mockPdClientForServiceGCSafePoint | ||
} | ||
|
||
var _ = check.Suite(&gcServiceSuite{ | ||
mockPdClientForServiceGCSafePoint{serviceSafePoint: make(map[string]uint64)}, | ||
}) | ||
|
||
func (s *gcServiceSuite) TestCheckSafetyOfStartTs(c *check.C) { | ||
ctx := context.Background() | ||
s.pdCli.UpdateServiceGCSafePoint(ctx, "service1", 10, 60) //nolint:errcheck | ||
err := CheckSafetyOfStartTs(ctx, s.pdCli, 50) | ||
c.Assert(err.Error(), check.Equals, "startTs less than gcSafePoint: [tikv:9006]GC life time is shorter than transaction duration, transaction starts at 50, GC safe point is 60") | ||
s.pdCli.UpdateServiceGCSafePoint(ctx, "service2", 10, 80) //nolint:errcheck | ||
s.pdCli.UpdateServiceGCSafePoint(ctx, "service3", 10, 70) //nolint:errcheck | ||
err = CheckSafetyOfStartTs(ctx, s.pdCli, 65) | ||
c.Assert(err, check.IsNil) | ||
c.Assert(s.pdCli.serviceSafePoint, check.DeepEquals, map[string]uint64{"service1": 60, "service2": 80, "service3": 70, "ticdc-changefeed-creating": 65}) | ||
|
||
} | ||
|
||
type mockPdClientForServiceGCSafePoint struct { | ||
pd.Client | ||
serviceSafePoint map[string]uint64 | ||
} | ||
|
||
func (m mockPdClientForServiceGCSafePoint) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) { | ||
minSafePoint := uint64(math.MaxUint64) | ||
for _, safePoint := range m.serviceSafePoint { | ||
if minSafePoint > safePoint { | ||
minSafePoint = safePoint | ||
} | ||
} | ||
if safePoint < minSafePoint && len(m.serviceSafePoint) != 0 { | ||
return minSafePoint, nil | ||
} | ||
m.serviceSafePoint[serviceID] = safePoint | ||
return minSafePoint, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.