test-api-clearing issues/31 поправил перезагрузку данных с битыми MapStore

This commit is contained in:
AKurakin 2023-10-09 13:07:31 +03:00
parent 6f04b15527
commit aa1e5f7ac1
2 changed files with 26 additions and 4 deletions

View file

@ -11,12 +11,14 @@ import org.springframework.stereotype.Service;
import ru.clearing.classes.objects.BusinessObject;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
import ru.spcex.platform.utils.log.ExceptionUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@Service
public class ImdgService {
@ -33,7 +35,7 @@ public class ImdgService {
return null;
}
public int reloadMapFromDB() {
public int reloadMapFromDB(List<String> warningMsgs) {
log.info("Reload all from DB...");
long loadTime = System.currentTimeMillis();
int count = 0;
@ -48,6 +50,8 @@ public class ImdgService {
ignoreUpdateMap.add(IMDGDistributedNames.Map_AccountBalance);
ignoreUpdateMap.add(IMDGDistributedNames.Map_KeyRate);
ignoreUpdateMap.add(IMDGDistributedNames.Map_LiabilitiesClaimsMoney);
ignoreUpdateMap.add("Map_TaskCodeDictionary");
ignoreUpdateMap.add("Map_TaskcodeDictionary");
try {
List<Callable<Long>> tasks = new ArrayList<>();
@ -63,6 +67,7 @@ public class ImdgService {
log.debug("Ignore sync for map {}", mapName);
continue;
}
AtomicInteger errorCount=new AtomicInteger(0);
tasks.add(() -> {
Long maxKey = null;
// MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
@ -84,6 +89,15 @@ public class ImdgService {
maxKey = map.keySet().stream().max(Long::compareTo).orElse(null);
log.trace("{} max(id)={}", mapName, maxKey);
} catch (IllegalArgumentException e) {
// когда нет MapStore: java.lang.IllegalArgumentException: First you should configure a map store at com.hazelcast.util.Preconditions.checkTrue(Preconditions.java:327)
// Такая ошибка обычно возникает во время разработки при частичном перезапуске IMDG (без отключения тестового сервиса) при работе над мапами.
log.error("Can not reload map \"{}\" cause: {}", mapName, ExceptionUtils.getStackTrace(e));
if (warningMsgs != null)
warningMsgs.add("Can not load from map \"" + mapName + "\" " + e.getMessage());
if (errorCount.incrementAndGet() > 10) {
throw new RuntimeException("Can not reload map " + mapName+", too many errors", e);
}
} catch (RuntimeException e) {
throw new RuntimeException("Can not reload map " + mapName, e);
}
@ -107,7 +121,6 @@ public class ImdgService {
executor.shutdown();
}
log.info("IDGenerator can not reinit. Max map ID {}", maxKey);
// plannerAllTodayMaker.makeSchedulerAllTodayMap();
} catch (InterruptedException | ExecutionException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();

View file

@ -13,6 +13,8 @@ import ru.spcex.platform.utils.log.ExceptionUtils;
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
@ -60,7 +62,9 @@ public class Controller extends HttpServerSimpleFramework {
Long n = kafkaService.putMessage(fullCLass, qName, msg);
writeLine(os, "<b>Message #" + n + "</b> success send: ");
} catch (Exception er) {
writeLine(os, "<p>Message error:" + ExceptionUtils.getStackTrace(er) + "</p>");
String errMsg = ExceptionUtils.getStackTrace(er);
errMsg = errMsg.replace("\n", "</br>\n");
writeLine(os, "<p>Message error:" + errMsg + "</p>");
}
writeLine(os, "<p>" + msg + "</p>");
} else {
@ -77,9 +81,14 @@ public class Controller extends HttpServerSimpleFramework {
os.flush();
try {
long clock = System.currentTimeMillis();
int count = imdgService.reloadMapFromDB();
List<String> warnMsg=new ArrayList<>();
int count = imdgService.reloadMapFromDB(warnMsg);
clock = System.currentTimeMillis() - clock;
writeLine(os, count + " map per " + clock + " ms</br>");
if (!warnMsg.isEmpty()) {
for (String msg : warnMsg)
writeLine(os, "Warning: " + msg + "</br>");
}
} catch (Throwable e) {
String msg = "Error reload: " + ExceptionUtils.getStackTrace(e);
log.error(msg);