You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.4 KiB

5 years ago
5 years ago
avoid data race of TraverseBfs (#3856) * avoid data race of TraverseBfs * close is enough avoid panic I1014 12:29:59.207120 volume_loading.go:131 loading sorted db /tmp/sw/test2_19.sdx error: unexpected file /tmp/sw/test2_19.idx size: 255 I1014 12:29:59.207125 volume_loading.go:119 open to write file /tmp/sw/test4_26.idx panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5260a4c] goroutine 287 [running]: github.com/seaweedfs/seaweedfs/weed/storage.(*SortedFileNeedleMap).Close(0x0) /Users/tochka/GolandProjects/seaweedfs/weed/storage/needle_map_sorted_file.go:97 +0x2c github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load.func1() /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:32 +0x8e github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load(0xc001b36280, 0x1, 0x1, 0x0, 0x69228c0?) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:205 +0x256c github.com/seaweedfs/seaweedfs/weed/storage.NewVolume({0x7ffeefbff6e0, 0x7}, {0x7ffeefbff6e0, 0x7}, {0xc0009a9284, 0x5}, 0x13, 0x0, 0x0, 0x0, ...) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume.go:62 +0x30f github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).loadExistingVolume(0xc0006f40c0, {0x846c8d0, 0xc0009ce600}, 0x0?, 0x1) /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:161 +0x4da github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes.func2() /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:201 +0xf9 created by github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:198 +0x150
2 years ago
5 years ago
avoid data race of TraverseBfs (#3856) * avoid data race of TraverseBfs * close is enough avoid panic I1014 12:29:59.207120 volume_loading.go:131 loading sorted db /tmp/sw/test2_19.sdx error: unexpected file /tmp/sw/test2_19.idx size: 255 I1014 12:29:59.207125 volume_loading.go:119 open to write file /tmp/sw/test4_26.idx panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5260a4c] goroutine 287 [running]: github.com/seaweedfs/seaweedfs/weed/storage.(*SortedFileNeedleMap).Close(0x0) /Users/tochka/GolandProjects/seaweedfs/weed/storage/needle_map_sorted_file.go:97 +0x2c github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load.func1() /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:32 +0x8e github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load(0xc001b36280, 0x1, 0x1, 0x0, 0x69228c0?) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:205 +0x256c github.com/seaweedfs/seaweedfs/weed/storage.NewVolume({0x7ffeefbff6e0, 0x7}, {0x7ffeefbff6e0, 0x7}, {0xc0009a9284, 0x5}, 0x13, 0x0, 0x0, 0x0, ...) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume.go:62 +0x30f github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).loadExistingVolume(0xc0006f40c0, {0x846c8d0, 0xc0009ce600}, 0x0?, 0x1) /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:161 +0x4da github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes.func2() /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:201 +0xf9 created by github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:198 +0x150
2 years ago
5 years ago
avoid data race of TraverseBfs (#3856) * avoid data race of TraverseBfs * close is enough avoid panic I1014 12:29:59.207120 volume_loading.go:131 loading sorted db /tmp/sw/test2_19.sdx error: unexpected file /tmp/sw/test2_19.idx size: 255 I1014 12:29:59.207125 volume_loading.go:119 open to write file /tmp/sw/test4_26.idx panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5260a4c] goroutine 287 [running]: github.com/seaweedfs/seaweedfs/weed/storage.(*SortedFileNeedleMap).Close(0x0) /Users/tochka/GolandProjects/seaweedfs/weed/storage/needle_map_sorted_file.go:97 +0x2c github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load.func1() /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:32 +0x8e github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load(0xc001b36280, 0x1, 0x1, 0x0, 0x69228c0?) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:205 +0x256c github.com/seaweedfs/seaweedfs/weed/storage.NewVolume({0x7ffeefbff6e0, 0x7}, {0x7ffeefbff6e0, 0x7}, {0xc0009a9284, 0x5}, 0x13, 0x0, 0x0, 0x0, ...) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume.go:62 +0x30f github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).loadExistingVolume(0xc0006f40c0, {0x846c8d0, 0xc0009ce600}, 0x0?, 0x1) /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:161 +0x4da github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes.func2() /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:201 +0xf9 created by github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:198 +0x150
2 years ago
5 years ago
avoid data race of TraverseBfs (#3856) * avoid data race of TraverseBfs * close is enough avoid panic I1014 12:29:59.207120 volume_loading.go:131 loading sorted db /tmp/sw/test2_19.sdx error: unexpected file /tmp/sw/test2_19.idx size: 255 I1014 12:29:59.207125 volume_loading.go:119 open to write file /tmp/sw/test4_26.idx panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5260a4c] goroutine 287 [running]: github.com/seaweedfs/seaweedfs/weed/storage.(*SortedFileNeedleMap).Close(0x0) /Users/tochka/GolandProjects/seaweedfs/weed/storage/needle_map_sorted_file.go:97 +0x2c github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load.func1() /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:32 +0x8e github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load(0xc001b36280, 0x1, 0x1, 0x0, 0x69228c0?) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:205 +0x256c github.com/seaweedfs/seaweedfs/weed/storage.NewVolume({0x7ffeefbff6e0, 0x7}, {0x7ffeefbff6e0, 0x7}, {0xc0009a9284, 0x5}, 0x13, 0x0, 0x0, 0x0, ...) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume.go:62 +0x30f github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).loadExistingVolume(0xc0006f40c0, {0x846c8d0, 0xc0009ce600}, 0x0?, 0x1) /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:161 +0x4da github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes.func2() /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:201 +0xf9 created by github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:198 +0x150
2 years ago
5 years ago
avoid data race of TraverseBfs (#3856) * avoid data race of TraverseBfs * close is enough avoid panic I1014 12:29:59.207120 volume_loading.go:131 loading sorted db /tmp/sw/test2_19.sdx error: unexpected file /tmp/sw/test2_19.idx size: 255 I1014 12:29:59.207125 volume_loading.go:119 open to write file /tmp/sw/test4_26.idx panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5260a4c] goroutine 287 [running]: github.com/seaweedfs/seaweedfs/weed/storage.(*SortedFileNeedleMap).Close(0x0) /Users/tochka/GolandProjects/seaweedfs/weed/storage/needle_map_sorted_file.go:97 +0x2c github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load.func1() /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:32 +0x8e github.com/seaweedfs/seaweedfs/weed/storage.(*Volume).load(0xc001b36280, 0x1, 0x1, 0x0, 0x69228c0?) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume_loading.go:205 +0x256c github.com/seaweedfs/seaweedfs/weed/storage.NewVolume({0x7ffeefbff6e0, 0x7}, {0x7ffeefbff6e0, 0x7}, {0xc0009a9284, 0x5}, 0x13, 0x0, 0x0, 0x0, ...) /Users/tochka/GolandProjects/seaweedfs/weed/storage/volume.go:62 +0x30f github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).loadExistingVolume(0xc0006f40c0, {0x846c8d0, 0xc0009ce600}, 0x0?, 0x1) /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:161 +0x4da github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes.func2() /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:201 +0xf9 created by github.com/seaweedfs/seaweedfs/weed/storage.(*DiskLocation).concurrentLoadingVolumes /Users/tochka/GolandProjects/seaweedfs/weed/storage/disk_location.go:198 +0x150
2 years ago
5 years ago
5 years ago
5 years ago
  1. package filer_pb
  2. import (
  3. "fmt"
  4. "sync"
  5. "time"
  6. "github.com/seaweedfs/seaweedfs/weed/util"
  7. )
  8. func TraverseBfs(filerClient FilerClient, parentPath util.FullPath, fn func(parentPath util.FullPath, entry *Entry)) (err error) {
  9. K := 5
  10. var jobQueueWg sync.WaitGroup
  11. queue := util.NewQueue()
  12. jobQueueWg.Add(1)
  13. queue.Enqueue(parentPath)
  14. terminates := make([]chan bool, K)
  15. for i := 0; i < K; i++ {
  16. terminates[i] = make(chan bool)
  17. go func(j int) {
  18. for {
  19. select {
  20. case <-terminates[j]:
  21. return
  22. default:
  23. t := queue.Dequeue()
  24. if t == nil {
  25. time.Sleep(329 * time.Millisecond)
  26. continue
  27. }
  28. dir := t.(util.FullPath)
  29. processErr := processOneDirectory(filerClient, dir, queue, &jobQueueWg, fn)
  30. if processErr != nil {
  31. err = processErr
  32. }
  33. jobQueueWg.Done()
  34. }
  35. }
  36. }(i)
  37. }
  38. jobQueueWg.Wait()
  39. for i := 0; i < K; i++ {
  40. close(terminates[i])
  41. }
  42. return
  43. }
  44. func processOneDirectory(filerClient FilerClient, parentPath util.FullPath, queue *util.Queue, jobQueueWg *sync.WaitGroup, fn func(parentPath util.FullPath, entry *Entry)) (err error) {
  45. return ReadDirAllEntries(filerClient, parentPath, "", func(entry *Entry, isLast bool) error {
  46. fn(parentPath, entry)
  47. if entry.IsDirectory {
  48. subDir := fmt.Sprintf("%s/%s", parentPath, entry.Name)
  49. if parentPath == "/" {
  50. subDir = "/" + entry.Name
  51. }
  52. jobQueueWg.Add(1)
  53. queue.Enqueue(util.FullPath(subDir))
  54. }
  55. return nil
  56. })
  57. }