Search in sources :

Example 11 with MetricException

use of org.apache.storm.metricstore.MetricException in project storm by apache.

the class RocksDbStore method validateConfig.

/**
 * Implements configuration validation of Metrics Store, validates storm configuration for Metrics Store.
 *
 * @param config Storm config to specify which store type, location of store and creation policy
 * @throws MetricException if there is a missing required configuration or if the store does not exist but
 *                         the config specifies not to create the store
 */
private void validateConfig(Map<String, Object> config) throws MetricException {
    if (!(config.containsKey(DaemonConfig.STORM_ROCKSDB_LOCATION))) {
        throw new MetricException("Not a vaild RocksDB configuration - Missing store location " + DaemonConfig.STORM_ROCKSDB_LOCATION);
    }
    if (!(config.containsKey(DaemonConfig.STORM_ROCKSDB_CREATE_IF_MISSING))) {
        throw new MetricException("Not a vaild RocksDB configuration - Does not specify creation policy " + DaemonConfig.STORM_ROCKSDB_CREATE_IF_MISSING);
    }
    // validate path defined
    String storePath = getRocksDbAbsoluteDir(config);
    boolean createIfMissing = ObjectReader.getBoolean(config.get(DaemonConfig.STORM_ROCKSDB_CREATE_IF_MISSING), false);
    if (!createIfMissing) {
        if (!(new File(storePath).exists())) {
            throw new MetricException("Configuration specifies not to create a store but no store currently exists at " + storePath);
        }
    }
    if (!(config.containsKey(DaemonConfig.STORM_ROCKSDB_METADATA_STRING_CACHE_CAPACITY))) {
        throw new MetricException("Not a valid RocksDB configuration - Missing metadata string cache size " + DaemonConfig.STORM_ROCKSDB_METADATA_STRING_CACHE_CAPACITY);
    }
    if (!config.containsKey(DaemonConfig.STORM_ROCKSDB_METRIC_RETENTION_HOURS)) {
        throw new MetricException("Not a valid RocksDB configuration - Missing metric retention " + DaemonConfig.STORM_ROCKSDB_METRIC_RETENTION_HOURS);
    }
}
Also used : File(java.io.File) MetricException(org.apache.storm.metricstore.MetricException)

Example 12 with MetricException

use of org.apache.storm.metricstore.MetricException in project storm by apache.

the class RocksDbMetricsWriter method storeMetadataString.

// converts a metadata string into a unique integer.  Updates the timestamp of the string
// so we can track when it was last used for later deletion on database cleanup.
private int storeMetadataString(KeyType type, String s, long metricTimestamp) throws MetricException {
    if (s == null) {
        throw new MetricException("No string for metric metadata string type " + type);
    }
    // attempt to find it in the string cache
    StringMetadata stringMetadata = stringMetadataCache.get(s);
    if (stringMetadata != null) {
        // make sure the timestamp on the metadata has the latest time
        stringMetadata.update(metricTimestamp, type);
        return stringMetadata.getStringId();
    }
    // attempt to find the string in the database
    try {
        stringMetadata = store.rocksDbGetStringMetadata(type, s);
    } catch (RocksDBException e) {
        throw new MetricException("Error reading metrics data", e);
    }
    if (stringMetadata != null) {
        // update to the latest timestamp and add to the string cache
        stringMetadata.update(metricTimestamp, type);
        stringMetadataCache.put(s, stringMetadata, false);
        return stringMetadata.getStringId();
    }
    // string does not exist, create using an unique string id and add to cache
    if (LOG.isDebugEnabled()) {
        LOG.debug(type + "." + s + " does not exist in cache or database");
    }
    int stringId = getUniqueMetadataStringId();
    stringMetadata = new StringMetadata(type, stringId, metricTimestamp);
    stringMetadataCache.put(s, stringMetadata, true);
    return stringMetadata.getStringId();
}
Also used : RocksDBException(org.rocksdb.RocksDBException) MetricException(org.apache.storm.metricstore.MetricException)

Example 13 with MetricException

use of org.apache.storm.metricstore.MetricException in project storm by apache.

the class RocksDbMetricsWriter method processBatchInsert.

// writes multiple metric values into the database as a batch operation.  The tree map keeps the keys sorted
// for faster insertion to RocksDB.
private void processBatchInsert(TreeMap<RocksDbKey, RocksDbValue> batchMap) throws MetricException {
    try (WriteBatch writeBatch = new WriteBatch()) {
        // take the batched metric data and write to the database
        for (RocksDbKey k : batchMap.keySet()) {
            RocksDbValue v = batchMap.get(k);
            writeBatch.put(k.getRaw(), v.getRaw());
        }
        store.db.write(writeOpts, writeBatch);
    } catch (Exception e) {
        String message = "Failed to store data to RocksDB";
        LOG.error(message, e);
        throw new MetricException(message, e);
    }
}
Also used : WriteBatch(org.rocksdb.WriteBatch) MetricException(org.apache.storm.metricstore.MetricException) RocksDBException(org.rocksdb.RocksDBException) MetricException(org.apache.storm.metricstore.MetricException)

Aggregations

MetricException (org.apache.storm.metricstore.MetricException)13 RocksDBException (org.rocksdb.RocksDBException)10 ReadOptions (org.rocksdb.ReadOptions)2 WriteBatch (org.rocksdb.WriteBatch)2 WriteOptions (org.rocksdb.WriteOptions)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 WorkerMetricList (org.apache.storm.generated.WorkerMetricList)1 WorkerMetricPoint (org.apache.storm.generated.WorkerMetricPoint)1 WorkerMetrics (org.apache.storm.generated.WorkerMetrics)1 AggLevel (org.apache.storm.metricstore.AggLevel)1 FilterOptions (org.apache.storm.metricstore.FilterOptions)1 Metric (org.apache.storm.metricstore.Metric)1 BlockBasedTableConfig (org.rocksdb.BlockBasedTableConfig)1 FlushOptions (org.rocksdb.FlushOptions)1 Options (org.rocksdb.Options)1 RocksIterator (org.rocksdb.RocksIterator)1