Java Code Examples for org.apache.cassandra.io.util.FileUtils#deleteRecursive()

The following examples show how to use org.apache.cassandra.io.util.FileUtils#deleteRecursive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CqlBulkRecordWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void prepareWriter() throws IOException
{
    try
    {
        if (writer == null)
        {
            writer = CQLSSTableWriter.builder()
                .forTable(schema)
                .using(insertStatement)
                .withPartitioner(ConfigHelper.getOutputPartitioner(conf))
                .inDirectory(outputDir)
                .withBufferSizeInMB(Integer.parseInt(conf.get(BUFFER_SIZE_IN_MB, "64")))
                .build();
        }
        if (loader == null)
        {
            ExternalClient externalClient = new ExternalClient(conf);
            
            externalClient.addKnownCfs(keyspace, schema);

            this.loader = new SSTableLoader(outputDir, externalClient, new BulkRecordWriter.NullOutputHandler()) {
                @Override
                public void onSuccess(StreamState finalState)
                {
                    if (deleteSrc)
                        FileUtils.deleteRecursive(outputDir);
                }
            };
        }
    }
    catch (Exception e)
    {
        throw new IOException(e);
    }      
}
 
Example 2
Source File: Directories.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void clearSnapshot(String snapshotName, List<File> snapshotDirectories)
{
    // If snapshotName is empty or null, we will delete the entire snapshot directory
    String tag = snapshotName == null ? "" : snapshotName;
    for (File dir : snapshotDirectories)
    {
        File snapshotDir = new File(dir, join(SNAPSHOT_SUBDIR, tag));
        if (snapshotDir.exists())
        {
            if (logger.isDebugEnabled())
                logger.debug("Removing snapshot directory {}", snapshotDir);
            FileUtils.deleteRecursive(snapshotDir);
        }
    }
}
 
Example 3
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public CfAssumptions()
{
    assumptions = new HashMap<String, Map<String, Map<String, String>>>();
    assumptionsChanged = false;
    assumptionDirectory = FBUtilities.getToolsOutputDirectory();

    File oldAssumptionDir = new File(System.getProperty("user.home") + File.separator + ".cassandra-cli");
    if (oldAssumptionDir.exists())
    {
        File oldAssumptionFile = new File(oldAssumptionDir, ASSUMPTIONS_FILENAME);
        if (oldAssumptionFile.exists())
            FileUtils.renameWithConfirm(oldAssumptionFile, new File(assumptionDirectory, ASSUMPTIONS_FILENAME));
        FileUtils.deleteRecursive(oldAssumptionDir);
    }
}
 
Example 4
Source File: CQLTester.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static void removeAllSSTables(String ks, List<String> tables)
{
    // clean up data directory which are stored as data directory/keyspace/data files
    for (File d : Directories.getKSChildDirectories(ks))
    {
        if (d.exists() && containsAny(d.getName(), tables))
            FileUtils.deleteRecursive(d);
    }
}
 
Example 5
Source File: ObjectMapper.java    From Rhombus with MIT License 5 votes vote down vote up
/**
 * Creates an SSTable keyspace output directory at defaultSSTableOutputPath and table output directories for each SSTable,
 * and initializes each SSTableWriter for each static and index table in this keyspace.
 * @param sorted Defines if the SSTableWriters created by this should be set as sorted, which improves performance if
 *               rows are inserted in SSTable sort order, but throws exceptions if they are inserted in the wrong order.
 * @throws CQLGenerationException
 * @throws IOException
 */
public void initializeSSTableWriters(boolean sorted) throws CQLGenerationException, IOException {
	Map<String, CDefinition> definitions = this.keyspaceDefinition.getDefinitions();

	// Make sure the SSTableOutput directory exists and is clear
	String keyspacePath = this.defaultSSTableOutputPath + "/" + this.keyspaceDefinition.getName();
	File keyspaceDir = new File(keyspacePath);
	if (keyspaceDir.exists()) {
		FileUtils.deleteRecursive(new File(keyspacePath));
	}
	if (!new File(keyspacePath).mkdir()) {
		throw new IOException("Failed to create SSTable keyspace output directory at " + keyspacePath);
	}

	this.SSTableWriters.put(CObjectShardList.SHARD_INDEX_TABLE_NAME, Pair.create(this.buildSSTableWriterForShardIndexTable(sorted), (Map<CIndex, CQLSSTableWriter>) null));

	for (String defName : definitions.keySet()) {
		// Build the CQLSSTableWriter for the static table
		CQLSSTableWriter staticWriter = buildSSTableWriterForStaticTable(definitions.get(defName), sorted);

		// Build the CQLSSTableWriter for all the index tables
		List<CIndex> indexes = definitions.get(defName).getIndexesAsList();
		Map<CIndex, CQLSSTableWriter> indexWriters = Maps.newHashMap();
		for (CIndex index : indexes) {
			CQLSSTableWriter writer = buildSSTableWriterForWideTable(definitions.get(defName), index, sorted);
			indexWriters.put(index, writer);
		}
		this.SSTableWriters.put(defName, Pair.create(staticWriter, indexWriters));
	}
}
 
Example 6
Source File: ObjectMapper.java    From Rhombus with MIT License 5 votes vote down vote up
/**
 * Removes an SSTable directory for a given table path if the directory is empty
 * @param tablePath Path to remove if empty
 */
private void clearSSTableDirectoryIfEmpty(String tablePath) {
	String SSTablePath = this.defaultSSTableOutputPath + "/" + keyspaceDefinition.getName() + "/" + tablePath;
	File SSTableDirectory = new File(SSTablePath);

	if (SSTableDirectory.isDirectory() && SSTableDirectory.list().length == 0) {
		FileUtils.deleteRecursive(SSTableDirectory);
	}
}
 
Example 7
Source File: ZookeeperTestServer.java    From blueflood with Apache License 2.0 5 votes vote down vote up
public void shutdown() {
    disconnect();
    if (zkServer != null) {
        zkServer.shutdown();
        zkServer = null;
    }
    FileUtils.deleteRecursive(logDir);
    FileUtils.deleteRecursive(dataDir);
}
 
Example 8
Source File: LuceneIndex.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Closes the index and removes all its files.
 */
public void delete() {
    Log.info("Removing");
    close();
    FileUtils.deleteRecursive(file);
}
 
Example 9
Source File: DirectoriesTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass()
{
    Directories.resetDataDirectoriesAfterTest();
    FileUtils.deleteRecursive(tempDataDir);
}
 
Example 10
Source File: CQLSSTableWriterClientTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown()
{
    FileUtils.deleteRecursive(this.testDirectory);
}
 
Example 11
Source File: TableScannerITCase.java    From Rhombus with MIT License 4 votes vote down vote up
@Test
public void testFourPartitions() throws Exception {
	String objectType = "simple";
	String index1Value = "value1";
	String index2Value = "value2";
	String savepointDirectoryName = "savepoint-test-dir";
	File savepointDirectory = new File(savepointDirectoryName);
	if (savepointDirectory.exists()) {
		FileUtils.deleteRecursive(savepointDirectory);
	}
	Integer numPartitions = 4;

	//Build the connection manager
	ConnectionManager cm = getConnectionManager();
	cm.setLogCql(true);

	//Build our keyspace definition object
	CKeyspaceDefinition definition = JsonUtil.objectFromJsonResource(CKeyspaceDefinition.class, this.getClass().getClassLoader(), "SimpleKeyspace.js");

	//Rebuild the keyspace and get the object mapper
	cm.buildKeyspace(definition, true);
	logger.debug("Built keyspace: {}", definition.getName());
	cm.setDefaultKeyspace(definition);
	ObjectMapper om = cm.getObjectMapper();
	om.setLogCql(true);

	// Insert 83 values
	Long valueCount = 83L;
	List<Map<String, Object>> values = this.getNValues(valueCount, index1Value, index2Value);
	for(Map<String, Object> insertValue : values) {
		om.insert(objectType, insertValue);
	}

	VisitorFactoryTester visitorFactory = new VisitorFactoryTester();
	TableScanner scanner = new TableScanner(om, objectType, numPartitions, visitorFactory, savepointDirectoryName);
	List<Map.Entry<Long, Long>> ranges = scanner.makeRanges();
	scanner.scan();

	Long totalCount = 0L;
	for(VisitorTester visitor : visitorFactory.getInstances()) {
		totalCount += visitor.getObjectCount();
	}

	assertEquals(valueCount, totalCount);

	this.verifySavepoints(numPartitions, savepointDirectoryName, objectType, om, ranges);

	cm.teardown();
}