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