prevent HK from trying to reparse while parsing is in progress

This commit is contained in:
2022-02-03 17:15:32 +01:00
parent 182c7d8fc1
commit 6a4e2f3ee3
2 changed files with 40 additions and 33 deletions

View File

@@ -51,8 +51,8 @@ type DemoMatchLoader struct {
db *ent.Client db *ent.Client
dp *DemoParser dp *DemoParser
parseDemo chan *Demo parseDemo chan *Demo
parseMap map[string]bool ParseMap map[string]bool
parseMapL *sync.Mutex ParseMapL *sync.Mutex
cache *cache.Cache cache *cache.Cache
connecting bool connecting bool
} }
@@ -160,8 +160,8 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
d.sentryFile = config.Sentry d.sentryFile = config.Sentry
d.db = config.Db d.db = config.Db
d.dp = &DemoParser{} d.dp = &DemoParser{}
d.parseMap = map[string]bool{} d.ParseMap = map[string]bool{}
d.parseMapL = new(sync.Mutex) d.ParseMapL = new(sync.Mutex)
d.cache = config.Cache d.cache = config.Cache
err := d.dp.Setup(config.Db, config.Worker, config.SprayTimeout) err := d.dp.Setup(config.Db, config.Worker, config.SprayTimeout)
if err != nil { if err != nil {
@@ -306,22 +306,22 @@ func (d *DemoMatchLoader) requestDemoInfo(matchId uint64, conclusionId uint64, t
func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
for demo := range d.parseDemo { for demo := range d.parseDemo {
d.parseMapL.Lock() d.ParseMapL.Lock()
if _, ok := d.parseMap[demo.ShareCode]; ok { if _, ok := d.ParseMap[demo.ShareCode]; ok {
log.Infof("[DL] Skipping %s: parsing in progress", demo.ShareCode) log.Infof("[DL] Skipping %s: parsing in progress", demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} else { } else {
d.parseMap[demo.ShareCode] = true d.ParseMap[demo.ShareCode] = true
} }
d.parseMapL.Unlock() d.ParseMapL.Unlock()
if !d.GCReady { if !d.GCReady {
log.Infof("[DL] Postponing match %d (%s): GC not ready", demo.MatchId, demo.ShareCode) log.Infof("[DL] Postponing match %d (%s): GC not ready", demo.MatchId, demo.ShareCode)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
d.parseDemo <- demo d.parseDemo <- demo
continue continue
} }
@@ -329,9 +329,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
matchId, _, _, err := DecodeSharecode(demo.ShareCode) matchId, _, _, err := DecodeSharecode(demo.ShareCode)
if err != nil || matchId == 0 { if err != nil || matchId == 0 {
log.Warningf("[DL] Can't parse match with sharecode %s: %v", demo.ShareCode, err) log.Warningf("[DL] Can't parse match with sharecode %s: %v", demo.ShareCode, err)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
@@ -342,9 +342,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
break break
default: default:
log.Errorf("[DL] Failure trying to lookup match %d in db: %v", matchId, e) log.Errorf("[DL] Failure trying to lookup match %d in db: %v", matchId, e)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
} else { } else {
@@ -357,16 +357,16 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
if err != nil { if err != nil {
log.Warningf("[DL] Parsing demo from match %d failed: %v", demo.MatchId, err) log.Warningf("[DL] Parsing demo from match %d failed: %v", demo.MatchId, err)
} }
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
log.Infof("[DL] Skipped match %d: already loaded", matchId) log.Infof("[DL] Skipped match %d: already loaded", matchId)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
@@ -376,9 +376,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
matchDetails, err := d.getMatchDetails(demo.ShareCode) matchDetails, err := d.getMatchDetails(demo.ShareCode)
if err != nil { if err != nil {
log.Warningf("[DL] Failure to get match-details for %d from GC: %v", demo.MatchId, err) log.Warningf("[DL] Failure to get match-details for %d from GC: %v", demo.MatchId, err)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
@@ -416,9 +416,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
Save(context.Background()) Save(context.Background())
if err != nil { if err != nil {
log.Warningf("[DL] Unable to create match %d: %v", matchZero.GetMatchid(), err) log.Warningf("[DL] Unable to create match %d: %v", matchZero.GetMatchid(), err)
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
continue continue
} }
@@ -499,8 +499,8 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
if err != nil { if err != nil {
log.Warningf("[DL] Can't queue demo %d for parsing: %v", demo.MatchId, err) log.Warningf("[DL] Can't queue demo %d for parsing: %v", demo.MatchId, err)
} }
d.parseMapL.Lock() d.ParseMapL.Lock()
delete(d.parseMap, demo.ShareCode) delete(d.ParseMap, demo.ShareCode)
d.parseMapL.Unlock() d.ParseMapL.Unlock()
} }
} }

View File

@@ -174,11 +174,18 @@ func housekeeping() {
} }
for _, m := range tMatches { for _, m := range tMatches {
demoLoader.ParseMapL.Lock()
if _, ok := demoLoader.ParseMap[m.ShareCode]; ok {
log.Infof("[HK] Skipping %s: parsing in progress", m.ShareCode)
demoLoader.ParseMapL.Unlock()
continue
}
log.Infof("[HK] Try reparsing match %d, played on %s", m.ID, m.Date) log.Infof("[HK] Try reparsing match %d, played on %s", m.ID, m.Date)
err := demoLoader.LoadDemo(&csgo.Demo{MatchId: m.ID, ShareCode: m.ShareCode}) err := demoLoader.LoadDemo(&csgo.Demo{MatchId: m.ID, ShareCode: m.ShareCode})
if err != nil { if err != nil {
log.Warningf("[HK] Failure trying to parse match %d: %v", m.ID, err) log.Warningf("[HK] Failure trying to parse match %d: %v", m.ID, err)
} }
demoLoader.ParseMapL.Unlock()
} }
// check for inconsistent matches // check for inconsistent matches