Search in sources :

Example 1 with TimeSeriesType

use of com.emc.storageos.db.client.impl.TimeSeriesType 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)

Example 2 with TimeSeriesType

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

the class DbClientTest method testConfigOverride.

@Test
public void testConfigOverride() {
    final int newTtl = 1234;
    TypeMap.DataObjectFieldConfiguration doConfig = new TypeMap.DataObjectFieldConfiguration();
    doConfig.setDoClass(FileShare.class);
    doConfig.setFieldName("status");
    doConfig.setTtl(newTtl);
    TypeMap.loadDataObjectConfiguration(Arrays.asList(doConfig));
    DataObjectType fsType = TypeMap.getDoType(FileShare.class);
    Assert.assertEquals(fsType.getColumnField("status").getTtl().intValue(), newTtl);
    TypeMap.TimeSeriesConfiguration tsConfig = new TypeMap.TimeSeriesConfiguration();
    tsConfig.setTsClass(EventTimeSeries.class);
    tsConfig.setTtl(newTtl);
    TypeMap.loadTimeSeriesConfiguration(Arrays.asList(tsConfig));
    TimeSeriesType tsType = TypeMap.getTimeSeriesType(EventTimeSeries.class);
    Assert.assertEquals(tsType.getTtl().intValue(), newTtl);
}
Also used : TimeSeriesType(com.emc.storageos.db.client.impl.TimeSeriesType) TypeMap(com.emc.storageos.db.client.impl.TypeMap) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Test(org.junit.Test)

Example 3 with TimeSeriesType

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

the class DataObjectScanner method processClass.

/**
 * Processes data object or time series class and extracts CF
 * requirements
 *
 * @param clazz data object or time series class
 */
@SuppressWarnings("unchecked")
@Override
protected void processClass(Class clazz) {
    if (DataObject.class.isAssignableFrom(clazz)) {
        if (!isDualDbSvcMode()) {
            addToTypeMap(clazz, _cfMap);
        } else if (KeyspaceUtil.isLocal(clazz)) {
            addToTypeMap(clazz, _cfMap);
        } else if (KeyspaceUtil.isGlobal(clazz)) {
            addToTypeMap(clazz, _geocfMap);
        } else {
            addToTypeMap(clazz, _geocfMap);
            addToTypeMap(clazz, _cfMap);
        }
    } else if (TimeSeries.class.isAssignableFrom(clazz)) {
        TimeSeriesType tsType = TypeMap.getTimeSeriesType(clazz);
        ColumnFamily cf = tsType.getCf();
        _cfMap.put(cf.getName(), cf);
        if (tsType.getCompactOptimized() && _dbCommonInfo != null && Boolean.TRUE.toString().equalsIgnoreCase(_dbCommonInfo.getProperty(DbClientImpl.DB_STAT_OPTIMIZE_DISK_SPACE, "false"))) {
            // modify TTL for Compaction Enable Series types
            int min_ttl = Integer.parseInt(_dbCommonInfo.getProperty(DbClientImpl.DB_LOG_MINIMAL_TTL, "604800"));
            if (min_ttl < tsType.getTtl()) {
                _log.info("Setting TTL for the CF {} equal to {}", cf.getName(), min_ttl);
                tsType.setTtl(min_ttl);
            }
        }
    } else if (SchemaRecord.class.isAssignableFrom(clazz)) {
        SchemaRecordType srType = TypeMap.getSchemaRecordType();
        ColumnFamily cf = srType.getCf();
        _cfMap.put(cf.getName(), cf);
    } else if (GlobalLock.class.isAssignableFrom(clazz)) {
        GlobalLockType glType = TypeMap.getGlobalLockType();
        ColumnFamily cf = glType.getCf();
        _geocfMap.put(cf.getName(), cf);
    } else {
        throw new IllegalStateException("Failed to process Class " + clazz.getName());
    }
}
Also used : GlobalLock(com.emc.storageos.db.client.model.GlobalLock) GlobalLockType(com.emc.storageos.db.client.impl.GlobalLockType) TimeSeries(com.emc.storageos.db.client.model.TimeSeries) TimeSeriesType(com.emc.storageos.db.client.impl.TimeSeriesType) SchemaRecordType(com.emc.storageos.db.client.impl.SchemaRecordType) ColumnFamily(com.netflix.astyanax.model.ColumnFamily)

Aggregations

TimeSeriesType (com.emc.storageos.db.client.impl.TimeSeriesType)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 ClassNameTimeSeriesSerializer (com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer)1 CompositeColumnNameSerializer (com.emc.storageos.db.client.impl.CompositeColumnNameSerializer)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 GlobalLockType (com.emc.storageos.db.client.impl.GlobalLockType)1 IndexColumnNameSerializer (com.emc.storageos.db.client.impl.IndexColumnNameSerializer)1 SchemaRecordType (com.emc.storageos.db.client.impl.SchemaRecordType)1 TimeSeriesColumnNameSerializer (com.emc.storageos.db.client.impl.TimeSeriesColumnNameSerializer)1 TypeMap (com.emc.storageos.db.client.impl.TypeMap)1 GlobalLock (com.emc.storageos.db.client.model.GlobalLock)1 TimeSeries (com.emc.storageos.db.client.model.TimeSeries)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1