use of com.alibaba.nacos.config.server.model.CacheItem in project nacos by alibaba.
the class ConfigCacheService method makeSure.
static CacheItem makeSure(final String groupKey) {
CacheItem item = CACHE.get(groupKey);
if (null != item) {
return item;
}
CacheItem tmp = new CacheItem(groupKey);
item = CACHE.putIfAbsent(groupKey, tmp);
return (null == item) ? tmp : item;
}
use of com.alibaba.nacos.config.server.model.CacheItem in project nacos by alibaba.
the class ConfigCacheService method makeSure.
static CacheItem makeSure(final String groupKey, String encryptedDataKey, boolean isBeta) {
CacheItem item = CACHE.get(groupKey);
if (null != item) {
setEncryptDateKey(item, encryptedDataKey, isBeta);
return item;
}
CacheItem tmp = new CacheItem(groupKey);
setEncryptDateKey(tmp, encryptedDataKey, isBeta);
item = CACHE.putIfAbsent(groupKey, tmp);
return (null == item) ? tmp : item;
}
use of com.alibaba.nacos.config.server.model.CacheItem in project nacos by alibaba.
the class ConfigCacheService method removeTag.
/**
* Delete tag config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param tag tag string value.
* @return remove success or not.
*/
public static boolean removeTag(String dataId, String group, String tenant, String tag) {
final String groupKey = GroupKey2.getKey(dataId, group, tenant);
final int lockResult = tryWriteLock(groupKey);
// If data is non-existent.
if (0 == lockResult) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}
// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
return false;
}
try {
if (!PropertyUtil.isDirectRead()) {
DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
}
CacheItem ci = CACHE.get(groupKey);
ci.tagMd5.remove(tag);
ci.tagLastModifiedTs.remove(tag);
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
return true;
} finally {
releaseWriteLock(groupKey);
}
}
use of com.alibaba.nacos.config.server.model.CacheItem in project nacos by alibaba.
the class ConfigCacheService method updateMd5.
/**
* Update md5 value.
*
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param lastModifiedTs lastModifiedTs long value.
*/
public static void updateMd5(String groupKey, String md5, long lastModifiedTs, String encryptedDataKey) {
CacheItem cache = makeSure(groupKey, encryptedDataKey, false);
if (cache.md5 == null || !cache.md5.equals(md5)) {
cache.md5 = md5;
cache.lastModifiedTs = lastModifiedTs;
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));
}
}
use of com.alibaba.nacos.config.server.model.CacheItem in project nacos by alibaba.
the class ConfigCacheService method tryWriteLock.
/**
* Try to add write lock. If it succeeded, then it can call {@link #releaseWriteLock(String)}.And it won't call if
* failed.
*
* @param groupKey groupKey string value.
* @return 0 - No data and failed. Positive number 0 - Success. Negative number - lock failed。
*/
static int tryWriteLock(String groupKey) {
CacheItem groupItem = CACHE.get(groupKey);
int result = (null == groupItem) ? 0 : (groupItem.rwLock.tryWriteLock() ? 1 : -1);
if (result < 0) {
DEFAULT_LOG.warn("[write-lock] failed, {}, {}", result, groupKey);
}
return result;
}
Aggregations