// File: yangwanyuan[P]HLKVDS/src/Tier.cc
// Function: hlkvds::FastTier::WriteBatchData(hlkvds::WriteBatch*)
Status FastTier::WriteBatchData(WriteBatch *batch) {
    uint32_t seg_id = 0;
    bool ret = false;

    ret = allocSegment(seg_id);
    if (!ret) {
        __ERROR("Cann't get a new Empty Segment.\n");
        return Status::Aborted("Can't allocate a Empty Segment.");
    }

    SegForSlice *seg = new SegForSlice(vol_, idxMgr_);
    for (std::list<KVSlice *>::iterator iter = batch->batch_.begin();
            iter != batch->batch_.end(); iter++) {
        if (seg->TryPut(*iter)) {
            seg->Put(*iter);
        }
        else {
            __ERROR("The Batch is too large, can't put in one segment");
            delete seg;
            return Status::Aborted("Batch is too large.");
        }
    }

    seg->SetSegId(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 $0xb8, %rsp
movq %rdi, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
movl $0x0, 0x9c(%rsp)
movb $0x0, 0x9b(%rsp)
leaq 0x9c(%rsp), %rsi
callq 0x4b110
andb $0x1, %al
movb %al, 0x9b(%rsp)
testb $0x1, 0x9b(%rsp)
jne 0x4add6
jmp 0x4ad52
movq 0x2627f(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x40(%rsp)
callq 0x8480
movq 0x40(%rsp), %rdi
movq %rax, %rdx
leaq 0x773c(%rip), %rsi      # 0x524b1
leaq 0x793c(%rip), %rcx      # 0x526b8
leaq 0x975f(%rip), %r8       # 0x544e2
movl $0x7c, %r9d
movb $0x0, %al
callq 0x86f0
movq 0x26241(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x7926(%rip), %rsi      # 0x526c7
movb $0x0, %al
callq 0x86f0
movq 0x26229(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x800c(%rip), %rsi      # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x48(%rsp), %rdi
leaq 0x791c(%rip), %rsi      # 0x526e8
callq 0x163e0
jmp 0x4b0ea
movl $0x50, %edi
callq 0x84f0
movq %rax, %rdi
movq 0x58(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x38(%rsp)
movq 0x10(%rax), %rdx
movq 0x1d8(%rax), %rsi
callq 0x432f0
jmp 0x4ae02
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x16410
movq %rax, 0x78(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x16460
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x16440
testb $0x1, %al
jne 0x4ae4b
jmp 0x4af86
movq 0x90(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x16490
movq 0x30(%rsp), %rdi
movq (%rax), %rsi
callq 0x418e0
testb $0x1, %al
jne 0x4ae75
jmp 0x4aec1
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x16490
movq 0x28(%rsp), %rdi
movq (%rax), %rsi
callq 0x41960
jmp 0x4af6e
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
callq 0x84b0
jmp 0x4b0f7
jmp 0x4aec3
movq 0x2610e(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x8480
movq 0x20(%rsp), %rdi
movq %rax, %rdx
leaq 0x75cb(%rip), %rsi      # 0x524b1
leaq 0x77cb(%rip), %rcx      # 0x526b8
leaq 0x95ee(%rip), %r8       # 0x544e2
movl $0x87, %r9d
movb $0x0, %al
callq 0x86f0
movq 0x260d0(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x77f6(%rip), %rsi      # 0x52708
movb $0x0, %al
callq 0x86f0
movq 0x260b8(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x7e9b(%rip), %rsi      # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x4af58
movq 0x18(%rsp), %rdi
callq 0x43240
movq 0x18(%rsp), %rdi
callq 0x84b0
movq 0x48(%rsp), %rdi
leaq 0x77d5(%rip), %rsi      # 0x52739
callq 0x163e0
jmp 0x4b0ea
jmp 0x4af70
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
callq 0x164c0
movq %rax, 0x68(%rsp)
jmp 0x4ae21
movq 0x90(%rsp), %rdi
movl 0x9c(%rsp), %esi
callq 0x164f0
movq 0x90(%rsp), %rdi
callq 0x41bb0
andb $0x1, %al
movb %al, 0x9b(%rsp)
testb $0x1, 0x9b(%rsp)
jne 0x4b080
jmp 0x4afc0
movq 0x26011(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x8480
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x74ce(%rip), %rsi      # 0x524b1
leaq 0x76ce(%rip), %rcx      # 0x526b8
leaq 0x94f1(%rip), %r8       # 0x544e2
movl $0x90, %r9d
movb $0x0, %al
callq 0x86f0
movq 0x25fd3(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x773e(%rip), %rsi      # 0x5274d
movb $0x0, %al
callq 0x86f0
movq 0x25fbb(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x7d9e(%rip), %rsi      # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x58(%rsp), %rax
movq 0x1d8(%rax), %rdi
movl 0x9c(%rsp), %esi
callq 0x511c0
movq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x4b06d
movq 0x8(%rsp), %rdi
callq 0x43240
movq 0x8(%rsp), %rdi
callq 0x84b0
movq 0x48(%rsp), %rdi
leaq 0x76f9(%rip), %rsi      # 0x52772
callq 0x16510
jmp 0x4b0ea
movq 0x90(%rsp), %rdi
callq 0x16540
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x64(%rsp)
movq 0x1d8(%rax), %rdi
movl 0x9c(%rsp), %esi
movl 0x64(%rsp), %edx
callq 0x51220
movq 0x90(%rsp), %rdi
callq 0x43330
movq 0x90(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x4b0e0
movq (%rsp), %rdi
callq 0x43240
movq (%rsp), %rdi
callq 0x84b0
movq 0x48(%rsp), %rdi
callq 0x16560
movq 0x50(%rsp), %rax
addq $0xb8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x8820
nopw %cs:(%rax,%rax)