mirror of https://github.com/apache/cassandra
move deleteAsync into DeletionService. patch by jbellis
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@894451 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dc6e4fe55f
commit
3655e91f56
|
|
@ -21,7 +21,7 @@ package org.apache.cassandra.db;
|
|||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.io.util.BufferedRandomAccessFile;
|
||||
import org.apache.cassandra.io.util.DataOutputBuffer;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
import org.apache.cassandra.io.DeletionService;
|
||||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.concurrent.StageManager;
|
||||
|
||||
|
|
@ -570,7 +570,7 @@ public class CommitLog
|
|||
if (header.isSafeToDelete())
|
||||
{
|
||||
logger_.info("Deleting obsolete commit log:" + oldFile);
|
||||
FileUtils.deleteAsync(oldFile);
|
||||
DeletionService.deleteAsync(oldFile);
|
||||
clHeaders_.remove(oldFile);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package org.apache.cassandra.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
|
||||
public class DeletionService
|
||||
{
|
||||
public static final ExecutorService executor = new JMXEnabledThreadPoolExecutor("FILEUTILS-DELETE-POOL");
|
||||
|
||||
public static void deleteAsync(final String file) throws IOException
|
||||
{
|
||||
Runnable deleter = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtils.deleteWithConfirm(new File(file));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
executor.submit(deleter);
|
||||
}
|
||||
}
|
||||
|
|
@ -37,43 +37,17 @@ public class FileUtils
|
|||
private static final double gb_ = 1024*1024*1024d;
|
||||
private static final double tb_ = 1024*1024*1024*1024d;
|
||||
|
||||
private static ExecutorService deleter_ = new JMXEnabledThreadPoolExecutor("FILEUTILS-DELETE-POOL");
|
||||
|
||||
public static void shutdown()
|
||||
{
|
||||
deleter_.shutdownNow();
|
||||
}
|
||||
|
||||
public static void deleteWithConfirm(File file) throws IOException
|
||||
{
|
||||
assert file.exists() : "attempted to delete non-existing file " + file.getName();
|
||||
if (logger_.isDebugEnabled())
|
||||
logger_.debug("Deleting " + file.getName());
|
||||
if (!file.delete())
|
||||
{
|
||||
throw new IOException("Failed to delete " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Deleter implements Runnable
|
||||
{
|
||||
File file_ = null;
|
||||
|
||||
public Deleter(File f)
|
||||
{
|
||||
file_ = f;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
if(file_ == null)
|
||||
return;
|
||||
logger_.debug("Deleting " + file_.getName());
|
||||
if (!file_.delete())
|
||||
{
|
||||
logger_.error("Unable to delete file " + file_.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FileComparator implements Comparator<File>
|
||||
{
|
||||
public int compare(File f, File f2)
|
||||
|
|
@ -113,13 +87,6 @@ public class FileUtils
|
|||
return f.delete();
|
||||
}
|
||||
|
||||
public static void deleteAsync(String file) throws IOException
|
||||
{
|
||||
File f = new File(file);
|
||||
Runnable deleter = new Deleter(f);
|
||||
deleter_.submit(deleter);
|
||||
}
|
||||
|
||||
public static boolean delete(List<String> files) throws IOException
|
||||
{
|
||||
boolean bVal = true;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.util.TreeMap;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import DataOutputBuffer;
|
||||
import org.apache.cassandra.io.util.DataOutputBuffer;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import static org.apache.cassandra.Util.column;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.apache.commons.lang.ArrayUtils;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.io.util.DataOutputBuffer;
|
||||
|
||||
public class ReadMessageTest
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.cassandra.dht.IPartitioner;
|
|||
import org.apache.cassandra.io.SSTableAccessor;
|
||||
import org.apache.cassandra.io.SSTableReader;
|
||||
import org.apache.cassandra.io.SSTableWriter;
|
||||
import org.apache.cassandra.io.util.DataOutputBuffer;
|
||||
import static org.apache.cassandra.Util.createTemporarySSTable;
|
||||
import static org.apache.cassandra.utils.FBUtilities.hexToBytes;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
|
|||
Loading…
Reference in New Issue