mirror of https://github.com/apache/cassandra
replace foreachColumnFamily with getValidColumnFamilies + for loop
patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@888531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e574a962c
commit
27ca056725
|
|
@ -32,7 +32,6 @@ import javax.management.*;
|
||||||
import org.apache.cassandra.concurrent.*;
|
import org.apache.cassandra.concurrent.*;
|
||||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||||
import org.apache.cassandra.db.*;
|
import org.apache.cassandra.db.*;
|
||||||
import org.apache.cassandra.db.filter.QueryPath;
|
|
||||||
import org.apache.cassandra.dht.*;
|
import org.apache.cassandra.dht.*;
|
||||||
import org.apache.cassandra.gms.*;
|
import org.apache.cassandra.gms.*;
|
||||||
import org.apache.cassandra.locator.*;
|
import org.apache.cassandra.locator.*;
|
||||||
|
|
@ -651,15 +650,20 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
|
||||||
* @param tag the tag given to the snapshot (null is permissible)
|
* @param tag the tag given to the snapshot (null is permissible)
|
||||||
*/
|
*/
|
||||||
public void takeSnapshot(String tableName, String tag) throws IOException
|
public void takeSnapshot(String tableName, String tag) throws IOException
|
||||||
|
{
|
||||||
|
Table tableInstance = getValidTable(tableName);
|
||||||
|
tableInstance.snapshot(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Table getValidTable(String tableName) throws IOException
|
||||||
{
|
{
|
||||||
if (DatabaseDescriptor.getTable(tableName) == null)
|
if (DatabaseDescriptor.getTable(tableName) == null)
|
||||||
{
|
{
|
||||||
throw new IOException("Table " + tableName + "does not exist");
|
throw new IOException("Table " + tableName + "does not exist");
|
||||||
}
|
}
|
||||||
Table tableInstance = Table.open(tableName);
|
return Table.open(tableName);
|
||||||
tableInstance.snapshot(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a snapshot for every table.
|
* Takes a snapshot for every table.
|
||||||
*
|
*
|
||||||
|
|
@ -688,44 +692,23 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
|
||||||
logger_.debug("Cleared out all snapshot directories");
|
logger_.debug("Cleared out all snapshot directories");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Iterable<ColumnFamilyStore> getValidColumnFamilies(String tableName, String... columnFamilies) throws IOException
|
||||||
* Applies the given Function to all matching column families.
|
|
||||||
* @param function Function taking a column family and possibly returning an IOException.
|
|
||||||
* @param tableName Name of matching table.
|
|
||||||
* @param columnFamilies Names of matching column families, or null for all.
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void foreachColumnFamily(Function<ColumnFamilyStore, IOException> function, String tableName, String... columnFamilies) throws IOException
|
|
||||||
{
|
{
|
||||||
if (DatabaseDescriptor.getTable(tableName) == null)
|
Table table = getValidTable(tableName);
|
||||||
{
|
Set<ColumnFamilyStore> valid = new HashSet<ColumnFamilyStore>();
|
||||||
throw new IOException("Table " + tableName + "does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
Table table = Table.open(tableName);
|
for (String cfName : columnFamilies.length == 0 ? table.getColumnFamilies() : Arrays.asList(columnFamilies))
|
||||||
Set<String> positiveColumnFamilies = table.getColumnFamilies();
|
|
||||||
|
|
||||||
// no columnFamilies means flush'em all.
|
|
||||||
if (columnFamilies == null || columnFamilies.length == 0)
|
|
||||||
{
|
{
|
||||||
columnFamilies = positiveColumnFamilies.toArray(new String[positiveColumnFamilies.size()]);
|
ColumnFamilyStore cfStore = table.getColumnFamilyStore(cfName);
|
||||||
}
|
if (cfStore == null)
|
||||||
|
|
||||||
for (String columnFamily : columnFamilies)
|
|
||||||
{
|
|
||||||
if (positiveColumnFamilies.contains(columnFamily))
|
|
||||||
{
|
|
||||||
ColumnFamilyStore cfStore = table.getColumnFamilyStore(columnFamily);
|
|
||||||
IOException result = function.apply(cfStore);
|
|
||||||
if (result != null)
|
|
||||||
throw result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// this means there was a cf passed in that is not recognized in the keyspace. report it and continue.
|
// this means there was a cf passed in that is not recognized in the keyspace. report it and continue.
|
||||||
logger_.warn(String.format("Invalid column family specified: %s. Proceeding with others.", columnFamily));
|
logger_.warn(String.format("Invalid column family specified: %s. Proceeding with others.", cfName));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
valid.add(cfStore);
|
||||||
}
|
}
|
||||||
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -736,24 +719,13 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
|
||||||
*/
|
*/
|
||||||
public void forceTableFlush(final String tableName, final String... columnFamilies) throws IOException
|
public void forceTableFlush(final String tableName, final String... columnFamilies) throws IOException
|
||||||
{
|
{
|
||||||
foreachColumnFamily(new Function<ColumnFamilyStore, IOException>()
|
for (ColumnFamilyStore cfStore : getValidColumnFamilies(tableName, columnFamilies))
|
||||||
{
|
{
|
||||||
public IOException apply(ColumnFamilyStore cfStore)
|
logger_.debug("Forcing binary flush on keyspace " + tableName + ", CF " + cfStore.getColumnFamilyName());
|
||||||
{
|
cfStore.forceFlushBinary();
|
||||||
try
|
logger_.debug("Forcing flush on keyspace " + tableName + ", CF " + cfStore.getColumnFamilyName());
|
||||||
{
|
cfStore.forceFlush();
|
||||||
logger_.debug("Forcing binary flush on keyspace " + tableName + ", CF " + cfStore.getColumnFamilyName());
|
}
|
||||||
cfStore.forceFlushBinary();
|
|
||||||
logger_.debug("Forcing flush on keyspace " + tableName + ", CF " + cfStore.getColumnFamilyName());
|
|
||||||
cfStore.forceFlush();
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, tableName, columnFamilies);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -767,18 +739,12 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
|
||||||
// request that all relevant endpoints generate trees
|
// request that all relevant endpoints generate trees
|
||||||
final MessagingService ms = MessagingService.instance();
|
final MessagingService ms = MessagingService.instance();
|
||||||
final List<InetAddress> endpoints = getNaturalEndpoints(getLocalToken());
|
final List<InetAddress> endpoints = getNaturalEndpoints(getLocalToken());
|
||||||
foreachColumnFamily(new Function<ColumnFamilyStore, IOException>()
|
for (ColumnFamilyStore cfStore : getValidColumnFamilies(tableName, columnFamilies))
|
||||||
{
|
{
|
||||||
public IOException apply(ColumnFamilyStore cfStore)
|
Message request = TreeRequestVerbHandler.makeVerb(tableName, cfStore.getColumnFamilyName());
|
||||||
{
|
for (InetAddress endpoint : endpoints)
|
||||||
Message request = TreeRequestVerbHandler.makeVerb(tableName,
|
ms.sendOneWay(request, endpoint);
|
||||||
cfStore.getColumnFamilyName());
|
}
|
||||||
for (InetAddress endpoint : endpoints)
|
|
||||||
ms.sendOneWay(request, endpoint);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, tableName, columnFamilies);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of MBean interface methods */
|
/* End of MBean interface methods */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue