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

*: Do retry when schema is expired #2094

Merged
merged 12 commits into from
Nov 28, 2016
Merged

*: Do retry when schema is expired #2094

merged 12 commits into from
Nov 28, 2016

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Nov 24, 2016

When the transaction encounters the invalid schema while it checks the validity of schema , we need to try again.
Make code more readable.

@@ -47,19 +47,19 @@ type Domain struct {

// loadInfoSchema loads infoschema at startTS into handle, usedSchemaVersion is the currently used
// infoschema version, if it is the same as the schema version at startTS, we don't need to reload again.
func (do *Domain) loadInfoSchema(handle *infoschema.Handle, usedSchemaVersion int64, startTS uint64) error {
func (do *Domain) loadInfoSchema(handle *infoschema.Handle, usedSchemaVersion int64, startTS uint64) (int64, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment for the first return value.

@@ -282,6 +282,7 @@ func (do *Domain) Reload() error {
defer do.m.Unlock()

var err error
var latestSchemaVersion int64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var (
err error
latestSchemaVersion int64
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't reach three or more variables. I think there is no need to change this format.

@@ -471,14 +482,18 @@ func (s *schemaValidityInfo) SetValidity(v bool, lastSuccTS uint64) {
s.mux.Unlock()
}

func (s *schemaValidityInfo) Check(txnTS uint64) error {
// Check checks schema validity. It returns the current schema version and an error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment about when this will be used, and when txnTS is 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -133,15 +134,32 @@ func (s *session) cleanRetryInfo() {
}
}

// TODO: Set them as system variables.
var (
checkSchemaValidityRetryTimes = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 seconds is a little too short.

@coocood coocood changed the title *: Do retry when schema is invalid *: Do retry when schema is expired Nov 25, 2016
@@ -433,52 +436,72 @@ func (m *MockFailure) getValue() bool {
}

type schemaValidityInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this struct is more and more complex and out of control on its way, I'm afraid

MockReloadFailed MockFailure // It mocks reload failed.
}

func (s *schemaValidityInfo) updateSchemaVersion(version int64) {
atomic.StoreInt64(&s.lastSchemaVer, version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't suggest use both atomic and RWMutex...
schemaValidityInfo is already a mess, it makes things from bad to worse.
If any bug caused by this style, it will be the most difficult bug to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, Do you have some suggestions?

mustExecSQL(c, se, "create table t1 (a int);")
mustExecSQL(c, se, "drop table if exists t2;")
mustExecSQL(c, se, "create table t2 (a int);")
startCh1 := make(chan struct{}, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unbuffered channel don't need size 0.... make(chan struct{})

// execute successfully
_, err := exec(s, "begin;")
<-start
<-start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why <-start two times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control the order of execution.

@coocood
Copy link
Member

coocood commented Nov 25, 2016

LGTM

// txnTS != 0, it means the transition isn't nil.
// txnTS <= s.recoveredTS, it means the transition begins before schema is recovered.
// schemaVer != currVer, it means the schema version is changed.
if txnTS != 0 && txnTS <= s.recoveredTS && schemaVer != currVer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think txnTS <= s.recoveredTS condition should be removed ?

schema version change during a transaction, this transaction is invalid.

}

// SetValidity sets the schema validity value.
// SetExpireInfo sets the schema validity value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetExpireInfo sets the schema expire info.

// If the schema is invalid, we need to rollback the current transaction.
func (s *session) checkSchemaValidOrRollback() error {
var ts uint64
if s.txn != nil {
ts = s.txn.StartTS()
} else {
s.schemaVerInCurrTxn = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If s.txn is nil, should we return nil here? For we have nothing to rollback.

@shenli
Copy link
Member

shenli commented Nov 28, 2016

LGTM

@zimulala zimulala changed the title *: Do retry when schema is expired [DNM]*: Do retry when schema is expired Nov 28, 2016
@zimulala zimulala changed the title [DNM]*: Do retry when schema is expired *: Do retry when schema is expired Nov 28, 2016
@zimulala zimulala merged commit 5c9f073 into master Nov 28, 2016
@zimulala zimulala deleted the zimuxia/wait-valid branch November 28, 2016 04:17
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 this pull request may close these issues.

4 participants