本文整理汇总了Java中org.apache.cassandra.config.DatabaseDescriptor.getCommitLogLocation方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseDescriptor.getCommitLogLocation方法的具体用法?Java DatabaseDescriptor.getCommitLogLocation怎么用?Java DatabaseDescriptor.getCommitLogLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.config.DatabaseDescriptor
的用法示例。
在下文中一共展示了DatabaseDescriptor.getCommitLogLocation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeRestoreArchive
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
public void maybeRestoreArchive()
{
if (Strings.isNullOrEmpty(restoreDirectories))
return;
for (String dir : restoreDirectories.split(","))
{
File[] files = new File(dir).listFiles();
if (files == null)
{
throw new RuntimeException("Unable to list director " + dir);
}
for (File fromFile : files)
{
File toFile = new File(DatabaseDescriptor.getCommitLogLocation(), new CommitLogDescriptor(CommitLogSegment.getNextId()).fileName());
String command = restoreCommand.replace("%from", fromFile.getPath());
command = command.replace("%to", toFile.getPath());
try
{
exec(command);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
}
示例2: construct
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
private static CommitLog construct()
{
CommitLog log = new CommitLog(DatabaseDescriptor.getCommitLogLocation(), CommitLogArchiver.construct());
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try
{
mbs.registerMBean(log, new ObjectName("org.apache.cassandra.db:type=Commitlog"));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
return log.start();
}
示例3: examineCommitLog
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
public static void examineCommitLog(Predicate<Mutation> processor) throws IOException
{
CommitLog.instance.sync(true);
CommitLogTestReplayer replayer = new CommitLogTestReplayer(CommitLog.instance, processor);
File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
replayer.recover(commitLogDir.listFiles());
}
示例4: maybeRestoreArchive
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
public void maybeRestoreArchive()
{
if (Strings.isNullOrEmpty(restoreDirectories))
return;
for (String dir : restoreDirectories.split(DELIMITER))
{
File[] files = new File(dir).listFiles();
if (files == null)
{
throw new RuntimeException("Unable to list directory " + dir);
}
for (File fromFile : files)
{
CommitLogDescriptor fromHeader = CommitLogDescriptor.fromHeader(fromFile);
CommitLogDescriptor fromName = CommitLogDescriptor.isValid(fromFile.getName()) ? CommitLogDescriptor.fromFileName(fromFile.getName()) : null;
CommitLogDescriptor descriptor;
if (fromHeader == null && fromName == null)
throw new IllegalStateException("Cannot safely construct descriptor for segment, either from its name or its header: " + fromFile.getPath());
else if (fromHeader != null && fromName != null && !fromHeader.equals(fromName))
throw new IllegalStateException(String.format("Cannot safely construct descriptor for segment, as name and header descriptors do not match (%s vs %s): %s", fromHeader, fromName, fromFile.getPath()));
else if (fromName != null && fromHeader == null && fromName.version >= CommitLogDescriptor.VERSION_21)
throw new IllegalStateException("Cannot safely construct descriptor for segment, as name descriptor implies a version that should contain a header descriptor, but that descriptor could not be read: " + fromFile.getPath());
else if (fromHeader != null)
descriptor = fromHeader;
else descriptor = fromName;
if (descriptor.version > CommitLogDescriptor.VERSION_21)
throw new IllegalStateException("Unsupported commit log version: " + descriptor.version);
File toFile = new File(DatabaseDescriptor.getCommitLogLocation(), descriptor.fileName());
if (toFile.exists())
{
logger.debug("Skipping restore of archive {} as the segment already exists in the restore location {}",
fromFile.getPath(), toFile.getPath());
continue;
}
String command = restoreCommand.replace("%from", fromFile.getPath());
command = command.replace("%to", toFile.getPath());
try
{
exec(command);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
}
示例5: CommitLogSegment
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
/**
* Constructs a new segment file.
*
* @param filePath if not null, recycles the existing file by renaming it and truncating it to CommitLog.SEGMENT_SIZE.
*/
CommitLogSegment(String filePath)
{
id = getNextId();
descriptor = new CommitLogDescriptor(id);
logFile = new File(DatabaseDescriptor.getCommitLogLocation(), descriptor.fileName());
boolean isCreating = true;
try
{
if (filePath != null)
{
File oldFile = new File(filePath);
if (oldFile.exists())
{
logger.debug("Re-using discarded CommitLog segment for {} from {}", id, filePath);
if (!oldFile.renameTo(logFile))
throw new IOException("Rename from " + filePath + " to " + id + " failed");
isCreating = false;
}
}
// Open the initial the segment file
logFileAccessor = new RandomAccessFile(logFile, "rw");
if (isCreating)
logger.debug("Creating new commit log segment {}", logFile.getPath());
// Map the segment, extending or truncating it to the standard segment size.
// (We may have restarted after a segment size configuration change, leaving "incorrectly"
// sized segments on disk.)
logFileAccessor.setLength(DatabaseDescriptor.getCommitLogSegmentSize());
fd = CLibrary.getfd(logFileAccessor.getFD());
buffer = logFileAccessor.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, DatabaseDescriptor.getCommitLogSegmentSize());
// write the header
CommitLogDescriptor.writeHeader(buffer, descriptor);
// mark the initial sync marker as uninitialised
buffer.putInt(CommitLogDescriptor.HEADER_SIZE, 0);
buffer.putLong(CommitLogDescriptor.HEADER_SIZE + 4, 0);
allocatePosition.set(CommitLogDescriptor.HEADER_SIZE + SYNC_MARKER_SIZE);
lastSyncedOffset = CommitLogDescriptor.HEADER_SIZE;
}
catch (IOException e)
{
throw new FSWriteError(e, logFile);
}
}
示例6: testNoCommitLog
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
@Test
public void testNoCommitLog() throws Exception
{
Mutation rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("row"));
rm.add("Standard1", Util.cellname("commit1"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
rm = new Mutation("NoCommitlogSpace", ByteBufferUtil.bytes("row"));
rm.add("Standard1", Util.cellname("commit2"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
boolean commitLogMessageFound = false;
boolean noCommitLogMessageFound = false;
File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
byte[] commitBytes = "commit".getBytes("UTF-8");
for(String filename : commitLogDir.list())
{
BufferedInputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(commitLogDir.getAbsolutePath()+File.separator+filename));
if (!isEmptyCommitLog(is))
{
while (findPatternInStream(commitBytes, is))
{
char c = (char)is.read();
if (c == '1')
commitLogMessageFound = true;
else if (c == '2')
noCommitLogMessageFound = true;
}
}
}
finally
{
if (is != null)
is.close();
}
}
assertTrue(commitLogMessageFound);
assertFalse(noCommitLogMessageFound);
}
示例7: CommitLogSegment
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
/**
* Constructs a new segment file.
*
* @param filePath if not null, recycles the existing file by renaming it and truncating it to CommitLog.SEGMENT_SIZE.
*/
CommitLogSegment(String filePath)
{
id = getNextId();
descriptor = new CommitLogDescriptor(id);
logFile = new File(DatabaseDescriptor.getCommitLogLocation(), descriptor.fileName());
boolean isCreating = true;
try
{
if (filePath != null)
{
File oldFile = new File(filePath);
if (oldFile.exists())
{
logger.debug("Re-using discarded CommitLog segment for {} from {}", id, filePath);
if (!oldFile.renameTo(logFile))
throw new IOException("Rename from " + filePath + " to " + id + " failed");
isCreating = false;
}
}
// Open the initial the segment file
logFileAccessor = new RandomAccessFile(logFile, "rw");
if (isCreating)
logger.debug("Creating new commit log segment {}", logFile.getPath());
// Map the segment, extending or truncating it to the standard segment size
logFileAccessor.setLength(DatabaseDescriptor.getCommitLogSegmentSize());
buffer = logFileAccessor.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, DatabaseDescriptor.getCommitLogSegmentSize());
checksum = new PureJavaCrc32();
bufferStream = new DataOutputStream(new ChecksummedOutputStream(new ByteBufferOutputStream(buffer), checksum));
buffer.putInt(CommitLog.END_OF_SEGMENT_MARKER);
buffer.position(0);
needsSync = true;
}
catch (IOException e)
{
throw new FSWriteError(e, logFile);
}
}
示例8: testNoCommitLog
import org.apache.cassandra.config.DatabaseDescriptor; //导入方法依赖的package包/类
@Test
public void testNoCommitLog() throws Exception
{
RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("row"));
rm.add("Standard1", ByteBufferUtil.bytes("commit1"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
rm = new RowMutation("NoCommitlogSpace", ByteBufferUtil.bytes("row"));
rm.add("Standard1", ByteBufferUtil.bytes("commit2"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
boolean commitLogMessageFound = false;
boolean noCommitLogMessageFound = false;
File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
byte[] commitBytes = "commit".getBytes("UTF-8");
for(String filename : commitLogDir.list())
{
BufferedInputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(commitLogDir.getAbsolutePath()+File.separator+filename));
if (!isEmptyCommitLog(is))
{
while (findPatternInStream(commitBytes, is))
{
char c = (char)is.read();
if (c == '1')
commitLogMessageFound = true;
else if (c == '2')
noCommitLogMessageFound = true;
}
}
}
finally
{
if (is != null)
is.close();
}
}
assertTrue(commitLogMessageFound);
assertFalse(noCommitLogMessageFound);
}