Search in sources :

Example 16 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerServiceTest method testSkipCreateOnConfig.

@Test
public void testSkipCreateOnConfig() throws Exception {
    KsDef ksDef = setupOtherKeyspace(configuration, "SkipCreatedKeyspace", false);
    cassandraClientHolder.getClient().system_add_keyspace(ksDef);
    schemaManagerService.createKeyspaceSchemasIfNeeded();
    List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
    boolean skipped = false;
    for (KsDef ks : keyspaces) {
        if (StringUtils.equals(ks.name, "SkipCreatedKeyspace")) {
            skipped = true;
        }
    }
    assertTrue(skipped);
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) Test(org.junit.Test)

Example 17 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerServiceTest method testCreateOnConfig.

@Test
public void testCreateOnConfig() throws Exception {
    KsDef ksDef = setupOtherKeyspace(configuration, "ConfigCreatedKeyspace", false);
    cassandraClientHolder.getClient().system_add_keyspace(ksDef);
    configuration.setBoolean("cassandra.autoCreateHiveSchema", true);
    schemaManagerService.createKeyspaceSchemasIfNeeded();
    List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
    for (KsDef ks : keyspaces) {
        if (StringUtils.equals(ks.name, "ConfigCreatedKeyspace")) {
            fail("keyspace not created by configuration");
        }
    }
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) Test(org.junit.Test)

Example 18 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerServiceTest method testDiscoverUnmappedKeyspaces.

@Test
public void testDiscoverUnmappedKeyspaces() throws Exception {
    cassandraClientHolder.getClient().system_add_keyspace(setupOtherKeyspace(configuration, "OtherKeyspace", false));
    // init the meta store for usage
    List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
    boolean foundCreated = false;
    // don't impose a keyspace maintenance burden. Looking for specifics is good enough
    for (KsDef ksDef : keyspaces) {
        if (StringUtils.equals(ksDef.name, "OtherKeyspace")) {
            foundCreated = true;
            break;
        }
    }
    assertTrue(foundCreated);
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) Test(org.junit.Test)

Example 19 with KsDef

use of org.apache.cassandra.thrift.KsDef in project coprhd-controller by CoprHD.

the class SchemaUtil method addColumnFamily.

/**
 * Adds CF to keyspace
 *
 * @param def
 * @return
 */
@SuppressWarnings("unchecked")
public String addColumnFamily(final ThriftColumnFamilyDefinitionImpl def) {
    AstyanaxContext<Cluster> context = clientContext.getClusterContext();
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) context.getConnectionPool();
    final String cfname = def.getName();
    _log.info("Adding CF: {}", cfname);
    try {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.ADD_COLUMN_FAMILY)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                client.set_keyspace(_keyspaceName);
                // This method can be retried several times, so server may already have received the 'creating CF' request
                // and created the CF, we check the existence of the CF first before issuing another 'creating CF' request
                // which will cause the 'CF already exists' exception
                KsDef kd = client.describe_keyspace(_keyspaceName);
                List<CfDef> cfs = kd.getCf_defs();
                for (CfDef cf : cfs) {
                    if (cf.getName().equals(cfname)) {
                        _log.info("The CF {} has already been created", cfname);
                        return null;
                    }
                }
                _log.info("To create CF {}", cfname);
                return client.system_add_column_family(def.getThriftColumnFamilyDefinition());
            }
        }, context.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } catch (final OperationException e) {
        throw DatabaseException.retryables.operationFailed(e);
    } catch (final ConnectionException e) {
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) Cluster(com.netflix.astyanax.Cluster) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) KsDef(org.apache.cassandra.thrift.KsDef) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) DbClient(com.emc.storageos.db.client.DbClient) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) CfDef(org.apache.cassandra.thrift.CfDef) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 20 with KsDef

use of org.apache.cassandra.thrift.KsDef in project atlasdb by palantir.

the class CassandraKeyValueServiceImpl method lowerConsistencyWhenSafe.

