Author: jbellis
Date: Tue Nov 2 23:21:41 2010
New Revision: 1030280
URL: http://svn.apache.org/viewvc?rev=1030280&view=rev
Log:
move code dealing w/ native constructs into clibrary; make native clibrary code
private. patch by jbellis
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/gms/Gossiper.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Tue Nov 2 23:21:41 2010
@@ -1202,15 +1202,15 @@ public class ColumnFamilyStore implement
// hard links
File targetLink = new File(snapshotDirectoryPath,
sourceFile.getName());
- FileUtils.createHardLink(sourceFile, targetLink);
+ CLibrary.createHardLink(sourceFile, targetLink);
sourceFile = new File(ssTable.indexFilename());
targetLink = new File(snapshotDirectoryPath, sourceFile.getName());
- FileUtils.createHardLink(sourceFile, targetLink);
+ CLibrary.createHardLink(sourceFile, targetLink);
sourceFile = new File(ssTable.filterFilename());
targetLink = new File(snapshotDirectoryPath, sourceFile.getName());
- FileUtils.createHardLink(sourceFile, targetLink);
+ CLibrary.createHardLink(sourceFile, targetLink);
if (logger_.isDebugEnabled())
logger_.debug("Snapshot for " + table_ + " table data file " +
sourceFile.getAbsolutePath() +
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/gms/Gossiper.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/gms/Gossiper.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/gms/Gossiper.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/gms/Gossiper.java
Tue Nov 2 23:21:41 2010
@@ -414,18 +414,18 @@ public class Gossiper implements IFailur
evictFromMembership(endpoint);
}
}
-
- if (!justRemovedEndPoints_.isEmpty())
+ }
+
+ if (!justRemovedEndPoints_.isEmpty())
+ {
+ Hashtable<InetAddress, Long> copy = new Hashtable<InetAddress,
Long>(justRemovedEndPoints_);
+ for (Map.Entry<InetAddress, Long> entry : copy.entrySet())
{
- Hashtable<InetAddress, Long> copy = new Hashtable<InetAddress,
Long>(justRemovedEndPoints_);
- for (Map.Entry<InetAddress, Long> entry : copy.entrySet())
+ if ((now - entry.getValue()) > StorageService.RING_DELAY)
{
- if ((now - entry.getValue()) > StorageService.RING_DELAY)
- {
- if (logger_.isDebugEnabled())
- logger_.debug(StorageService.RING_DELAY + "
elapsed, " + entry.getKey() + " gossip quarantine over");
- justRemovedEndPoints_.remove(entry.getKey());
- }
+ if (logger_.isDebugEnabled())
+ logger_.debug(StorageService.RING_DELAY + " elapsed, "
+ entry.getKey() + " gossip quarantine over");
+ justRemovedEndPoints_.remove(entry.getKey());
}
}
}
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileUtils.java
Tue Nov 2 23:21:41 2010
@@ -151,29 +151,6 @@ public class FileUtils
}
/**
- * calculate the total space used by a file or directory
- *
- * @param path the path
- * @return total space used.
- */
- public static long getUsedDiskSpaceForPath(String path)
- {
- File file = new File(path);
-
- if (file.isFile())
- {
- return file.length();
- }
-
- long diskSpace = 0;
- for (File childFile: file.listFiles())
- {
- diskSpace += getUsedDiskSpaceForPath(childFile.getPath());
- }
- return diskSpace;
- }
-
- /**
* Deletes all files and subdirectories under "dir".
* @param dir Directory to be deleted
* @throws IOException if any part of the tree cannot be deleted
@@ -192,66 +169,4 @@ public class FileUtils
// The directory is now empty so now it can be smoked
deleteWithConfirm(dir);
}
-
- /**
- * Create a hard link for a given file.
- *
- * @param sourceFile The name of the source file.
- * @param destinationFile The name of the destination file.
- *
- * @throws IOException if an error has occurred while creating the link.
- */
- public static void createHardLink(File sourceFile, File destinationFile)
throws IOException
- {
- try
- {
- int result = CLibrary.link(sourceFile.getAbsolutePath(),
destinationFile.getAbsolutePath());
- assert result == 0; // success is always zero
- }
- catch (UnsatisfiedLinkError e)
- {
- createHardLinkWithExec(sourceFile, destinationFile);
- }
- catch (RuntimeException e)
- {
- if (!(e instanceof LastErrorException))
- throw e;
- // there are 17 different error codes listed on the man page.
punt until/unless we find which
- // ones actually turn up in practice.
- throw new IOException(String.format("Unable to create hard link
from %s to %s (errno %d)",
- sourceFile, destinationFile,
CLibrary.errno(e)));
- }
- }
-
- private static void createHardLinkWithExec(File sourceFile, File
destinationFile) throws IOException
- {
- String osname = System.getProperty("os.name");
- ProcessBuilder pb;
- if (osname.startsWith("Windows"))
- {
- float osversion =
Float.parseFloat(System.getProperty("os.version"));
- if (osversion >= 6.0f)
- {
- pb = new ProcessBuilder("cmd", "/c", "mklink", "/H",
destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
- }
- else
- {
- pb = new ProcessBuilder("fsutil", "hardlink", "create",
destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
- }
- }
- else
- {
- pb = new ProcessBuilder("ln", sourceFile.getAbsolutePath(),
destinationFile.getAbsolutePath());
- pb.redirectErrorStream(true);
- }
- Process p = pb.start();
- try
- {
- p.waitFor();
- }
- catch (InterruptedException e)
- {
- throw new RuntimeException(e);
- }
- }
}
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/CassandraDaemon.java
Tue Nov 2 23:21:41 2010
@@ -64,7 +64,7 @@ public class CassandraDaemon
private void setup() throws IOException, TTransportException
{
- FBUtilities.tryMlockall();
+ CLibrary.tryMlockall();
// log4j
String file = System.getProperty("storage-config") + File.separator +
"log4j.properties";
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/CLibrary.java
Tue Nov 2 23:21:41 2010
@@ -18,6 +18,9 @@
*/
package org.apache.cassandra.utils;
+import java.io.File;
+import java.io.IOException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,10 +31,10 @@ public final class CLibrary
{
private static Logger logger = LoggerFactory.getLogger(CLibrary.class);
- public static final int MCL_CURRENT = 1;
- public static final int MCL_FUTURE = 2;
+ private static final int MCL_CURRENT = 1;
+ private static final int MCL_FUTURE = 2;
- public static final int ENOMEM = 12;
+ private static final int ENOMEM = 12;
static
{
@@ -49,12 +52,12 @@ public final class CLibrary
}
}
- public static native int mlockall(int flags) throws LastErrorException;
- public static native int munlockall() throws LastErrorException;
+ private static native int mlockall(int flags) throws LastErrorException;
+ private static native int munlockall() throws LastErrorException;
- public static native int link(String from, String to) throws
LastErrorException;
+ private static native int link(String from, String to) throws
LastErrorException;
- public static int errno(RuntimeException e)
+ private static int errno(RuntimeException e)
{
assert e instanceof LastErrorException;
try
@@ -69,4 +72,95 @@ public final class CLibrary
}
private CLibrary() {}
+
+ public static void tryMlockall()
+ {
+ try
+ {
+ int result = mlockall(MCL_CURRENT);
+ assert result == 0; // mlockall should always be zero on success
+ }
+ catch (UnsatisfiedLinkError e)
+ {
+ // this will have already been logged by CLibrary, no need to
repeat it
+ }
+ catch (RuntimeException e)
+ {
+ if (!(e instanceof LastErrorException))
+ throw e;
+ if (errno(e) == ENOMEM &&
System.getProperty("os.name").toLowerCase().contains("linux"))
+ {
+ logger.warn("Unable to lock JVM memory (ENOMEM)."
+ + " This can result in part of the JVM being
swapped out, especially with mmapped I/O enabled."
+ + " Increase RLIMIT_MEMLOCK or run Cassandra as
root.");
+ }
+ else if
(!System.getProperty("os.name").toLowerCase().contains("mac"))
+ {
+ // OS X allows mlockall to be called, but always returns an
error
+ logger.warn("Unknown mlockall error " + errno(e));
+ }
+ }
+ }
+
+ /**
+ * Create a hard link for a given file.
+ *
+ * @param sourceFile The name of the source file.
+ * @param destinationFile The name of the destination file.
+ *
+ * @throws java.io.IOException if an error has occurred while creating the
link.
+ */
+ public static void createHardLink(File sourceFile, File destinationFile)
throws IOException
+ {
+ try
+ {
+ int result = link(sourceFile.getAbsolutePath(),
destinationFile.getAbsolutePath());
+ assert result == 0; // success is always zero
+ }
+ catch (UnsatisfiedLinkError e)
+ {
+ createHardLinkWithExec(sourceFile, destinationFile);
+ }
+ catch (RuntimeException e)
+ {
+ if (!(e instanceof LastErrorException))
+ throw e;
+ // there are 17 different error codes listed on the man page.
punt until/unless we find which
+ // ones actually turn up in practice.
+ throw new IOException(String.format("Unable to create hard link
from %s to %s (errno %d)",
+ sourceFile, destinationFile,
errno(e)));
+ }
+ }
+
+ private static void createHardLinkWithExec(File sourceFile, File
destinationFile) throws IOException
+ {
+ String osname = System.getProperty("os.name");
+ ProcessBuilder pb;
+ if (osname.startsWith("Windows"))
+ {
+ float osversion =
Float.parseFloat(System.getProperty("os.version"));
+ if (osversion >= 6.0f)
+ {
+ pb = new ProcessBuilder("cmd", "/c", "mklink", "/H",
destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
+ }
+ else
+ {
+ pb = new ProcessBuilder("fsutil", "hardlink", "create",
destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
+ }
+ }
+ else
+ {
+ pb = new ProcessBuilder("ln", sourceFile.getAbsolutePath(),
destinationFile.getAbsolutePath());
+ pb.redirectErrorStream(true);
+ }
+ Process p = pb.start();
+ try
+ {
+ p.waitFor();
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
Modified:
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=1030280&r1=1030279&r2=1030280&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java
(original)
+++
cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/FBUtilities.java
Tue Nov 2 23:21:41 2010
@@ -551,33 +551,4 @@ public class FBUtilities
throw new RuntimeException(e);
}
}
-
- public static void tryMlockall()
- {
- try
- {
- int result = CLibrary.mlockall(CLibrary.MCL_CURRENT);
- assert result == 0; // mlockall should always be zero on success
- }
- catch (UnsatisfiedLinkError e)
- {
- // this will have already been logged by CLibrary, no need to
repeat it
- }
- catch (RuntimeException e)
- {
- if (!(e instanceof LastErrorException))
- throw e;
- if (CLibrary.errno(e) == CLibrary.ENOMEM &&
System.getProperty("os.name").toLowerCase().contains("linux"))
- {
- logger_.warn("Unable to lock JVM memory (ENOMEM)."
- + " This can result in part of the JVM being
swapped out, especially with mmapped I/O enabled."
- + " Increase RLIMIT_MEMLOCK or run Cassandra as
root.");
- }
- else if
(!System.getProperty("os.name").toLowerCase().contains("mac"))
- {
- // OS X allows mlockall to be called, but always returns an
error
- logger_.warn("Unknown mlockall error " + CLibrary.errno(e));
- }
- }
- }
}