Search in sources :

Example 1 with StoreStats

use of voldemort.store.stats.StoreStats in project voldemort by voldemort.

the class StorageService method registerEngine.

/**
 * Register the given engine with the storage repository
 *
 * @param engine Register the storage engine
 * @param isReadOnly Boolean indicating if this store is read-only
 * @param storeType The type of the store
 * @param storeDef store definition for the store to be registered
 */
public void registerEngine(StorageEngine<ByteArray, byte[], byte[]> engine, boolean isReadOnly, String storeType, StoreDefinition storeDef) {
    Cluster cluster = this.metadata.getCluster();
    storeRepository.addStorageEngine(engine);
    /* Now add any store wrappers that are enabled */
    Store<ByteArray, byte[], byte[]> store = engine;
    boolean isMetadata = store.getName().compareTo(MetadataStore.METADATA_STORE_NAME) == 0;
    boolean isSlop = storeType.compareTo("slop") == 0;
    boolean isView = storeType.compareTo(ViewStorageConfiguration.TYPE_NAME) == 0;
    if (voldemortConfig.isVerboseLoggingEnabled())
        store = new LoggingStore<ByteArray, byte[], byte[]>(store, cluster.getName(), SystemTime.INSTANCE);
    if (!isSlop) {
        if (!isReadOnly && !isMetadata && !isView) {
            // wrap store to enforce retention policy
            if (voldemortConfig.isEnforceRetentionPolicyOnRead() && storeDef != null) {
                RetentionEnforcingStore retentionEnforcingStore = new RetentionEnforcingStore(store, storeDef, voldemortConfig.isDeleteExpiredValuesOnRead(), SystemTime.INSTANCE);
                metadata.addMetadataStoreListener(store.getName(), retentionEnforcingStore);
                store = retentionEnforcingStore;
            }
            if (voldemortConfig.isEnableRebalanceService()) {
                ProxyPutStats proxyPutStats = new ProxyPutStats(aggregatedProxyPutStats);
                if (voldemortConfig.isJmxEnabled()) {
                    JmxUtils.registerMbean(proxyPutStats, JmxUtils.createObjectName("voldemort.store.rebalancing", engine.getName() + "-proxy-puts"));
                }
                store = new RedirectingStore(store, metadata, storeRepository, failureDetector, storeFactory, proxyPutWorkerPool, proxyPutStats);
                if (voldemortConfig.isJmxEnabled()) {
                    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
                    ObjectName name = null;
                    if (this.voldemortConfig.isEnableJmxClusterName())
                        name = JmxUtils.createObjectName(cluster.getName() + "." + JmxUtils.getPackageName(RedirectingStore.class), store.getName());
                    else
                        name = JmxUtils.createObjectName(JmxUtils.getPackageName(RedirectingStore.class), store.getName());
                    synchronized (mbeanServer) {
                        if (mbeanServer.isRegistered(name))
                            JmxUtils.unregisterMbean(mbeanServer, name);
                        JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(store), name);
                    }
                }
            }
        }
        if (voldemortConfig.isMetadataCheckingEnabled() && !isMetadata) {
            store = new InvalidMetadataCheckingStore(metadata.getNodeId(), store, metadata);
        }
    }
    if (voldemortConfig.isStatTrackingEnabled()) {
        StatTrackingStore statStore = new StatTrackingStore(store, this.storeStats);
        store = statStore;
        if (voldemortConfig.isJmxEnabled()) {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName name = null;
            if (this.voldemortConfig.isEnableJmxClusterName())
                name = JmxUtils.createObjectName(metadata.getCluster().getName() + "." + JmxUtils.getPackageName(store.getClass()), store.getName());
            else
                name = JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName());
            synchronized (mbeanServer) {
                if (mbeanServer.isRegistered(name))
                    JmxUtils.unregisterMbean(mbeanServer, name);
                JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(new StoreStatsJmx(statStore.getStats())), name);
            }
        }
        // metadata store)
        if (voldemortConfig.isEnableQuotaLimiting() && !isMetadata) {
            StoreStats currentStoreStats = statStore.getStats();
            FileBackedCachingStorageEngine quotaStore = (FileBackedCachingStorageEngine) storeRepository.getStorageEngine(SystemStoreConstants.SystemStoreName.voldsys$_store_quotas.toString());
            QuotaLimitStats quotaStats = new QuotaLimitStats(this.aggregatedQuotaStats);
            QuotaLimitingStore rateLimitingStore = new QuotaLimitingStore(store, currentStoreStats, quotaStats, quotaStore, metadata);
            if (voldemortConfig.isJmxEnabled()) {
                JmxUtils.registerMbean(quotaStats, JmxUtils.createObjectName("voldemort.store.quota", store.getName() + "-quota-limit-stats"));
            }
            store = rateLimitingStore;
        }
    }
    storeRepository.addLocalStore(store);
}
Also used : StoreStats(voldemort.store.stats.StoreStats) RedirectingStore(voldemort.store.rebalancing.RedirectingStore) Cluster(voldemort.cluster.Cluster) LoggingStore(voldemort.store.logging.LoggingStore) ObjectName(javax.management.ObjectName) StatTrackingStore(voldemort.store.stats.StatTrackingStore) FileBackedCachingStorageEngine(voldemort.store.configuration.FileBackedCachingStorageEngine) ProxyPutStats(voldemort.store.rebalancing.ProxyPutStats) RetentionEnforcingStore(voldemort.store.retention.RetentionEnforcingStore) ByteArray(voldemort.utils.ByteArray) InvalidMetadataCheckingStore(voldemort.store.invalidmetadata.InvalidMetadataCheckingStore) QuotaLimitingStore(voldemort.store.quota.QuotaLimitingStore) QuotaLimitStats(voldemort.store.quota.QuotaLimitStats) StoreStatsJmx(voldemort.store.stats.StoreStatsJmx) MBeanServer(javax.management.MBeanServer)

