// File: 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
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x208(%rbp)
addq $0xc0, %rdi
callq 0x21d30
testb $0x1, %al
jne 0x1e4fc
jmp 0x1e501
jmp 0x1ec79
movq -0x208(%rbp), %rdi
addq $0xc0, %rdi
callq 0x21d50
movq %rax, -0x10(%rbp)
movq -0x208(%rbp), %rdi
addq $0xc0, %rdi
callq 0x21db0
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x21d80
testb $0x1, %al
jne 0x1e545
jmp 0x1ec79
leaq -0x10(%rbp), %rdi
callq 0x21de0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x21de0
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x1e8e8
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x210(%rbp)
subq $0x3, %rax
ja 0x1e8a1
movq -0x210(%rbp), %rax
leaq 0xe701(%rip), %rcx      # 0x2cc98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x228(%rbp)
addq $0x8, %rax
movq %rax, -0x220(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x214(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x48(%rbp), %rdi
callq 0x4160
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
leaq -0x68(%rbp), %rdi
callq 0x4160
jmp 0x1e5ee
movl -0x214(%rbp), %ecx
movq -0x220(%rbp), %rsi
movq -0x228(%rbp), %rdi
movl $0x1, %edx
leaq -0x48(%rbp), %r8
leaq -0x68(%rbp), %r9
callq 0x18150
jmp 0x1e616
leaq -0x68(%rbp), %rdi
callq 0x4200
leaq -0x48(%rbp), %rdi
callq 0x4200
jmp 0x1e8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1e650
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4200
leaq -0x48(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x240(%rbp)
addq $0x8, %rax
movq %rax, -0x238(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x22c(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4160
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x4160
jmp 0x1e6b2
movl -0x22c(%rbp), %ecx
movq -0x238(%rbp), %rsi
movq -0x240(%rbp), %rdi
movl $0x1, %edx
leaq -0x98(%rbp), %r8
leaq -0xb8(%rbp), %r9
callq 0x182a0
jmp 0x1e6e0
leaq -0xb8(%rbp), %rdi
callq 0x4200
leaq -0x98(%rbp), %rdi
callq 0x4200
jmp 0x1e8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1e723
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4200
leaq -0x98(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x258(%rbp)
addq $0x8, %rax
movq %rax, -0x250(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x244(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x4160
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x4160
jmp 0x1e788
movl -0x244(%rbp), %ecx
movq -0x250(%rbp), %rsi
movq -0x258(%rbp), %rdi
movl $0x1, %edx
leaq -0xd8(%rbp), %r8
leaq -0xf8(%rbp), %r9
callq 0x18000
jmp 0x1e7b6
leaq -0xf8(%rbp), %rdi
callq 0x4200
leaq -0xd8(%rbp), %rdi
callq 0x4200
jmp 0x1e8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1e7f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4200
leaq -0xd8(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x278(%rbp)
addq $0x8, %rax
movq %rax, -0x270(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x264(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x118(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x4160
movq -0x278(%rbp), %rdi
movq -0x270(%rbp), %rsi
movl -0x264(%rbp), %ecx
movq -0x260(%rbp), %r8
movl $0x1, %edx
callq 0x183f0
jmp 0x1e876
leaq -0x118(%rbp), %rdi
callq 0x4200
jmp 0x1e8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
jmp 0x1e8a3
movq -0x208(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x280(%rbp)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x21e40
movq -0x280(%rbp), %rdi
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rsi
callq 0x21e00
movq %rax, -0x128(%rbp)
jmp 0x1e518
movq -0x28(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x1e912
movq -0x208(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x18c60
movq -0x28(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x14, %eax
jle 0x1ec62
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x288(%rbp)
subq $0x3, %rax
ja 0x1ec1b
movq -0x288(%rbp), %rax
leaq 0xe350(%rip), %rcx      # 0x2cc88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x2a8(%rbp)
addq $0x8, %rax
movq %rax, -0x2a0(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x294(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x148(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x4160
movq -0x2a8(%rbp), %rdi
movq -0x2a0(%rbp), %rsi
movl -0x294(%rbp), %ecx
movq -0x290(%rbp), %r8
movl $0x1, %edx
callq 0x18650
jmp 0x1e9ad
leaq -0x148(%rbp), %rdi
callq 0x4200
jmp 0x1ec1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x2c0(%rbp)
addq $0x8, %rax
movq %rax, -0x2b8(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2ac(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x168(%rbp), %rdi
callq 0x4160
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
leaq -0x188(%rbp), %rdi
callq 0x4160
jmp 0x1ea2f
movl -0x2ac(%rbp), %ecx
movq -0x2b8(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
movl $0x1, %edx
leaq -0x168(%rbp), %r8
leaq -0x188(%rbp), %r9
callq 0x18760
jmp 0x1ea5d
leaq -0x188(%rbp), %rdi
callq 0x4200
leaq -0x168(%rbp), %rdi
callq 0x4200
jmp 0x1ec1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1eaa0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4200
leaq -0x168(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x2d8(%rbp)
addq $0x8, %rax
movq %rax, -0x2d0(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c4(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x4160
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x4160
jmp 0x1eb05
movl -0x2c4(%rbp), %ecx
movq -0x2d0(%rbp), %rsi
movq -0x2d8(%rbp), %rdi
movl $0x1, %edx
leaq -0x1a8(%rbp), %r8
leaq -0x1c8(%rbp), %r9
callq 0x18500
jmp 0x1eb33
leaq -0x1c8(%rbp), %rdi
callq 0x4200
leaq -0x1a8(%rbp), %rdi
callq 0x4200
jmp 0x1ec1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1eb76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x4200
leaq -0x1a8(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
movq -0x208(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, -0x2f8(%rbp)
addq $0x8, %rax
movq %rax, -0x2f0(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2e4(%rbp)
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
leaq -0x1e8(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x4160
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movl -0x2e4(%rbp), %ecx
movq -0x2e0(%rbp), %r8
movl $0x1, %edx
callq 0x188b0
jmp 0x1ebf3
leaq -0x1e8(%rbp), %rdi
callq 0x4200
jmp 0x1ec1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x4200
jmp 0x1ec82
jmp 0x1ec1d
movq -0x208(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x300(%rbp)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x21e40
movq -0x300(%rbp), %rdi
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rsi
callq 0x21e00
movq %rax, -0x1f8(%rbp)
jmp 0x1e518
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x21e40
movq %rax, -0x200(%rbp)
jmp 0x1e518
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x45b0
nopl (%rax,%rax)