// File: /workspace/github_cpp_makefile_star2_O2/tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::updateTransactionMap()
void MP2Node::updateTransactionMap() {
    if (txMap.empty()) { // nothing to check here
        return;
    }
    // Go through each entry in the transaction map
    for (auto it = txMap.begin(); it != txMap.end();) {
        int txId = it->first;
        Transaction *transaction = &it->second;

        // if this transaction has enough successful replies, log success
        if (transaction->successCount >= QUORUM) { // operation successful! log success as coordinator
            switch (transaction->type) {
                case READ:
                    log->logReadSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case UPDATE:
                    log->logUpdateSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case CREATE:
                    log->logCreateSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case DELETE:
                    log->logDeleteSuccess(&memberNode->addr, true, txId, transaction->key);
                    break;
                default:
                    break;
            }
            txMap.erase(it++);
            continue;
        }
        // This transaction DOES NOT have enough success replies...
        // So we check if it has reached maximum replies, or it has timed out
        if (transaction->totalCount == TOTAL || par->getcurrtime() - transaction->timestamp > OPERATION_TIMEOUT) { // operation failed :( log failure as coordinator
            switch (transaction->type) {
                case READ:
                    log->logReadFail(&memberNode->addr, true, txId, transaction->key);
                    break;
                case UPDATE:
                    log->logUpdateFail(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case CREATE:
                    log->logCreateFail(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case DELETE:
                    log->logDeleteFail(&memberNode->addr, true, txId, transaction->key);
                    break;
                default:
                    break;
            }
            txMap.erase(it++);
            continue;
        }
        // otherwise, we don't do anything
        // since if transaction doesn't exist in the map, it's already resolved
        it++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, (%rsp)
cmpq $0x0, 0xe8(%rdi)
je 0xd5ec
movq (%rsp), %rcx
leaq 0xc0(%rcx), %rax
movq %rax, 0x8(%rsp)
movq 0xd8(%rcx), %r13
leaq 0xc8(%rcx), %rax
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rbx
leaq 0x58(%rsp), %r14
leaq 0x10(%rsp), %r12
cmpq 0x30(%rsp), %r13
je 0xd5ec
movl 0x20(%r13), %r15d
cmpl $0x2, 0x28(%r13)
jl 0xd31a
movl 0x38(%r13), %eax
cmpq $0x3, %rax
ja 0xd5cc
leaq 0x6984(%rip), %rcx      # 0x13c34
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
leaq 0x40(%r13), %rsi
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x33a0
leaq 0x60(%r13), %rsi
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x33a0
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %rbx, %r8
movq %r14, %r9
callq 0xa4a2
movq %r14, %rdi
movq %rbx, %r15
leaq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r12
jmp 0xd4bc
cmpl $0x3, 0x2c(%r13)
je 0xd337
movq (%rsp), %rax
movq 0x58(%rax), %rdi
callq 0xabe4
subl 0x34(%r13), %eax
cmpl $0x15, %eax
jl 0xd3ac
movl 0x38(%r13), %eax
cmpq $0x3, %rax
ja 0xd5cc
leaq 0x68d8(%rip), %rcx      # 0x13c24
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
leaq 0x40(%r13), %rsi
movq %r14, %rdi
callq 0x33a0
leaq 0x60(%r13), %rsi
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x33a0
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xa794
movq %rbx, %rdi
movq %r14, %r15
leaq 0x10(%rsp), %r12
jmp 0xd523
movq %r13, %rdi
callq 0x31d0
movq %rax, %r13
jmp 0xd285
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
leaq 0x40(%r13), %rsi
movq %rbx, %rdi
callq 0x33a0
leaq 0x60(%r13), %rsi
leaq 0x178(%rsp), %r14
movq %r14, %rdi
callq 0x33a0
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %rbx, %r8
movq %r14, %r9
callq 0xa626
movq %r14, %rdi
movq %rbx, %r15
leaq 0x10(%rsp), %r12
jmp 0xd4bc
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
addq $0x8, %r12
leaq 0x40(%r13), %rsi
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0x33a0
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %r12
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %r14, %r8
callq 0xa6e8
movq %r14, %r15
leaq 0x58(%rsp), %r14
jmp 0xd5c4
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
leaq 0x40(%r13), %rsi
leaq 0x198(%rsp), %rbx
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x33a0
leaq 0x60(%r13), %rsi
movq %rbx, %rdi
callq 0x33a0
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xa564
movq %rbx, %rdi
movq %r14, %r15
leaq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r12
callq 0x3120
leaq 0x58(%rsp), %r14
jmp 0xd5c4
movq (%rsp), %rax
movq %r12, %r14
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
leaq 0x40(%r13), %rsi
movq %r14, %rdi
callq 0x33a0
leaq 0x60(%r13), %rsi
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x33a0
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xa902
movq %rbx, %rdi
movq %r14, %r15
movq %r14, %r12
leaq 0x58(%rsp), %r14
callq 0x3120
leaq 0x38(%rsp), %rbx
jmp 0xd5c4
movq (%rsp), %rax
movq %r12, %r14
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
addq $0x8, %r12
leaq 0x40(%r13), %rsi
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0x33a0
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %r12
leaq 0x58(%rsp), %r14
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0xa9c4
movq %rbx, %r15
leaq 0x38(%rsp), %rbx
jmp 0xd5c4
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
addq $0x8, %r12
leaq 0x40(%r13), %rsi
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
callq 0x33a0
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0xa856
movq %rbx, %r15
leaq 0x10(%rsp), %r12
leaq 0x38(%rsp), %rbx
movq %r15, %rdi
callq 0x3120
movq %r13, %rdi
callq 0x31d0
movq %rax, %r15
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0xff7c
movq %r15, %r13
jmp 0xd285
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3120
jmp 0xd613
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3120
jmp 0xd642
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x3120
jmp 0xd66b
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x3120
jmp 0xd687
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x3120
jmp 0xd6a6
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0xd6b8
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3490
nop