Example 2 with StoreStats

use of voldemort.store.stats.StoreStats in project voldemort by voldemort.

the class RestPipelineFactory method createAndRegisterMBeansForAllStoreStats.

public void createAndRegisterMBeansForAllStoreStats(VoldemortConfig config, List<StoreDefinition> storeDefinitions) {
    storeStatsMap = new ConcurrentHashMap<String, StoreStats>();
    boolean isJmxEnabled = config.isJmxEnabled();
    for (StoreDefinition storeDefinition : Utils.notNull(storeDefinitions)) {
        String storeName = storeDefinition.getName();
        // Add to concurrentHashMap
        storeStatsMap.put(storeName, new StoreStats(storeName, aggregatedStoreStats));
        // Register storeStats MBeans for every store
        if (isJmxEnabled) {
            JmxUtils.registerMbean(new StoreStatsJmx(storeStatsMap.get(storeName)), JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()) + ".store.stats", storeName));
        }
    }
    // Register Mbean for aggregated server store stats
    if (isJmxEnabled) {
        JmxUtils.registerMbean(new StoreStatsJmx(aggregatedStoreStats), JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()) + ".store.stats", JmxUtils.getClassName(this.aggregatedStoreStats.getClass())));
    }
}
Also used : StoreStats(voldemort.store.stats.StoreStats) StoreDefinition(voldemort.store.StoreDefinition) StoreStatsJmx(voldemort.store.stats.StoreStatsJmx)

Example 3 with StoreStats

use of voldemort.store.stats.StoreStats in project voldemort by voldemort.

the class StorageWorkerThread method run.

