Search in sources :

Example 21 with IORuntimeException

use of net.openhft.chronicle.core.io.IORuntimeException in project cassandra by apache.

the class Dump method dump.

public static void dump(List<String> arguments, String rollCycle, boolean follow) {
    StringBuilder sb = new StringBuilder();
    ReadMarshallable reader = wireIn -> {
        sb.setLength(0);
        int version = wireIn.read(BinLog.VERSION).int16();
        if (version > FullQueryLogger.CURRENT_VERSION) {
            throw new IORuntimeException("Unsupported record version [" + version + "] - highest supported version is [" + FullQueryLogger.CURRENT_VERSION + ']');
        }
        String type = wireIn.read(BinLog.TYPE).text();
        if (!FullQueryLogger.SINGLE_QUERY.equals((type)) && !FullQueryLogger.BATCH.equals((type))) {
            throw new IORuntimeException("Unsupported record type field [" + type + "] - supported record types are [" + FullQueryLogger.SINGLE_QUERY + ", " + FullQueryLogger.BATCH + ']');
        }
        sb.append("Type: ").append(type).append(System.lineSeparator());
        long queryStartTime = wireIn.read(FullQueryLogger.QUERY_START_TIME).int64();
        sb.append("Query start time: ").append(queryStartTime).append(System.lineSeparator());
        int protocolVersion = wireIn.read(FullQueryLogger.PROTOCOL_VERSION).int32();
        sb.append("Protocol version: ").append(protocolVersion).append(System.lineSeparator());
        QueryOptions options = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wireIn.read(FullQueryLogger.QUERY_OPTIONS).bytes()), ProtocolVersion.decode(protocolVersion, true));
        long generatedTimestamp = wireIn.read(FullQueryLogger.GENERATED_TIMESTAMP).int64();
        sb.append("Generated timestamp:").append(generatedTimestamp).append(System.lineSeparator());
        int generatedNowInSeconds = wireIn.read(FullQueryLogger.GENERATED_NOW_IN_SECONDS).int32();
        sb.append("Generated nowInSeconds:").append(generatedNowInSeconds).append(System.lineSeparator());
        switch(type) {
            case (FullQueryLogger.SINGLE_QUERY):
                dumpQuery(options, wireIn, sb);
                break;
            case (FullQueryLogger.BATCH):
                dumpBatch(options, wireIn, sb);
                break;
            default:
                throw new IORuntimeException("Log entry of unsupported type " + type);
        }
        System.out.print(sb.toString());
        System.out.flush();
    };
    // Backoff strategy for spinning on the queue, not aggressive at all as this doesn't need to be low latency
    Pauser pauser = Pauser.millis(100);
    List<ChronicleQueue> queues = arguments.stream().distinct().map(path -> SingleChronicleQueueBuilder.single(new File(path)).readOnly(true).rollCycle(RollCycles.valueOf(rollCycle)).build()).collect(Collectors.toList());
    List<ExcerptTailer> tailers = queues.stream().map(ChronicleQueue::createTailer).collect(Collectors.toList());
    boolean hadWork = true;
    while (hadWork) {
        hadWork = false;
        for (ExcerptTailer tailer : tailers) {
            while (tailer.readDocument(reader)) {
                hadWork = true;
            }
        }
        if (follow) {
            if (!hadWork) {
                // Chronicle queue doesn't support blocking so use this backoff strategy
                pauser.pause();
            }
            // Don't terminate the loop even if there wasn't work
            hadWork = true;
        }
    }
}
Also used : IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) Unpooled(io.netty.buffer.Unpooled) Bytes(net.openhft.chronicle.bytes.Bytes) Option(io.airlift.airline.Option) ReadMarshallable(net.openhft.chronicle.wire.ReadMarshallable) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Pauser(net.openhft.chronicle.threads.Pauser) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) BinLog(org.apache.cassandra.utils.binlog.BinLog) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Collectors(java.util.stream.Collectors) File(java.io.File) BufferUnderflowException(java.nio.BufferUnderflowException) WireIn(net.openhft.chronicle.wire.WireIn) Command(io.airlift.airline.Command) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) List(java.util.List) ValueIn(net.openhft.chronicle.wire.ValueIn) FullQueryLogger(org.apache.cassandra.fql.FullQueryLogger) RollCycles(net.openhft.chronicle.queue.RollCycles) Arguments(io.airlift.airline.Arguments) Collections(java.util.Collections) QueryOptions(org.apache.cassandra.cql3.QueryOptions) QueryOptions(org.apache.cassandra.cql3.QueryOptions) Pauser(net.openhft.chronicle.threads.Pauser) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) ReadMarshallable(net.openhft.chronicle.wire.ReadMarshallable) IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) File(java.io.File)

