Example usage for org.apache.cassandra.service StorageServiceMBean forceKeyspaceFlush

List of usage examples for org.apache.cassandra.service StorageServiceMBean forceKeyspaceFlush

Introduction

In this page you can find the example usage for org.apache.cassandra.service StorageServiceMBean forceKeyspaceFlush.

Prototype

public void forceKeyspaceFlush(String keyspaceName, String... tableNames)
        throws IOException, ExecutionException, InterruptedException;

Source Link

Document

Flush all memtables for the given column families, or all columnfamilies for the given keyspace if none are explicitly listed.

Usage

From source file:org.apache.beam.sdk.io.cassandra.CassandraIOTest.java

License:Apache License

/**
 * Force the flush of cassandra memTables to SSTables to update size_estimates.
 * https://wiki.apache.org/cassandra/MemtableSSTable This is what cassandra spark connector does
 * through nodetool binary call. See:/*from www  .j a  v  a 2  s .  c om*/
 * https://github.com/datastax/spark-cassandra-connector/blob/master/spark-cassandra-connector
 * /src/it/scala/com/datastax/spark/connector/rdd/partitioner/DataSizeEstimatesSpec.scala which
 * uses the same JMX service as bellow. See:
 * https://github.com/apache/cassandra/blob/cassandra-3.X
 * /src/java/org/apache/cassandra/tools/nodetool/Flush.java
 */
@SuppressWarnings("unused")
private static void flushMemTables() throws Exception {
    JMXServiceURL url = new JMXServiceURL(String.format("service:jmx:rmi://%s/jndi/rmi://%s:%s/jmxrmi",
            CASSANDRA_HOST, CASSANDRA_HOST, jmxPort));
    JMXConnector jmxConnector = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
    ObjectName objectName = new ObjectName(STORAGE_SERVICE_MBEAN);
    StorageServiceMBean mBeanProxy = JMX.newMBeanProxy(mBeanServerConnection, objectName,
            StorageServiceMBean.class);
    mBeanProxy.forceKeyspaceFlush(CASSANDRA_KEYSPACE, CASSANDRA_TABLE);
    jmxConnector.close();
    Thread.sleep(FLUSH_TIMEOUT);
}