@Override
public void run() {
    Object message = messageEvent.getMessage();
    boolean fromLocalZone = false;
    if (message instanceof VoldemortStoreRequest) {
        VoldemortStoreRequest storeRequestObject = (VoldemortStoreRequest) message;
        this.requestObject = storeRequestObject.getRequestObject();
        long now = System.currentTimeMillis();
        if (requestObject.getRequestOriginTimeInMs() + requestObject.getRoutingTimeoutInMs() <= now) {
            RestErrorHandler.writeErrorResponse(messageEvent, HttpResponseStatus.REQUEST_TIMEOUT, "current time: " + now + "\torigin time: " + requestObject.getRequestOriginTimeInMs() + "\ttimeout in ms: " + requestObject.getRoutingTimeoutInMs());
            return;
        } else {
            fromLocalZone = isLocalZoneId(storeRequestObject.getZoneId());
            this.store = storeRequestObject.getStore();
            String storeName = store.getName();
            performanceStats = storeStatsMap.get(storeName);
            if (performanceStats == null) {
                // Add to concurrentHashMap
                storeStatsMap.putIfAbsent(storeName, new StoreStats(storeName, aggregatedStoreStats));
                performanceStats = storeStatsMap.get(storeName);
                // Register MBeans for new store performance stats
                if (isJmxEnabled) {
                    JmxUtils.registerMbean(new StoreStatsJmx(performanceStats), JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()) + ".store.stats", storeName));
                }
            }
            switch(requestObject.getOperationType()) {
                case VoldemortOpCode.GET_OP_CODE:
                    if (logger.isDebugEnabled()) {
                        logger.debug("Incoming get request");
                    }
                    try {
                        List<Versioned<byte[]>> versionedValues = store.get(requestObject.getKey(), null);
                        // handle non existing key
                        if (versionedValues.size() > 0) {
                            GetResponseSender responseConstructor = new GetResponseSender(messageEvent, requestObject.getKey(), versionedValues, storeName);
                            responseConstructor.sendResponse(performanceStats, fromLocalZone, requestObject.getRequestOriginTimeInMs());
                        } else {
                            logger.error("Error when doing get. Key does not exist");
                            RestErrorHandler.writeErrorResponse(messageEvent, NOT_FOUND, "Key does not exist");
                        }
                    } catch (Exception e) {
                        getErrorHandler.handleExceptions(messageEvent, e);
                    }
                    break;
                case VoldemortOpCode.GET_ALL_OP_CODE:
                    if (logger.isDebugEnabled()) {
                        logger.debug("Incoming get all request");
                    }
                    try {
                        Map<ByteArray, List<Versioned<byte[]>>> keyValuesMap = store.getAll(requestObject.getIterableKeys(), null);
                        // check if there is at least one valid key
                        // before sending response
                        boolean hasAtleastOneValidKey = false;
                        for (List<Versioned<byte[]>> values : keyValuesMap.values()) {
                            if (values.size() > 0) {
                                hasAtleastOneValidKey = true;
                                break;
                            }
                        }
                        if (hasAtleastOneValidKey) {
                            GetAllResponseSender responseConstructor = new GetAllResponseSender(messageEvent, keyValuesMap, storeName);
                            responseConstructor.sendResponse(performanceStats, fromLocalZone, requestObject.getRequestOriginTimeInMs());
                        } else {
                            logger.error("Error when doing getall. Key does not exist or key is null");
                            RestErrorHandler.writeErrorResponse(messageEvent, NOT_FOUND, "Key does not exist or key is null");
                        }
                    } catch (Exception e) {
                        getErrorHandler.handleExceptions(messageEvent, e);
                    }
                    break;
                case VoldemortOpCode.PUT_OP_CODE:
                    if (logger.isDebugEnabled()) {
                        logger.debug("Incoming put request");
                    }
                    try {
                        store.put(requestObject.getKey(), requestObject.getValue(), null);
                        PutResponseSender responseConstructor = new PutResponseSender(messageEvent);
                        responseConstructor.sendResponse(performanceStats, fromLocalZone, requestObject.getRequestOriginTimeInMs());
                    } catch (Exception e) {
                        putErrorHandler.handleExceptions(messageEvent, e);
                    }
                    break;
                case VoldemortOpCode.DELETE_OP_CODE:
                    if (logger.isDebugEnabled()) {
                        logger.debug("Incoming delete request");
                    }
                    try {
                        boolean result = store.delete(requestObject.getKey(), requestObject.getVersion());
                        if (!result) {
                            logger.error("Error when doing delete. Non Existing key/version. Nothing to delete");
                            RestErrorHandler.writeErrorResponse(messageEvent, NOT_FOUND, "Non Existing key/version. Nothing to delete");
                            break;
                        }
                        DeleteResponseSender responseConstructor = new DeleteResponseSender(messageEvent);
                        responseConstructor.sendResponse(performanceStats, fromLocalZone, requestObject.getRequestOriginTimeInMs());
                    } catch (Exception e) {
                        deleteErrorHandler.handleExceptions(messageEvent, e);
                    }
                    break;
                case VoldemortOpCode.GET_VERSION_OP_CODE:
                    if (logger.isDebugEnabled()) {
                        logger.debug("Incoming get version request");
                    }
                    try {
                        List<Version> versions = store.getVersions(requestObject.getKey());
                        // handle non existing key
                        if (versions.size() > 0) {
                            GetVersionResponseSender responseConstructor = new GetVersionResponseSender(messageEvent, requestObject.getKey(), versions, storeName);
                            responseConstructor.sendResponse(performanceStats, fromLocalZone, requestObject.getRequestOriginTimeInMs());
                        } else {
                            logger.error("Error when doing getversion. Key does not exist or key is null");
                            RestErrorHandler.writeErrorResponse(messageEvent, NOT_FOUND, "Key does not exist or key is null");
                        }
                    } catch (Exception e) {
                        getVersionErrorHandler.handleExceptions(messageEvent, e);
                    }
                    break;
                default:
                    // above, the code stops here.
                    return;
            }
        }
    }
}
Also used : PutResponseSender(voldemort.rest.PutResponseSender) StoreStats(voldemort.store.stats.StoreStats) GetResponseSender(voldemort.rest.GetResponseSender) Versioned(voldemort.versioning.Versioned) DeleteResponseSender(voldemort.rest.DeleteResponseSender) GetAllResponseSender(voldemort.rest.GetAllResponseSender) GetVersionResponseSender(voldemort.rest.GetVersionResponseSender) Version(voldemort.versioning.Version) ByteArray(voldemort.utils.ByteArray) List(java.util.List) StoreStatsJmx(voldemort.store.stats.StoreStatsJmx)

