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

GetStaleTimestamp may return future TSO #1053

Closed
you06 opened this issue Nov 9, 2023 · 0 comments · Fixed by #1054
Closed

GetStaleTimestamp may return future TSO #1053

you06 opened this issue Nov 9, 2023 · 0 comments · Fixed by #1054

Comments

@you06
Copy link
Contributor

you06 commented Nov 9, 2023

This test may return future TSO when calling GetStaleTimestamp, which is a correctness risk.

func TestNonFutureStaleTSO(t *testing.T) {
	o := oracles.NewEmptyPDOracle()
	oracles.SetEmptyPDOracleLastTs(o, oracle.GoTimeToTS(time.Now()))
	for i := 0; i < 100; i++ {
		time.Sleep(10 * time.Millisecond)
		now := time.Now()
		upperBound := now.Add(5 * time.Millisecond) // allow 5ms time drift

		closeCh := make(chan struct{})
		go func() {
			time.Sleep(100 * time.Microsecond)
			oracles.SetEmptyPDOracleLastTs(o, oracle.GoTimeToTS(now))
			close(closeCh)
		}()
	CHECK:
		for {
			select {
			case <-closeCh:
				break CHECK
			default:
				ts, err := o.GetStaleTimestamp(context.Background(), oracle.GlobalTxnScope, 0)
				assert.Nil(t, err)
				staleTime := oracle.GetTimeFromTS(ts)
				if staleTime.After(upperBound) && time.Since(now) < time.Millisecond /* only check staleTime within 1ms */ {
					assert.Less(t, staleTime, upperBound, i)
					t.FailNow()
				}
			}
		}
	}
}

The test should pass because stale timestamp should not be a future ts. But we got:

Error:      	"2023-11-09 15:44:50.757 +0900 JST" is not less than "2023-11-09 15:44:50.751395 +0900 JST m=+0.030711501"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant