List of usage examples for org.apache.cassandra.config DatabaseDescriptor getAllDataFileLocations
public static String[] getAllDataFileLocations()
From source file:com.btoddb.flume.sinks.cassandra.EmbeddedServerHelper.java
License:Apache License
public static void cleanup() throws IOException { // clean up commitlog String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), }; for (String dirName : directoryNames) { File dir = new File(dirName); if (!dir.exists()) throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); FileUtils.deleteRecursive(dir);/* w w w. j a v a2 s . c o m*/ } // clean up data directory which are stored as data directory/table/data files for (String dirName : DatabaseDescriptor.getAllDataFileLocations()) { File dir = new File(dirName); if (!dir.exists()) throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); FileUtils.deleteRecursive(dir); } }
From source file:com.isthari.spring.cloud.config.cassandra.CassandraServiceDataCleaner.java
License:Apache License
/** * Collects all data dirs and returns a set of String paths on the file system. * * @return//from ww w . j a v a 2s . co m */ private Set<String> getDataDirs() { Set<String> dirs = new HashSet<String>(); for (String s : DatabaseDescriptor.getAllDataFileLocations()) { dirs.add(s); } dirs.add(DatabaseDescriptor.getCommitLogLocation()); return dirs; }
From source file:com.jeklsoft.cassandraclient.EmbeddedCassandra.java
License:Apache License
private void makeDirsIfNotExist() throws IOException { for (String s : Arrays.asList(DatabaseDescriptor.getAllDataFileLocations())) { forceMkdir(new File(s)); }/*from w w w . j a va 2 s . c o m*/ forceMkdir(new File(DatabaseDescriptor.getCommitLogLocation())); }
From source file:com.meteogroup.cassandra.embedded.EmbeddedCassandraLoader.java
License:Open Source License
public static void tearDownCassandra() throws IOException { cassandraHost = null;/*from w w w. jav a 2 s .co m*/ cassandraNativePort = -1; if (cassandraDaemon != null) { cassandraDaemon.stop(); } EmbeddedConfigurationLoader.reset(); for (String dataFileLocation : DatabaseDescriptor.getAllDataFileLocations()) { Files.walkFileTree(Paths.get(dataFileLocation), new Deleter()); } }
From source file:com.navercorp.pinpoint.plugin.cassandra.CassandraTestHelper.java
License:Apache License
private static void cleanUpFiles() throws IOException { Set<String> fileLocations = new HashSet<String>(); for (String dataFileLocation : DatabaseDescriptor.getAllDataFileLocations()) { fileLocations.add(dataFileLocation); }/*w ww.java 2 s . c o m*/ fileLocations.add(DatabaseDescriptor.getCommitLogLocation()); fileLocations.add(DatabaseDescriptor.getSavedCachesLocation()); for (String fileLocation : fileLocations) { File location = new File(fileLocation); if (location.exists() && location.isDirectory()) { FileUtils.deleteDirectory(fileLocation); } } }
From source file:com.savoirtech.bundles.cassandra.AbstractCassandraDaemon.java
License:Apache License
/** * This is a hook for concrete daemons to initialize themselves suitably. * <p/>//from w w w . ja v a 2s .c o m * Subclasses should override this to finish the job (listening on ports, etc.) * * @throws java.io.IOException */ protected void setup() { logger.info("JVM vendor/version: {}/{}", System.getProperty("java.vm.name"), System.getProperty("java.version")); logger.info("Heap size: {}/{}", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory()); logger.info("Classpath: {}", System.getProperty("java.class.path")); CLibrary.tryMlockall(); listenPort = DatabaseDescriptor.getRpcPort(); listenAddr = DatabaseDescriptor.getRpcAddress(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { exceptions.incrementAndGet(); logger.error("Exception in thread " + t, e); for (Throwable e2 = e; e2 != null; e2 = e2.getCause()) { // some code, like FileChannel.map, will wrap an OutOfMemoryError in another exception if (e2 instanceof OutOfMemoryError) { System.exit(100); } } } }); // check all directories(data, commitlog, saved cache) for existence and permission Iterable<String> dirs = Iterables.concat(Arrays.asList(DatabaseDescriptor.getAllDataFileLocations()), Arrays.asList(new String[] { DatabaseDescriptor.getCommitLogLocation(), DatabaseDescriptor.getSavedCachesLocation() })); for (String dataDir : dirs) { logger.debug("Checking directory {}", dataDir); File dir = new File(dataDir); if (dir.exists()) { assert dir.isDirectory() && dir.canRead() && dir.canWrite() && dir.canExecute() : String .format("Directory %s is not accessible.", dataDir); } } // Migrate sstables from pre-#2749 to the correct location if (Directories.sstablesNeedsMigration()) { Directories.migrateSSTables(); } if (CacheService.instance == null) // should never happen { throw new RuntimeException("Failed to initialize Cache Service."); } // check the system table to keep user from shooting self in foot by changing partitioner, cluster name, etc. // we do a one-off scrub of the system table first; we can't load the list of the rest of the tables, // until system table is opened. for (CFMetaData cfm : Schema.instance.getTableMetaData(Table.SYSTEM_KS).values()) { ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_KS, cfm.cfName); } try { SystemTable.checkHealth(); } catch (ConfigurationException e) { logger.error("Fatal exception during initialization", e); System.exit(100); } // load keyspace descriptions. try { DatabaseDescriptor.loadSchemas(); } catch (IOException e) { logger.error("Fatal exception during initialization", e); System.exit(100); } // clean up debris in the rest of the tables for (String table : Schema.instance.getTables()) { for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values()) { ColumnFamilyStore.scrubDataDirectories(table, cfm.cfName); } } // initialize keyspaces for (String table : Schema.instance.getTables()) { if (logger.isDebugEnabled()) { logger.debug("opening keyspace " + table); } Table.open(table); } if (CacheService.instance.keyCache.size() > 0) { logger.info("completed pre-loading ({} keys) key cache.", CacheService.instance.keyCache.size()); } if (CacheService.instance.rowCache.size() > 0) { logger.info("completed pre-loading ({} keys) row cache.", CacheService.instance.rowCache.size()); } try { GCInspector.instance.start(); } catch (Throwable t) { logger.warn("Unable to start GCInspector (currently only supported on the Sun JVM)"); } // replay the log if necessary try { CommitLog.instance.recover(); } catch (IOException e) { logger.error("Fatal configuration error", e); System.err.println(e.getMessage() + "\nFatal configuration error; unable to start server. See log for stacktrace."); System.exit(1); } SystemTable.finishStartup(); // start server internals StorageService.instance.registerDaemon(this); try { StorageService.instance.initServer(); } catch (ConfigurationException e) { logger.error("Fatal configuration error", e); System.err.println(e.getMessage() + "\nFatal configuration error; unable to start server. See log for stacktrace."); System.exit(1); } Mx4jTool.maybeLoad(); }
From source file:com.springsource.insight.plugin.cassandra.embeded.EmbeddedCassandraService.java
License:Open Source License
/** * Collects all data dirs and returns a set of String paths on the file system. * * @return//w ww. j ava 2s . c o m */ private Set<String> getDataDirs() { Set<String> dirs = new HashSet<String>(); for (String s : DatabaseDescriptor.getAllDataFileLocations()) { dirs.add(s); } dirs.add(DatabaseDescriptor.getCommitLogLocation()); dirs.add(DatabaseDescriptor.getSavedCachesLocation()); return dirs; }
From source file:com.stratio.cassandra.index.RowIndexConfig.java
License:Apache License
/** * Builds a new {@link RowIndexConfig} for the column family defined by the specified metadata using the specified * index options.//from w w w .j av a2s. c o m * * @param metadata The metadata of the indexed column family. * @param options The index options. */ public RowIndexConfig(CFMetaData metadata, Map<String, String> options) { // Setup refresh seconds String refreshOption = options.get(REFRESH_SECONDS_OPTION); if (refreshOption != null) { try { refreshSeconds = Double.parseDouble(refreshOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a strictly positive double", REFRESH_SECONDS_OPTION); throw new RuntimeException(msg); } if (refreshSeconds <= 0) { String msg = String.format("'%s' must be strictly positive", REFRESH_SECONDS_OPTION); throw new RuntimeException(msg); } } else { refreshSeconds = DEFAULT_REFRESH_SECONDS; } // Setup write buffer size String ramBufferSizeOption = options.get(RAM_BUFFER_MB_OPTION); if (ramBufferSizeOption != null) { try { ramBufferMB = Integer.parseInt(ramBufferSizeOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a strictly positive integer", RAM_BUFFER_MB_OPTION); throw new RuntimeException(msg); } if (ramBufferMB <= 0) { String msg = String.format("'%s' must be strictly positive", RAM_BUFFER_MB_OPTION); throw new RuntimeException(msg); } } else { ramBufferMB = DEFAULT_RAM_BUFFER_MB; } // Setup max merge size String maxMergeSizeMBOption = options.get(MAX_MERGE_MB_OPTION); if (maxMergeSizeMBOption != null) { try { maxMergeMB = Integer.parseInt(maxMergeSizeMBOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a strictly positive integer", MAX_MERGE_MB_OPTION); throw new RuntimeException(msg); } if (maxMergeMB <= 0) { String msg = String.format("'%s' must be strictly positive", MAX_MERGE_MB_OPTION); throw new RuntimeException(msg); } } else { maxMergeMB = DEFAULT_MAX_MERGE_MB; } // Setup max cached MB String maxCachedMBOption = options.get(MAX_CACHED_MB_OPTION); if (maxCachedMBOption != null) { try { maxCachedMB = Integer.parseInt(maxCachedMBOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a strictly positive integer", MAX_CACHED_MB_OPTION); throw new RuntimeException(msg); } if (maxCachedMB <= 0) { String msg = String.format("'%s' must be strictly positive", MAX_CACHED_MB_OPTION); throw new RuntimeException(msg); } } else { maxCachedMB = DEFAULT_MAX_CACHED_MB; } // Setup queues in index pool String indexPoolNumQueuesOption = options.get(INDEXING_THREADS_OPTION); if (indexPoolNumQueuesOption != null) { try { indexingThreads = Integer.parseInt(indexPoolNumQueuesOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a positive integer", INDEXING_THREADS_OPTION); throw new RuntimeException(msg); } } else { indexingThreads = DEFAULT_INDEXING_THREADS; } // Setup queues in index pool String indexPoolQueuesSizeOption = options.get(INDEXING_QUEUES_SIZE_OPTION); if (indexPoolQueuesSizeOption != null) { try { indexingQueuesSize = Integer.parseInt(indexPoolQueuesSizeOption); } catch (NumberFormatException e) { String msg = String.format("'%s' must be a strictly positive integer", INDEXING_QUEUES_SIZE_OPTION); throw new RuntimeException(msg); } if (indexingQueuesSize <= 0) { String msg = String.format("'%s' must be strictly positive", INDEXING_QUEUES_SIZE_OPTION); throw new RuntimeException(msg); } } else { indexingQueuesSize = DEFAULT_INDEXING_QUEUES_SIZE; } // Get columns mapping schema String schemaOption = options.get(SCHEMA_OPTION); if (schemaOption != null && !schemaOption.trim().isEmpty()) { try { schema = Schema.fromJson(schemaOption); schema.validate(metadata); } catch (Exception e) { String msg = String.format("'%s' is invalid : %s", SCHEMA_OPTION, e.getMessage()); throw new RuntimeException(msg); } } else { String msg = String.format("'%s' required", SCHEMA_OPTION); throw new RuntimeException(msg); } // Get Lucene directory path String[] dataFileLocations = DatabaseDescriptor.getAllDataFileLocations(); StringBuilder directoryPathBuilder = new StringBuilder(); directoryPathBuilder.append(dataFileLocations[0]); directoryPathBuilder.append(File.separatorChar); directoryPathBuilder.append(metadata.ksName); directoryPathBuilder.append(File.separatorChar); directoryPathBuilder.append(metadata.cfName); directoryPathBuilder.append("-"); directoryPathBuilder.append(ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(metadata.cfId))); directoryPathBuilder.append(File.separatorChar); directoryPathBuilder.append(INDEXES_DIR_NAME); path = directoryPathBuilder.toString(); }
From source file:com.stratio.cassandra.lucene.IndexConfig.java
License:Apache License
private static Path parsePath(Map<String, String> options, CFMetaData metadata) { String pathOption = options.get(DIRECTORY_PATH_OPTION); if (pathOption == null) { String pathString = DatabaseDescriptor.getAllDataFileLocations()[0] + File.separatorChar + metadata.ksName + File.separatorChar + metadata.cfName + "-" + metadata.cfId + File.separatorChar + INDEXES_DIR_NAME; return Paths.get(pathString); } else {/* ww w .ja v a 2s . c om*/ return Paths.get(pathOption); } }
From source file:com.stratio.decision.unit.engine.action.CassandraServer.java
License:Apache License
private static void cleanup() throws IOException { // clean up commitlog String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), }; for (String dirName : directoryNames) { File dir = new File(dirName); if (!dir.exists()) { log.error("No such directory: " + dir.getAbsolutePath()); throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); }// ww w. j av a 2s.c o m FileUtils.deleteRecursive(dir); } // clean up data directory which are stored as data directory/table/data // files for (String dirName : DatabaseDescriptor.getAllDataFileLocations()) { File dir = new File(dirName); if (!dir.exists()) { log.error("No such directory: " + dir.getAbsolutePath()); throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); } FileUtils.deleteRecursive(dir); } }