private void lowerConsistencyWhenSafe() {
    Set<String> dcs;
    Map<String, String> strategyOptions;
    try {
        dcs = clientPool.runWithRetry(client -> CassandraVerifier.sanityCheckDatacenters(client, config));
        KsDef ksDef = clientPool.runWithRetry(client -> client.describe_keyspace(config.getKeyspaceOrThrow()));
        strategyOptions = Maps.newHashMap(ksDef.getStrategy_options());
        if (dcs.size() == 1) {
            String dc = dcs.iterator().next();
            if (strategyOptions.get(dc) != null) {
                int currentRf = Integer.parseInt(strategyOptions.get(dc));
                if (currentRf == config.replicationFactor()) {
                    if (currentRf == 2 && config.clusterMeetsNormalConsistencyGuarantees()) {
                        log.info("Setting Read Consistency to ONE, as cluster has only one datacenter at RF2.");
                        readConsistency = ConsistencyLevel.ONE;
                    }
                }
            }
        }
    } catch (TException e) {
        return;
    }
}
Also used : Arrays(java.util.Arrays) Throwables(com.palantir.common.base.Throwables) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) LeaderConfig(com.palantir.atlasdb.config.LeaderConfig) Column(org.apache.cassandra.thrift.Column) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) ImmutableCandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweepingRequest) ColumnGetter(com.palantir.atlasdb.keyvalue.cassandra.paging.ColumnGetter) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) AnnotationType(com.palantir.atlasdb.util.AnnotationType) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) Stream(java.util.stream.Stream) CASResult(org.apache.cassandra.thrift.CASResult) StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) Cells(com.palantir.atlasdb.keyvalue.impl.Cells) AbstractKeyValueService(com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService) Iterables(com.google.common.collect.Iterables) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) Callable(java.util.concurrent.Callable) LockLeader(com.palantir.atlasdb.config.LockLeader) AsyncInitializer(com.palantir.async.initializer.AsyncInitializer) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Builder(com.google.common.collect.ImmutableMap.Builder) Multimaps(com.google.common.collect.Multimaps) LinkedHashMap(java.util.LinkedHashMap) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) Lists(com.google.common.collect.Lists) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) Predicates(com.google.common.base.Predicates) Functions(com.google.common.base.Functions) FunctionCheckedException(com.palantir.common.base.FunctionCheckedException) TException(org.apache.thrift.TException) QosClient(com.palantir.atlasdb.qos.QosClient) CandidateRowsForSweepingIterator(com.palantir.atlasdb.keyvalue.cassandra.sweep.CandidateRowsForSweepingIterator) AnnotatedCallable(com.palantir.atlasdb.util.AnnotatedCallable) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Preconditions(com.google.common.base.Preconditions) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) SlicePredicates(com.palantir.atlasdb.keyvalue.cassandra.thrift.SlicePredicates) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ClosableIterator(com.palantir.common.base.ClosableIterator) LoggerFactory(org.slf4j.LoggerFactory) MutationMap(com.palantir.atlasdb.keyvalue.cassandra.thrift.MutationMap) Random(java.util.Random) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) ByteBuffer(java.nio.ByteBuffer) KeyValueServices(com.palantir.atlasdb.keyvalue.impl.KeyValueServices) HashMultimap(com.google.common.collect.HashMultimap) Mutation(org.apache.cassandra.thrift.Mutation) CassandraRangePagingIterable(com.palantir.atlasdb.keyvalue.cassandra.paging.CassandraRangePagingIterable) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable) Collection(java.util.Collection) QosAwareThrowables(com.palantir.atlasdb.qos.ratelimit.QosAwareThrowables) AutoDelegate(com.palantir.processors.AutoDelegate) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ThriftColumnGetter(com.palantir.atlasdb.keyvalue.cassandra.paging.ThriftColumnGetter) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) List(java.util.List) KsDef(org.apache.cassandra.thrift.KsDef) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) UnsafeArg(com.palantir.logsafe.UnsafeArg) Entry(java.util.Map.Entry) Range(com.palantir.atlasdb.keyvalue.cassandra.thrift.SlicePredicates.Range) Optional(java.util.Optional) Mutations(com.palantir.atlasdb.keyvalue.cassandra.thrift.Mutations) ConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel) Limit(com.palantir.atlasdb.keyvalue.cassandra.thrift.SlicePredicates.Limit) AtlasDbMetrics(com.palantir.atlasdb.util.AtlasDbMetrics) Supplier(com.google.common.base.Supplier) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) FakeQosClient(com.palantir.atlasdb.qos.FakeQosClient) SafeArg(com.palantir.logsafe.SafeArg) ImmutableList(com.google.common.collect.ImmutableList) RowGetter(com.palantir.atlasdb.keyvalue.cassandra.paging.RowGetter) ClosableIterators(com.palantir.common.base.ClosableIterators) UnavailableException(org.apache.cassandra.thrift.UnavailableException) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Value(com.palantir.atlasdb.keyvalue.api.Value) IterablePartitioner(com.palantir.atlasdb.keyvalue.impl.IterablePartitioner) CfDef(org.apache.cassandra.thrift.CfDef) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) SetMultimap(com.google.common.collect.SetMultimap) PalantirRuntimeException(com.palantir.common.exception.PalantirRuntimeException) SimpleTokenBackedResultsPage(com.palantir.util.paging.SimpleTokenBackedResultsPage) CandidateRowForSweeping(com.palantir.atlasdb.keyvalue.cassandra.sweep.CandidateRowForSweeping) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Idempotent(com.palantir.common.annotation.Idempotent) TException(org.apache.thrift.TException) KsDef(org.apache.cassandra.thrift.KsDef)

Aggregations

KsDef (org.apache.cassandra.thrift.KsDef)25 CfDef (org.apache.cassandra.thrift.CfDef)11 Cassandra (org.apache.cassandra.thrift.Cassandra)7 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)7 NotFoundException (org.apache.cassandra.thrift.NotFoundException)7 Test (org.junit.Test)7 TException (org.apache.thrift.TException)6 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)4 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)4 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)4 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)2 DbClient (com.emc.storageos.db.client.DbClient)2 KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)2 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)2 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2