Search in sources :

Example 1 with FSWriteError

use of org.apache.cassandra.io.FSWriteError in project cassandra by apache.

the class DatabaseDescriptor method createAllDirectories.

/**
     * Creates all storage-related directories.
     */
public static void createAllDirectories() {
    try {
        if (conf.data_file_directories.length == 0)
            throw new ConfigurationException("At least one DataFileDirectory must be specified", false);
        for (String dataFileDirectory : conf.data_file_directories) FileUtils.createDirectory(dataFileDirectory);
        if (conf.commitlog_directory == null)
            throw new ConfigurationException("commitlog_directory must be specified", false);
        FileUtils.createDirectory(conf.commitlog_directory);
        if (conf.hints_directory == null)
            throw new ConfigurationException("hints_directory must be specified", false);
        FileUtils.createDirectory(conf.hints_directory);
        if (conf.saved_caches_directory == null)
            throw new ConfigurationException("saved_caches_directory must be specified", false);
        FileUtils.createDirectory(conf.saved_caches_directory);
        if (conf.cdc_enabled) {
            if (conf.cdc_raw_directory == null)
                throw new ConfigurationException("cdc_raw_directory must be specified", false);
            FileUtils.createDirectory(conf.cdc_raw_directory);
        }
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException("Bad configuration; unable to start server: " + e.getMessage());
    } catch (FSWriteError e) {
        throw new IllegalStateException(e.getCause().getMessage() + "; unable to start server");
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) FSWriteError(org.apache.cassandra.io.FSWriteError)

Example 2 with FSWriteError

use of org.apache.cassandra.io.FSWriteError in project cassandra by apache.

the class Directories method getWriteableLocation.

/**
     * Returns a non-blacklisted data directory that _currently_ has {@code writeSize} bytes as usable space, null if
     * there is not enough space left in all directories.
     *
     * @throws FSWriteError if all directories are blacklisted.
     */
public DataDirectory getWriteableLocation(long writeSize) {
    List<DataDirectoryCandidate> candidates = new ArrayList<>();
    long totalAvailable = 0L;
    // pick directories with enough space and so that resulting sstable dirs aren't blacklisted for writes.
    boolean tooBig = false;
    for (DataDirectory dataDir : paths) {
        if (BlacklistedDirectories.isUnwritable(getLocationForDisk(dataDir))) {
            logger.trace("removing blacklisted candidate {}", dataDir.location);
            continue;
        }
        DataDirectoryCandidate candidate = new DataDirectoryCandidate(dataDir);
        // exclude directory if its total writeSize does not fit to data directory
        if (candidate.availableSpace < writeSize) {
            logger.trace("removing candidate {}, usable={}, requested={}", candidate.dataDirectory.location, candidate.availableSpace, writeSize);
            tooBig = true;
            continue;
        }
        candidates.add(candidate);
        totalAvailable += candidate.availableSpace;
    }
    if (candidates.isEmpty())
        if (tooBig)
            throw new FSDiskFullWriteError(new IOException("Insufficient disk space to write " + writeSize + " bytes"), "");
        else
            throw new FSWriteError(new IOException("All configured data directories have been blacklisted as unwritable for erroring out"), "");
    // shortcut for single data directory systems
    if (candidates.size() == 1)
        return candidates.get(0).dataDirectory;
    sortWriteableCandidates(candidates, totalAvailable);
    return pickWriteableDirectory(candidates);
}
Also used : FSDiskFullWriteError(org.apache.cassandra.io.FSDiskFullWriteError) FSWriteError(org.apache.cassandra.io.FSWriteError) IOException(java.io.IOException)

Example 3 with FSWriteError

use of org.apache.cassandra.io.FSWriteError in project cassandra by apache.

the class EncryptedSegment method write.

void write(int startMarker, int nextMarker) {
    int contentStart = startMarker + SYNC_MARKER_SIZE;
    final int length = nextMarker - contentStart;
    // The length may be 0 when the segment is being closed.
    assert length > 0 || length == 0 && !isStillAllocating();
    final ICompressor compressor = encryptionContext.getCompressor();
    final int blockSize = encryptionContext.getChunkLength();
    try {
        ByteBuffer inputBuffer = buffer.duplicate();
        inputBuffer.limit(contentStart + length).position(contentStart);
        ByteBuffer buffer = manager.getBufferPool().getThreadLocalReusableBuffer(DatabaseDescriptor.getCommitLogSegmentSize());
        // save space for the sync marker at the beginning of this section
        final long syncMarkerPosition = lastWrittenPos;
        channel.position(syncMarkerPosition + ENCRYPTED_SECTION_HEADER_SIZE);
        // loop over the segment data in encryption buffer sized chunks
        while (contentStart < nextMarker) {
            int nextBlockSize = nextMarker - blockSize > contentStart ? blockSize : nextMarker - contentStart;
            ByteBuffer slice = inputBuffer.duplicate();
            slice.limit(contentStart + nextBlockSize).position(contentStart);
            buffer = EncryptionUtils.compress(slice, buffer, true, compressor);
            // reuse the same buffer for the input and output of the encryption operation
            buffer = EncryptionUtils.encryptAndWrite(buffer, channel, true, cipher);
            contentStart += nextBlockSize;
            manager.addSize(buffer.limit() + ENCRYPTED_BLOCK_HEADER_SIZE);
        }
        lastWrittenPos = channel.position();
        // rewind to the beginning of the section and write out the sync marker
        buffer.position(0).limit(ENCRYPTED_SECTION_HEADER_SIZE);
        writeSyncMarker(buffer, 0, (int) syncMarkerPosition, (int) lastWrittenPos);
        buffer.putInt(SYNC_MARKER_SIZE, length);
        buffer.rewind();
        manager.addSize(buffer.limit());
        channel.position(syncMarkerPosition);
        channel.write(buffer);
        SyncUtil.force(channel, true);
    } catch (Exception e) {
        throw new FSWriteError(e, getPath());
    }
}
Also used : FSWriteError(org.apache.cassandra.io.FSWriteError) ICompressor(org.apache.cassandra.io.compress.ICompressor) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 4 with FSWriteError

use of org.apache.cassandra.io.FSWriteError in project cassandra by apache.

the class MemoryMappedSegment method write.

@Override
void write(int startMarker, int nextMarker) {
    // zero out the next sync marker so replayer can cleanly exit
    if (nextMarker <= buffer.capacity() - SYNC_MARKER_SIZE) {
        buffer.putInt(nextMarker, 0);
        buffer.putInt(nextMarker + 4, 0);
    }
    // write previous sync marker to point to next sync marker
    // we don't chain the crcs here to ensure this method is idempotent if it fails
    writeSyncMarker(buffer, startMarker, startMarker, nextMarker);
    try {
        SyncUtil.force((MappedByteBuffer) buffer);
    } catch (// MappedByteBuffer.force() does not declare IOException but can actually throw it
    Exception e) {
        throw new FSWriteError(e, getPath());
    }
    CLibrary.trySkipCache(fd, startMarker, nextMarker, logFile.getAbsolutePath());
}
Also used : FSWriteError(org.apache.cassandra.io.FSWriteError) IOException(java.io.IOException)

Example 5 with FSWriteError

use of org.apache.cassandra.io.FSWriteError in project cassandra by apache.

the class HintsStore method openWriter.

private HintsWriter openWriter() {
    lastUsedTimestamp = Math.max(System.currentTimeMillis(), lastUsedTimestamp + 1);
    HintsDescriptor descriptor = new HintsDescriptor(hostId, lastUsedTimestamp, writerParams);
    try {
        return HintsWriter.create(hintsDirectory, descriptor);
    } catch (IOException e) {
        throw new FSWriteError(e, descriptor.fileName());
    }
}
Also used : FSWriteError(org.apache.cassandra.io.FSWriteError) IOException(java.io.IOException)

Aggregations

FSWriteError (org.apache.cassandra.io.FSWriteError)23 IOException (java.io.IOException)15 ByteBuffer (java.nio.ByteBuffer)5 File (java.io.File)3 DiskFailurePolicy (org.apache.cassandra.config.Config.DiskFailurePolicy)2 Test (org.junit.Test)2 PrintStream (java.io.PrintStream)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 ExecutionException (java.util.concurrent.ExecutionException)1 CRC32 (java.util.zip.CRC32)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 DataDirectory (org.apache.cassandra.db.Directories.DataDirectory)1 SerializationHeader (org.apache.cassandra.db.SerializationHeader)1 CommitLogSegment (org.apache.cassandra.db.commitlog.CommitLogSegment)1 Allocation (org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 IndexedTerm (org.apache.cassandra.index.sasi.sa.IndexedTerm)1 FSDiskFullWriteError (org.apache.cassandra.io.FSDiskFullWriteError)1 FSReadError (org.apache.cassandra.io.FSReadError)1