// File: yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::writeDataImmediately(hlkvds::KVSlice&)
Status DS_MultiVolume_Impl::writeDataImmediately(KVSlice& slice) {
    uint32_t seg_id = 0;
    bool ret = false;

    int vol_id = pickVol();
    Volume *vol = volMap_[vol_id];

    //TODO: use GcSegment first, need abstract segment.
    while (!vol->Alloc(seg_id)) {
        ret = vol->ForeGC();
        if (!ret) {
            __ERROR("Cann't get a new Empty Segment.\n");
            return Status::Aborted("Can't allocate a Empty Segment.");
        }
    }

    SegLatencyFriendly *seg = new SegLatencyFriendly(vol, idxMgr_);
    seg->Put(&slice);
    seg->SegSegId(seg_id);
    ret = seg->WriteSegToDevice();
    if(!ret) {
        __ERROR("Write batch segment to device failed");
        vol->FreeForFailed(seg_id);
        delete seg;
        return Status::IOError("could not write batch segment to device ");
    }
    uint32_t free_size = seg->GetFreeSize();
    vol->Use(seg_id, free_size);
    seg->UpdateToIndex();
    delete seg;
    return Status::OK();
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x28(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq 0x78(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movl $0x0, 0x6c(%rsp)
movb $0x0, 0x6b(%rsp)
callq 0x11fa0
movq 0x38(%rsp), %rdi
movl %eax, 0x64(%rsp)
addq $0x28, %rdi
leaq 0x64(%rsp), %rsi
callq 0x15a50
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x6c(%rsp), %rsi
callq 0x50e40
xorb $-0x1, %al
testb $0x1, %al
jne 0x12c7b
jmp 0x12d21
movq 0x58(%rsp), %rdi
callq 0x51250
andb $0x1, %al
movb %al, 0x6b(%rsp)
testb $0x1, 0x6b(%rsp)
jne 0x12d1c
jmp 0x12c98
movq 0x5e339(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x8480
movq 0x20(%rsp), %rdi
movq %rax, %rdx
leaq 0x3f7f6(%rip), %rsi     # 0x524b1
leaq 0x3fbd4(%rip), %rcx     # 0x52896
leaq 0x3f888(%rip), %r8      # 0x52551
movl $0x1d2, %r9d            # imm = 0x1D2
movb $0x0, %al
callq 0x86f0
movq 0x5e2fb(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3f9e0(%rip), %rsi     # 0x526c7
movb $0x0, %al
callq 0x86f0
movq 0x5e2e3(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x400c6(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x28(%rsp), %rdi
leaq 0x3f9d6(%rip), %rsi     # 0x526e8
callq 0x163e0
jmp 0x12eb1
jmp 0x12c61
movl $0x48, %edi
callq 0x84f0
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x18(%rsp)
movq 0x58(%rsp), %rsi
movq 0x20(%rax), %rdx
callq 0x43600
jmp 0x12d4b
movq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x43700
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x168c0
movq 0x50(%rsp), %rdi
callq 0x438f0
andb $0x1, %al
movb %al, 0x6b(%rsp)
testb $0x1, 0x6b(%rsp)
jne 0x12e5c
jmp 0x12d8f
movq 0x5e242(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x8480
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x3f6ff(%rip), %rsi     # 0x524b1
leaq 0x3fadd(%rip), %rcx     # 0x52896
leaq 0x3f791(%rip), %r8      # 0x52551
movl $0x1dc, %r9d            # imm = 0x1DC
movb $0x0, %al
callq 0x86f0
movq 0x5e204(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3f96f(%rip), %rsi     # 0x5274d
movb $0x0, %al
callq 0x86f0
movq 0x5e1ec(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3ffcf(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x58(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x511c0
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x12e2f
movq 0x8(%rsp), %rdi
callq 0x434f0
movq 0x8(%rsp), %rdi
callq 0x84b0
movq 0x28(%rsp), %rdi
leaq 0x3f937(%rip), %rsi     # 0x52772
callq 0x16510
jmp 0x12eb1
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
callq 0x84b0
jmp 0x12ebe
movq 0x50(%rsp), %rdi
callq 0x168e0
movl %eax, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x51220
movq 0x50(%rsp), %rdi
callq 0x44190
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x12ea7
movq (%rsp), %rdi
callq 0x434f0
movq (%rsp), %rdi
callq 0x84b0
movq 0x28(%rsp), %rdi
callq 0x16560
movq 0x30(%rsp), %rax
addq $0x88, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x8820
nopl (%rax,%rax)