Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ List of contributors, in chronological order:
* James Munson (https://github.com/jmunson)
* Luan Dang (https://github.com/luanmdang)
* Martin Simon (https://github.com/barnumbirr)
* Walid Moghrabi (https://github.com/Hybrid512)
* Nathan Gray (https://github.com/NathanGray-ChurchillNavigation)
5 changes: 5 additions & 0 deletions database/goleveldb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func internalOpen(path string, throttleCompaction bool) (*leveldb.DB, error) {
o.CompactionL0Trigger = 32
o.WriteL0PauseTrigger = 96
o.WriteL0SlowdownTrigger = 64
o.BlockCacheCapacity = 128 * opt.MiB
o.CompactionTableSize = 64 * opt.MiB
o.CompactionTableSizeMultiplier = 2
o.NoSync = true
o.WriteBuffer = 256 * opt.MiB
}

return leveldb.OpenFile(path, o)
Expand Down
110 changes: 101 additions & 9 deletions deb/index_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"sync"

Expand All @@ -25,6 +26,7 @@ type indexFiles struct {
acquireByHash bool
byHashAlgorithms []string
skipBz2 bool
mu sync.Mutex
}

type indexFile struct {
Expand Down Expand Up @@ -102,7 +104,7 @@ func (file *indexFile) Finalize(signer pgp.Signer) error {
if err != nil {
return fmt.Errorf("unable to collect checksums: %s", err)
}
file.parent.generatedFiles[file.relativePath+ext] = checksumInfo
file.parent.recordGeneratedFile(file.relativePath+ext, checksumInfo)
}

filedir := filepath.Dir(filepath.Join(file.parent.basePath, file.relativePath))
Expand Down Expand Up @@ -133,12 +135,14 @@ func (file *indexFile) Finalize(signer pgp.Signer) error {
}

if file.parent.suffix != "" {
file.parent.renameMap[filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+ext)] =
filepath.Join(file.parent.basePath, file.relativePath+ext)
file.parent.recordRename(
filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+ext),
filepath.Join(file.parent.basePath, file.relativePath+ext),
)
}

if file.acquireByHash {
sums := file.parent.generatedFiles[file.relativePath+ext]
sums := file.parent.generatedFile(file.relativePath + ext)
all := map[string]string{"SHA512": sums.SHA512, "SHA256": sums.SHA256, "SHA1": sums.SHA1, "MD5Sum": sums.MD5}
algorithms, algErr := file.parent.hashAlgorithms()
if algErr != nil {
Expand All @@ -162,8 +166,10 @@ func (file *indexFile) Finalize(signer pgp.Signer) error {
}

if file.parent.suffix != "" {
file.parent.renameMap[filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+gpgExt)] =
filepath.Join(file.parent.basePath, file.relativePath+gpgExt)
file.parent.recordRename(
filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+gpgExt),
filepath.Join(file.parent.basePath, file.relativePath+gpgExt),
)
}

err = file.parent.publishedStorage.PutFile(filepath.Join(file.parent.basePath, file.relativePath+file.parent.suffix+gpgExt),
Expand All @@ -181,8 +187,10 @@ func (file *indexFile) Finalize(signer pgp.Signer) error {
}

if file.parent.suffix != "" {
file.parent.renameMap[filepath.Join(file.parent.basePath, "In"+file.relativePath+file.parent.suffix)] =
filepath.Join(file.parent.basePath, "In"+file.relativePath)
file.parent.recordRename(
filepath.Join(file.parent.basePath, "In"+file.relativePath+file.parent.suffix),
filepath.Join(file.parent.basePath, "In"+file.relativePath),
)
}

err = file.parent.publishedStorage.PutFile(filepath.Join(file.parent.basePath, "In"+file.relativePath+file.parent.suffix),
Expand Down Expand Up @@ -306,7 +314,31 @@ func newIndexFiles(publishedStorage aptly.PublishedStorage, basePath, tempDir, s
}
}

func (files *indexFiles) recordGeneratedFile(relativePath string, checksumInfo utils.ChecksumInfo) {
files.mu.Lock()
defer files.mu.Unlock()

files.generatedFiles[relativePath] = checksumInfo
}

func (files *indexFiles) generatedFile(relativePath string) utils.ChecksumInfo {
files.mu.Lock()
defer files.mu.Unlock()

return files.generatedFiles[relativePath]
}

func (files *indexFiles) recordRename(oldName, newName string) {
files.mu.Lock()
defer files.mu.Unlock()

files.renameMap[oldName] = newName
}

func (files *indexFiles) PackageIndex(component, arch string, udeb bool, installer bool, distribution string) *indexFile {
files.mu.Lock()
defer files.mu.Unlock()

if arch == ArchitectureSource {
udeb = false
}
Expand Down Expand Up @@ -348,6 +380,9 @@ func (files *indexFiles) PackageIndex(component, arch string, udeb bool, install
}

func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexFile {
files.mu.Lock()
defer files.mu.Unlock()

if arch == ArchitectureSource {
udeb = false
}
Expand Down Expand Up @@ -383,6 +418,9 @@ func (files *indexFiles) ReleaseIndex(component, arch string, udeb bool) *indexF
}

func (files *indexFiles) ContentsIndex(component, arch string, udeb bool) *indexFile {
files.mu.Lock()
defer files.mu.Unlock()

if arch == ArchitectureSource {
udeb = false
}
Expand Down Expand Up @@ -415,6 +453,9 @@ func (files *indexFiles) ContentsIndex(component, arch string, udeb bool) *index
}

func (files *indexFiles) LegacyContentsIndex(arch string, udeb bool) *indexFile {
files.mu.Lock()
defer files.mu.Unlock()

if arch == ArchitectureSource {
udeb = false
}
Expand Down Expand Up @@ -447,6 +488,9 @@ func (files *indexFiles) LegacyContentsIndex(arch string, udeb bool) *indexFile
}

func (files *indexFiles) SkelIndex(component, path string) *indexFile {
files.mu.Lock()
defer files.mu.Unlock()

key := fmt.Sprintf("si-%s-%s", component, path)
file, ok := files.indexes[key]

Expand Down Expand Up @@ -485,10 +529,58 @@ func (files *indexFiles) FinalizeAll(progress aptly.Progress, signer pgp.Signer)
defer progress.ShutdownBar()
}

parallelFiles := make([]*indexFile, 0, len(files.indexes))
serialFiles := make([]*indexFile, 0)

for _, file := range files.indexes {
if signer != nil && (file.detachedSign || file.clearSign) {
serialFiles = append(serialFiles, file)
continue
}
parallelFiles = append(parallelFiles, file)
}

if len(parallelFiles) > 0 {
workerCount := min(max(runtime.NumCPU(), 1), len(parallelFiles))
jobs := make(chan *indexFile)
errs := make(chan error, len(parallelFiles))

var wg sync.WaitGroup
wg.Add(workerCount)
for i := 0; i < workerCount; i++ {
go func() {
defer wg.Done()
for file := range jobs {
errs <- file.Finalize(nil)
}
}()
}

for _, file := range parallelFiles {
jobs <- file
}
close(jobs)

wg.Wait()
close(errs)

for finalizeErr := range errs {
if finalizeErr != nil && err == nil {
err = finalizeErr
}
if progress != nil {
progress.AddBar(1)
}
}
if err != nil {
return err
}
}

for _, file := range serialFiles {
err = file.Finalize(signer)
if err != nil {
return
return err
}
if progress != nil {
progress.AddBar(1)
Expand Down
Loading
Loading