use of org.apache.cassandra.db.filter.QueryFilter in project eiger by wlloyd.
the class SystemTable method isBootstrapped.
public static boolean isBootstrapped() {
Table table = Table.open(Table.SYSTEM_TABLE);
QueryFilter filter = QueryFilter.getNamesFilter(decorate(BOOTSTRAP_KEY), new QueryPath(STATUS_CF), BOOTSTRAP);
ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
if (cf == null)
return false;
IColumn c = cf.getColumn(BOOTSTRAP);
return c.value().get(c.value().position()) == 1;
}
use of org.apache.cassandra.db.filter.QueryFilter in project eiger by wlloyd.
the class SystemTable method getCurrentLocalNodeId.
/**
* Read the current local node id from the system table or null if no
* such node id is recorded.
*/
public static NodeId getCurrentLocalNodeId() {
ByteBuffer id = null;
Table table = Table.open(Table.SYSTEM_TABLE);
QueryFilter filter = QueryFilter.getIdentityFilter(decorate(CURRENT_LOCAL_NODE_ID_KEY), new QueryPath(NODE_ID_CF));
ColumnFamily cf = table.getColumnFamilyStore(NODE_ID_CF).getColumnFamily(filter);
if (cf != null) {
// Even though gc_grace==0 on System table, we can have a race where we get back tombstones (see CASSANDRA-2824)
cf = ColumnFamilyStore.removeDeleted(cf, 0);
assert cf.getColumnCount() <= 1;
if (cf.getColumnCount() > 0)
id = cf.iterator().next().name();
}
if (id != null) {
return NodeId.wrap(id);
} else {
return null;
}
}
use of org.apache.cassandra.db.filter.QueryFilter in project eiger by wlloyd.
the class SystemTable method purgeIncompatibleHints.
/** if hints become incompatible across versions of cassandra, that logic (and associated purging) is managed here. */
private static void purgeIncompatibleHints() throws IOException {
ByteBuffer upgradeMarker = ByteBufferUtil.bytes("Pre-1.0 hints purged");
Table table = Table.open(Table.SYSTEM_TABLE);
QueryFilter filter = QueryFilter.getNamesFilter(decorate(COOKIE_KEY), new QueryPath(STATUS_CF), upgradeMarker);
ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
if (cf != null) {
logger.debug("Pre-1.0 hints already purged");
return;
}
// marker not found. Snapshot + remove hints and add the marker
ColumnFamilyStore hintsCfs = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HintedHandOffManager.HINTS_CF);
if (hintsCfs.getSSTables().size() > 0) {
logger.info("Possible old-format hints found. Truncating");
try {
hintsCfs.truncate();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
logger.debug("Marking pre-1.0 hints purged");
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, COOKIE_KEY);
rm.add(new QueryPath(STATUS_CF, null, upgradeMarker), ByteBufferUtil.bytes("oh yes, they were purged"), LamportClock.getVersion());
rm.apply();
}
use of org.apache.cassandra.db.filter.QueryFilter in project eiger by wlloyd.
the class SystemTable method loadTokens.
/**
* Return a map of stored tokens to IP addresses
*
*/
public static HashMap<Token, InetAddress> loadTokens() {
HashMap<Token, InetAddress> tokenMap = new HashMap<Token, InetAddress>();
IPartitioner p = StorageService.getPartitioner();
Table table = Table.open(Table.SYSTEM_TABLE);
QueryFilter filter = QueryFilter.getIdentityFilter(decorate(RING_KEY), new QueryPath(STATUS_CF));
ColumnFamily cf = ColumnFamilyStore.removeDeleted(table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter), Integer.MAX_VALUE);
if (cf != null) {
for (IColumn column : cf.getSortedColumns()) {
try {
ByteBuffer v = column.value();
byte[] addr = new byte[v.remaining()];
ByteBufferUtil.arrayCopy(v, v.position(), addr, 0, v.remaining());
tokenMap.put(p.getTokenFactory().fromByteArray(column.name()), InetAddress.getByAddress(addr));
} catch (UnknownHostException e) {
throw new IOError(e);
}
}
}
return tokenMap;
}
use of org.apache.cassandra.db.filter.QueryFilter in project eiger by wlloyd.
the class SystemTable method checkHealth.
/**
* One of three things will happen if you try to read the system table:
* 1. files are present and you can read them: great
* 2. no files are there: great (new node is assumed)
* 3. files are present but you can't read them: bad
* @throws ConfigurationException
*/
public static void checkHealth() throws ConfigurationException, IOException {
Table table = null;
try {
table = Table.open(Table.SYSTEM_TABLE);
} catch (AssertionError err) {
// this happens when a user switches from OPP to RP.
ConfigurationException ex = new ConfigurationException("Could not read system table!");
ex.initCause(err);
throw ex;
}
SortedSet<ByteBuffer> cols = new TreeSet<ByteBuffer>(BytesType.instance);
cols.add(CLUSTERNAME);
QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCATION_KEY), new QueryPath(STATUS_CF), cols);
ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
if (cf == null) {
// this is a brand new node
ColumnFamilyStore cfs = table.getColumnFamilyStore(STATUS_CF);
if (!cfs.getSSTables().isEmpty())
throw new ConfigurationException("Found system table files, but they couldn't be loaded!");
// no system files. this is a new node.
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF);
cf.addColumn(new Column(CLUSTERNAME, ByteBufferUtil.bytes(DatabaseDescriptor.getClusterName()), LamportClock.getVersion()));
rm.add(cf);
rm.apply();
return;
}
IColumn clusterCol = cf.getColumn(CLUSTERNAME);
assert clusterCol != null;
String savedClusterName = ByteBufferUtil.string(clusterCol.value());
if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName());
}
Aggregations