mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-14 19:27:32 +08:00
better delayed deletion
This commit is contained in:
@@ -165,17 +165,25 @@ func bench_read() {
|
|||||||
readStats.printStats()
|
readStats.printStats()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type delayedFile struct {
|
||||||
|
enterTime time.Time
|
||||||
|
fp *operation.FilePart
|
||||||
|
}
|
||||||
|
|
||||||
func writeFiles(idChan chan int, fileIdLineChan chan string, s *stats) {
|
func writeFiles(idChan chan int, fileIdLineChan chan string, s *stats) {
|
||||||
deleteChan := make(chan *operation.FilePart, 100)
|
deleteChan := make(chan *delayedFile, 100)
|
||||||
var waitForDeletions sync.WaitGroup
|
var waitForDeletions sync.WaitGroup
|
||||||
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
|
|
||||||
for i := 0; i < 7; i++ {
|
for i := 0; i < 7; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
waitForDeletions.Add(1)
|
waitForDeletions.Add(1)
|
||||||
for fp := range deleteChan {
|
for df := range deleteChan {
|
||||||
if fp == nil {
|
if df == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if df.enterTime.Add(time.Second).Before(time.Now()) {
|
||||||
|
time.Sleep(df.enterTime.Add(time.Second).Sub(time.Now()))
|
||||||
|
}
|
||||||
|
fp := df.fp
|
||||||
serverLimitChan[fp.Server] <- true
|
serverLimitChan[fp.Server] <- true
|
||||||
if e := util.Delete("http://" + fp.Server + "/" + fp.Fid); e == nil {
|
if e := util.Delete("http://" + fp.Server + "/" + fp.Fid); e == nil {
|
||||||
s.completed++
|
s.completed++
|
||||||
@@ -202,7 +210,7 @@ func writeFiles(idChan chan int, fileIdLineChan chan string, s *stats) {
|
|||||||
if _, err := fp.Upload(0, *b.server); err == nil {
|
if _, err := fp.Upload(0, *b.server); err == nil {
|
||||||
if rand.Intn(100) < *b.deletePercentage {
|
if rand.Intn(100) < *b.deletePercentage {
|
||||||
s.total++
|
s.total++
|
||||||
deleteChan <- fp
|
deleteChan <- &delayedFile{time.Now(), fp}
|
||||||
} else {
|
} else {
|
||||||
fileIdLineChan <- fp.Fid
|
fileIdLineChan <- fp.Fid
|
||||||
}
|
}
|
||||||
@@ -320,7 +328,7 @@ func readFileIds(fileName string, fileIdLineChan chan string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lines := make([]string, 0, *b.numberOfFiles)
|
lines := make([]string, 0, readStats.total)
|
||||||
for {
|
for {
|
||||||
if line, err := Readln(r); err == nil {
|
if line, err := Readln(r); err == nil {
|
||||||
lines = append(lines, string(line))
|
lines = append(lines, string(line))
|
||||||
@@ -329,7 +337,7 @@ func readFileIds(fileName string, fileIdLineChan chan string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(lines) > 0 {
|
if len(lines) > 0 {
|
||||||
for i := 0; i < *b.numberOfFiles; i++ {
|
for i := 0; i < readStats.total; i++ {
|
||||||
fileIdLineChan <- lines[rand.Intn(len(lines))]
|
fileIdLineChan <- lines[rand.Intn(len(lines))]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user