Search in sources :

Example 6 with QueryFilter

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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Example 7 with QueryFilter

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;
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) ByteBuffer(java.nio.ByteBuffer)

Example 8 with QueryFilter

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();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ConfigurationException(org.apache.cassandra.config.ConfigurationException)

Example 9 with QueryFilter

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) Token(org.apache.cassandra.dht.Token) ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IOError(java.io.IOError) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 10 with QueryFilter

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());
}
Also used : ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) ConfigurationException(org.apache.cassandra.config.ConfigurationException)

Aggregations

QueryFilter (org.apache.cassandra.db.filter.QueryFilter)26 QueryPath (org.apache.cassandra.db.filter.QueryPath)22 ByteBuffer (java.nio.ByteBuffer)7 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)7 ColumnFamily (org.apache.cassandra.db.ColumnFamily)6 File (java.io.File)5 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)5 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)5 Test (org.junit.Test)5 IColumn (org.apache.cassandra.db.IColumn)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 CloseableIterator (org.apache.cassandra.utils.CloseableIterator)3 ArrayList (java.util.ArrayList)2 ConfigurationException (org.apache.cassandra.config.ConfigurationException)2 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)2 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)2 SliceQueryFilter (org.apache.cassandra.db.filter.SliceQueryFilter)2 Closeable (java.io.Closeable)1