Search in sources :

Example 1 with ClassNameTimeSeriesSerializer

use of com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer in project coprhd-controller by CoprHD.

the class SchemaUtil method checkCf.

/**
 * Checks all required CF's against keyspace definition. Any missing
 * CF's are created on the fly.
 * Note: it will require all nodes are online and converge at target Cassandra schema version
 * if parameter waitAllNodesConverge is true, otherwise, only require there's only one schema
 * version across current cluster.
 */
public void checkCf(boolean waitAllNodesConverge) throws InterruptedException, ConnectionException {
    KeyspaceDefinition kd = clientContext.getCluster().describeKeyspace(_keyspaceName);
    Cluster cluster = clientContext.getCluster();
    // Get default GC grace period for all index CFs in local DB
    Integer indexGcGrace = isGeoDbsvc() ? null : getIntProperty(DbClientImpl.DB_CASSANDRA_INDEX_GC_GRACE_PERIOD, null);
    Iterator<ColumnFamily> it = getCfMap().values().iterator();
    String latestSchemaVersion = null;
    while (it.hasNext()) {
        ColumnFamily cf = it.next();
        String comparator = cf.getColumnSerializer().getComparatorType().getTypeName();
        if (comparator.equals("CompositeType")) {
            if (cf.getColumnSerializer() instanceof CompositeColumnNameSerializer) {
                comparator = CompositeColumnNameSerializer.getComparatorName();
            } else if (cf.getColumnSerializer() instanceof IndexColumnNameSerializer) {
                comparator = IndexColumnNameSerializer.getComparatorName();
            } else if (cf.getColumnSerializer() instanceof ClassNameTimeSeriesSerializer) {
                comparator = ClassNameTimeSeriesSerializer.getComparatorName();
            } else if (cf.getColumnSerializer() instanceof TimeSeriesColumnNameSerializer) {
                comparator = TimeSeriesColumnNameSerializer.getComparatorName();
            } else {
                throw new IllegalArgumentException();
            }
        }
        ThriftColumnFamilyDefinitionImpl cfd = (ThriftColumnFamilyDefinitionImpl) kd.getColumnFamily(cf.getName());
        CfDef cdef = null;
        // The CF's gc_grace_period will be set if it's an index CF
        Integer cfGcGrace = cf.getColumnSerializer() instanceof IndexColumnNameSerializer ? indexGcGrace : null;
        // If there's specific configuration particular for this CF, take it.
        cfGcGrace = getIntProperty(DbClientImpl.DB_CASSANDRA_GC_GRACE_PERIOD_PREFIX + cf.getName(), cfGcGrace);
        if (cfd == null) {
            cfd = (ThriftColumnFamilyDefinitionImpl) cluster.makeColumnFamilyDefinition().setKeyspace(_keyspaceName).setName(cf.getName()).setComparatorType(comparator).setKeyValidationClass(cf.getKeySerializer().getComparatorType().getTypeName());
            if (_keyspaceName.equals(DbClientContext.LOCAL_KEYSPACE_NAME)) {
                cdef = cfd.getThriftColumnFamilyDefinition();
                String retry = cdef.getSpeculative_retry();
                if (!retry.equals(PERCENTILE)) {
                    try {
                        cdef.setSpeculative_retry(PERCENTILE);
                    } catch (Exception e) {
                        _log.info("Failed to set speculative_retry e=", e);
                    }
                }
            }
            TimeSeriesType tsType = TypeMap.getTimeSeriesType(cf.getName());
            if (tsType != null && tsType.getCompactOptimized() && _dbCommonInfo != null && Boolean.TRUE.toString().equalsIgnoreCase(_dbCommonInfo.getProperty(DbClientImpl.DB_STAT_OPTIMIZE_DISK_SPACE, "false"))) {
                String compactionStrategy = _dbCommonInfo.getProperty(DbClientImpl.DB_CASSANDRA_OPTIMIZED_COMPACTION_STRATEGY, "SizeTieredCompactionStrategy");
                _log.info("Setting DB compaction strategy to {}", compactionStrategy);
                int gcGrace = Integer.parseInt(_dbCommonInfo.getProperty(DbClientImpl.DB_CASSANDRA_GC_GRACE_PERIOD, // default is 10 days
                "864000"));
                _log.info("Setting DB GC grace period to {}", gcGrace);
                cfd.setCompactionStrategy(compactionStrategy).setGcGraceSeconds(gcGrace);
            } else if (cfGcGrace != null) {
                _log.info("Setting CF:{} gc_grace_period to {}", cf.getName(), cfGcGrace.intValue());
                cfd.setGcGraceSeconds(cfGcGrace.intValue());
            }
            latestSchemaVersion = addColumnFamily(cfd);
        } else {
            boolean modified = false;
            String existingComparator = cfd.getComparatorType();
            if (!matchComparator(existingComparator, comparator)) {
                _log.info("Comparator mismatch: db {} / schema {}", existingComparator, comparator);
                cfd.setComparatorType(comparator);
                modified = true;
            }
            TimeSeriesType tsType = TypeMap.getTimeSeriesType(cf.getName());
            if (tsType != null && tsType.getCompactOptimized() && _dbCommonInfo != null) {
                String compactionStrategy = _dbCommonInfo.getProperty(DbClientImpl.DB_CASSANDRA_OPTIMIZED_COMPACTION_STRATEGY, "SizeTieredCompactionStrategy");
                String existingStrategy = cfd.getCompactionStrategy();
                if (existingStrategy == null || !existingStrategy.contains(compactionStrategy)) {
                    _log.info("Setting DB compaction strategy to {}", compactionStrategy);
                    cfd.setCompactionStrategy(compactionStrategy);
                    modified = true;
                }
                int gcGrace = Integer.parseInt(_dbCommonInfo.getProperty(DbClientImpl.DB_CASSANDRA_GC_GRACE_PERIOD, "864000"));
                if (gcGrace != cfd.getGcGraceSeconds()) {
                    _log.info("Setting DB GC grace period to {}", gcGrace);
                    cfd.setGcGraceSeconds(gcGrace);
                    modified = true;
                }
            } else if (cfGcGrace != null && cfd.getGcGraceSeconds() != cfGcGrace.intValue()) {
                _log.info("Setting CF:{} gc_grace_period to {}", cf.getName(), cfGcGrace.intValue());
                cfd.setGcGraceSeconds(cfGcGrace.intValue());
                modified = true;
            }
            if (_keyspaceName.equals(DbClientContext.LOCAL_KEYSPACE_NAME)) {
                cdef = cfd.getThriftColumnFamilyDefinition();
                String retry = cdef.getSpeculative_retry();
                if (!retry.equals(PERCENTILE)) {
                    try {
                        cdef.setSpeculative_retry(PERCENTILE);
                        modified = true;
                    } catch (Exception e) {
                        _log.info("Failed to set speculative retry e=", e);
                    }
                }
            }
            if (modified) {
                latestSchemaVersion = updateColumnFamily(cfd);
            }
        }
    }
    if (latestSchemaVersion != null) {
        if (waitAllNodesConverge) {
            clientContext.waitForSchemaAgreement(latestSchemaVersion, _statusChecker.getClusterNodeCount());
        } else {
            clientContext.waitForSchemaAgreement(latestSchemaVersion, -1);
        }
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TimeSeriesType(com.emc.storageos.db.client.impl.TimeSeriesType) Cluster(com.netflix.astyanax.Cluster) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) UnknownHostException(java.net.UnknownHostException) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) IndexColumnNameSerializer(com.emc.storageos.db.client.impl.IndexColumnNameSerializer) ClassNameTimeSeriesSerializer(com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer) TimeSeriesColumnNameSerializer(com.emc.storageos.db.client.impl.TimeSeriesColumnNameSerializer) CompositeColumnNameSerializer(com.emc.storageos.db.client.impl.CompositeColumnNameSerializer) ThriftColumnFamilyDefinitionImpl(com.netflix.astyanax.thrift.ddl.ThriftColumnFamilyDefinitionImpl) CfDef(org.apache.cassandra.thrift.CfDef)

Aggregations

AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ClassNameTimeSeriesSerializer (com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer)1 CompositeColumnNameSerializer (com.emc.storageos.db.client.impl.CompositeColumnNameSerializer)1 IndexColumnNameSerializer (com.emc.storageos.db.client.impl.IndexColumnNameSerializer)1 TimeSeriesColumnNameSerializer (com.emc.storageos.db.client.impl.TimeSeriesColumnNameSerializer)1 TimeSeriesType (com.emc.storageos.db.client.impl.TimeSeriesType)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 Cluster (com.netflix.astyanax.Cluster)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)1 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)1 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)1 ThriftColumnFamilyDefinitionImpl (com.netflix.astyanax.thrift.ddl.ThriftColumnFamilyDefinitionImpl)1 UnknownHostException (java.net.UnknownHostException)1 CfDef (org.apache.cassandra.thrift.CfDef)1