内存检查工具 及内纯漏存
parent
fd7e47ff65
commit
ffee38af5b
|
@ -169,35 +169,81 @@ public class MongoUtil {
|
|||
String s1 = gson.toJson(user);//内存
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject obj = (JsonObject) parser.parse(s1);
|
||||
JsonObject mem = (JsonObject) parser.parse(s1);
|
||||
JsonParser parser1 = new JsonParser();
|
||||
JsonObject obj1 = (JsonObject) parser1.parse(s); //也可以 不好排查
|
||||
if(obj.equals(obj1)){
|
||||
|
||||
JsonObject db = (JsonObject) parser1.parse(s);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
StringBuilder stringBuilder2 = new StringBuilder();
|
||||
if (equill(db, mem, stringBuilder, stringBuilder2)) {
|
||||
LOGGER.info("匹配" + byId.getId());
|
||||
}else {
|
||||
} else {
|
||||
File file1 = new File(SysUtil.getPath("conf/checkout_db" + id + ".txt"));
|
||||
try (PrintWriter printWriter = new PrintWriter(new FileOutputStream(file1));) {
|
||||
printWriter.print(s);
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
prientFile(file1, stringBuilder, s);
|
||||
File file2 = new File(SysUtil.getPath("conf/checkout_mem" + id + ".txt"));
|
||||
try (PrintWriter printWriter = new PrintWriter(new FileOutputStream(file2));) {
|
||||
printWriter.print(s1);
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
prientFile(file2, stringBuilder2, s1);
|
||||
|
||||
LOGGER.error("定期检查数据库对象数据一致性 err" + byId.getId());
|
||||
}
|
||||
|
||||
|
||||
}, new LinkedList<>(ids), 300);
|
||||
}
|
||||
|
||||
private static void prientFile(File file, StringBuilder stringBuilder, String s) {
|
||||
|
||||
try (PrintWriter printWriter = new PrintWriter(new FileOutputStream(file));) {
|
||||
printWriter.print(stringBuilder.toString());
|
||||
printWriter.print("\r\n\r\n");
|
||||
printWriter.print(s);
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean equill(JsonObject o1, JsonObject o2, StringBuilder builder, StringBuilder builder2) {
|
||||
boolean is = true;
|
||||
try {
|
||||
Iterator<Map.Entry<String, JsonElement>> i = o1.entrySet().iterator();
|
||||
|
||||
while (i.hasNext()) {
|
||||
Map.Entry<String, JsonElement> e = i.next();
|
||||
String key = e.getKey();
|
||||
JsonElement value = e.getValue();
|
||||
if (value == null) {
|
||||
if (!(o2.get(key) == null && o2.has(key))) {
|
||||
builder.append("type0000:o1 k-v= [" + key + ":" + value + "]\r\n");
|
||||
builder2.append("type0000:o2 k-v= [" + key + ":" + o2.get(key) + "]\r\n");
|
||||
is = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (value instanceof JsonObject && o2.get(key) instanceof JsonObject) {
|
||||
if (!equill((JsonObject) value, (JsonObject) o2.get(key), builder, builder2)) {
|
||||
// builder.append("type111111:o1 = [" + o1 + "]\r\n");
|
||||
// builder2.append( "type111111:o2 = [" + o2 + "]\r\n");
|
||||
is = false;
|
||||
}
|
||||
} else {
|
||||
if (!value.equals(o2.get(key))) {
|
||||
builder.append("type22222:o1 k-v= [" + key + ":" + value + "]\r\n");
|
||||
builder2.append("type22222:o2 k-v= [" + key + ":" + o2.get(key) + "]\r\n");
|
||||
is = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (ClassCastException unused) {
|
||||
is = false;
|
||||
} catch (NullPointerException unused) {
|
||||
is = false;
|
||||
}
|
||||
|
||||
return is;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package com.ljsd.jieling.db.mongo;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.*;
|
||||
import com.ljsd.common.mogodb.LjsdMongoTemplate;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import util.MathUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public class MongoUtiltest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
File dbf3 = new File(SysUtil.getPath("conf/checkout_db10043724" + ".txt"));
|
||||
File memf3 = new File(SysUtil.getPath("conf/checkout_mem10043724" + ".txt"));
|
||||
|
||||
byte[] allbytes = Files.readAllBytes(dbf3.toPath());
|
||||
byte[] allbytes2 = Files.readAllBytes(memf3.toPath());
|
||||
String db = new String(allbytes, Charset.defaultCharset());
|
||||
String mem = new String(allbytes2, Charset.defaultCharset());
|
||||
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject obj = (JsonObject) parser.parse(db);
|
||||
JsonParser parser1 = new JsonParser();
|
||||
JsonObject obj1 = (JsonObject) parser1.parse(mem);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
StringBuilder stringBuilder2 = new StringBuilder();
|
||||
if (MongoUtil.equill(obj1, obj, stringBuilder,stringBuilder2)) {
|
||||
|
||||
System.out.println("匹配");
|
||||
} else {
|
||||
|
||||
File file3 = new File(SysUtil.getPath("conf/checkout_diffmem__" +dbf3.getName()+ ".txt"));
|
||||
try (PrintWriter printWriter = new PrintWriter(new FileOutputStream(file3));) {
|
||||
printWriter.print(stringBuilder.toString());
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
File file4 = new File(SysUtil.getPath("conf/checkout_diffdb__" +dbf3.getName()+ ".txt"));
|
||||
try (PrintWriter printWriter = new PrintWriter(new FileOutputStream(file4));) {
|
||||
printWriter.print(stringBuilder2.toString());
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -134,6 +134,7 @@ public class ExpeditionManager extends MongoBase {
|
|||
}
|
||||
|
||||
public WorldTreasureReward getWorldTreasureReward() {
|
||||
updateString("worldTreasureReward", worldTreasureReward);
|
||||
return worldTreasureReward;
|
||||
}
|
||||
|
||||
|
@ -146,6 +147,7 @@ public class ExpeditionManager extends MongoBase {
|
|||
}
|
||||
|
||||
public void setExpeditionLeve(int expeditionLeve) {
|
||||
updateString("expeditionLeve", expeditionLeve);
|
||||
this.expeditionLeve = expeditionLeve;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ public class GuildMyInfo extends MongoBase {
|
|||
curPos = path.remove(0);
|
||||
}
|
||||
setCurPos(curPos);
|
||||
setPath(path);
|
||||
setPreMoveTimestamp(timestamp);
|
||||
return curPos;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue