add autobootstrap

patch by jbellis; reviewed by Eric Evans for CASSANDRA-438

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@822876 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-10-07 19:41:47 +00:00
parent fe1aa5b52d
commit ff3dd4dcec
3 changed files with 39 additions and 13 deletions

View File

@ -102,17 +102,12 @@ launch_service()
{
pidpath=$1
foreground=$2
bootstrap=$3
cassandra_parms="-Dcassandra -Dstorage-config=$CASSANDRA_CONF"
if [ "x$pidpath" != "x" ]; then
cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath"
fi
if [ "x$bootstrap" != "x" ]; then
cassandra_parms="$cassandra_parms -Dbootstrap=$bootstrap"
fi
# The cassandra-foreground option will tell CassandraDaemon not
# to close stdout/stderr, but it's up to us not to background.
if [ "x$foreground" != "x" ]; then
@ -143,10 +138,6 @@ while true; do
foreground="yes"
shift
;;
-b)
bootstrap="true"
shift
;;
-h)
echo "Usage: $0 [-f] [-h] [-p pidfile] [-b]"
exit 0
@ -163,7 +154,7 @@ while true; do
done
# Start up the service
launch_service "$pidfile" "$foreground" "$bootstrap"
launch_service "$pidfile" "$foreground"
exit $?

View File

@ -27,9 +27,11 @@ import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.utils.BasicUtilities;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.db.filter.IdentityQueryFilter;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.filter.QueryFilter;
import org.apache.cassandra.db.filter.NamesQueryFilter;
import org.apache.cassandra.net.EndPoint;
public class SystemTable
@ -38,6 +40,7 @@ public class SystemTable
public static final String STATUS_CF = "LocationInfo"; // keep the old CF string for backwards-compatibility
private static final String LOCATION_KEY = "L";
private static final String BOOTSTRAP_KEY = "Bootstrap";
private static final byte[] BOOTSTRAP = utf8("B");
private static final byte[] TOKEN = utf8("Token");
private static final byte[] GENERATION = utf8("Generation");
private static StorageMetadata metadata;
@ -135,6 +138,38 @@ public class SystemTable
return metadata;
}
public static boolean isBootstrapped()
{
Table table = null;
try
{
table = Table.open(Table.SYSTEM_TABLE);
QueryFilter filter = new NamesQueryFilter(BOOTSTRAP_KEY, new QueryPath(STATUS_CF), BOOTSTRAP);
ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
return cf != null;
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
public static void setBootstrapped()
{
ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, STATUS_CF);
cf.addColumn(new Column(BOOTSTRAP, new byte[] {1}, System.currentTimeMillis()));
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, BOOTSTRAP_KEY);
rm.add(cf);
try
{
rm.apply();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
public static class StorageMetadata
{
private Token token;

View File

@ -137,11 +137,10 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
*/
public static StorageService instance()
{
String bs = System.getProperty("bootstrap");
boolean bootstrap = bs != null && bs.contains("true");
if (instance_ == null)
{
boolean bootstrap = !(DatabaseDescriptor.getSeeds().contains(getLocalControlEndPoint().getHost()) || SystemTable.isBootstrapped());
synchronized (StorageService.class)
{
if (instance_ == null)
@ -205,6 +204,7 @@ public final class StorageService implements IEndPointStateChangeSubscriber, Sto
logger_.debug("Removed " + s.getHost() + " as a bootstrap source");
if (bootstrapSet.isEmpty())
{
SystemTable.setBootstrapped();
isBootstrapMode = false;
updateTokenMetadata(storageMetadata_.getToken(), StorageService.tcpAddr_, false);