Search in sources :

Example 11 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath 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 12 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath 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 13 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class SystemTable method setIndexRemoved.

public static void setIndexRemoved(String table, String indexName) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ByteBufferUtil.bytes(table));
    rm.delete(new QueryPath(INDEX_CF, null, ByteBufferUtil.bytes(indexName)), LamportClock.getVersion());
    try {
        rm.apply();
    } catch (IOException e) {
        throw new IOError(e);
    }
    forceBlockingFlush(INDEX_CF);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) IOError(java.io.IOError) IOException(java.io.IOException)

Example 14 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath 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)

Example 15 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class Migration method getLastMigrationId.

public static UUID getLastMigrationId() {
    DecoratedKey<?> dkey = StorageService.getPartitioner().decorateKey(LAST_MIGRATION_KEY);
    Table defs = Table.open(Table.SYSTEM_TABLE);
    ColumnFamilyStore cfStore = defs.getColumnFamilyStore(SCHEMA_CF);
    QueryFilter filter = QueryFilter.getNamesFilter(dkey, new QueryPath(SCHEMA_CF), LAST_MIGRATION_KEY);
    ColumnFamily cf = cfStore.getColumnFamily(filter);
    if (cf == null || cf.getColumnNames().size() == 0)
        return null;
    else
        return UUIDGen.getUUID(cf.getColumn(LAST_MIGRATION_KEY).value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)123 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)11 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 IColumn (org.apache.cassandra.db.IColumn)6 ArrayList (java.util.ArrayList)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4