Merge branch 'cassandra-3.1' into trunk

This commit is contained in:
Marcus Eriksson 2015-11-11 08:56:12 +01:00
commit 55811e5610
4 changed files with 17 additions and 21 deletions

View File

@ -6,6 +6,7 @@
3.1
Merged from 3.0:
* Keep the file open in trySkipCache (CASSANDRA-10669)
* Updated trigger example (CASSANDRA-10257)
Merged from 2.2:
* (Hadoop) fix splits calculation (CASSANDRA-10640)

View File

@ -59,7 +59,6 @@ public class SSTableRewriter extends Transactional.AbstractTransactional impleme
// the set of final readers we will expose on commit
private final LifecycleTransaction transaction; // the readers we are rewriting (updated as they are replaced)
private final List<SSTableReader> preparedForCommit = new ArrayList<>();
private final Map<Descriptor, Integer> fileDescriptors = new HashMap<>(); // the file descriptors for each reader descriptor we are rewriting
private long currentlyOpenedEarlyAt; // the position (in MB) in the target file we last (re)opened at
@ -87,8 +86,6 @@ public class SSTableRewriter extends Transactional.AbstractTransactional impleme
public SSTableRewriter(LifecycleTransaction transaction, long maxAge, boolean isOffline, long preemptiveOpenInterval, boolean keepOriginals)
{
this.transaction = transaction;
for (SSTableReader sstable : this.transaction.originals())
fileDescriptors.put(sstable.descriptor, CLibrary.getfd(sstable.getFilename()));
this.maxAge = maxAge;
this.isOffline = isOffline;
this.keepOriginals = keepOriginals;
@ -160,7 +157,7 @@ public class SSTableRewriter extends Transactional.AbstractTransactional impleme
for (SSTableReader reader : transaction.originals())
{
RowIndexEntry index = reader.getPosition(key, SSTableReader.Operator.GE);
CLibrary.trySkipCache(fileDescriptors.get(reader.descriptor), 0, index == null ? 0 : index.position, reader.getFilename());
CLibrary.trySkipCache(reader.getFilename(), 0, index == null ? 0 : index.position);
}
}
else

View File

@ -17,7 +17,9 @@
*/
package org.apache.cassandra.utils;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.channels.FileChannel;
@ -148,7 +150,18 @@ public final class CLibrary
public static void trySkipCache(String path, long offset, long len)
{
trySkipCache(getfd(path), offset, len, path);
File f = new File(path);
if (!f.exists())
return;
try (FileInputStream fis = new FileInputStream(f))
{
trySkipCache(getfd(fis.getChannel()), offset, len, path);
}
catch (IOException e)
{
logger.warn("Could not skip cache", e);
}
}
public static void trySkipCache(int fd, long offset, long len, String path)
@ -326,18 +339,4 @@ public final class CLibrary
return -1;
}
public static int getfd(String path)
{
try(FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ))
{
return getfd(channel);
}
catch (IOException e)
{
JVMStabilityInspector.inspectThrowable(e);
// ignore
return -1;
}
}
}

View File

@ -31,7 +31,6 @@ public class CLibraryTest
{
File file = FileUtils.createTempFile("testSkipCache", "1");
int fd = CLibrary.getfd(file.getPath());
CLibrary.trySkipCache(fd, 0, 0, file.getPath());
CLibrary.trySkipCache(file.getPath(), 0, 0);
}
}