MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Init

Method Init

internal/stats/dau_manager.go:56–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54}
55
56func (this *DAUManager) Init() error {
57 // recover from cache
58 _ = this.recover()
59
60 // create table
61 store, storeErr := kvstore.DefaultStore()
62 if storeErr != nil {
63 return storeErr
64 }
65
66 db, dbErr := store.NewDB("dau")
67 if dbErr != nil {
68 return dbErr
69 }
70
71 {
72 table, err := kvstore.NewTable[[]byte]("ip", kvstore.NewNilValueEncoder())
73 if err != nil {
74 return err
75 }
76 db.AddTable(table)
77 this.ipTable = table
78 }
79
80 {
81 table, err := kvstore.NewTable[uint64]("stats", kvstore.NewIntValueEncoder[uint64]())
82 if err != nil {
83 return err
84 }
85 db.AddTable(table)
86 }
87
88 // clean expires items
89 goman.New(func() {
90 idles.RunTicker(this.cleanTicker, func() {
91 err := this.CleanStats()
92 if err != nil {
93 remotelogs.Error("DAU_MANAGER", "clean stats failed: "+err.Error())
94 }
95 })
96 })
97
98 // dump ip to kvstore
99 goman.New(func() {
100 // cache latest IPs to reduce kv queries
101 var cachedIPs []IPInfo
102 var maxIPs = runtime.NumCPU() * 8
103 if maxIPs <= 0 {
104 maxIPs = 8
105 } else if maxIPs > 64 {
106 maxIPs = 64
107 }
108
109 var day = fasttime.Now().Ymd()
110
111 Loop:
112 for ipInfo := range this.ipChan {
113 // check day

Callers

nothing calls this directly

Calls 15

recoverMethod · 0.95
AddTableMethod · 0.95
CleanStatsMethod · 0.95
processIPMethod · 0.95
CloseMethod · 0.95
DefaultStoreFunction · 0.92
NewTableFunction · 0.92
NewNilValueEncoderFunction · 0.92
NewFunction · 0.92
RunTickerFunction · 0.92
ErrorFunction · 0.92
NowFunction · 0.92

Tested by

no test coverage detected