Search in sources :

Example 11 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class CommitLogTest method testRecovery.

protected Void testRecovery(byte[] logData, int version) throws Exception {
    File logFile = tmpFile(version);
    try (OutputStream lout = new FileOutputStreamPlus(logFile)) {
        lout.write(logData);
        // statics make it annoying to test things correctly
        // CASSANDRA-1119 / CASSANDRA-1179 throw on failure*/
        CommitLog.instance.recover(logFile.path());
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 12 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class CommitLogUpgradeTestMaker method makeLog.

public void makeLog() throws IOException, InterruptedException {
    CommitLog commitLog = CommitLog.instance;
    System.out.format("\nUsing commit log size: %dmb, compressor: %s, encryption: %s, sync: %s, %s\n", mb(DatabaseDescriptor.getCommitLogSegmentSize()), commitLog.configuration.getCompressorName(), commitLog.configuration.useEncryption(), commitLog.executor.getClass().getSimpleName(), randomSize ? "random size" : "");
    final List<CommitlogExecutor> threads = new ArrayList<>();
    ScheduledExecutorService scheduled = startThreads(commitLog, threads);
    Thread.sleep(runTimeMs);
    stop = true;
    scheduled.shutdown();
    Assert.assertTrue(scheduled.awaitTermination(1, TimeUnit.MINUTES));
    int hash = 0;
    int cells = 0;
    for (CommitlogExecutor t : threads) {
        t.join();
        hash += t.hash;
        cells += t.cells;
    }
    commitLog.shutdownBlocking();
    File dataDir = new File(CommitLogUpgradeTest.DATA_DIR + FBUtilities.getReleaseVersionString());
    System.out.format("Data will be stored in %s\n", dataDir);
    if (dataDir.exists())
        FileUtils.deleteRecursive(dataDir);
    dataDir.tryCreateDirectories();
    for (File f : new File(DatabaseDescriptor.getCommitLogLocation()).tryList()) FileUtils.createHardLink(f, new File(dataDir, f.name()));
    Properties prop = new Properties();
    prop.setProperty(CFID_PROPERTY, Schema.instance.getTableMetadata(KEYSPACE, TABLE).id.toString());
    prop.setProperty(CELLS_PROPERTY, Integer.toString(cells));
    prop.setProperty(HASH_PROPERTY, Integer.toString(hash));
    prop.store(new FileOutputStreamPlus(new File(dataDir, PROPERTIES_FILE)), "CommitLog upgrade test, version " + FBUtilities.getReleaseVersionString());
    System.out.println("Done");
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 13 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class DirectoriesTest method createFile.

private File createFile(String fileName, int size) {
    File newFile = new File(fileName);
    try (FileOutputStreamPlus writer = new FileOutputStreamPlus(newFile)) {
        writer.write(new byte[size]);
        writer.flush();
    } catch (IOException ignore) {
    }
    return newFile;
}
Also used : IOException(java.io.IOException) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 14 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class TTLTest method copyFile.

private static void copyFile(File src, File dest) throws IOException {
    byte[] buf = new byte[65536];
    if (src.isFile()) {
        File target = new File(dest, src.name());
        int rd;
        FileInputStreamPlus is = new FileInputStreamPlus(src);
        FileOutputStreamPlus os = new FileOutputStreamPlus(target);
        while ((rd = is.read(buf)) >= 0) os.write(buf, 0, rd);
        os.close();
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 15 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class TableSnapshotTest method writeBatchToFile.

private Long writeBatchToFile(File file) throws IOException {
    FileOutputStreamPlus out = new FileOutputStreamPlus(file);
    out.write(1);
    out.write(2);
    out.write(3);
    out.close();
    return 3L;
}
Also used : FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Aggregations

FileOutputStreamPlus (org.apache.cassandra.io.util.FileOutputStreamPlus)16 File (org.apache.cassandra.io.util.File)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataOutputStream (java.io.DataOutputStream)6 OutputStream (java.io.OutputStream)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 FileInputStreamPlus (org.apache.cassandra.io.util.FileInputStreamPlus)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 DataOutputStreamPlus (org.apache.cassandra.io.util.DataOutputStreamPlus)1 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)1 EncryptionContext (org.apache.cassandra.security.EncryptionContext)1 BloomFilter (org.apache.cassandra.utils.BloomFilter)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1