/** * This method checks that a result from a Cassandra lightweight transaction is either * * (a) a successful application of proposed changes, or * (b) an unsuccessful application, but the state of the world in Cassandra as indicated by the casResult * matches the casMap. * * Otherwise, it throws an IllegalStateException. * * @param casResult the CAS result to verify * @param casMap the intended state of the world * @throws IllegalStateException if the transaction was not successful, and the state of the world does not match * the intended state, as indicated in the casMap */ public static void verifyCompatible(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap) { if (!isSuccessfullyApplied(casResult)) { Set<Incongruency> incongruencies = getIncongruencies(casResult, casMap); if (!incongruencies.isEmpty()) { throw new IllegalStateException("[BACKUP/RESTORE] Observed incongruent state of the world; the" + " following incongruencies were observed: " + incongruencies); } /* * If there are no incongruencies, then the state of the world is what we wanted it to be - possibly * because we were upgrading and this call was made in parallel. Since the DB is in the desired state, * we're continuing here. */ log.debug("[BACKUP/RESTORE] CAS failed, but the DB state is as desired - continuing."); } }
/** * This method checks that a result from a Cassandra lightweight transaction is either * * (a) a successful application of proposed changes, or * (b) an unsuccessful application, but the state of the world in Cassandra as indicated by the casResult * matches the casMap. * * Otherwise, it throws an IllegalStateException. * * @param casResult the CAS result to verify * @param casMap the intended state of the world * @throws IllegalStateException if the transaction was not successful, and the state of the world does not match * the intended state, as indicated in the casMap */ public static void verifyCompatible(CqlResult casResult, Map<String, Pair<byte[], byte[]>> casMap) { if (!isSuccessfullyApplied(casResult)) { Set<Incongruency> incongruencies = getIncongruencies(casResult, casMap); if (!incongruencies.isEmpty()) { throw new IllegalStateException("[BACKUP/RESTORE] Observed incongruent state of the world; the" + " following incongruencies were observed: " + incongruencies); } /* * If there are no incongruencies, then the state of the world is what we wanted it to be - possibly * because we were upgrading and this call was made in parallel. Since the DB is in the desired state, * we're continuing here. */ log.debug("[BACKUP/RESTORE] CAS failed, but the DB state is as desired - continuing."); } }