Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table/tables: fix bug for jepsen test on cached table #37020

Merged
merged 20 commits into from Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -60,7 +60,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.1-0.20220809034808-2ed2113d1090
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
github.com/tikv/client-go/v2 v2.0.1-0.20220815094724-025596b7a20a
github.com/tikv/pd/client v0.0.0-20220725055910-7187a7ab72db
github.com/twmb/murmur3 v1.1.3
github.com/uber/jaeger-client-go v2.22.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -906,8 +906,8 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tikv/client-go/v2 v2.0.1-0.20220809034808-2ed2113d1090 h1:tugwRUqH0gYZ0noHr17AVSKxNVd+Jl2BmNqgANeDIok=
github.com/tikv/client-go/v2 v2.0.1-0.20220809034808-2ed2113d1090/go.mod h1:v3DEt8LS9olI6D6El17pYBWq7B28hw3NnDFTxQHDLpY=
github.com/tikv/client-go/v2 v2.0.1-0.20220815094724-025596b7a20a h1:WFR3seA8YtBhDn47YJSW1P1/lwBIXsk0vALnRVuaL/M=
github.com/tikv/client-go/v2 v2.0.1-0.20220815094724-025596b7a20a/go.mod h1:v3DEt8LS9olI6D6El17pYBWq7B28hw3NnDFTxQHDLpY=
github.com/tikv/pd/client v0.0.0-20220725055910-7187a7ab72db h1:r1eMh9Rny3hfWuBuxOnbsCRrR4FhthiNxLQ5rAUtaww=
github.com/tikv/pd/client v0.0.0-20220725055910-7187a7ab72db/go.mod h1:ew8kS0yIcEaSetuuywkTLIUBR+sz3J5XvAYRae11qwc=
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=
Expand Down
9 changes: 6 additions & 3 deletions table/tables/cache.go
Expand Up @@ -290,8 +290,11 @@ func (c *cachedTable) renewLease(handle StateRemote, ts uint64, data *cacheData,
tid := c.Meta().ID
lease := leaseFromTS(ts, leaseDuration)
newLease, err := handle.RenewReadLease(context.Background(), tid, data.Lease, lease)
if err != nil && !kv.IsTxnRetryableError(err) {
log.Warn("Renew read lease error", zap.Error(err))
if err != nil {
if !kv.IsTxnRetryableError(err) {
log.Warn("Renew read lease error", zap.Error(err))
}
return
}
if newLease > 0 {
c.cacheData.Store(&cacheData{
Expand All @@ -317,7 +320,7 @@ func (c *cachedTable) WriteLockAndKeepAlive(ctx context.Context, exit chan struc
return
}

t := time.NewTicker(cacheTableWriteLease)
t := time.NewTicker(cacheTableWriteLease / 2)
defer t.Stop()
for {
select {
Expand Down
28 changes: 18 additions & 10 deletions table/tables/state_remote.go
Expand Up @@ -123,9 +123,11 @@ func (h *stateRemoteHandle) LockForRead(ctx context.Context, tid int64, newLease
}
// The old lock is outdated, clear orphan lock.
if now > lease {
succ = true
if err := h.updateRow(ctx, tid, "READ", newLease); err != nil {
return errors.Trace(err)
if newLease > now { // Note the check, don't decrease the lease value!
succ = true
if err := h.updateRow(ctx, tid, "READ", newLease); err != nil {
return errors.Trace(err)
}
}
return nil
}
Expand Down Expand Up @@ -209,6 +211,10 @@ func (h *stateRemoteHandle) lockForWriteOnce(ctx context.Context, tid int64, lea
_lease = ts
}
case CachedTableLockRead:
newLease := ts
if newLease < lease { // Never, never decrease lease
newLease = lease
}
// Change from READ to INTEND
if _, err = h.execSQL(ctx,
"update mysql.table_cache_meta set lock_type='INTEND', oldReadLease=%?, lease=%? where tid=%?",
Expand Down Expand Up @@ -243,13 +249,15 @@ func (h *stateRemoteHandle) lockForWriteOnce(ctx context.Context, tid int64, lea
// And then retry changing the lock to WRITE
waitAndRetry = waitForLeaseExpire(oldReadLease, now)
case CachedTableLockWrite:
if err = h.updateRow(ctx, tid, "WRITE", ts); err != nil {
return errors.Trace(err)
}
{
_updateLocal = true
_lockType = CachedTableLockWrite
_lease = ts
if ts > lease { // Note the check, don't decrease lease value!
if err = h.updateRow(ctx, tid, "WRITE", ts); err != nil {
return errors.Trace(err)
}
{
_updateLocal = true
_lockType = CachedTableLockWrite
_lease = ts
}
}
}
return nil
Expand Down