private ByteBuffer getEmptyReadsByteBuffer() { final Reads reads = new Reads(); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { reads.serialize(output); return ByteBuffer.wrap(output.toByteArray()); } catch (IOException e) { throw new RuntimeException("unexpected exception", e); } }
/** * Given a possible new transaction to commit, check for the existence of a high priority with which it conflicts. */ private String checkHighPriorityConflict(Writes writes, String dumpDescription) { // Sanity check assert Thread.holdsLock(this.raft); assert this.raft.highPrioTx != null; assert Thread.holdsLock(this.raft.highPrioTx.view); // Check for conflict final Reads reads = this.raft.highPrioTx.view.getReads(); final Conflict conflict = reads.findConflict(writes); if (conflict == null) return null; // Report conflicts if (dumpDescription != null) { this.dumpConflicts(reads, writes, dumpDescription + " fails due to conflicts with high priority transaction " + this.raft.highPrioTx); } // Fail return "transaction conflicts with a high priority transaction: " + conflict; }
void dumpConflicts(Reads reads, Mutations writes, String description) { final StringBuilder buf = new StringBuilder(); buf.append(description).append(':'); for (String conflict : reads.getConflicts(writes)) buf.append("\n ").append(conflict); this.info(buf.toString()); }
final long readsDataSize = reads.serializedLength(); if (readsDataSize != (int)readsDataSize) throw new KVTransactionException(tx, "transaction read information exceeds maximum length"); readsData = Util.allocateByteBuffer((int)readsDataSize); try (ByteBufferOutputStream output = new ByteBufferOutputStream(readsData)) { reads.serialize(output); } catch (IOException e) { throw new RuntimeException("unexpected exception", e);
assert !skipConflictCheck || !tx.view.getReads().isConflict(logEntry.getWrites()); final Conflict conflict; if (!skipConflictCheck && (conflict = tx.view.getReads().findConflict(logEntry.getWrites())) != null) { if (this.log.isDebugEnabled()) this.debug("cannot rebase " + tx + " past " + logEntry + ", failing: " + conflict);
reads = new Reads(new ByteBufferInputStream(msg.getReadsData())); } catch (Exception e) { this.error("error decoding reads data in " + msg, e);
assert logEntry != null; try { final Conflict conflict = reads.findConflict(logEntry.getMutations()); if (conflict != null) { if (dumpDesc != null)