Skip to content

Commit adc1378

Browse files
Shivaji KharseShivaji Kharse
authored andcommitted
resolve rate-limit failures when downloading datasets
1 parent 7888830 commit adc1378

5 files changed

Lines changed: 111 additions & 29 deletions

File tree

.github/workflows/ci-dgraph-integration2-tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ jobs:
2929
with:
3030
fetch-depth: 0
3131

32+
- name: Restore benchmark dataset cache
33+
uses: actions/cache/restore@v4
34+
with:
35+
path: dgraphtest/datafiles
36+
key: dataset-dgraphtest-v1
37+
38+
- name: Ensure datafiles directory
39+
run: mkdir -p dgraphtest/datafiles
40+
3241
- name: Set up Go
3342
uses: actions/setup-go@v6
3443
with:
@@ -55,3 +64,10 @@ jobs:
5564
go clean -testcache
5665
# sleep
5766
sleep 5
67+
68+
- name: Save benchmark dataset cache
69+
if: success()
70+
uses: actions/cache/save@v4
71+
with:
72+
path: dgraphtest/datafiles
73+
key: dataset-dgraphtest-v1

.github/workflows/ci-dgraph-ldbc-tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ jobs:
2828
- name: Checkout Dgraph
2929
uses: actions/checkout@v5
3030

31+
- name: Restore LDBC dataset cache
32+
uses: actions/cache/restore@v4
33+
with:
34+
path: ${{ github.workspace }}/test-data
35+
key: dataset-ldbc-v1
36+
3137
- name: Set up Go
3238
uses: actions/setup-go@v6
3339
with:
@@ -61,6 +67,13 @@ jobs:
6167
# move the binary
6268
cp dgraph/dgraph ~/go/bin/dgraph
6369
# run the ldbc tests
64-
cd t; ./t --suite=ldbc
70+
cd t; ./t --suite=ldbc --tmp=${{ github.workspace }}/test-data
6571
# clean up docker containers after test execution
6672
./t -r
73+
74+
- name: Save LDBC dataset cache
75+
if: success()
76+
uses: actions/cache/save@v4
77+
with:
78+
path: ${{ github.workspace }}/test-data
79+
key: dataset-ldbc-v1

.github/workflows/ci-dgraph-load-tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v5
2929

30+
- name: Restore load test dataset cache
31+
uses: actions/cache/restore@v4
32+
with:
33+
path: ${{ github.workspace }}/test-data
34+
key: dataset-load-v1
35+
3036
- name: Set up Go
3137
uses: actions/setup-go@v6
3238
with:
@@ -60,8 +66,15 @@ jobs:
6066
# move the binary
6167
cp dgraph/dgraph ~/go/bin/dgraph
6268
# run the load tests
63-
cd t; ./t --suite=load
69+
cd t; ./t --suite=load --tmp=${{ github.workspace }}/test-data
6470
# clean up docker containers after test execution
6571
./t -r
6672
# sleep
6773
sleep 5
74+
75+
- name: Save load test dataset cache
76+
if: success()
77+
uses: actions/cache/save@v4
78+
with:
79+
path: ${{ github.workspace }}/test-data
80+
key: dataset-load-v1

dgraphtest/load.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"runtime"
2121
"strconv"
2222
"strings"
23+
"time"
2324

2425
"github.com/pkg/errors"
2526

@@ -41,10 +42,10 @@ func (c *LocalCluster) HostDgraphBinaryPath() string {
4142
}
4243

4344
var datafiles = map[string]string{
44-
"1million.schema": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/1million.schema?raw=true",
45-
"1million.rdf.gz": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/1million.rdf.gz?raw=true",
46-
"21million.schema": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/21million.schema?raw=true",
47-
"21million.rdf.gz": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/data/21million.rdf.gz?raw=true",
45+
"1million.schema": "https://raw.githubusercontent.com/dgraph-io/dgraph-benchmarks/refs/heads/main/data/1million.schema",
46+
"1million.rdf.gz": "https://media.githubusercontent.com/media/dgraph-io/dgraph-benchmarks/refs/heads/main/data/1million.rdf.gz",
47+
"21million.schema": "https://raw.githubusercontent.com/dgraph-io/dgraph-benchmarks/refs/heads/main/data/21million.schema",
48+
"21million.rdf.gz": "https://media.githubusercontent.com/media/dgraph-io/dgraph-benchmarks/refs/heads/main/data/21million.rdf.gz",
4849
}
4950

5051
type DatasetType int
@@ -604,11 +605,22 @@ func (d *Dataset) ensureFile(filename string) string {
604605
}
605606

