@@ -1159,7 +1159,27 @@ var rdfFileNames = [...]string{
11591159 "workAt_0.rdf" }
11601160
11611161var 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
11651185func 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