Initial commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"stat/common/log"
|
||||
"stat/tool/sqSync/model"
|
||||
|
||||
"stat/tool/sqSync/service"
|
||||
)
|
||||
|
||||
func initMongoDB() error {
|
||||
|
||||
if err := model.InitMongoDB(); err != nil {
|
||||
log.Error("InitMongoDB err", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
initMongoDB()
|
||||
// _ = service.SyncDistrictInfo()
|
||||
_ = service.SyncUserInfo()
|
||||
// _ = service.SyncAdsInfo()
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// DistrictInfo 渠道原始信息
|
||||
type DistrictInfo struct {
|
||||
Code string `bson:"code"` //商区码
|
||||
Name string `bson:"name"` //账号
|
||||
Mobile string `bson:"mobile"` //手机号
|
||||
Parent string `bson:"parent"` //parent
|
||||
Password string `bson:"password"` //密码
|
||||
DiscType int `bson:"discType"` //商区类型/结算类型
|
||||
DividendRatio float64 `bson:"dividendRatio"` //分红比例 参与结算
|
||||
DisSettlement bool `bson:"disSettlement"` //禁止结算
|
||||
UserUnitCent float64 `bson:"userUnitCent"` //用户单价 单位:分
|
||||
NUDeductionRatio float64 `bson:"nuDeductionRatio"` //新增用户扣量比例
|
||||
NUDedLowerOutset int64 `bson:"nuDedLowerOutset"` //新增用户扣量起点
|
||||
NUDedAt time.Time `bson:"nuDedAt"` //新增用户扣量时间
|
||||
RechgDeductionRatio float64 `bson:"rechgDeductionRatio"` //充值扣量比例
|
||||
RechgDedLowerOutset int64 `bson:"rechgDedLowerOutset"` //充值扣量起点
|
||||
RechgDedAt time.Time `bson:"rechgDedAt"` //充值扣量时间
|
||||
ChildMax int `bson:"childMax"` //最大孩子数
|
||||
Disable bool `bson:"disable"` //禁用
|
||||
Lock bool `bson:"lock"` //禁止登陆
|
||||
DisTrans bool `bson:"disTrans"` //禁止交易
|
||||
DisAd bool `bson:"disAd"` //禁止广告
|
||||
DisMulDivi bool `bson:"disMulDivi"` //禁止多级分成(目前针对CPS)
|
||||
PayPassword string `bson:"payPassword"` //支付密码
|
||||
BalanceCent decimal.Decimal `bson:"balance"` //余额 单位:分
|
||||
Remark string `bson:"remark"` //备注
|
||||
CreatedAt time.Time `bson:"createdAt"` //文档创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` //文档更新时间
|
||||
}
|
||||
|
||||
// YhDistrictCodeInfo 渠道码信息
|
||||
type YhDistrictCodeInfo struct {
|
||||
DiscCode string `bson:"discCode"` //商圈码
|
||||
PromSeq string `bson:"promSeq"` //推广序列
|
||||
Remark string `bson:"remark"` //备注
|
||||
PromCode string `bson:"promCode"` //备注
|
||||
CreatedAt time.Time `bson:"createdAt"`
|
||||
DeletedAt time.Time `bson:"deletedAt,omitempty"` //删除时间
|
||||
}
|
||||
|
||||
const CollDistrict = "district"
|
||||
const CollDistrictCode = "disc_prom_seqe"
|
||||
|
||||
var dbDistrict *mongos.MongoTool
|
||||
var dbDistrictcode *mongos.MongoTool
|
||||
|
||||
func DistrictInit() {
|
||||
dbDistrict = mongos.New(ManagerYh, CollDistrict)
|
||||
dbDistrictcode = mongos.New(ManagerYh, CollDistrictCode)
|
||||
}
|
||||
|
||||
// FindYhDistrictInfo 查询所有渠道
|
||||
func FindSQDistrictInfo(ctx context.Context) ([]DistrictInfo, error) {
|
||||
list := make([]DistrictInfo, 0)
|
||||
query := bson.M{}
|
||||
|
||||
if err := dbDistrict.Find(ctx, &list, query); err != nil {
|
||||
log.Error(fmt.Sprintf("model %s FindYhDistrictInfo Find error", CollDistrict), log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// FindSQDistrictCodeInfo 查询渠道的渠道码
|
||||
func FindSQDistrictCodeInfo(ctx context.Context, discCode string) ([]YhDistrictCodeInfo, error) {
|
||||
list := make([]YhDistrictCodeInfo, 0)
|
||||
query := bson.M{"discCode": discCode}
|
||||
|
||||
if err := dbDistrictcode.Find(ctx, &list, query); err != nil {
|
||||
log.Error(fmt.Sprintf("model %s FindYhDistrictInfo Find error", CollDistrict), log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"stat/models"
|
||||
)
|
||||
|
||||
var (
|
||||
ManagerYh *mongos.Manager
|
||||
ManagerStat *mongos.Manager
|
||||
)
|
||||
|
||||
// InitMongoDB 初始化同步数据库
|
||||
func InitMongoDB() error {
|
||||
yhDB := mongos.NewManager("mongodb://read:6zwcDUpPy7dMkLTeWwHX@172.104.42.200:47017,139.162.18.46:47017,139.162.35.214:47017/sz?direct=game&maxPoolSize=200&connectTimeout=30&authSource=admin")
|
||||
if err := yhDB.Connect(); err != nil {
|
||||
log.Error("mgoDB connect err", log.E(err))
|
||||
return err
|
||||
}
|
||||
ManagerYh = yhDB
|
||||
|
||||
// 初始化表链接
|
||||
DistrictInit()
|
||||
UserInit()
|
||||
|
||||
statDB := mongos.NewManager("mongodb://bill:E4OSVEd6zuWibxJo@118.107.44.79:47017/statcentre?direct=game&maxPoolSize=200&connectTimeout=30&authSource=statcentre")
|
||||
if err := statDB.Connect(); err != nil {
|
||||
log.Error("mgoDB connect err", log.E(err))
|
||||
return err
|
||||
}
|
||||
mongos.MgoManager = statDB
|
||||
fmt.Println(statDB)
|
||||
// 初始化数据库索引
|
||||
models.InitIndex()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type YhUser struct {
|
||||
UID uint64 `json:"id" bson:"id"` //用户id
|
||||
SysType string `json:"sysType" bson:"sysType"` //系统类型
|
||||
DevType string `json:"deviceType" bson:"deviceType"` //设备类型
|
||||
Mobile string `json:"mobile" bson:"mobile"` //手机号
|
||||
Name string `json:"nickName" bson:"nickName"` //名字
|
||||
DistrictCode string `json:"agentInviteCode" bson:"agentInviteCode"` //商区码
|
||||
PromSeqe string `json:"promSeqe" bson:"promSeqe"` //推广序列
|
||||
PromCode string `json:"inviteCode" bson:"inviteCode"` //邀请码
|
||||
IsDirect bool `json:"isDirect" bson:"isDirect"` //true:是直推用户
|
||||
CreatedAt time.Time `bson:"createdAt"` //文档创建时间
|
||||
}
|
||||
|
||||
const CollUser = "server_user"
|
||||
|
||||
var dbUser *mongos.MongoTool
|
||||
|
||||
func UserInit() {
|
||||
dbUser = mongos.New(ManagerYh, CollUser)
|
||||
}
|
||||
|
||||
// FindSQUserInfo 查询用户
|
||||
func FindSQUserInfo(ctx context.Context, skip int64, limit int64) ([]YhUser, error) {
|
||||
list := make([]YhUser, 0)
|
||||
query := bson.M{}
|
||||
sort := bson.D{{Key: "_id", Value: 1}}
|
||||
opts := options.Find().SetSkip(skip).SetLimit(limit).SetSort(sort).SetProjection(bson.M{"id": 1, "sysType": 1, "deviceType": 1, "mobile": 1, "nickName": 1, "agentInviteCode": 1, "inviteCode": 1, "isDirect": 1, "createdAt": 1})
|
||||
|
||||
if err := dbUser.Find(ctx, &list, query, opts); err != nil {
|
||||
log.Error(fmt.Sprintf("model %s FindYhUserInfo Find error", CollDistrict), log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/log"
|
||||
"stat/models/registermod"
|
||||
"stat/tool/sqSync/model"
|
||||
)
|
||||
|
||||
func SyncUserInfo() error {
|
||||
skip := int64(0)
|
||||
limit := int64(10000)
|
||||
ctx := context.Background()
|
||||
//fmt.Println("before delete:", skip)
|
||||
for {
|
||||
//fmt.Println(skip)
|
||||
userlist, err := model.FindSQUserInfo(ctx, skip, limit)
|
||||
if err != nil {
|
||||
log.Error("SyncUserInfo FindSQUserInfo", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 转换
|
||||
//fmt.Println(len(userlist))
|
||||
|
||||
docs := make([]*registermod.RegisterMod, 0)
|
||||
for _, userInfo := range userlist {
|
||||
doc := registermod.RegisterMod{
|
||||
UserId: userInfo.UID,
|
||||
AppId: 2,
|
||||
SysType: userInfo.SysType,
|
||||
DevType: userInfo.DevType,
|
||||
Mobile: userInfo.Mobile,
|
||||
Name: userInfo.Name,
|
||||
IsDirect: userInfo.IsDirect,
|
||||
DistrictCode: userInfo.DistrictCode,
|
||||
RegisterTime: userInfo.CreatedAt,
|
||||
IsDeduction: false,
|
||||
PromCode: userInfo.PromCode,
|
||||
}
|
||||
docs = append(docs, &doc)
|
||||
}
|
||||
|
||||
if err = registermod.AddManyRegisterCode(ctx, &docs); err != nil {
|
||||
log.Error("SyncUserInfo AddManyRegisterCode", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
skip = skip + int64(len(userlist))
|
||||
//fmt.Println(skip)
|
||||
if int64(len(userlist)) < limit {
|
||||
log.Info("SyncUserInfo total:", log.Any("total", skip))
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
滑动窗口告诉发送端 接收端还有多少缓冲去可以接受数据, 于是发送端可以根据这个接收端的处理能力来发送数据,而不会导致接收端处理不过来
|
||||
以此控制发送数据的速率,从而达到流量控制,窗口大小是一个16bit字段,大小65536 socket的接收缓冲区大小
|
||||
|
||||
CLose sync =1 seq=x
|
||||
syc-send sync=1 ACK=1 seq=y ack=x=1 listen
|
||||
EStablisend ACK=1 seq=x+1 ack=y+1 SYNC-Recv
|
||||
|
||||
|
||||
Fin——wait FIN =1 seq
|
||||
fin_wait2 ACk=1 seq=v ack=u+1
|
||||
FIN=1,acl
|
||||
|
||||
半关闭状态, 客户端没有数据发送来 closewait 半关闭状态
|
||||
|
||||
Timewait 和closewait的区别:
|
||||
timewait 指主动发起关闭连接方 在收到对端 fin +ack后进入等待关闭,施放
|
||||
确保客户端发送的最后一个ACK报文能够到达服务器,因为ACK可能丢失, 服务器可能认为没收到,启动超时从传机制,导致服务器处理close_wait状态,新的连接不会出现旧连接报文
|
||||
|
||||
closewait 被动关闭的机器接收到对方请求关闭的fin豹纹,在第一次ACK应答后,进入close——wait状态, 同志应用层发送剩余数据,关闭相关资源
|
||||
我们一般在/etc/sysctl.conf文件中来修改默认值
|
||||
|
||||
滑动窗口
|
||||
动态改变窗口大小来调节两台主机间数据传输,tcp/IP支持全双工的数据传输,因此TCP有两个滑动串口, 一个用于接收, 一个用于发送
|
||||
|
||||
TCP的确认机制,滑动串口是TCP使用的一种流量控制方法,该协议允许发送在同志并等待确认前可以连续发送多个分组,犹豫发送方不必每发送一个分组就停止袭来等待确认,因此该协议
|
||||
可以加速数据船
|
||||
流量控制,端到端,接收端额应用层处理速度决定
|
||||
|
||||
|
||||
分布式一致性
|
||||
对于一个分布式系统而言,分区容错性是一个最基本的要求,因此既然是一个分布式系统,那么分布式系统中的组件必然需要被部署到不同的节点
|
||||
分区容错性也就成为一个分布式系统必然需要面对和解决的问题,因此系统架构师往往把精力花在如何根据业务特点在C一致性和A可用性之前寻求平衡
|
||||
base理论
|
||||
基本可用 出现不可预知状态时,允许
|
||||
软状态,允许数据存在中间状态,并认为该状态不会影响系统的整体可用性,即允许系统在不同节点的数据副本之间进行数据同步的过程存在延时。
|
||||
最终一致性
|
||||
最终一致性 强调的是所有的数据副本,在经过一段时间的同步之后,最终都能够达到一个一直的状态,因此最终一致性的本质是需要系统保证最终数据能够达到一致,而不需要实时保证系统数据的
|
||||
强一致性。
|
||||
大型高可用可扩展的分布式系统和传统ACID特性相反, 牺牲强一致性来活动可用性,
|
||||
A 原子性 一致性 隔离性能 持久性
|
||||
|
||||
etcd就是使用raft算法来保持数据一致性的 与raft类似的还有POXOS算法和 ZAB协议等
|
||||
|
||||
etcd和console
|
||||
|
||||
leader 和 follower
|
||||
选举超时时间 一定周期/时间 150ms-300ms 之间的随机数 心跳<选举周期
|
||||
|
||||
|
||||
选举周期
|
||||
周期数
|
||||
|
||||
|
||||
面对对象编程:
|
||||
|
||||
|
||||
封装
|
||||
public、pretected、private
|
||||
|
||||
|
||||
继承
|
||||
|
||||
|
||||
|
||||
|
||||
多态
|
||||
|
||||
nginx 是以even处理模型为基础摩卡,它为了支持跨平台,抽象出了event模块,一部IO,主要是epoll
|
||||
event模块的主要功能就是监听,监听accept后建立的连接,对读写事件进行添加删除,事件处理模型和nginx的非阻塞IO模型结合在一起使用,当IO可读可写的时候,相应的事件就会被唤醒
|
||||
此时就会处理事件的回掉函数
|
||||
|
||||
|
||||
|
||||
面试:
|
||||
拓扑:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user