diff --git a/server/app/config.go b/server/app/config.go index f6b196a..5867897 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -3,7 +3,6 @@ package app import ( "encoding/json" "io/ioutil" - "mapserver/coords" "mapserver/layer" "os" "runtime" @@ -11,15 +10,14 @@ import ( ) type Config struct { - Port int `json:"port"` - EnableRendering bool `json:"enablerendering"` - Webdev bool `json:"webdev"` - WebApi *WebApiConfig `json:"webapi"` - RenderState *RenderStateType `json:"renderstate"` - Layers []layer.Layer `json:"layers"` - RenderingFetchLimit int `json:"renderingfetchlimit"` - RenderingJobs int `json:"renderingjobs"` - RenderingQueue int `json:"renderingqueue"` + Port int `json:"port"` + EnableRendering bool `json:"enablerendering"` + Webdev bool `json:"webdev"` + WebApi *WebApiConfig `json:"webapi"` + Layers []layer.Layer `json:"layers"` + RenderingFetchLimit int `json:"renderingfetchlimit"` + RenderingJobs int `json:"renderingjobs"` + RenderingQueue int `json:"renderingqueue"` } type WebApiConfig struct { @@ -30,20 +28,6 @@ type WebApiConfig struct { SecretKey string `json:"secretkey"` } -type RenderStateType struct { - //Initial rendering flag (true=still active) - InitialRun bool `json:"initialrun"` - LegacyProcessed int `json:"legacyprocessed"` - - //Last initial rendering coords - LastX int `json:"lastx"` - LastY int `json:"lasty"` - LastZ int `json:"lastz"` - - //Last mtime of incremental rendering - LastMtime int64 `json:"lastmtime"` -} - var lock sync.Mutex const ConfigFile = "mapserver.json" @@ -79,14 +63,6 @@ func ParseConfig(filename string) (*Config, error) { SecretKey: RandStringRunes(16), } - rstate := RenderStateType{ - InitialRun: true, - LastX: coords.MinCoord - 1, - LastY: coords.MinCoord - 1, - LastZ: coords.MinCoord - 1, - LastMtime: 0, - } - layers := []layer.Layer{ layer.Layer{ Id: 0, @@ -101,7 +77,6 @@ func ParseConfig(filename string) (*Config, error) { EnableRendering: true, Webdev: false, WebApi: &webapi, - RenderState: &rstate, Layers: layers, RenderingFetchLimit: 1000, RenderingJobs: runtime.NumCPU(), diff --git a/server/tilerendererjob/incremental.go b/server/tilerendererjob/incremental.go index 70eba26..e703f1a 100644 --- a/server/tilerendererjob/incremental.go +++ b/server/tilerendererjob/incremental.go @@ -5,6 +5,7 @@ import ( "mapserver/coords" "mapserver/settings" "time" + "github.com/sirupsen/logrus" ) @@ -36,7 +37,7 @@ func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) { } lastMtime = result.LastMtime - ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, lastMtime) + ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, lastMtime) tiles := renderMapblocks(ctx, jobs, result.List) diff --git a/server/tilerendererjob/initial.go b/server/tilerendererjob/initial.go index 5bf32e3..667d3b2 100644 --- a/server/tilerendererjob/initial.go +++ b/server/tilerendererjob/initial.go @@ -1,11 +1,12 @@ package tilerendererjob import ( - "github.com/sirupsen/logrus" "mapserver/app" - "mapserver/settings" "mapserver/coords" + "mapserver/settings" "time" + + "github.com/sirupsen/logrus" ) type InitialRenderEvent struct { @@ -21,7 +22,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { } fields := logrus.Fields{ - "totalLegacyCount": totalLegacyCount + "totalLegacyCount": totalLegacyCount, } logrus.WithFields(fields).Info("Starting initial rendering job") @@ -40,6 +41,8 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { panic(err) } + legacyProcessed := ctx.Settings.GetInt(settings.SETTING_LEGACY_PROCESSED, 0) + if len(result.List) == 0 && !result.HasMore { ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false) @@ -50,7 +53,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { ctx.WebEventbus.Emit("initial-render-progress", &ev) fields := logrus.Fields{ - "legacyblocks": rstate.LegacyProcessed, + "legacyblocks": legacyProcessed, } logrus.WithFields(fields).Info("initial rendering complete") @@ -60,19 +63,20 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { tiles := renderMapblocks(ctx, jobs, result.List) lastcoords = result.LastPos - rstate.LastMtime = result.LastMtime + ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, result.LastMtime) //Save current positions of initial run - rstate.LastX = lastcoords.X - rstate.LastY = lastcoords.Y - rstate.LastZ = lastcoords.Z - rstate.LegacyProcessed += result.UnfilteredCount - ctx.Config.Save() + ctx.Settings.SetInt(settings.SETTING_LASTX, lastcoords.X) + ctx.Settings.SetInt(settings.SETTING_LASTY, lastcoords.Y) + ctx.Settings.SetInt(settings.SETTING_LASTZ, lastcoords.Z) + legacyProcessed += result.UnfilteredCount + + ctx.Settings.SetInt(settings.SETTING_LEGACY_PROCESSED, legacyProcessed) t := time.Now() elapsed := t.Sub(start) - progress := int(float64(rstate.LegacyProcessed) / float64(totalLegacyCount) * 100) + progress := int(float64(legacyProcessed) / float64(totalLegacyCount) * 100) ev := InitialRenderEvent{ Progress: progress, @@ -83,7 +87,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { fields := logrus.Fields{ "mapblocks": len(result.List), "tiles": tiles, - "processed": rstate.LegacyProcessed, + "processed": legacyProcessed, "progress%": progress, "X": lastcoords.X, "Y": lastcoords.Y, diff --git a/server/tilerendererjob/job.go b/server/tilerendererjob/job.go index 7357ea9..c5ea8a4 100644 --- a/server/tilerendererjob/job.go +++ b/server/tilerendererjob/job.go @@ -3,18 +3,18 @@ package tilerendererjob import ( "mapserver/app" "mapserver/coords" + "mapserver/settings" ) func Job(ctx *app.App) { - rstate := ctx.Config.RenderState jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue) for i := 0; i < ctx.Config.RenderingJobs; i++ { go worker(ctx, jobs) } - if rstate.InitialRun { + if ctx.Settings.GetBool(settings.SETTING_INITIAL_RUN, true) { //fast, unsafe mode err := ctx.Objectdb.EnableSpeedSafetyTradeoff(true) if err != nil {