Example 4 with StoreStats

use of voldemort.store.stats.StoreStats in project voldemort by voldemort.

the class AbstractStoreClientFactory method close.

public void close() {
    this.threadPool.shutdown();
    try {
        if (!this.threadPool.awaitTermination(10, TimeUnit.SECONDS))
            this.threadPool.shutdownNow();
    } catch (InterruptedException e) {
        // okay, fine, playing nice didn't work
        this.threadPool.shutdownNow();
    }
    if (failureDetector != null) {
        failureDetector.destroy();
        if (isJmxEnabled) {
            JmxUtils.unregisterMbean(JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), JmxUtils.getClassName(failureDetector.getClass()) + identifierString));
            JmxUtils.unregisterMbean(JmxUtils.createObjectName(JmxUtils.getPackageName(threadPool.getClass()), JmxUtils.getClassName(threadPool.getClass()) + identifierString));
            JmxUtils.unregisterMbean(JmxUtils.createObjectName("voldemort.store.stats.aggregate", "aggregate-perf" + identifierString));
            for (StoreStats stats : this.cachedStoreStats.values()) {
                stats.unregisterJmx();
            }
        }
    }
    releaseZenStoreResources();
}
Also used : StoreStats(voldemort.store.stats.StoreStats)

Aggregations

StoreStats (voldemort.store.stats.StoreStats)4 StoreStatsJmx (voldemort.store.stats.StoreStatsJmx)3 ByteArray (voldemort.utils.ByteArray)2 List (java.util.List)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Cluster (voldemort.cluster.Cluster)1 DeleteResponseSender (voldemort.rest.DeleteResponseSender)1 GetAllResponseSender (voldemort.rest.GetAllResponseSender)1 GetResponseSender (voldemort.rest.GetResponseSender)1 GetVersionResponseSender (voldemort.rest.GetVersionResponseSender)1 PutResponseSender (voldemort.rest.PutResponseSender)1 StoreDefinition (voldemort.store.StoreDefinition)1 FileBackedCachingStorageEngine (voldemort.store.configuration.FileBackedCachingStorageEngine)1 InvalidMetadataCheckingStore (voldemort.store.invalidmetadata.InvalidMetadataCheckingStore)1 LoggingStore (voldemort.store.logging.LoggingStore)1 QuotaLimitStats (voldemort.store.quota.QuotaLimitStats)1 QuotaLimitingStore (voldemort.store.quota.QuotaLimitingStore)1 ProxyPutStats (voldemort.store.rebalancing.ProxyPutStats)1 RedirectingStore (voldemort.store.rebalancing.RedirectingStore)1