Add RwMutexes to all collections. #116

This commit is contained in:
Andrey Smirnov
2014-10-08 16:16:07 +04:00
parent 2ed76f1e4c
commit ac983ff65d
4 changed files with 20 additions and 8 deletions

View File

@@ -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"))

View File

@@ -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"))

View File

@@ -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"))

View File

@@ -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"))