Skip to content

Commit

Permalink
domain: lock reload and fix version check.
Browse files Browse the repository at this point in the history
 In mysql test , sometimes the domain’s schema version  may be changed
lesser because of another slow transaction.
So we must use lock to guarantee reload once at same time and update
the version check way.
It is very hard to write a test for this, so if we can pass mysql test
using HBase with no error, I think it is fixed.
  • Loading branch information
siddontang committed Nov 27, 2015
1 parent 58b0496 commit 7c1fc58
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package domain

import (
"sync"
"sync/atomic"
"time"

Expand All @@ -40,6 +41,7 @@ type Domain struct {
leaseCh chan time.Duration
// nano seconds
lastLeaseTS int64
m sync.Mutex
}

func (do *Domain) loadInfoSchema(txn kv.Transaction) (err error) {
Expand All @@ -50,7 +52,9 @@ func (do *Domain) loadInfoSchema(txn kv.Transaction) (err error) {
}

info := do.infoHandle.Get()
if info != nil && schemaMetaVersion > 0 && schemaMetaVersion == info.SchemaMetaVersion() {
if info != nil && schemaMetaVersion <= info.SchemaMetaVersion() {
// info may be changed by other txn, so here its version may be bigger than schema version,
// so we don't need to reload.
log.Debugf("schema version is still %d, no need reload", schemaMetaVersion)
return nil
}
Expand Down Expand Up @@ -139,6 +143,10 @@ func (do *Domain) tryReload() {
}

func (do *Domain) reload() error {
// lock here for only once at same time.
do.m.Lock()
defer do.m.Unlock()

err := kv.RunInNewTxn(do.store, false, do.loadInfoSchema)
if err != nil {
return errors.Trace(err)
Expand Down

0 comments on commit 7c1fc58

Please sign in to comment.