From 825b11a9d533261d09cb1c2ff91f4b7423046dbc Mon Sep 17 00:00:00 2001 From: Saint <sainthxd@gmail.com> Date: Thu, 23 Jun 2016 11:25:20 +0800 Subject: [PATCH] [cassandra2] add sigar dependency in the test scope and tracing function --- cassandra2/pom.xml | 64 +++++++++++++++++++ .../com/yahoo/ycsb/db/CassandraCQLClient.java | 26 ++++++-- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/cassandra2/pom.xml b/cassandra2/pom.xml index 28a843bc..45916e79 100644 --- a/cassandra2/pom.xml +++ b/cassandra2/pom.xml @@ -62,6 +62,14 @@ LICENSE file. <version>4.12</version> <scope>test</scope> </dependency> + <!-- only for Cassandra test (Cassandra 2.2+ uses Sigar for collecting system information, and Sigar requires some native lib files) --> + <dependency> + <groupId>org.hyperic</groupId> + <artifactId>sigar-dist</artifactId> + <version>1.6.4.129</version> + <type>zip</type> + <scope>test</scope> + </dependency> </dependencies> <profiles> @@ -78,4 +86,60 @@ LICENSE file. </properties> </profile> </profiles> + <!-- sigar-dist can be downloaded from jboss repository --> + <repositories> + <repository> + <id>central2</id> + <name>sigar Repository</name> + <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url> + <layout>default</layout> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + <!-- unzip sigar-dist/lib files. + References: + http://stackoverflow.com/questions/5388661/unzip-dependency-in-maven + https://arviarya.wordpress.com/2013/09/22/sigar-access-operating-system-and-hardware-level-information/ + --> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack-sigar</id> + <phase>process-test-resources<!-- or any other valid maven phase --></phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <includeGroupIds>org.hyperic</includeGroupIds> + <includeArtifactIds>sigar-dist</includeArtifactIds> + <includes>**/sigar-bin/lib/*</includes> + <excludes>**/sigar-bin/lib/*jar</excludes> + <outputDirectory> + ${project.build.directory}/cassandra-dependency + </outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.8</version> + <configuration> + <systemProperties> + <property> + <name>java.library.path</name> + <value>${project.build.directory}/cassandra-dependency/hyperic-sigar-1.6.4/sigar-bin/lib</value> + </property> + </systemProperties> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/cassandra2/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java b/cassandra2/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java index d4dc8c77..91faf029 100644 --- a/cassandra2/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java +++ b/cassandra2/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java @@ -64,7 +64,9 @@ public class CassandraCQLClient extends DB { public static final String KEYSPACE_PROPERTY_DEFAULT = "ycsb"; public static final String USERNAME_PROPERTY = "cassandra.username"; public static final String PASSWORD_PROPERTY = "cassandra.password"; - + public static final String TRACING_PROPERTY = "cassandra.tracing"; + public static final String TRACING_PROPERTY_DEFAULT = "false"; + public static final String HOSTS_PROPERTY = "hosts"; public static final String PORT_PROPERTY = "port"; public static final String PORT_PROPERTY_DEFAULT = "9042"; @@ -92,7 +94,9 @@ public class CassandraCQLClient extends DB { private static final AtomicInteger INIT_COUNT = new AtomicInteger(0); private static boolean debug = false; - + + private static boolean trace = false; + /** * Initialize any state for this DB. Called once per DB instance; there is one * DB instance per client thread. @@ -116,7 +120,7 @@ public class CassandraCQLClient extends DB { debug = Boolean.parseBoolean(getProperties().getProperty("debug", "false")); - + trace = Boolean.valueOf(getProperties().getProperty(TRACING_PROPERTY, TRACING_PROPERTY_DEFAULT)); String host = getProperties().getProperty(HOSTS_PROPERTY); if (host == null) { throw new DBException(String.format( @@ -254,7 +258,9 @@ public class CassandraCQLClient extends DB { if (debug) { System.out.println(stmt.toString()); } - + if (trace) { + stmt.enableTracing(); + } ResultSet rs = session.execute(stmt); if (rs.isExhausted()) { @@ -343,7 +349,9 @@ public class CassandraCQLClient extends DB { if (debug) { System.out.println(stmt.toString()); } - + if (trace) { + stmt.enableTracing(); + } ResultSet rs = session.execute(stmt); HashMap<String, ByteIterator> tuple; @@ -432,7 +440,9 @@ public class CassandraCQLClient extends DB { if (debug) { System.out.println(insertStmt.toString()); } - + if (trace) { + insertStmt.enableTracing(); + } session.execute(insertStmt); return Status.OK; @@ -465,7 +475,9 @@ public class CassandraCQLClient extends DB { if (debug) { System.out.println(stmt.toString()); } - + if (trace) { + stmt.enableTracing(); + } session.execute(stmt); return Status.OK; -- GitLab