public JournalCommand<?> load(Location location) throws IOException { DataByteArrayInputStream is = new DataByteArrayInputStream(journal.read(location)); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>) type.createMessage(); message.mergeFramed(is); return message; }
public ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }
void process(JournalCommand<?> data, final Location location, final IndexAware onSequenceAssignedCallback) throws IOException { data.visit(new Visitor() { @Override public void visit(KahaAddMessageCommand command) throws IOException {
LOG.error("KahaDB failed to store to Journal, command of type: " + data.type(), ioe); brokerService.handleIOException(ioe); throw ioe;
JournalCommand<?> command = load(location); KahaAddMessageCommand addMessage = null; switch (command.type()) { case KAHA_UPDATE_MESSAGE_COMMAND: addMessage = ((KahaUpdateMessageCommand) command).getMessage(); break; default: throw new IOException("Could not load journal record, unexpected command type: " + command.type() + " at location: " + location);
/** * Creates a new ByteSequence that represents the marshaled form of the given Journal Command. * * @param command * The Journal Command that should be marshaled to bytes for writing. * * @return the byte representation of the given journal command. * * @throws IOException if an error occurs while serializing the command. */ protected ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }
data.visit(new Visitor() { @Override public void visit(final KahaAddScheduledJobCommand command) throws IOException {
/** * Loads a previously stored JournalMessage * * @param location * @return * @throws IOException */ public JournalCommand<?> load(Location location) throws IOException { long start = System.currentTimeMillis(); ByteSequence data = journal.read(location); long end = System.currentTimeMillis(); if( LOG_SLOW_ACCESS_TIME>0 && end-start > LOG_SLOW_ACCESS_TIME) { if (LOG.isInfoEnabled()) { LOG.info("Slow KahaDB access: Journal read took: "+(end-start)+" ms"); } } DataByteArrayInputStream is = new DataByteArrayInputStream(data); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if( type == null ) { try { is.close(); } catch (IOException e) {} throw new IOException("Could not load journal record, null type information from: " + readByte + " at location: "+location); } JournalCommand<?> message = (JournalCommand<?>)type.createMessage(); message.mergeFramed(is); return message; }
public void process(JournalCommand<?> command) throws IOException { switch (command.type()) { case KAHA_PREPARE_COMMAND: KahaPrepareCommand prepareCommand = (KahaPrepareCommand) command; getTx(TransactionIdConversion.convert(prepareCommand.getTransactionInfo())); break; case KAHA_COMMIT_COMMAND: KahaCommitCommand commitCommand = (KahaCommitCommand) command; removeTx(TransactionIdConversion.convert(commitCommand.getTransactionInfo())); break; case KAHA_TRACE_COMMAND: break; default: throw new IOException("Unexpected command in transaction journal: " + command); } }
private Location store(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); Location location = journal.write(os.toByteSequence(), true); journal.setLastAppendLocation(location); return location; }
/** * do minimal recovery till we reach the last inDoubtLocation * @param data * @param location * @param inDoubtlocation * @throws IOException */ void process(JournalCommand<?> data, final Location location, final Location inDoubtlocation) throws IOException { if (inDoubtlocation != null && location.compareTo(inDoubtlocation) >= 0) { process(data, location, (IndexAware) null); } else { // just recover producer audit data.visit(new Visitor() { @Override public void visit(KahaAddMessageCommand command) throws IOException { metadata.producerSequenceIdTracker.isDuplicate(command.getMessageId()); } }); } }
/** * Loads a previously stored JournalMessage * * @param location * The location of the journal command to read. * * @return a new un-marshaled JournalCommand instance. * * @throws IOException if an error occurs reading the stored command. */ protected JournalCommand<?> load(Location location) throws IOException { ByteSequence data = journal.read(location); DataByteArrayInputStream is = new DataByteArrayInputStream(data); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { try { is.close(); } catch (IOException e) { } throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>)type.createMessage(); message.mergeFramed(is); return message; }
LOG.error("KahaDB failed to store to Journal, command of type: " + data.type(), ioe); brokerService.handleIOException(ioe); throw ioe;
public ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }
void process(JournalCommand<?> data, final Location location) throws IOException { data.visit(new Visitor() { @Override public void visit(KahaAddMessageCommand command) throws IOException {
public JournalCommand<?> load(Location location) throws IOException { DataByteArrayInputStream is = new DataByteArrayInputStream(journal.read(location)); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>) type.createMessage(); message.mergeFramed(is); return message; }
LOG.error("KahaDB failed to store to Journal, command of type: " + data.type(), ioe); brokerService.handleIOException(ioe); throw ioe;
public ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }
void process(JournalCommand<?> data, final Location location, final IndexAware onSequenceAssignedCallback) throws IOException { data.visit(new Visitor() { @Override public void visit(KahaAddMessageCommand command) throws IOException {
public JournalCommand<?> load(Location location) throws IOException { DataByteArrayInputStream is = new DataByteArrayInputStream(journal.read(location)); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>) type.createMessage(); message.mergeFramed(is); return message; }