Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Allow choosing different number of parallels for upload and download
Browse files Browse the repository at this point in the history
  • Loading branch information
jkawamoto committed Feb 1, 2021
1 parent 994c0b8 commit 65324af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
37 changes: 23 additions & 14 deletions renter/renterutil/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
// PseudoKV implements a key-value store by uploading and downloading data from Sia
// hosts.
type PseudoKV struct {
DB MetaDB
M, N, P int
Uploader ChunkUploader
Downloader ChunkDownloader
Deleter SectorDeleter
DB MetaDB
M, N, UP, DP int
Uploader ChunkUploader
Downloader ChunkDownloader
Deleter SectorDeleter
}

// Put uploads r to hosts and associates it with the specified key. Any existing
Expand All @@ -33,7 +33,7 @@ func (kv PseudoKV) Put(ctx context.Context, key []byte, r io.Reader) error {
return err
}
var bu BlobUploader
if kv.P == 1 {
if kv.UP <= 1 {
bu = SerialBlobUploader{
U: kv.Uploader,
M: kv.M,
Expand All @@ -44,7 +44,7 @@ func (kv PseudoKV) Put(ctx context.Context, key []byte, r io.Reader) error {
U: kv.Uploader,
M: kv.M,
N: kv.N,
P: kv.P,
P: kv.UP,
}
}
return bu.UploadBlob(ctx, kv.DB, b, r)
Expand Down Expand Up @@ -87,11 +87,20 @@ func (kv PseudoKV) Resume(ctx context.Context, key []byte, rs io.ReadSeeker) err
return err
}

bu := ParallelBlobUploader{
U: kv.Uploader,
M: kv.M,
N: kv.N,
P: kv.P,
var bu BlobUploader
if kv.UP <= 1 {
bu = SerialBlobUploader{
U: kv.Uploader,
M: kv.M,
N: kv.N,
}
} else {
bu = ParallelBlobUploader{
U: kv.Uploader,
M: kv.M,
N: kv.N,
P: kv.UP,
}
}
return bu.UploadBlob(ctx, kv.DB, b, rs)
}
Expand All @@ -104,14 +113,14 @@ func (kv PseudoKV) GetRange(ctx context.Context, key []byte, w io.Writer, off, n
return err
}
var bd BlobDownloader
if kv.P == 1 {
if kv.DP == 1 {
bd = SerialBlobDownloader{
D: kv.Downloader,
}
} else {
bd = ParallelBlobDownloader{
D: kv.Downloader,
P: kv.P,
P: kv.DP,
}
}
return bd.DownloadBlob(ctx, kv.DB, b, w, off, n)
Expand Down
13 changes: 7 additions & 6 deletions renter/renterutil/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func createTestingKV(tb testing.TB, numHosts, m, n int) PseudoKV {
DB: db,
M: m,
N: n,
P: 3, // TODO: is this a sane default?
UP: 3, // TODO: is this a sane default?
DP: 3, // TODO: is this a sane default?
Uploader: ParallelChunkUploader{Hosts: hs},
Downloader: ParallelChunkDownloader{Hosts: hs},
Deleter: SerialSectorDeleter{Hosts: hs},
Expand Down Expand Up @@ -207,11 +208,11 @@ func TestKVResumeHost(t *testing.T) {
}
db := NewEphemeralMetaDB()
kv := PseudoKV{
DB: db,
M: 2,
N: 3,
P: 2,

DB: db,
M: 2,
N: 3,
UP: 2,
DP: 2,
Uploader: ParallelChunkUploader{Hosts: hs},
Downloader: SerialChunkDownloader{Hosts: hs},
}
Expand Down

0 comments on commit 65324af

Please sign in to comment.