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");
}
}
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);
}
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());
}
}
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());
}
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());
}
}
Aggregations