store/tikv: move safepoint test to /tests (#23637)
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package tikv
|
||||
package tikv_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -22,12 +22,13 @@ import (
|
||||
"github.com/pingcap/errors"
|
||||
"github.com/pingcap/parser/terror"
|
||||
tidbkv "github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/store/tikv"
|
||||
"github.com/pingcap/tidb/store/tikv/kv"
|
||||
)
|
||||
|
||||
type testSafePointSuite struct {
|
||||
OneByOneSuite
|
||||
store *KVStore
|
||||
store tikv.StoreProbe
|
||||
prefix string
|
||||
}
|
||||
|
||||
@ -35,7 +36,7 @@ var _ = Suite(&testSafePointSuite{})
|
||||
|
||||
func (s *testSafePointSuite) SetUpSuite(c *C) {
|
||||
s.OneByOneSuite.SetUpSuite(c)
|
||||
s.store = NewTestStore(c)
|
||||
s.store = tikv.StoreProbe{KVStore: NewTestStore(c)}
|
||||
s.prefix = fmt.Sprintf("seek_%d", time.Now().Unix())
|
||||
}
|
||||
|
||||
@ -45,7 +46,7 @@ func (s *testSafePointSuite) TearDownSuite(c *C) {
|
||||
s.OneByOneSuite.TearDownSuite(c)
|
||||
}
|
||||
|
||||
func (s *testSafePointSuite) beginTxn(c *C) *KVTxn {
|
||||
func (s *testSafePointSuite) beginTxn(c *C) tikv.TxnProbe {
|
||||
txn, err := s.store.Begin()
|
||||
c.Assert(err, IsNil)
|
||||
return txn
|
||||
@ -62,9 +63,9 @@ func mymakeKeys(rowNum int, prefix string) []tidbkv.Key {
|
||||
|
||||
func (s *testSafePointSuite) waitUntilErrorPlugIn(t uint64) {
|
||||
for {
|
||||
saveSafePoint(s.store.GetSafePointKV(), t+10)
|
||||
s.store.SaveSafePoint(t + 10)
|
||||
cachedTime := time.Now()
|
||||
newSafePoint, err := loadSafePoint(s.store.GetSafePointKV())
|
||||
newSafePoint, err := s.store.LoadSafePoint()
|
||||
if err == nil {
|
||||
s.store.UpdateSPCache(newSafePoint, cachedTime)
|
||||
break
|
||||
@ -87,7 +88,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) {
|
||||
_, err = txn2.Get(context.TODO(), encodeKey(s.prefix, s08d("key", 0)))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.waitUntilErrorPlugIn(txn2.startTS)
|
||||
s.waitUntilErrorPlugIn(txn2.StartTS())
|
||||
|
||||
_, geterr2 := txn2.Get(context.TODO(), encodeKey(s.prefix, s08d("key", 0)))
|
||||
c.Assert(geterr2, NotNil)
|
||||
@ -99,7 +100,7 @@ func (s *testSafePointSuite) TestSafePoint(c *C) {
|
||||
// for txn seek
|
||||
txn3 := s.beginTxn(c)
|
||||
|
||||
s.waitUntilErrorPlugIn(txn3.startTS)
|
||||
s.waitUntilErrorPlugIn(txn3.StartTS())
|
||||
|
||||
_, seekerr := txn3.Iter(encodeKey(s.prefix, ""), nil)
|
||||
c.Assert(seekerr, NotNil)
|
||||
@ -112,10 +113,9 @@ func (s *testSafePointSuite) TestSafePoint(c *C) {
|
||||
keys := mymakeKeys(10, s.prefix)
|
||||
txn4 := s.beginTxn(c)
|
||||
|
||||
s.waitUntilErrorPlugIn(txn4.startTS)
|
||||
s.waitUntilErrorPlugIn(txn4.StartTS())
|
||||
|
||||
snapshot := newTiKVSnapshot(s.store, txn4.StartTS(), 0)
|
||||
_, batchgeterr := snapshot.BatchGet(context.Background(), keys)
|
||||
_, batchgeterr := txn4.BatchGet(context.Background(), keys)
|
||||
c.Assert(batchgeterr, NotNil)
|
||||
isFallBehind = terror.ErrorEqual(errors.Cause(geterr2), kv.ErrGCTooEarly)
|
||||
isMayFallBehind = terror.ErrorEqual(errors.Cause(geterr2), kv.ErrPDServerTimeout.GenWithStackByArgs("start timestamp may fall behind safe point"))
|
||||
@ -16,6 +16,7 @@ package tikv_test
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -24,6 +25,7 @@ import (
|
||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||
"github.com/pingcap/tidb/store/tikv"
|
||||
"github.com/pingcap/tidb/store/tikv/config"
|
||||
"github.com/pingcap/tidb/store/tikv/util/codec"
|
||||
pd "github.com/tikv/pd/client"
|
||||
)
|
||||
|
||||
@ -98,3 +100,17 @@ func (s *OneByOneSuite) TearDownSuite(c *C) {
|
||||
withTiKVGlobalLock.RUnlock()
|
||||
}
|
||||
}
|
||||
|
||||
func encodeKey(prefix, s string) []byte {
|
||||
return codec.EncodeBytes(nil, []byte(fmt.Sprintf("%s_%s", prefix, s)))
|
||||
}
|
||||
|
||||
func valueBytes(n int) []byte {
|
||||
return []byte(fmt.Sprintf("value%d", n))
|
||||
}
|
||||
|
||||
// s08d is for returning format string "%s%08d" to keep string sorted.
|
||||
// e.g.: "0002" < "0011", otherwise "2" > "11"
|
||||
func s08d(prefix string, n int) string {
|
||||
return fmt.Sprintf("%s%08d", prefix, n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user