Example 22 with IORuntimeException

use of net.openhft.chronicle.core.io.IORuntimeException in project Chronicle-Bytes by OpenHFT.

the class StreamingDataInput method read8bit.

default <ACS extends Appendable & CharSequence> boolean read8bit(@NotNull ACS sb) throws IORuntimeException, IllegalArgumentException, BufferUnderflowException {
    AppendableUtil.setLength(sb, 0);
    long len0 = BytesInternal.readStopBit(this);
    if (len0 == -1)
        return false;
    int len = Maths.toUInt31(len0);
    try {
        AppendableUtil.parse8bit(this, sb, len);
    } catch (IOException e) {
        throw new IORuntimeException(e);
    }
    return true;
}
Also used : IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) IOException(java.io.IOException)

Example 23 with IORuntimeException

use of net.openhft.chronicle.core.io.IORuntimeException in project Chronicle-Bytes by OpenHFT.

the class RandomDataInput method readUtf8.

/**
 * Truncates {@code sb} (it must be a {@link StringBuilder} or {@link Bytes}) and reads a char
 * sequence from the given {@code offset}, encoded as Utf8, into it. Returns offset <i>after</i>
 * the read Utf8, if a normal char sequence was read, or {@code -1 - offset}, if {@code null}
 * was observed (in this case, {@code sb} is truncated too, but not updated then, by querying
 * {@code sb} only this case is indistinguishable from reading an empty char sequence).
 *
 * @param offset the offset in this {@code RandomDataInput} to read char sequence from
 * @param sb     the buffer to read char sequence into (truncated first)
 * @param <ACS>  buffer type, must be {@code StringBuilder} or {@code Bytes}
 * @return offset after the normal read char sequence, or -1 - offset, if char sequence is
 * {@code null}
 * @see RandomDataOutput#writeUtf8(long, CharSequence)
 */
default <ACS extends Appendable & CharSequence> long readUtf8(long offset, @NotNull ACS sb) throws IORuntimeException, IllegalArgumentException, BufferUnderflowException {
    AppendableUtil.setLength(sb, 0);
    // TODO insert some bounds check here
    long utfLen;
    if ((utfLen = readByte(offset++)) < 0) {
        utfLen &= 0x7FL;
        long b;
        int count = 7;
        while ((b = readByte(offset++)) < 0) {
            utfLen |= (b & 0x7FL) << count;
            count += 7;
        }
        if (b != 0) {
            if (count > 56)
                throw new IORuntimeException("Cannot read more than 9 stop bits of positive value");
            utfLen |= (b << count);
        } else {
            if (count > 63)
                throw new IORuntimeException("Cannot read more than 10 stop bits of negative value");
            utfLen = ~utfLen;
        }
    }
    if (utfLen == -1)
        return ~offset;
    int len = Maths.toUInt31(utfLen);
    BytesInternal.parseUtf8(this, offset, sb, len);
    return offset + utfLen;
}
Also used : IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException)

Aggregations

IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)23 Test (org.junit.Test)10 File (java.io.File)9 IOException (java.io.IOException)4 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)4 EOFException (java.io.EOFException)3 StreamCorruptedException (java.io.StreamCorruptedException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ValueIn (net.openhft.chronicle.wire.ValueIn)3 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Bytes (net.openhft.chronicle.bytes.Bytes)2 Jvm (net.openhft.chronicle.core.Jvm)2 OS (net.openhft.chronicle.core.OS)2 LongValue (net.openhft.chronicle.core.values.LongValue)2 StoreFileListener (net.openhft.chronicle.queue.impl.StoreFileListener)2 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)2 Pauser (net.openhft.chronicle.threads.Pauser)2