Skip to content

Commit

Permalink
Fix data race in loadSQLChainProfile metastete.go
Browse files Browse the repository at this point in the history
  • Loading branch information
zeqing-guo committed Dec 25, 2018
1 parent 41365e9 commit eba1cb8
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 25 deletions.
21 changes: 8 additions & 13 deletions blockproducer/metastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ func (s *metaState) storeBaseAccount(k proto.AccountAddress, v *accountObject) (

func (s *metaState) loadSQLChainObject(k proto.DatabaseID) (o *sqlchainObject, loaded bool) {
var old *sqlchainObject
o = new(sqlchainObject)
if old, loaded = s.dirty.databases[k]; loaded {
if o == nil {
if old == nil {
loaded = false
return
}
deepcopier.Copy(old).To(o)
o = new(sqlchainObject)
deepcopier.Copy(&old.SQLChainProfile).To(&o.SQLChainProfile)
return
}
if old, loaded = s.readonly.databases[k]; loaded {
deepcopier.Copy(old).To(o)
o = new(sqlchainObject)
deepcopier.Copy(&old.SQLChainProfile).To(&o.SQLChainProfile)
return
}
return
}
Expand Down Expand Up @@ -725,6 +728,7 @@ func (s *metaState) updatePermission(tx *types.UpdatePermission) (err error) {
} else {
so.Users[targetUserIndex].Permission = tx.Permission
}
s.dirty.databases[tx.TargetSQLChain.DatabaseID()] = so
return
}

Expand Down Expand Up @@ -834,15 +838,6 @@ func (s *metaState) loadROSQLChains(addr proto.AccountAddress) (dbs []*types.SQL
return
}

func (s *metaState) loadROSQLChainsByDatabaseID(dbid proto.DatabaseID) (db *types.SQLChainProfile, ok bool) {
var databaseObj *sqlchainObject
db = &types.SQLChainProfile{}
if databaseObj, ok = s.readonly.databases[dbid]; ok {
deepcopier.Copy(databaseObj).To(db)
}
return
}

func (s *metaState) applyTransaction(tx pi.Transaction) (err error) {
switch t := tx.(type) {
case *types.Transfer:
Expand Down
3 changes: 0 additions & 3 deletions blockproducer/metastate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,8 @@ func TestMetaState(t *testing.T) {
var dbs []*types.SQLChainProfile
dbs = ms.loadROSQLChains(addr1)
So(len(dbs), ShouldEqual, 1)
So(dbs[0].ID, ShouldEqual, dbid1)
dbs = ms.loadROSQLChains(addr2)
So(len(dbs), ShouldEqual, 2)
So(dbs[0].ID, ShouldEqual, dbid1)
So(dbs[1].ID, ShouldEqual, dbid2)
dbs = ms.loadROSQLChains(addr4)
So(dbs, ShouldBeEmpty)
})
Expand Down
1 change: 0 additions & 1 deletion cmd/cql-adapter/storage/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"math/rand"
"os"
"path/filepath"

// Import sqlite3 manually.
_ "github.com/CovenantSQL/go-sqlite3-encrypt"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/cql-faucet/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/utils/log"
uuid "github.com/satori/go.uuid"

// Load sqlite3 database driver.
_ "github.com/CovenantSQL/go-sqlite3-encrypt"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/cql-minerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"os"
"os/signal"
"runtime"

//"runtime/trace"
"syscall"
"time"
Expand Down
1 change: 0 additions & 1 deletion crypto/hash/hashfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package hash
import (
"encoding/binary"
"hash/fnv"

// "crypto/sha256" benchmark is at least 10% faster on
// i7-4870HQ CPU @ 2.50GHz than "github.com/minio/sha256-simd"
"crypto/sha256"
Expand Down
5 changes: 2 additions & 3 deletions rpc/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
"sync"
"testing"

. "github.com/smartystreets/goconvey/convey"
mux "github.com/xtaci/smux"

"github.com/CovenantSQL/CovenantSQL/proto"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
. "github.com/smartystreets/goconvey/convey"
mux "github.com/xtaci/smux"
)

const (
Expand Down
1 change: 0 additions & 1 deletion storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/CovenantSQL/CovenantSQL/twopc"
"github.com/CovenantSQL/CovenantSQL/utils/log"

// Register CovenantSQL/go-sqlite3-encrypt engine.
_ "github.com/CovenantSQL/go-sqlite3-encrypt"
)
Expand Down
1 change: 0 additions & 1 deletion xenomint/xxx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path"
"sync/atomic"

//"runtime/trace"
"sync"
"syscall"
Expand Down

0 comments on commit eba1cb8

Please sign in to comment.