use of org.apache.cassandra.io.util.File in project cassandra by apache.
the class HintsStore method hasExpired.
private boolean hasExpired(HintsDescriptor descriptor, long now) {
Long cachedExpiresAt = hintsExpirations.get(descriptor);
if (null != cachedExpiresAt)
return cachedExpiresAt <= now;
File hintFile = new File(hintsDirectory, descriptor.fileName());
// the file does not exist or if an I/O error occurs
if (!hintFile.exists() || hintFile.lastModified() == 0)
return false;
// 'lastModified' can be considered as the upper bound of the hint creation time.
// So the TTL upper bound of all hints in the file can be estimated by lastModified + maxGcgs of all tables
long ttl = hintFile.lastModified() + Schema.instance.largestGcgs();
hintsExpirations.put(descriptor, ttl);
return ttl <= now;
}
use of org.apache.cassandra.io.util.File in project cassandra by apache.
the class HintsWriter method create.
// HintsWriter owns channel
@SuppressWarnings("resource")
static HintsWriter create(File directory, HintsDescriptor descriptor) throws IOException {
File file = descriptor.file(directory);
FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
int fd = NativeLibrary.getfd(channel);
CRC32 crc = new CRC32();
try (DataOutputBuffer dob = DataOutputBuffer.scratchBuffer.get()) {
// write the descriptor
descriptor.serialize(dob);
ByteBuffer descriptorBytes = dob.buffer();
updateChecksum(crc, descriptorBytes);
channel.write(descriptorBytes);
if (descriptor.isEncrypted())
return new EncryptedHintsWriter(directory, descriptor, file, channel, fd, crc);
if (descriptor.isCompressed())
return new CompressedHintsWriter(directory, descriptor, file, channel, fd, crc);
return new HintsWriter(directory, descriptor, file, channel, fd, crc);
} catch (Throwable e) {
channel.close();
throw e;
}
}
use of org.apache.cassandra.io.util.File in project cassandra by apache.
the class ClusterUtils method getDataDirectories.
/**
* Get all data directories for the given instance.
*
* @param instance to get data directories for
* @return data directories
*/
public static List<File> getDataDirectories(IInstance instance) {
IInstanceConfig conf = instance.config();
// this isn't safe as it assumes the implementation of InstanceConfig
// might need to get smarter... some day...
String[] ds = (String[]) conf.get("data_file_directories");
List<File> files = new ArrayList<>(ds.length);
for (int i = 0; i < ds.length; i++) files.add(new File(ds[i]));
return files;
}
use of org.apache.cassandra.io.util.File in project cassandra by apache.
the class ClusterUtils method getCommitLogDirectory.
/**
* Get the commit log directory for the given instance.
*
* @param instance to get the commit log directory for
* @return commit log directory
*/
public static File getCommitLogDirectory(IInstance instance) {
IInstanceConfig conf = instance.config();
// this isn't safe as it assumes the implementation of InstanceConfig
// might need to get smarter... some day...
String d = (String) conf.get("commitlog_directory");
return new File(d);
}
use of org.apache.cassandra.io.util.File in project cassandra by apache.
the class ClusterUtils method getSavedCachesDirectory.
/**
* Get the saved caches directory for the given instance.
*
* @param instance to get the saved caches directory for
* @return saved caches directory
*/
public static File getSavedCachesDirectory(IInstance instance) {
IInstanceConfig conf = instance.config();
// this isn't safe as it assumes the implementation of InstanceConfig
// might need to get smarter... some day...
String d = (String) conf.get("saved_caches_directory");
return new File(d);
}
Aggregations