弹出超出BFile数量限制的BFile
()
| 371 | |
| 372 | // 弹出超出BFile数量限制的BFile |
| 373 | func (this *FS) shiftOpenFiles() { |
| 374 | var l = this.bList.Len() |
| 375 | var count = l - this.opt.MaxOpenFiles |
| 376 | if count <= 0 { |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | var bNames []string |
| 381 | var searchCount int |
| 382 | this.bList.Range(func(item *linkedlist.Item[string]) (goNext bool) { |
| 383 | searchCount++ |
| 384 | |
| 385 | var bName = item.Value |
| 386 | var bFile = this.bMap[bName] |
| 387 | if bFile.CanClose() { |
| 388 | bNames = append(bNames, bName) |
| 389 | count-- |
| 390 | } |
| 391 | return count > 0 && searchCount < 8 && searchCount < l-8 |
| 392 | }) |
| 393 | |
| 394 | for _, bName := range bNames { |
| 395 | var bFile = this.bMap[bName] |
| 396 | var item = this.bItemMap[bName] |
| 397 | |
| 398 | // clean |
| 399 | delete(this.bMap, bName) |
| 400 | delete(this.bItemMap, bName) |
| 401 | this.bList.Remove(item) |
| 402 | |
| 403 | // add to closing queue |
| 404 | this.closingBMap[bFile.Filename()] = zero.Zero{} |
| 405 | |
| 406 | // MUST run in goroutine |
| 407 | go func(bFile *BlocksFile) { |
| 408 | // 因为 closingBChan 可能已经关闭 |
| 409 | defer func() { |
| 410 | recover() |
| 411 | }() |
| 412 | |
| 413 | this.closingBChan <- bFile |
| 414 | }(bFile) |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | func (this *FS) waitBFile(bPath string) error { |
| 419 | this.mu.RLock() |