Description
Mailbox creation method in `CassandraMailboxMapper`:
private boolean trySave(Mailbox cassandraMailbox, CassandraId cassandraId) { boolean isCreated = mailboxPathV2DAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId).block(); if (isCreated) { Optional<Mailbox> simpleMailbox = retrieveMailbox(cassandraId).blockOptional(); simpleMailbox.ifPresent(mbx -> mailboxPathV2DAO.delete(mbx.generateAssociatedPath()).block()); mailboxDAO.save(cassandraMailbox).block(); } return isCreated; }
Shortly:
1. Persisting a mailboxPath
2. Persisting a mailbox.
There's should be a case: after step 1 finishes, step 2 fails, it leads to the mailboxPath & mailbox inconsistent. To avoid this, you can perform retry on the step 2 to reduce the chance producing inconsistent.
DOD: update the code, write unit tests to prove it `reduce the chance producing inconsistent`