// File: yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::ReadData(hlkvds::KVSlice&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
Status DS_MultiVolume_Impl::ReadData(KVSlice &slice, string &data) {
    HashEntry *entry;
    entry = &slice.GetHashEntry();

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

    uint64_t data_offset = 0;
    if (!vol->CalcDataOffsetPhyFromEntry(entry, data_offset)) {
        return Status::Aborted("Calculate data offset failed.");
    }

    uint16_t data_len = entry->GetDataSize();

    if (data_len == 0) {
        //The key is not exist
        return Status::NotFound("Key is not found.");
    }

    char *mdata = new char[data_len];
    if (!vol->Read(mdata, data_len, data_offset)) {
        __ERROR("Could not read data at position");
        delete[] mdata;
        return Status::IOError("Could not read data at position.");
    }
    data.assign(mdata, data_len);
    delete[] mdata;

    __DEBUG("get key: %s, data offset %ld, head_offset is %ld", slice.GetKeyStr().c_str(), data_offset, entry->GetHeaderOffset());

    return Status::OK();
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x20(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rdi
callq 0x116b0
movq 0x30(%rsp), %rdi
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rsi
callq 0x13530
movq 0x30(%rsp), %rdi
movl %eax, 0x5c(%rsp)
addq $0x28, %rdi
leaq 0x5c(%rsp), %rsi
callq 0x15a50
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x51320
testb $0x1, %al
jne 0x133e9
movq 0x20(%rsp), %rdi
leaq 0x3f3bc(%rip), %rsi     # 0x5279b
callq 0x163e0
jmp 0x13523
movq 0x60(%rsp), %rdi
callq 0x16580
movw %ax, 0x46(%rsp)
movzwl 0x46(%rsp), %eax
cmpl $0x0, %eax
jne 0x13418
movq 0x20(%rsp), %rdi
leaq 0x3f3ab(%rip), %rsi     # 0x527b9
callq 0x165a0
jmp 0x13523
movzwl 0x46(%rsp), %eax
movl %eax, %edi
callq 0x8040
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movzwl 0x46(%rsp), %eax
movl %eax, %edx
movq 0x48(%rsp), %rcx
callq 0x50ed0
testb $0x1, %al
jne 0x134e9
jmp 0x1344e
movq 0x5db83(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x8480
movq 0x18(%rsp), %rdi
movq %rax, %rdx
leaq 0x3f040(%rip), %rsi     # 0x524b1
leaq 0x3f353(%rip), %rcx     # 0x527cb
leaq 0x3f0d2(%rip), %r8      # 0x52551
movl $0xb3, %r9d
movb $0x0, %al
callq 0x86f0
movq 0x5db45(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3f337(%rip), %rsi     # 0x527d4
movb $0x0, %al
callq 0x86f0
movq 0x5db2d(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3f910(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x134d6
movq 0x10(%rsp), %rdi
callq 0x8610
movq 0x20(%rsp), %rdi
leaq 0x3f312(%rip), %rsi     # 0x527f4
callq 0x16510
jmp 0x13523
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movzwl 0x46(%rsp), %eax
movl %eax, %edx
callq 0x8660
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x13519
movq 0x8(%rsp), %rdi
callq 0x8610
movq 0x20(%rsp), %rdi
callq 0x16560
movq 0x28(%rsp), %rax
addq $0x88, %rsp
retq