use of com.alibaba.nacos.config.server.model.ConfigInfoWrapper in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method completeMd5.
@Override
public Boolean completeMd5() {
LogUtil.DEFAULT_LOG.info("[start completeMd5]");
int perPageSize = 1000;
int rowCount = configInfoCount();
int pageCount = (int) Math.ceil(rowCount * 1.0 / perPageSize);
int actualRowCount = 0;
for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
Page<ConfigInfoWrapper> page = findAllConfigInfoForDumpAll(pageNo, perPageSize);
if (page != null) {
for (ConfigInfoWrapper cf : page.getPageItems()) {
String md5InDb = cf.getMd5();
final String content = cf.getContent();
final String tenant = cf.getTenant();
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
if (StringUtils.isBlank(md5InDb)) {
try {
updateMd5(cf.getDataId(), cf.getGroup(), tenant, md5, new Timestamp(cf.getLastModified()));
} catch (Exception e) {
LogUtil.DEFAULT_LOG.error("[completeMd5-error] datId:{} group:{} lastModified:{}", new Object[] { cf.getDataId(), cf.getGroup(), new Timestamp(cf.getLastModified()) });
}
} else {
if (!md5InDb.equals(md5)) {
try {
updateMd5(cf.getDataId(), cf.getGroup(), tenant, md5, new Timestamp(cf.getLastModified()));
} catch (Exception e) {
LogUtil.DEFAULT_LOG.error("[completeMd5-error] datId:{} group:{} lastModified:{}", new Object[] { cf.getDataId(), cf.getGroup(), new Timestamp(cf.getLastModified()) });
}
}
}
}
actualRowCount += page.getPageItems().size();
LogUtil.DEFAULT_LOG.info("[completeMd5] {} / {}", actualRowCount, rowCount);
}
}
return true;
}
use of com.alibaba.nacos.config.server.model.ConfigInfoWrapper in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method convertChangeConfig.
@Override
public List<ConfigInfoWrapper> convertChangeConfig(List<Map<String, Object>> list) {
List<ConfigInfoWrapper> configs = new ArrayList<ConfigInfoWrapper>();
for (Map<String, Object> map : list) {
String dataId = (String) map.get("data_id");
String group = (String) map.get("group_id");
String tenant = (String) map.get("tenant_id");
String content = (String) map.get("content");
long mTime = ((Timestamp) map.get("gmt_modified")).getTime();
ConfigInfoWrapper config = new ConfigInfoWrapper();
config.setDataId(dataId);
config.setGroup(group);
config.setTenant(tenant);
config.setContent(content);
config.setLastModified(mTime);
configs.add(config);
}
return configs;
}
use of com.alibaba.nacos.config.server.model.ConfigInfoWrapper in project nacos by alibaba.
the class DumpAllProcessor method process.
@Override
public boolean process(NacosTask task) {
long currentMaxId = persistService.findConfigMaxId();
long lastMaxId = 0;
while (lastMaxId < currentMaxId) {
Page<ConfigInfoWrapper> page = persistService.findAllConfigInfoFragment(lastMaxId, PAGE_SIZE);
if (page != null && page.getPageItems() != null && !page.getPageItems().isEmpty()) {
for (ConfigInfoWrapper cf : page.getPageItems()) {
long id = cf.getId();
lastMaxId = Math.max(id, lastMaxId);
if (cf.getDataId().equals(AggrWhitelist.AGGRIDS_METADATA)) {
AggrWhitelist.load(cf.getContent());
}
if (cf.getDataId().equals(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA)) {
ClientIpWhiteList.load(cf.getContent());
}
if (cf.getDataId().equals(SwitchService.SWITCH_META_DATAID)) {
SwitchService.load(cf.getContent());
}
ConfigCacheService.dump(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified(), cf.getType(), cf.getEncryptedDataKey());
final String content = cf.getContent();
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
LogUtil.DUMP_LOG.info("[dump-all-ok] {}, {}, length={}, md5={}", GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), content.length(), md5);
}
DEFAULT_LOG.info("[all-dump] {} / {}", lastMaxId, currentMaxId);
} else {
lastMaxId += PAGE_SIZE;
}
}
return true;
}
use of com.alibaba.nacos.config.server.model.ConfigInfoWrapper in project nacos by alibaba.
the class DumpService method dumpConfigInfo.
private void dumpConfigInfo(DumpAllProcessor dumpAllProcessor) throws IOException {
int timeStep = 6;
boolean isAllDump = true;
// initial dump all
FileInputStream fis = null;
Timestamp heartheatLastStamp = null;
try {
if (isQuickStart()) {
File heartbeatFile = DiskUtil.heartBeatFile();
if (heartbeatFile.exists()) {
fis = new FileInputStream(heartbeatFile);
String heartheatTempLast = IoUtils.toString(fis, Constants.ENCODE);
heartheatLastStamp = Timestamp.valueOf(heartheatTempLast);
if (TimeUtils.getCurrentTime().getTime() - heartheatLastStamp.getTime() < timeStep * 60 * 60 * 1000) {
isAllDump = false;
}
}
}
if (isAllDump) {
LogUtil.DEFAULT_LOG.info("start clear all config-info.");
DiskUtil.clearAll();
dumpAllProcessor.process(new DumpAllTask());
} else {
Timestamp beforeTimeStamp = getBeforeStamp(heartheatLastStamp, timeStep);
DumpChangeProcessor dumpChangeProcessor = new DumpChangeProcessor(this, beforeTimeStamp, TimeUtils.getCurrentTime());
dumpChangeProcessor.process(new DumpChangeTask());
Runnable checkMd5Task = () -> {
LogUtil.DEFAULT_LOG.error("start checkMd5Task");
List<String> diffList = ConfigCacheService.checkMd5();
for (String groupKey : diffList) {
String[] dg = GroupKey.parseKey(groupKey);
String dataId = dg[0];
String group = dg[1];
String tenant = dg[2];
ConfigInfoWrapper configInfo = persistService.queryConfigInfo(dataId, group, tenant);
ConfigCacheService.dumpChange(dataId, group, tenant, configInfo.getContent(), configInfo.getLastModified(), configInfo.getEncryptedDataKey());
}
LogUtil.DEFAULT_LOG.error("end checkMd5Task");
};
ConfigExecutor.scheduleConfigTask(checkMd5Task, 0, 12, TimeUnit.HOURS);
}
} catch (IOException e) {
LogUtil.FATAL_LOG.error("dump config fail" + e.getMessage());
throw e;
} finally {
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
LogUtil.DEFAULT_LOG.warn("close file failed");
}
}
}
}
use of com.alibaba.nacos.config.server.model.ConfigInfoWrapper in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method completeMd5.
@Override
public Boolean completeMd5() {
DEFAULT_LOG.info("[start completeMd5]");
int perPageSize = 1000;
int rowCount = configInfoCount();
int pageCount = (int) Math.ceil(rowCount * 1.0 / perPageSize);
int actualRowCount = 0;
for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
Page<ConfigInfoWrapper> page = findAllConfigInfoForDumpAll(pageNo, perPageSize);
if (page != null) {
for (ConfigInfoWrapper cf : page.getPageItems()) {
String md5InDb = cf.getMd5();
final String content = cf.getContent();
final String tenant = cf.getTenant();
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
if (StringUtils.isBlank(md5InDb)) {
try {
updateMd5(cf.getDataId(), cf.getGroup(), tenant, md5, new Timestamp(cf.getLastModified()));
} catch (Throwable e) {
LogUtil.DEFAULT_LOG.error("[completeMd5-error] datId:{} group:{} lastModified:{}", cf.getDataId(), cf.getGroup(), new Timestamp(cf.getLastModified()));
}
} else {
if (!md5InDb.equals(md5)) {
try {
updateMd5(cf.getDataId(), cf.getGroup(), tenant, md5, new Timestamp(cf.getLastModified()));
} catch (Throwable e) {
LogUtil.DEFAULT_LOG.error("[completeMd5-error] datId:{} group:{} lastModified:{}", cf.getDataId(), cf.getGroup(), new Timestamp(cf.getLastModified()));
}
}
}
}
actualRowCount += page.getPageItems().size();
DEFAULT_LOG.info("[completeMd5] {} / {}", actualRowCount, rowCount);
}
}
return true;
}
Aggregations