// File: yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::ReqMerge(hlkvds::Request*)
void DS_MultiVolume_Impl::ReqMerge(Request* req) {
    int shard_id = req->GetShardsWQId();

    std::unique_lock<std::mutex> lck_seg_map(segMapMtx_, std::defer_lock);

    std::mutex *seg_mtx = segMtxVec_[shard_id];
    std::unique_lock<std::mutex> lck_seg(*seg_mtx);

    lck_seg_map.lock();
    SegForReq *seg = segMap_[shard_id];
    lck_seg_map.unlock();

    if (seg->TryPut(req)) {
        seg->Put(req);
    } else {
        seg->Completion();
        segWteWQ_->Add_task(seg);

        int vol_id = pickVol();
        seg = new SegForReq(volMap_[vol_id], idxMgr_, options_.expired_time);

        lck_seg_map.lock();
        std::map<int, SegForReq*>::iterator iter = segMap_.find(shard_id);
        segMap_.erase(iter);
        segMap_.insert( make_pair(shard_id, seg) );
        lck_seg_map.unlock();

        seg->Put(req);
    }

}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x16da0
movq 0x60(%rsp), %rsi
movl %eax, 0xf4(%rsp)
addq $0x60, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x16db0
movq 0x60(%rsp), %rdi
addq $0xb8, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x16d00
movq (%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x15a10
jmp 0x15329
leaq 0xe0(%rsp), %rdi
callq 0x16dd0
jmp 0x15338
movq 0x60(%rsp), %rdi
addq $0x88, %rdi
leaq 0xf4(%rsp), %rsi
callq 0x16c10
movq %rax, 0x58(%rsp)
jmp 0x15358
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x16e30
jmp 0x15377
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x42bf0
movb %al, 0x57(%rsp)
jmp 0x15392
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x1539c
jmp 0x153ea
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x42c50
jmp 0x153b3
jmp 0x155c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x155ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x155e2
movq 0xa8(%rsp), %rdi
callq 0x42ce0
jmp 0x153f9
movq 0x60(%rsp), %rax
movq 0x158(%rax), %rdi
movq 0xa8(%rsp), %rsi
callq 0x16e80
jmp 0x15414
movq 0x60(%rsp), %rdi
callq 0x11fa0
movl %eax, 0x50(%rsp)
jmp 0x15424
movl 0x50(%rsp), %eax
movl %eax, 0xa4(%rsp)
movl $0xd8, %edi
callq 0x84f0
movq %rax, 0x48(%rsp)
jmp 0x15440
movq 0x60(%rsp), %rdi
addq $0x28, %rdi
leaq 0xa4(%rsp), %rsi
callq 0x15a50
movq %rax, 0x40(%rsp)
jmp 0x1545d
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rcx
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rcx), %rax
movq 0x20(%rcx), %rdx
movl 0x10(%rax), %ecx
callq 0x42b00
jmp 0x15481
movq 0x48(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x16dd0
jmp 0x1549d
movq 0x60(%rsp), %rdi
addq $0x88, %rdi
leaq 0xf4(%rsp), %rsi
callq 0x16f00
movq %rax, 0x38(%rsp)
jmp 0x154bd
movq 0x60(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x98(%rsp)
addq $0x88, %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rsi
callq 0x16f30
movq %rax, 0x30(%rsp)
jmp 0x154fa
movq 0x60(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x88(%rsp)
addq $0x88, %rax
movq %rax, 0x18(%rsp)
leaq 0xf4(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x15b90
movq %rdx, 0x20(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x15537
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl %ecx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
leaq 0x78(%rsp), %rsi
callq 0x15b40
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x15566
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movb %al, 0x70(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x16e30
jmp 0x15587
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x42c50
jmp 0x1559e
jmp 0x155c0
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
callq 0x84b0
jmp 0x155e2
leaq 0xc0(%rsp), %rdi
callq 0x15c30
leaq 0xe0(%rsp), %rdi
callq 0x15c30
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xc0(%rsp), %rdi
callq 0x15c30
leaq 0xe0(%rsp), %rdi
callq 0x15c30
movq 0xb8(%rsp), %rdi
callq 0x8820
nopl (%rax)