mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-02 04:50:49 +00:00
Consistently use transactions to update database
For any action which is multi-step (requires updating more than 1 DB key), use transaction to make update atomic. Also pack big chunks of updates (importing packages for importing and mirror updates) into single transaction to improve aptly performance and get some isolation. Note that still layers up (Collections) provide some level of isolation, so this is going to shine with the future PRs to remove collection locks. Spin-off of #459
This commit is contained in:
committed by
Andrey Smirnov
parent
67e38955ae
commit
77d7c3871a
+22
-9
@@ -914,21 +914,27 @@ func (collection *PublishedRepoCollection) CheckDuplicate(repo *PublishedRepo) *
|
||||
}
|
||||
|
||||
// Update stores updated information about repo in DB
|
||||
func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) (err error) {
|
||||
err = collection.db.Put(repo.Key(), repo.Encode())
|
||||
func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) error {
|
||||
transaction, err := collection.db.OpenTransaction()
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
defer transaction.Discard()
|
||||
|
||||
err = transaction.Put(repo.Key(), repo.Encode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if repo.SourceKind == SourceLocalRepo {
|
||||
for component, item := range repo.sourceItems {
|
||||
err = collection.db.Put(repo.RefKey(component), item.packageRefs.Encode())
|
||||
err = transaction.Put(repo.RefKey(component), item.packageRefs.Encode())
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
return transaction.Commit()
|
||||
}
|
||||
|
||||
// LoadComplete loads additional information for remote repo
|
||||
@@ -1170,6 +1176,13 @@ func (collection *PublishedRepoCollection) Remove(publishedStorageProvider aptly
|
||||
storage, prefix, distribution string, collectionFactory *CollectionFactory, progress aptly.Progress,
|
||||
force, skipCleanup bool) error {
|
||||
|
||||
transaction, err := collection.db.OpenTransaction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer transaction.Discard()
|
||||
|
||||
// TODO: load via transaction
|
||||
collection.loadList()
|
||||
|
||||
repo, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||
@@ -1221,17 +1234,17 @@ func (collection *PublishedRepoCollection) Remove(publishedStorageProvider aptly
|
||||
}
|
||||
}
|
||||
|
||||
err = collection.db.Delete(repo.Key())
|
||||
err = transaction.Delete(repo.Key())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, component := range repo.Components() {
|
||||
err = collection.db.Delete(repo.RefKey(component))
|
||||
err = transaction.Delete(repo.RefKey(component))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return transaction.Commit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user