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);
}
}
}
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);
}
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());
}
}
Aggregations