Search in sources :

Example 1 with IncompatibleJournalException

use of com.questdb.ex.IncompatibleJournalException in project questdb by bluestreak01.

the class JournalDeltaConsumer method doRead.

@Override
@SuppressWarnings("unchecked")
protected void doRead(ReadableByteChannel channel) throws JournalNetworkException {
    try {
        reset();
        journalServerStateConsumer.read(channel);
        this.state = journalServerStateConsumer.getValue();
        if (state.getTxn() == -1) {
            journal.notifyListener(JournalEvents.EVT_JNL_TRANSACTION_REFUSED);
            throw new IncompatibleJournalException("Server refused txn for %s", journal.getLocation());
        }
        if (state.getTxn() < journal.getTxn()) {
            journal.rollback(state.getTxn(), state.getTxPin());
            return;
        }
        journal.beginTx();
        createPartitions(state);
        if (state.isSymbolTables()) {
            journalSymbolTableConsumer.read(channel);
        }
        for (int i = 0, k = state.getNonLagPartitionCount(); i < k; i++) {
            JournalServerState.PartitionMetadata meta = state.getMeta(i);
            if (meta.getEmpty() == 0) {
                PartitionDeltaConsumer partitionDeltaConsumer = getPartitionDeltaConsumer(meta.getPartitionIndex());
                partitionDeltaConsumer.read(channel);
            }
        }
        if (state.getLagPartitionName() == null && journal.hasIrregularPartition()) {
            // delete lag partition
            journal.removeIrregularPartition();
        } else if (state.getLagPartitionName() != null) {
            if (lagPartitionDeltaConsumer == null || !journal.hasIrregularPartition() || !state.getLagPartitionName().equals(journal.getIrregularPartition().getName())) {
                Partition temp = journal.createTempPartition(state.getLagPartitionName());
                lagPartitionDeltaConsumer = new PartitionDeltaConsumer(temp.open());
                journal.setIrregularPartition(temp);
            }
            lagPartitionDeltaConsumer.read(channel);
        }
    } catch (JournalException e) {
        throw new JournalNetworkException(e);
    }
}
Also used : Partition(com.questdb.store.Partition) JournalException(com.questdb.std.ex.JournalException) IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException) JournalNetworkException(com.questdb.std.ex.JournalNetworkException) JournalServerState(com.questdb.net.ha.model.JournalServerState) IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException)

Aggregations

IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)1 JournalServerState (com.questdb.net.ha.model.JournalServerState)1 JournalException (com.questdb.std.ex.JournalException)1 JournalNetworkException (com.questdb.std.ex.JournalNetworkException)1 Partition (com.questdb.store.Partition)1