From ac983ff65dc9e615110ebc0c9423ef2abeb645b5 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 8 Oct 2014 16:16:07 +0400 Subject: [PATCH] Add RwMutexes to all collections. #116 --- deb/local.go | 5 ++++- deb/publish.go | 5 ++++- deb/remote.go | 5 ++++- deb/snapshot.go | 13 ++++++++----- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/deb/local.go b/deb/local.go index 31f336f4..8cbbb7f9 100644 --- a/deb/local.go +++ b/deb/local.go @@ -7,6 +7,7 @@ import ( "github.com/smira/aptly/database" "github.com/ugorji/go/codec" "log" + "sync" ) // LocalRepo is a collection of packages created locally @@ -88,6 +89,7 @@ func (repo *LocalRepo) RefKey() []byte { // LocalRepoCollection does listing, updating/adding/deleting of LocalRepos type LocalRepoCollection struct { + *sync.RWMutex db database.Storage list []*LocalRepo } @@ -95,7 +97,8 @@ type LocalRepoCollection struct { // NewLocalRepoCollection loads LocalRepos from DB and makes up collection func NewLocalRepoCollection(db database.Storage) *LocalRepoCollection { result := &LocalRepoCollection{ - db: db, + RWMutex: &sync.RWMutex{}, + db: db, } blobs := db.FetchByPrefix([]byte("L")) diff --git a/deb/publish.go b/deb/publish.go index 7e1c5f9f..539364ac 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -14,6 +14,7 @@ import ( "path/filepath" "sort" "strings" + "sync" "time" ) @@ -648,6 +649,7 @@ func (p *PublishedRepo) RemoveFiles(publishedStorageProvider aptly.PublishedStor // PublishedRepoCollection does listing, updating/adding/deleting of PublishedRepos type PublishedRepoCollection struct { + *sync.RWMutex db database.Storage list []*PublishedRepo } @@ -655,7 +657,8 @@ type PublishedRepoCollection struct { // NewPublishedRepoCollection loads PublishedRepos from DB and makes up collection func NewPublishedRepoCollection(db database.Storage) *PublishedRepoCollection { result := &PublishedRepoCollection{ - db: db, + RWMutex: &sync.RWMutex{}, + db: db, } blobs := db.FetchByPrefix([]byte("U")) diff --git a/deb/remote.go b/deb/remote.go index c109a535..83f87096 100644 --- a/deb/remote.go +++ b/deb/remote.go @@ -16,6 +16,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "syscall" "time" ) @@ -593,6 +594,7 @@ func (repo *RemoteRepo) RefKey() []byte { // RemoteRepoCollection does listing, updating/adding/deleting of RemoteRepos type RemoteRepoCollection struct { + *sync.RWMutex db database.Storage list []*RemoteRepo } @@ -600,7 +602,8 @@ type RemoteRepoCollection struct { // NewRemoteRepoCollection loads RemoteRepos from DB and makes up collection func NewRemoteRepoCollection(db database.Storage) *RemoteRepoCollection { result := &RemoteRepoCollection{ - db: db, + RWMutex: &sync.RWMutex{}, + db: db, } blobs := db.FetchByPrefix([]byte("R")) diff --git a/deb/snapshot.go b/deb/snapshot.go index 0c273480..0f85581a 100644 --- a/deb/snapshot.go +++ b/deb/snapshot.go @@ -10,6 +10,7 @@ import ( "github.com/ugorji/go/codec" "log" "strings" + "sync" "time" ) @@ -131,12 +132,12 @@ func (s *Snapshot) Decode(input []byte) error { if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") { // probably it is broken DB from go < 1.2, try decoding w/o time.Time var snapshot11 struct { - UUID string - Name string + UUID string + Name string CreatedAt []byte - SourceKind string - SourceIDs []string + SourceKind string + SourceIDs []string Description string } @@ -160,6 +161,7 @@ func (s *Snapshot) Decode(input []byte) error { // SnapshotCollection does listing, updating/adding/deleting of Snapshots type SnapshotCollection struct { + *sync.RWMutex db database.Storage list []*Snapshot } @@ -167,7 +169,8 @@ type SnapshotCollection struct { // NewSnapshotCollection loads Snapshots from DB and makes up collection func NewSnapshotCollection(db database.Storage) *SnapshotCollection { result := &SnapshotCollection{ - db: db, + RWMutex: &sync.RWMutex{}, + db: db, } blobs := db.FetchByPrefix([]byte("S"))