|
15 | 15 | package external
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "bytes" |
18 | 19 | "context"
|
19 | 20 | "encoding/hex"
|
20 | 21 | goerrors "errors"
|
21 | 22 | "flag"
|
22 | 23 | "fmt"
|
23 | 24 | "io"
|
| 25 | + "strings" |
24 | 26 | "testing"
|
25 | 27 | "time"
|
26 | 28 |
|
@@ -88,11 +90,9 @@ func writePlainFile(s *writeTestSuite) {
|
88 | 90 | }
|
89 | 91 |
|
90 | 92 | func cleanOldFiles(ctx context.Context, store storage.ExternalStorage, subDir string) {
|
91 |
| - dataFiles, statFiles, err := GetAllFileNames(ctx, store, subDir) |
| 93 | + filenames, err := GetAllFileNames(ctx, store, subDir) |
92 | 94 | intest.AssertNoError(err)
|
93 |
| - err = store.DeleteFiles(ctx, dataFiles) |
94 |
| - intest.AssertNoError(err) |
95 |
| - err = store.DeleteFiles(ctx, statFiles) |
| 95 | + err = store.DeleteFiles(ctx, filenames) |
96 | 96 | intest.AssertNoError(err)
|
97 | 97 | }
|
98 | 98 |
|
@@ -249,7 +249,7 @@ type readTestSuite struct {
|
249 | 249 |
|
250 | 250 | func readFileSequential(t *testing.T, s *readTestSuite) {
|
251 | 251 | ctx := context.Background()
|
252 |
| - files, _, err := GetAllFileNames(ctx, s.store, "/"+s.subDir) |
| 252 | + files, _, err := getKVAndStatFilesByScan(ctx, s.store, "/"+s.subDir) |
253 | 253 | intest.AssertNoError(err)
|
254 | 254 |
|
255 | 255 | buf := make([]byte, s.memoryLimit)
|
@@ -285,9 +285,32 @@ func readFileSequential(t *testing.T, s *readTestSuite) {
|
285 | 285 | )
|
286 | 286 | }
|
287 | 287 |
|
| 288 | +func getKVAndStatFilesByScan(ctx context.Context, |
| 289 | + store storage.ExternalStorage, |
| 290 | + nonPartitionedDir string, |
| 291 | +) ([]string, []string, error) { |
| 292 | + names, err := GetAllFileNames(ctx, store, nonPartitionedDir) |
| 293 | + if err != nil { |
| 294 | + return nil, nil, err |
| 295 | + } |
| 296 | + var data, stats []string |
| 297 | + for _, path := range names { |
| 298 | + bs := []byte(path) |
| 299 | + lastIdx := bytes.LastIndexByte(bs, '/') |
| 300 | + secondLastIdx := bytes.LastIndexByte(bs[:lastIdx], '/') |
| 301 | + parentDir := path[secondLastIdx+1 : lastIdx] |
| 302 | + if strings.HasSuffix(parentDir, statSuffix) { |
| 303 | + stats = append(stats, path) |
| 304 | + } else { |
| 305 | + data = append(data, path) |
| 306 | + } |
| 307 | + } |
| 308 | + return data, stats, nil |
| 309 | +} |
| 310 | + |
288 | 311 | func readFileConcurrently(t *testing.T, s *readTestSuite) {
|
289 | 312 | ctx := context.Background()
|
290 |
| - files, _, err := GetAllFileNames(ctx, s.store, "/"+s.subDir) |
| 313 | + files, _, err := getKVAndStatFilesByScan(ctx, s.store, "/"+s.subDir) |
291 | 314 | intest.AssertNoError(err)
|
292 | 315 |
|
293 | 316 | conc := min(s.concurrency, len(files))
|
@@ -336,7 +359,7 @@ func readFileConcurrently(t *testing.T, s *readTestSuite) {
|
336 | 359 |
|
337 | 360 | func readMergeIter(t *testing.T, s *readTestSuite) {
|
338 | 361 | ctx := context.Background()
|
339 |
| - files, _, err := GetAllFileNames(ctx, s.store, "/"+s.subDir) |
| 362 | + files, _, err := getKVAndStatFilesByScan(ctx, s.store, "/"+s.subDir) |
340 | 363 | intest.AssertNoError(err)
|
341 | 364 |
|
342 | 365 | if s.beforeCreateReader != nil {
|
@@ -484,7 +507,7 @@ type mergeTestSuite struct {
|
484 | 507 |
|
485 | 508 | func mergeStep(t *testing.T, s *mergeTestSuite) {
|
486 | 509 | ctx := context.Background()
|
487 |
| - datas, _, err := GetAllFileNames(ctx, s.store, "/"+s.subDir) |
| 510 | + datas, _, err := getKVAndStatFilesByScan(ctx, s.store, "/"+s.subDir) |
488 | 511 | intest.AssertNoError(err)
|
489 | 512 |
|
490 | 513 | mergeOutput := "merge_output"
|
@@ -527,7 +550,7 @@ func mergeStep(t *testing.T, s *mergeTestSuite) {
|
527 | 550 |
|
528 | 551 | func newMergeStep(t *testing.T, s *mergeTestSuite) {
|
529 | 552 | ctx := context.Background()
|
530 |
| - datas, stats, err := GetAllFileNames(ctx, s.store, "/"+s.subDir) |
| 553 | + datas, stats, err := getKVAndStatFilesByScan(ctx, s.store, "/"+s.subDir) |
531 | 554 | intest.AssertNoError(err)
|
532 | 555 |
|
533 | 556 | mergeOutput := "merge_output"
|
@@ -647,7 +670,7 @@ func TestReadAllDataLargeFiles(t *testing.T) {
|
647 | 670 | writeExternalOneFile(suite2)
|
648 | 671 | t.Logf("minKey: %s, maxKey: %s", minKey, maxKey)
|
649 | 672 |
|
650 |
| - dataFiles, statFiles, err := GetAllFileNames(ctx, store, "") |
| 673 | + dataFiles, statFiles, err := getKVAndStatFilesByScan(ctx, store, "") |
651 | 674 | intest.AssertNoError(err)
|
652 | 675 | intest.Assert(len(dataFiles) == 2)
|
653 | 676 |
|
@@ -800,7 +823,7 @@ func TestReadAllData(t *testing.T) {
|
800 | 823 |
|
801 | 824 | finishCreateFiles:
|
802 | 825 |
|
803 |
| - dataFiles, statFiles, err := GetAllFileNames(ctx, store, "/") |
| 826 | + dataFiles, statFiles, err := getKVAndStatFilesByScan(ctx, store, "/") |
804 | 827 | require.NoError(t, err)
|
805 | 828 | require.Equal(t, 2091, len(dataFiles))
|
806 | 829 |
|
|
0 commit comments