Example usage for org.apache.cassandra.io.sstable CorruptSSTableException CorruptSSTableException

List of usage examples for org.apache.cassandra.io.sstable CorruptSSTableException CorruptSSTableException

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable CorruptSSTableException CorruptSSTableException.

Prototype

public CorruptSSTableException(Throwable cause, String path) 

Source Link

Usage

From source file:com.fullcontact.cassandra.io.compress.CompressedRandomAccessReader.java

License:Apache License

@Override
protected void reBuffer() {
    CompressionMetadata.Chunk chunk = metadata.chunkFor(current);
    try {// ww  w.  j  a v  a  2 s .com
        decompressChunk(chunk);
    } catch (CorruptBlockException e) {
        throw new CorruptSSTableException(e, getPath());
    } catch (IOException e) {
        throw new FSReadError(e, getPath());
    }
}

From source file:com.fullcontact.cassandra.io.compress.CompressionMetadata.java

License:Apache License

@VisibleForTesting
CompressionMetadata(String indexFilePath, long compressedLength, FileSystem fs) {
    this.indexFilePath = indexFilePath;

    DataInputStream stream;/*from  w  ww.j av  a2 s .  c om*/
    try {
        stream = fs.open(new Path(indexFilePath));
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    try {
        String compressorName = stream.readUTF();
        int optionCount = stream.readInt();
        Map<String, String> options = new HashMap<String, String>();
        for (int i = 0; i < optionCount; ++i) {
            String key = stream.readUTF();
            String value = stream.readUTF();
            options.put(key, value);
        }
        int chunkLength = stream.readInt();
        try {
            parameters = new CompressionParameters(compressorName, chunkLength, options);
        } catch (ConfigurationException e) {
            throw new RuntimeException("Cannot create CompressionParameters for stored parameters", e);
        }

        dataLength = stream.readLong();
        compressedFileLength = compressedLength;
        chunkOffsets = readChunkOffsets(stream);
    } catch (IOException e) {
        throw new CorruptSSTableException(e, indexFilePath);
    } finally {
        FileUtils.closeQuietly(stream);
    }
}

From source file:com.fullcontact.cassandra.io.compress.CompressionMetadata.java

License:Apache License

/**
 * Read offsets of the individual chunks from the given input.
 *
 * @param input Source of the data./*  www . ja va 2 s. c  om*/
 * @return collection of the chunk offsets.
 */
private Memory readChunkOffsets(DataInput input) {
    try {
        int chunkCount = input.readInt();
        Memory offsets = Memory.allocate(chunkCount * 8);

        for (int i = 0; i < chunkCount; i++) {
            try {
                offsets.setLong(i * 8, input.readLong());
            } catch (EOFException e) {
                String msg = String.format("Corrupted Index File %s: read %d but expected %d chunks.",
                        indexFilePath, i, chunkCount);
                throw new CorruptSSTableException(new IOException(msg, e), indexFilePath);
            }
        }

        return offsets;
    } catch (IOException e) {
        throw new FSReadError(e, indexFilePath);
    }
}

From source file:com.fullcontact.cassandra.io.compress.CompressionMetadata.java

License:Apache License

/**
 * Get a chunk of compressed data (offset, length) corresponding to given position
 *
 * @param position Position in the file.
 * @return pair of chunk offset and length.
 *//*from  ww  w  .ja  v  a2s.  c o  m*/
public Chunk chunkFor(long position) {
    // position of the chunk
    int idx = 8 * (int) (position / parameters.chunkLength());

    if (idx >= chunkOffsets.size())
        throw new CorruptSSTableException(new EOFException(), indexFilePath);

    long chunkOffset = chunkOffsets.getLong(idx);
    long nextChunkOffset = (idx + 8 == chunkOffsets.size()) ? compressedFileLength
            : chunkOffsets.getLong(idx + 8);

    return new Chunk(chunkOffset, (int) (nextChunkOffset - chunkOffset - 4)); // "4" bytes reserved for checksum
}