|
26 | 26 |
|
27 | 27 | #include <algorithm>
|
28 | 28 | #include <cstdint>
|
| 29 | +#include <future> |
29 | 30 | #include <memory>
|
30 | 31 | #include <string>
|
31 | 32 | #include <utility>
|
@@ -537,54 +538,68 @@ MetaStatusCode Partition::GetAllBlockGroup(
|
537 | 538 | }
|
538 | 539 |
|
539 | 540 | void Partition::StartS3Compact() {
|
540 |
| - S3CompactManager::GetInstance().Register( |
541 |
| - S3Compact{inodeManager_, partitionInfo_}); |
| 541 | + // register s3 compaction task in a separate thread, since the caller may |
| 542 | + // holds a pthread wrlock when calling this function, and create `S3Compact` |
| 543 | + // will acquire a bthread rwlock, may cause thread switching, thus causing a |
| 544 | + // deadlock. |
| 545 | + // FIXME(wuhanqing): handle it in a more elegant way |
| 546 | + auto handle = std::async(std::launch::async, [this]() { |
| 547 | + S3CompactManager::GetInstance().Register( |
| 548 | + S3Compact{inodeManager_, partitionInfo_}); |
| 549 | + }); |
| 550 | + |
| 551 | + handle.wait(); |
542 | 552 | }
|
543 | 553 |
|
544 | 554 | void Partition::CancelS3Compact() {
|
545 | 555 | S3CompactManager::GetInstance().Cancel(partitionInfo_.partitionid());
|
546 | 556 | }
|
547 | 557 |
|
548 | 558 | void Partition::StartVolumeDeallocate() {
|
549 |
| - FsInfo fsInfo; |
550 |
| - bool ok = |
551 |
| - FsInfoManager::GetInstance().GetFsInfo(partitionInfo_.fsid(), &fsInfo); |
552 |
| - if (!ok) { |
553 |
| - LOG(ERROR) |
554 |
| - << "Partition start volume deallocate fail, get fsinfo fail. fsid=" |
555 |
| - << partitionInfo_.fsid(); |
556 |
| - return; |
557 |
| - } |
558 |
| - |
559 |
| - if (!fsInfo.detail().has_volume()) { |
560 |
| - LOG(INFO) << "Partition not belong to volume, do not need start " |
561 |
| - "deallocate. partitionInfo=" |
562 |
| - << partitionInfo_.DebugString(); |
563 |
| - return; |
564 |
| - } |
565 |
| - |
566 |
| - VolumeDeallocateCalOption calOpt; |
567 |
| - calOpt.kvStorage = kvStorage_; |
568 |
| - calOpt.inodeStorage = inodeStorage_; |
569 |
| - calOpt.nameGen = nameGen_; |
570 |
| - auto copysetNode = |
571 |
| - copyset::CopysetNodeManager::GetInstance().GetSharedCopysetNode( |
572 |
| - partitionInfo_.poolid(), partitionInfo_.copysetid()); |
573 |
| - if (copysetNode == nullptr) { |
574 |
| - LOG(ERROR) << "Partition get copyset node failed. poolid=" |
575 |
| - << partitionInfo_.poolid() |
576 |
| - << ", copysetid=" << partitionInfo_.copysetid(); |
577 |
| - return; |
578 |
| - } |
579 |
| - |
580 |
| - InodeVolumeSpaceDeallocate task(partitionInfo_.fsid(), |
581 |
| - partitionInfo_.partitionid(), copysetNode); |
582 |
| - task.Init(calOpt); |
583 |
| - |
584 |
| - VolumeDeallocateManager::GetInstance().Register(std::move(task)); |
585 |
| - |
586 |
| - VLOG(3) << "Partition start volume deallocate success. partitionInfo=" |
587 |
| - << partitionInfo_.DebugString(); |
| 559 | + // FIXME(wuhanqing): same as `StartS3Compact` |
| 560 | + auto handle = std::async(std::launch::async, [this]() { |
| 561 | + FsInfo fsInfo; |
| 562 | + bool ok = FsInfoManager::GetInstance().GetFsInfo( |
| 563 | + partitionInfo_.fsid(), &fsInfo); |
| 564 | + if (!ok) { |
| 565 | + LOG(ERROR) << "Partition start volume deallocate fail, get fsinfo " |
| 566 | + "fail. fsid=" |
| 567 | + << partitionInfo_.fsid(); |
| 568 | + return; |
| 569 | + } |
| 570 | + |
| 571 | + if (!fsInfo.detail().has_volume()) { |
| 572 | + LOG(INFO) << "Partition not belong to volume, do not need start " |
| 573 | + "deallocate. partitionInfo=" |
| 574 | + << partitionInfo_.DebugString(); |
| 575 | + return; |
| 576 | + } |
| 577 | + |
| 578 | + VolumeDeallocateCalOption calOpt; |
| 579 | + calOpt.kvStorage = kvStorage_; |
| 580 | + calOpt.inodeStorage = inodeStorage_; |
| 581 | + calOpt.nameGen = nameGen_; |
| 582 | + auto copysetNode = |
| 583 | + copyset::CopysetNodeManager::GetInstance().GetSharedCopysetNode( |
| 584 | + partitionInfo_.poolid(), partitionInfo_.copysetid()); |
| 585 | + if (copysetNode == nullptr) { |
| 586 | + LOG(ERROR) << "Partition get copyset node failed. poolid=" |
| 587 | + << partitionInfo_.poolid() |
| 588 | + << ", copysetid=" << partitionInfo_.copysetid(); |
| 589 | + return; |
| 590 | + } |
| 591 | + |
| 592 | + InodeVolumeSpaceDeallocate task( |
| 593 | + partitionInfo_.fsid(), partitionInfo_.partitionid(), copysetNode); |
| 594 | + task.Init(calOpt); |
| 595 | + |
| 596 | + VolumeDeallocateManager::GetInstance().Register(std::move(task)); |
| 597 | + |
| 598 | + VLOG(3) << "Partition start volume deallocate success. partitionInfo=" |
| 599 | + << partitionInfo_.DebugString(); |
| 600 | + }); |
| 601 | + |
| 602 | + handle.wait(); |
588 | 603 | }
|
589 | 604 |
|
590 | 605 | void Partition::CancelVolumeDeallocate() {
|
|
0 commit comments