606607
func downloadFile(fname, url string) error {
607-
cmd := exec.Command("wget", "-O", fname, url)
608-
cmd.Dir = datasetFilesPath
609-
610-
if _, err := cmd.CombinedOutput(); err != nil {
611-
return fmt.Errorf("error downloading file %s: %w", fname, err)
608+
const maxRetries = 3
609+
fpath := filepath.Join(datasetFilesPath, fname)
610+
for attempt := 1; attempt <= maxRetries; attempt++ {
611+
cmd := exec.Command("wget", "--tries=3", "--waitretry=5", "--retry-connrefused", "-O", fname, url)
612+
cmd.Dir = datasetFilesPath
613+
614+
if out, err := cmd.CombinedOutput(); err != nil {
615+
log.Printf("attempt %d/%d failed to download %s: %v\n%s", attempt, maxRetries, fname, err, string(out))
616+
if attempt < maxRetries {
617+
time.Sleep(time.Duration(attempt*5) * time.Second)
618+
continue
619+
}
620+
_ = os.Remove(fpath)
621+
return fmt.Errorf("error downloading file %s after %d attempts: %w", fname, maxRetries, err)
622+
}
623+
return nil
612624
}
613625
return nil
614626
}

t/t.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,27 @@ var rdfFileNames = [...]string{
11591159
"workAt_0.rdf"}
11601160

11611161
var ldbcDataFiles = map[string]string{
1162-
"ldbcTypes.schema": "https://github.com/dgraph-io/dgraph-benchmarks/blob/main/ldbc/sf0.3/ldbcTypes.schema?raw=true",
1162+
"ldbcTypes.schema": "https://raw.githubusercontent.com/dgraph-io/dgraph-benchmarks/refs/heads/main/ldbc/sf0.3/ldbcTypes.schema",
1163+
}
1164+
1165+
func wgetWithRetry(fname, url, dir string) error {
1166+
const maxRetries = 3
1167+
fpath := filepath.Join(dir, fname)
1168+
for attempt := 1; attempt <= maxRetries; attempt++ {
1169+
cmd := exec.Command("wget", "--tries=3", "--waitretry=5", "--retry-connrefused", "-O", fname, url)
1170+
cmd.Dir = dir
1171+
if out, err := cmd.CombinedOutput(); err != nil {
1172+
fmt.Printf("attempt %d/%d failed to download %s: %v\n%s\n", attempt, maxRetries, fname, err, string(out))
1173+
if attempt < maxRetries {
1174+
time.Sleep(time.Duration(attempt*5) * time.Second)
1175+
continue
1176+
}
1177+
_ = os.Remove(fpath)
1178+
return fmt.Errorf("failed to download %s after %d attempts: %w", fname, maxRetries, err)
1179+
}
1180+
return nil
1181+
}
1182+
return nil
11631183
}
11641184

11651185
func downloadDataFiles() {
@@ -1168,12 +1188,13 @@ func downloadDataFiles() {
11681188
return
11691189
}
11701190
for fname, link := range datafiles {
1171-
cmd := exec.Command("wget", "-O", fname, link)
1172-
cmd.Dir = *tmp
1173-
1174-
if out, err := cmd.CombinedOutput(); err != nil {
1175-
fmt.Printf("Error %v\n", err)
1176-
panic(fmt.Sprintf("error downloading a file: %s", string(out)))
1191+
fpath := filepath.Join(*tmp, fname)
1192+
if fi, err := os.Stat(fpath); err == nil && fi.Size() > 0 {
1193+
fmt.Printf("Skipping %s (already exists)\n", fname)
1194+
continue
1195+
}
1196+
if err := wgetWithRetry(fname, link, *tmp); err != nil {
1197+
panic(fmt.Sprintf("error downloading %s: %v", fname, err))
11771198
}
11781199
}
11791200
}
@@ -1189,20 +1210,26 @@ func downloadLDBCFiles(dir string) {
11891210
}
11901211

11911212
start := time.Now()
1213+
sem := make(chan struct{}, 5)
11921214
var wg sync.WaitGroup
11931215
for fname, link := range ldbcDataFiles {
1216+
fpath := filepath.Join(dir, fname)
1217+
if fi, err := os.Stat(fpath); err == nil && fi.Size() > 0 {
1218+
fmt.Printf("Skipping %s (already exists)\n", fname)
1219+
continue
1220+
}
11941221
wg.Add(1)
1195-
go func(fname, link string, wg *sync.WaitGroup) {
1222+
go func(fname, link string) {
11961223
defer wg.Done()
1197-
start := time.Now()
1198-
cmd := exec.Command("wget", "-O", fname, link)
1199-
cmd.Dir = dir
1200-
if out, err := cmd.CombinedOutput(); err != nil {
1201-
fmt.Printf("Error %v\n", err)
1202-
panic(fmt.Sprintf("error downloading a file: %s", string(out)))
1224+
sem <- struct{}{}
1225+
defer func() { <-sem }()
1226+
1227+
dlStart := time.Now()
1228+
if err := wgetWithRetry(fname, link, dir); err != nil {
1229+
panic(fmt.Sprintf("error downloading %s: %v", fname, err))
12031230
}
1204-
fmt.Printf("Downloaded %s to %s in %s \n", fname, dir, time.Since(start))
1205-
}(fname, link, &wg)
1231+
fmt.Printf("Downloaded %s to %s in %s \n", fname, dir, time.Since(dlStart))
1232+
}(fname, link)
12061233
}
12071234
wg.Wait()
12081235
fmt.Printf("Downloaded %d files in %s \n", len(ldbcDataFiles), time.Since(start))
@@ -1387,7 +1414,9 @@ func run() error {
13871414
needsData := testSuiteContainsAny("load", "ldbc", "all")
13881415
if needsData && *tmp == "" {
13891416
*tmp = filepath.Join(os.TempDir(), "dgraph-test-data")
1390-
x.Check(testutil.MakeDirEmpty([]string{*tmp}))
1417+
}
1418+
if needsData {
1419+
x.Check(os.MkdirAll(*tmp, 0755))
13911420
}
13921421
if testSuiteContainsAny("load", "all") {
13931422
downloadDataFiles()
@@ -1449,7 +1478,6 @@ func main() {
14491478
procId = rand.Intn(1000)
14501479

14511480
err := run()
1452-
_ = os.RemoveAll(*tmp)
14531481
if err != nil {
14541482
os.Exit(1)
14551483
}

0 commit comments

Comments
 (0)