Search in sources :

Example 11 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily 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)

Example 12 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class ColumnField method processProperty.

/**
 * Helper to reflect on PropertyDescriptor and fill out _type and _name
 * information;
 */
private void processProperty() {
    // ignore if no get method
    if (_property.getReadMethod() == null) {
        return;
    }
    Method readMethod = _property.getReadMethod();
    Annotation[] annotations = readMethod.getAnnotations();
    ColumnFamily<String, IndexColumnName> indexCF = null;
    int minPrefixChars;
    boolean isLazyLoadable = false;
    boolean hasRelationIndex = false;
    for (int i = 0; i < annotations.length; i++) {
        Annotation a = annotations[i];
        if (a instanceof Id) {
            _colType = ColumnType.Id;
            _name = "Id";
        } else if (a instanceof Name) {
            _name = ((Name) a).value();
            if (Number.class.isAssignableFrom(_valueType) || _valueType == URI.class || _valueType == String.class || _valueType == Date.class || _valueType == Boolean.class || _valueType == Byte.class || _valueType == Long.class || _valueType == byte[].class || _valueType.isEnum() || _valueType == Calendar.class) {
                _colType = ColumnType.Primitive;
                compositeName = new CompositeColumnName(_name);
            } else if (NamedURI.class == _valueType) {
                _colType = ColumnType.NamedURI;
                compositeName = new CompositeColumnName(_name);
            } else if (AbstractChangeTrackingSet.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingSet;
            } else if (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingMap;
            } else if (AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingSetMap;
            } else if (AbstractSerializableNestedObject.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.NestedObject;
                compositeName = new CompositeColumnName(_name);
            } else if (Collection.class.isAssignableFrom(_valueType) || DataObject.class.isAssignableFrom(_valueType)) {
                isLazyLoadable = true;
            } else {
                throw new IllegalArgumentException(_name + " " + _valueType + " " + _property + " " + _parentType.getDataObjectClass());
            }
        } else if (a instanceof Ttl) {
            _ttl = ((Ttl) a).value();
        } else if (a instanceof RelationIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((RelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _indexRefType = ((RelationIndex) a).type();
            deactivateIfEmpty = ((RelationIndex) a).deactivateIfEmpty();
            _index = new RelationDbIndex(indexCF);
        } else if (a instanceof AlternateId) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((AlternateId) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _index = new AltIdDbIndex(indexCF);
        } else if (a instanceof ClassNameTimeSeries) {
            ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>(((ClassNameTimeSeries) a).value(), StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
            _index = new ClassNameTimeSeriesDBIndex(newIndexCF);
        } else if (a instanceof TimeSeriesAlternateId) {
            ColumnFamily<String, TimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, TimeSeriesIndexColumnName>(((TimeSeriesAlternateId) a).value(), StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
            _index = new TimeSeriesDbIndex(newIndexCF);
        } else if (a instanceof NamedRelationIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((NamedRelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _indexRefType = ((NamedRelationIndex) a).type();
            _index = new NamedRelationDbIndex(indexCF);
        } else if (a instanceof PrefixIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((PrefixIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            minPrefixChars = ((PrefixIndex) a).minChars();
            _index = new PrefixDbIndex(indexCF, minPrefixChars);
        } else if (a instanceof PermissionsIndex && AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((PermissionsIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _index = new PermissionsDbIndex(indexCF);
        } else if (a instanceof Encrypt && _valueType == String.class) {
            _encrypt = true;
        } else if (a instanceof ScopedLabelIndex) {
            ScopedLabelIndex scopeLabelIndex = (ScopedLabelIndex) a;
            indexCF = new ColumnFamily<String, IndexColumnName>(scopeLabelIndex.cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            minPrefixChars = scopeLabelIndex.minChars();
            _index = new ScopedLabelDbIndex(indexCF, minPrefixChars);
        } else if (a instanceof ClockIndependent) {
            clockIndValue = ((ClockIndependent) a).value();
        } else if (a instanceof DecommissionedIndex && Boolean.class.isAssignableFrom(_valueType)) {
            if (!_property.getName().equals(DataObject.INACTIVE_FIELD_NAME) || _parentType.getDataObjectClass().getAnnotation(NoInactiveIndex.class) == null) {
                indexCF = new ColumnFamily<String, IndexColumnName>(((DecommissionedIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
                _index = new DecommissionedDbIndex(indexCF);
            }
        } else if (a instanceof IndexByKey && (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType) || AbstractChangeTrackingSet.class.isAssignableFrom(_valueType))) {
            _indexByKey = true;
        } else if (a instanceof Relation) {
            hasRelationIndex = true;
            if (((Relation) a).type().equals(DataObject.class)) {
                _mappedByType = _valueType;
            } else {
                _mappedByType = ((Relation) a).type();
            }
            _mappedByField = ((Relation) a).mappedBy();
        } else if (a instanceof AggregatedIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((AggregatedIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            String groupBy = ((AggregatedIndex) a).groupBy();
            boolean global = ((AggregatedIndex) a).classGlobal();
            _index = new AggregateDbIndex(indexCF, groupBy, global);
        }
    }
    if (_name == null) {
        String className = _parentType.getDataObjectClass().getName();
        String fieldName = _property.getName();
        throw new IllegalArgumentException(String.format("@Name annotation missing from field '%s' in class '%s'", fieldName, className));
    }
    if (_index != null) {
        _index.setFieldName(_name);
        _index.setIndexByKey(_indexByKey);
    }
    if (isLazyLoadable && hasRelationIndex) {
        lazyLoaded = true;
    }
}
Also used : NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) DecommissionedIndex(com.emc.storageos.db.client.model.DecommissionedIndex) Name(com.emc.storageos.db.client.model.Name) PrefixIndex(com.emc.storageos.db.client.model.PrefixIndex) NoInactiveIndex(com.emc.storageos.db.client.model.NoInactiveIndex) AggregatedIndex(com.emc.storageos.db.client.model.AggregatedIndex) Method(java.lang.reflect.Method) Encrypt(com.emc.storageos.db.client.model.Encrypt) PermissionsIndex(com.emc.storageos.db.client.model.PermissionsIndex) DataObject(com.emc.storageos.db.client.model.DataObject) IndexByKey(com.emc.storageos.db.client.model.IndexByKey) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) Id(com.emc.storageos.db.client.model.Id) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) AbstractChangeTrackingSetMap(com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap) Ttl(com.emc.storageos.db.client.model.Ttl) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClockIndependent(com.emc.storageos.db.client.model.ClockIndependent) Relation(com.emc.storageos.db.client.model.Relation) ScopedLabelIndex(com.emc.storageos.db.client.model.ScopedLabelIndex) NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) RelationIndex(com.emc.storageos.db.client.model.RelationIndex) Annotation(java.lang.annotation.Annotation) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId)

Example 13 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelper method checkIndexingCF.

/**
 * Scan all the indices and related data object records, to find out
 * the index record is existing but the related data object records is missing.
 *
 * @return number of the corrupted rows in this index CF
 * @throws ConnectionException
 */
public void checkIndexingCF(IndexAndCf indexAndCf, boolean toConsole, CheckResult checkResult, boolean isParallel) throws ConnectionException {
    initSchemaVersions();
    String indexCFName = indexAndCf.cf.getName();
    Map<String, ColumnFamily<String, CompositeColumnName>> objCfs = getDataObjectCFs();
    _log.info("Start checking the index CF {} with double confirmed option: {}", indexCFName, doubleConfirmed);
    Map<ColumnFamily<String, CompositeColumnName>, Map<String, List<IndexEntry>>> objsToCheck = new HashMap<>();
    ColumnFamilyQuery<String, IndexColumnName> query = indexAndCf.keyspace.prepareQuery(indexAndCf.cf);
    OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().setRowLimit(dbClient.DEFAULT_PAGE_SIZE).withColumnRange(new RangeBuilder().setLimit(0).build()).execute();
    int scannedRows = 0;
    long beginTime = System.currentTimeMillis();
    for (Row<String, IndexColumnName> row : result.getResult()) {
        RowQuery<String, IndexColumnName> rowQuery = indexAndCf.keyspace.prepareQuery(indexAndCf.cf).getKey(row.getKey()).autoPaginate(true).withColumnRange(new RangeBuilder().setLimit(dbClient.DEFAULT_PAGE_SIZE).build());
        ColumnList<IndexColumnName> columns;
        while (!(columns = rowQuery.execute().getResult()).isEmpty()) {
            for (Column<IndexColumnName> column : columns) {
                scannedRows++;
                ObjectEntry objEntry = extractObjectEntryFromIndex(row.getKey(), column.getName(), indexAndCf.indexType, toConsole);
                if (objEntry == null) {
                    continue;
                }
                ColumnFamily<String, CompositeColumnName> objCf = objCfs.get(objEntry.getClassName());
                if (objCf == null) {
                    logMessage(String.format("DataObject does not exist for %s", row.getKey()), true, toConsole);
                    continue;
                }
                if (skipCheckCFs.contains(objCf.getName())) {
                    _log.debug("Skip checking CF {} for index CF {}", objCf.getName(), indexAndCf.cf.getName());
                    continue;
                }
                Map<String, List<IndexEntry>> objKeysIdxEntryMap = objsToCheck.get(objCf);
                if (objKeysIdxEntryMap == null) {
                    objKeysIdxEntryMap = new HashMap<>();
                    objsToCheck.put(objCf, objKeysIdxEntryMap);
                }
                List<IndexEntry> idxEntries = objKeysIdxEntryMap.get(objEntry.getObjectId());
                if (idxEntries == null) {
                    idxEntries = new ArrayList<>();
                    objKeysIdxEntryMap.put(objEntry.getObjectId(), idxEntries);
                }
                idxEntries.add(new IndexEntry(row.getKey(), column.getName()));
            }
            int size = getObjsSize(objsToCheck);
            if (size >= INDEX_OBJECTS_BATCH_SIZE) {
                if (isParallel) {
                    processBatchIndexObjectsWithMultipleThreads(indexAndCf, toConsole, objsToCheck, checkResult);
                } else {
                    processBatchIndexObjects(indexAndCf, toConsole, objsToCheck, checkResult);
                }
                objsToCheck = new HashMap<>();
            }
            if (scannedRows >= THRESHHOLD_FOR_OUTPUT_DEBUG) {
                _log.info("{} data objects have been check with time {}", scannedRows, DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - beginTime));
                scannedRows = 0;
                beginTime = System.currentTimeMillis();
            }
        }
    }
    // Detect whether the DataObject CFs have the records
    if (isParallel) {
        processBatchIndexObjectsWithMultipleThreads(indexAndCf, toConsole, objsToCheck, checkResult);
    } else {
        processBatchIndexObjects(indexAndCf, toConsole, objsToCheck, checkResult);
    }
}
Also used : HashMap(java.util.HashMap) RangeBuilder(com.netflix.astyanax.util.RangeBuilder) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ColumnList(com.netflix.astyanax.model.ColumnList) List(java.util.List) ArrayList(java.util.ArrayList) Rows(com.netflix.astyanax.model.Rows) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

ColumnFamily (com.netflix.astyanax.model.ColumnFamily)13 Keyspace (com.netflix.astyanax.Keyspace)8 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)7 Test (org.junit.Test)7 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)6 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)6 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)5 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)4 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)4 FileShare (com.emc.storageos.db.client.model.FileShare)4 Order (com.emc.storageos.db.client.model.uimodels.Order)4 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)3 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 TimeSeriesType (com.emc.storageos.db.client.impl.TimeSeriesType)2 ClassNameTimeSeries (com.emc.storageos.db.client.model.ClassNameTimeSeries)2 MutationBatch (com.netflix.astyanax.MutationBatch)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ClassNameTimeSeriesSerializer (com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer)1