Search in sources :

Example 21 with IOError

use of java.io.IOError in project eiger by wlloyd.

the class LeveledManifest method serialize.

public synchronized void serialize() {
    File manifestFile = cfs.directories.getOrCreateLeveledManifest();
    File oldFile = new File(manifestFile.getPath().replace(EXTENSION, "-old.json"));
    File tmpFile = new File(manifestFile.getPath().replace(EXTENSION, "-tmp.json"));
    JsonFactory f = new JsonFactory();
    try {
        JsonGenerator g = f.createJsonGenerator(tmpFile, JsonEncoding.UTF8);
        g.useDefaultPrettyPrinter();
        g.writeStartObject();
        g.writeArrayFieldStart("generations");
        for (int level = 0; level < generations.length; level++) {
            g.writeStartObject();
            g.writeNumberField("generation", level);
            g.writeArrayFieldStart("members");
            for (SSTableReader ssTableReader : generations[level]) g.writeNumber(ssTableReader.descriptor.generation);
            // members
            g.writeEndArray();
            // generation
            g.writeEndObject();
        }
        // for field generations
        g.writeEndArray();
        // write global object
        g.writeEndObject();
        g.close();
        if (oldFile.exists() && manifestFile.exists())
            FileUtils.deleteWithConfirm(oldFile);
        if (manifestFile.exists())
            FileUtils.renameWithConfirm(manifestFile, oldFile);
        assert tmpFile.exists();
        FileUtils.renameWithConfirm(tmpFile, manifestFile);
        logger.debug("Saved manifest {}", manifestFile);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) IOError(java.io.IOError) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) IOException(java.io.IOException) File(java.io.File)

Example 22 with IOError

use of java.io.IOError in project eiger by wlloyd.

the class AbstractRowResolver method preprocess.

public void preprocess(Message message) {
    byte[] body = message.getMessageBody();
    FastByteArrayInputStream bufIn = new FastByteArrayInputStream(body);
    try {
        ReadResponse result = ReadResponse.serializer().deserialize(new DataInputStream(bufIn), message.getVersion());
        if (logger.isDebugEnabled())
            logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest" : "data");
        replies.put(message, result);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) ReadResponse(org.apache.cassandra.db.ReadResponse) IOError(java.io.IOError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 23 with IOError

use of java.io.IOError in project eiger by wlloyd.

the class CompressedSegmentedFile method getSegment.

public FileDataInput getSegment(long position) {
    try {
        RandomAccessReader file = CompressedRandomAccessReader.open(path, metadata);
        file.seek(position);
        return file;
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : CompressedRandomAccessReader(org.apache.cassandra.io.compress.CompressedRandomAccessReader) IOError(java.io.IOError) IOException(java.io.IOException)

Example 24 with IOError

use of java.io.IOError in project eiger by wlloyd.

the class MmappedSegmentedFile method getSegment.

/**
     * @return The segment containing the given position: must be closed after use.
     */
public FileDataInput getSegment(long position) {
    Segment segment = floor(position);
    if (segment.right != null) {
        // segment is mmap'd
        return new MappedFileDataInput(segment.right, path, (int) (position - segment.left));
    }
    // not mmap'd: open a braf covering the segment
    try {
        // FIXME: brafs are unbounded, so this segment will cover the rest of the file, rather than just the row
        RandomAccessReader file = RandomAccessReader.open(new File(path));
        file.seek(position);
        return file;
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : IOError(java.io.IOError) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 25 with IOError

use of java.io.IOError in project eiger by wlloyd.

the class RowRepairResolver method scheduleRepairs.

/**
     * For each row version, compare with resolved (the superset of all row versions);
     * if it is missing anything, send a mutation to the endpoint it come from.
     */
public static List<IAsyncResult> scheduleRepairs(ColumnFamily resolved, String table, DecoratedKey<?> key, List<ColumnFamily> versions, List<InetAddress> endpoints) {
    List<IAsyncResult> results = new ArrayList<IAsyncResult>(versions.size());
    for (int i = 0; i < versions.size(); i++) {
        ColumnFamily diffCf = ColumnFamily.diff(versions.get(i), resolved);
        if (// no repair needs to happen
        diffCf == null)
            continue;
        // create and send the row mutation message based on the diff
        RowMutation rowMutation = new RowMutation(table, key.key);
        rowMutation.add(diffCf);
        Message repairMessage;
        try {
            // use a separate verb here because we don't want these to be get the white glove hint-
            // on-timeout behavior that a "real" mutation gets
            repairMessage = rowMutation.getMessage(StorageService.Verb.READ_REPAIR, Gossiper.instance.getVersion(endpoints.get(i)));
        } catch (IOException e) {
            throw new IOError(e);
        }
        results.add(MessagingService.instance().sendRR(repairMessage, endpoints.get(i)));
    }
    return results;
}
Also used : Message(org.apache.cassandra.net.Message) IOError(java.io.IOError) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IAsyncResult(org.apache.cassandra.net.IAsyncResult)

Aggregations

IOError (java.io.IOError)49 IOException (java.io.IOException)42 File (java.io.File)8 DataInputStream (java.io.DataInputStream)5 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Console (java.io.Console)4 IPartitioner (org.apache.cassandra.dht.IPartitioner)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 SshClient (org.apache.sshd.client.SshClient)3 UserInteraction (org.apache.sshd.client.auth.keyboard.UserInteraction)3 ClientChannel (org.apache.sshd.client.channel.ClientChannel)3 ClientSession (org.apache.sshd.client.session.ClientSession)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 PrintWriter (java.io.PrintWriter)2