Search in sources :

Example 1 with DataManagerFullException

use of com.emc.storageos.coordinator.client.service.DataManagerFullException in project coprhd-controller by CoprHD.

the class DistributedDataManagerImpl method checkLimit.

/**
 * Check that adding a new node to this data manager would not exceed the max node limit
 *
 * @throws Exception if the limit has been reached
 */
private void checkLimit() throws Exception {
    // in order to speed up writes, check limits against the cache
    // instead of doing live checkExists if possible
    ensureCacheStarted();
    Integer children = null;
    if (_basePathCache != null) {
        List<ChildData> childData = _basePathCache.getCurrentData();
        if (childData != null) {
            children = childData.size();
        }
    }
    if (children == null) {
        _log.warn("{}: cached child node data is not available; falling back to checkExists", _basePath);
        Stat stat = _zkClient.checkExists().forPath(_basePath);
        if (stat != null) {
            children = stat.getNumChildren();
        }
    }
    if (children != null) {
        _log.debug("{}: current nodes = {}; maxNodes = {}", Arrays.asList(_basePath, children.toString(), Long.toString(_maxNodes)).toArray());
        if (children >= _maxNodes) {
            _log.warn("{}: rejecting create because limit of {} has been reached", _basePath, _maxNodes);
            throw new DataManagerFullException();
        }
    }
}
Also used : DataManagerFullException(com.emc.storageos.coordinator.client.service.DataManagerFullException) Stat(org.apache.zookeeper.data.Stat) ChildData(org.apache.curator.framework.recipes.cache.ChildData)

Aggregations

DataManagerFullException (com.emc.storageos.coordinator.client.service.DataManagerFullException)1 ChildData (org.apache.curator.framework.recipes.cache.ChildData)1 Stat (org.apache.zookeeper.data.Stat)1