Search in sources :

Example 1 with WrappedException

use of org.apache.cassandra.utils.WrappedException in project cassandra by apache.

the class UnfilteredSerializer method deserializeRowBody.

public Row deserializeRowBody(DataInputPlus in, SerializationHeader header, SerializationHelper helper, int flags, int extendedFlags, Row.Builder builder) throws IOException {
    try {
        boolean isStatic = isStatic(extendedFlags);
        boolean hasTimestamp = (flags & HAS_TIMESTAMP) != 0;
        boolean hasTTL = (flags & HAS_TTL) != 0;
        boolean hasDeletion = (flags & HAS_DELETION) != 0;
        boolean deletionIsShadowable = (extendedFlags & HAS_SHADOWABLE_DELETION) != 0;
        boolean hasComplexDeletion = (flags & HAS_COMPLEX_DELETION) != 0;
        boolean hasAllColumns = (flags & HAS_ALL_COLUMNS) != 0;
        Columns headerColumns = header.columns(isStatic);
        if (header.isForSSTable()) {
            // Skip row size
            in.readUnsignedVInt();
            // previous unfiltered size
            in.readUnsignedVInt();
        }
        LivenessInfo rowLiveness = LivenessInfo.EMPTY;
        if (hasTimestamp) {
            long timestamp = header.readTimestamp(in);
            int ttl = hasTTL ? header.readTTL(in) : LivenessInfo.NO_TTL;
            int localDeletionTime = hasTTL ? header.readLocalDeletionTime(in) : LivenessInfo.NO_EXPIRATION_TIME;
            rowLiveness = LivenessInfo.withExpirationTime(timestamp, ttl, localDeletionTime);
        }
        builder.addPrimaryKeyLivenessInfo(rowLiveness);
        builder.addRowDeletion(hasDeletion ? new Row.Deletion(header.readDeletionTime(in), deletionIsShadowable) : Row.Deletion.LIVE);
        Columns columns = hasAllColumns ? headerColumns : Columns.serializer.deserializeSubset(headerColumns, in);
        final LivenessInfo livenessInfo = rowLiveness;
        try {
            columns.apply(column -> {
                try {
                    if (column.isSimple())
                        readSimpleColumn(column, in, header, helper, builder, livenessInfo);
                    else
                        readComplexColumn(column, in, header, helper, hasComplexDeletion, builder, livenessInfo);
                } catch (IOException e) {
                    throw new WrappedException(e);
                }
            }, false);
        } catch (WrappedException e) {
            if (e.getCause() instanceof IOException)
                throw (IOException) e.getCause();
            throw e;
        }
        return builder.build();
    } catch (RuntimeException | AssertionError e) {
        // exception, it just make we catch it properly and mark the sstable as corrupted.
        throw new IOException("Error building row with data deserialized from " + in, e);
    }
}
Also used : WrappedException(org.apache.cassandra.utils.WrappedException) Deletion(org.apache.cassandra.db.rows.Row.Deletion) IOException(java.io.IOException)

Example 2 with WrappedException

use of org.apache.cassandra.utils.WrappedException in project cassandra by apache.

the class UnfilteredSerializer method serializeRowBody.

@Inline
private void serializeRowBody(Row row, int flags, SerializationHeader header, DataOutputPlus out) throws IOException {
    boolean isStatic = row.isStatic();
    Columns headerColumns = header.columns(isStatic);
    LivenessInfo pkLiveness = row.primaryKeyLivenessInfo();
    Row.Deletion deletion = row.deletion();
    if ((flags & HAS_TIMESTAMP) != 0)
        header.writeTimestamp(pkLiveness.timestamp(), out);
    if ((flags & HAS_TTL) != 0) {
        header.writeTTL(pkLiveness.ttl(), out);
        header.writeLocalDeletionTime(pkLiveness.localExpirationTime(), out);
    }
    if ((flags & HAS_DELETION) != 0)
        header.writeDeletionTime(deletion.time(), out);
    if ((flags & HAS_ALL_COLUMNS) == 0)
        Columns.serializer.serializeSubset(Collections2.transform(row, ColumnData::column), headerColumns, out);
    SearchIterator<ColumnMetadata, ColumnMetadata> si = headerColumns.iterator();
    try {
        row.apply(cd -> {
            ColumnMetadata column = si.next(cd.column());
            assert column != null : cd.column.toString();
            try {
                if (cd.column.isSimple())
                    Cell.serializer.serialize((Cell) cd, column, out, pkLiveness, header);
                else
                    writeComplexColumn((ComplexColumnData) cd, column, (flags & HAS_COMPLEX_DELETION) != 0, pkLiveness, header, out);
            } catch (IOException e) {
                throw new WrappedException(e);
            }
        }, false);
    } catch (WrappedException e) {
        if (e.getCause() instanceof IOException)
            throw (IOException) e.getCause();
        throw e;
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) WrappedException(org.apache.cassandra.utils.WrappedException) Deletion(org.apache.cassandra.db.rows.Row.Deletion) IOException(java.io.IOException) Inline(net.nicoulaj.compilecommand.annotations.Inline)

Aggregations

IOException (java.io.IOException)2 Deletion (org.apache.cassandra.db.rows.Row.Deletion)2 WrappedException (org.apache.cassandra.utils.WrappedException)2 Inline (net.nicoulaj.compilecommand.annotations.Inline)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1