定期抽查数据
parent
67930da50f
commit
e20c183619
|
@ -1,9 +1,17 @@
|
|||
package com.ljsd.jieling.db.mongo;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
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 io.netty.util.internal.MathUtil;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import util.MathUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -11,9 +19,12 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
public class MongoUtil {
|
||||
|
||||
|
@ -105,6 +116,88 @@ public class MongoUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void checkDb(){
|
||||
Set<Integer> set = OnlineUserManager.sessionMap.keySet();
|
||||
Integer[] integers = set.toArray(new Integer[0]);
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i <3 ; i++) {
|
||||
int i1 = random.nextInt(set.size());
|
||||
ids.add(integers[i1]);
|
||||
}
|
||||
InnerMessageUtil.broadcastWithRandom(user->{
|
||||
int id = user.getId();
|
||||
User byId = MongoUtil.getInstence().getMyMongoTemplate().findById(User.getCollectionName(), user.getId(), User.class);
|
||||
Gson gson = new GsonBuilder()
|
||||
.addSerializationExclusionStrategy(new ExclusionStrategy() {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes arg0) {
|
||||
Transient annotation = arg0.getAnnotation(Transient.class);
|
||||
if (annotation != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> arg0) {
|
||||
return false;
|
||||
}
|
||||
}).create();
|
||||
|
||||
|
||||
String s = gson.toJson(byId);
|
||||
String s1 = gson.toJson(user);//内存
|
||||
|
||||
char v1[] = s.toCharArray();
|
||||
char v2[] = s1.toCharArray();
|
||||
int n = v2.length;
|
||||
int m2 = v2.length;
|
||||
int j = 0;
|
||||
while (n-- != 0) {
|
||||
if (v1[j] != v2[j]){
|
||||
System.out.println("args = [" + v1[j] + "][" + v2[j] + "]\r\n");
|
||||
break;}
|
||||
j++;
|
||||
}
|
||||
|
||||
int start= Math.max(0,j-50);
|
||||
int end = Math.min(j+1,m2);
|
||||
if(j!=m2){
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
File file3 = new File("conf/checkout_diff_start"+id+".txt");
|
||||
String substring = s1.substring(start, end);
|
||||
String dbstring = s.substring(start, end);
|
||||
try(PrintWriter printWriter = new PrintWriter(new FileOutputStream(file3));) {
|
||||
printWriter.print("mem\r\n"+substring);
|
||||
printWriter.print("\r\n");
|
||||
printWriter.print("db\r\n"+dbstring);
|
||||
printWriter.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.error("定期检查数据库对象数据一致性 err"+byId.getId()+" \r\nmem_string \r\n"+substring+" \r\ndb_string \r\n"+dbstring);
|
||||
}else {
|
||||
LOGGER.info("定期检查数据库对象数据一致性 匹配"+byId.getId());
|
||||
}
|
||||
|
||||
}, new LinkedList<>(ids), 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.ljsd.jieling.kefu;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.thread.task.MinuteTask;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
//checkdb
|
||||
public class Cmd_checkdb extends GmAbstract {
|
||||
@Override
|
||||
public boolean exec(String[] args) throws Exception {
|
||||
|
||||
// for (int i = 0; i <150 ; i++) {
|
||||
// String key = RedisKey.getKey(RedisKey.FORCE_RANK, "", false);
|
||||
// RedisUtil.getInstence().zsetAddOne(key, String.valueOf(10000+i), 10000+i);
|
||||
// }
|
||||
|
||||
MongoUtil.checkDb();
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.ljsd.jieling.kefu;
|
||||
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/5/28 15:43
|
||||
* //reload 10043343
|
||||
*/
|
||||
public class cmd_reload extends GmRoleAbstract {
|
||||
@Override
|
||||
public boolean exec(String[] args) throws Exception {
|
||||
|
||||
|
||||
User user = getUser();
|
||||
if (null == user) {
|
||||
return true;
|
||||
}
|
||||
int id = user.getId();
|
||||
UserManager.removeUser(user.getId());
|
||||
user = MongoUtil.getInstence().getMyMongoTemplate().findById(User.getCollectionName(), id, User.class);
|
||||
UserManager.addUser(user);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ public class OnlineUserManager {
|
|||
sessionMap.put(uid, session);
|
||||
}
|
||||
|
||||
public static Map<Integer, ISession> sessionMap = new DefinaMap<>();
|
||||
public static Map<Integer, ISession> sessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static void userOffline(int uid) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class BuyGoodsLogic {
|
|||
|
||||
public static void flushEveryDay(User user) throws Exception {
|
||||
//更新5星成长礼
|
||||
user.getPlayerInfoManager().getRechargeInfo().getBuyGoodsTimes().put(21,0);
|
||||
user.getPlayerInfoManager().getRechargeInfo().updateBuyGoodsTimes(21,0);
|
||||
List<CommonProto.GiftGoodsInfo> goodsBagInfo = new ArrayList<>(SRechargeCommodityConfig.rechargeCommodityConfigMap.size());
|
||||
BuyGoodsLogic.getGoodsBagInfo(user.getId(), goodsBagInfo,false);
|
||||
ISession session = OnlineUserManager.getSessionByUid(user.getId());
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.ljsd.jieling.thread.task;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.fight.CheckFight;
|
||||
import com.ljsd.jieling.config.reportData.DataMessageUtils;
|
||||
|
@ -12,6 +16,7 @@ import com.ljsd.jieling.db.redis.RedisKey;
|
|||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.hotfix.HotfixUtil;
|
||||
import com.ljsd.jieling.kefu.GmRoleAbstract;
|
||||
import com.ljsd.jieling.ktbeans.BeanBuilder.KtBeanBuilderUtils;
|
||||
import com.ljsd.jieling.ktbeans.KTRequestBeans.LoginParamType;
|
||||
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
|
||||
|
@ -38,13 +43,21 @@ import com.ljsd.jieling.logic.question.QuestionLogic;
|
|||
import com.ljsd.jieling.logic.store.BuyGoodsLogic;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.server.SessionManager;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.Family;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
public class MinuteTask extends Thread {
|
||||
|
@ -119,6 +132,11 @@ public class MinuteTask extends Thread {
|
|||
if(minute ==0){
|
||||
LOGGER.info("everyHourTask start ...");
|
||||
Poster.getPoster().dispatchEvent(new HourTaskEvent(hour));
|
||||
try {
|
||||
MongoUtil.checkDb();
|
||||
}catch (Exception e){
|
||||
LOGGER.error("定期检查数据库对象数据一致性err"+e);
|
||||
}
|
||||
LOGGER.info("everyHourTask end ...");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue