forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate nodes2ways DB #274
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9bf6b0b
feat: interface declaration of waysnodes
wangyoucao577 ebd9e7d
feat: add writer interface
wangyoucao577 b9d6a6d
feat: implement nodes2way stores in boltdb
wangyoucao577 1a6cbb4
feat: implement query way/ways
wangyoucao577 3943cda
test: db ut
wangyoucao577 ff8c033
chore: dependency for boltdb
wangyoucao577 f27deba
chore: fix dependency for boltdb
wangyoucao577 dd20e52
feat: way2nodes csv utilities
wangyoucao577 4aad342
feat: add new nodes2way-db-builder to extract way-nodes from csv and …
wangyoucao577 34c9939
feat: manually sync db to improve write performance
wangyoucao577 c21d529
chore: ignore new binary and vscode config for source code management
wangyoucao577 cedcc30
fix: improve error info
wangyoucao577 f10aaf2
feat: cli to query ways from nodes
wangyoucao577 e01781d
refactor: rename cmd
wangyoucao577 e91fe38
feat: measure querying time cost, only output by glog which will not …
wangyoucao577 04da7af
feat: print db statitics
wangyoucao577 6e87f77
feat: more specified error message
wangyoucao577 cc2d5bc
docs: add two cli tools
wangyoucao577 d53ba82
refactor: rename bucket name
wangyoucao577 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
) | ||
|
||
var flags struct { | ||
snappyCompressed bool | ||
in string // E.g., wayid2nodeids.csv or wayid2nodeids.csv.snappy | ||
out string // DB path | ||
} | ||
|
||
func init() { | ||
flag.StringVar(&flags.in, "i", "wayid2nodeids.csv.snappy", "Input wayid2nodeids csv file path, e.g., wayid2nodeids.csv or wayid2nodeids.csv.snappy.") | ||
flag.StringVar(&flags.out, "o", "nodes2way.db", "Output DB file path.") | ||
flag.BoolVar(&flags.snappyCompressed, "snappy-compressed", true, "Whether input csv snappy compressed or not.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"time" | ||
|
||
"github.com/Telenav/osrm-backend/integration/util/waysnodes" | ||
"github.com/golang/glog" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
defer glog.Flush() | ||
|
||
pipeline() | ||
} | ||
|
||
func pipeline() { | ||
startTime := time.Now() | ||
|
||
wayNodesChan := make(chan *waysnodes.WayNodes) | ||
errChan := make(chan error) | ||
|
||
go func() { | ||
errChan <- newStore(wayNodesChan, flags.out) | ||
}() | ||
go func() { | ||
errChan <- newReader(flags.in, flags.snappyCompressed, wayNodesChan) | ||
close(wayNodesChan) | ||
}() | ||
|
||
for i := 0; i < 2; i++ { | ||
if err := <-errChan; err != nil { | ||
glog.Error(err) | ||
os.Exit(1) | ||
return | ||
} | ||
} | ||
|
||
glog.Infof("%s totally takes %f seconds for processing.", os.Args[0], time.Now().Sub(startTime).Seconds()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/csv" | ||
"io" | ||
"os" | ||
"time" | ||
|
||
"github.com/golang/snappy" | ||
|
||
"github.com/Telenav/osrm-backend/integration/util/waysnodes" | ||
"github.com/Telenav/osrm-backend/integration/util/waysnodes/way2nodescsv" | ||
"github.com/golang/glog" | ||
) | ||
|
||
func newReader(in string, snappyCompressed bool, out chan<- *waysnodes.WayNodes) error { | ||
startTime := time.Now() | ||
|
||
f, err := os.Open(in) | ||
defer f.Close() | ||
if err != nil { | ||
return err | ||
} | ||
glog.V(1).Infof("open %s succeed.\n", in) | ||
|
||
var r *csv.Reader | ||
if snappyCompressed { | ||
r = csv.NewReader(snappy.NewReader(f)) | ||
} else { | ||
r = csv.NewReader(f) | ||
} | ||
r.ReuseRecord = true | ||
r.FieldsPerRecord = -1 // disable fields count check | ||
|
||
var total, succeed int | ||
for { | ||
record, err := r.Read() | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
total++ | ||
|
||
wayNodes := waysnodes.WayNodes{} | ||
wayNodes.WayID, wayNodes.NodeIDs, err = way2nodescsv.ParseRecord(record) | ||
if err != nil { | ||
glog.Warningf("Parse record %v failed, err: %v", record, err) | ||
continue | ||
} | ||
out <- &wayNodes | ||
succeed++ | ||
} | ||
|
||
glog.V(1).Infof("Read wayID,nodeID,nodeID,... from file %s, total count %d, succeed parsed %d, takes %f seconds", in, total, succeed, time.Now().Sub(startTime).Seconds()) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/Telenav/osrm-backend/integration/util/waysnodes" | ||
"github.com/Telenav/osrm-backend/integration/util/waysnodes/nodes2wayblotdb" | ||
"github.com/golang/glog" | ||
) | ||
|
||
func newStore(in <-chan *waysnodes.WayNodes, out string) (err error) { | ||
startTime := time.Now() | ||
|
||
db, err := nodes2wayblotdb.Open(out, false) | ||
if err != nil { | ||
return | ||
} | ||
defer func() { | ||
err = db.Close() | ||
}() | ||
|
||
var inCount, succeedCount int | ||
for { | ||
wayNodes, ok := <-in | ||
if !ok { | ||
break | ||
} | ||
inCount++ | ||
|
||
if err := db.Write(wayNodes.WayID, wayNodes.NodeIDs); err != nil { | ||
if glog.V(3) { // avoid affect performance by verbose log | ||
glog.Infof("Update %+v into db failed, err: %v", wayNodes, err) | ||
} | ||
continue | ||
} | ||
succeedCount++ | ||
} | ||
|
||
glog.V(1).Infof("Built DB %s, in count %d, succeed count %d, takes %f seconds", out, inCount, succeedCount, time.Now().Sub(startTime).Seconds()) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/Telenav/osrm-backend/integration/pkg/wayidsflag" | ||
) | ||
|
||
var flags struct { | ||
nodeIDs wayidsflag.WayIDs //TODO: will refactor it to intsflag.Int64s later | ||
db string | ||
dbStat bool | ||
} | ||
|
||
func init() { | ||
flag.Var(&flags.nodeIDs, "nodes", "Continuously comma-seperated nodeIDs on a route. E.g. '167772220006101,167772220007101,167772220008101'.") | ||
flag.StringVar(&flags.db, "db", "nodes2way.db", "DB file path.") | ||
flag.BoolVar(&flags.dbStat, "dbstat", false, "Print DB statistics.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/Telenav/osrm-backend/integration/util/waysnodes/nodes2wayblotdb" | ||
"github.com/golang/glog" | ||
) | ||
|
||
// output logs to stderr without timestamp | ||
var cliLog = log.New(os.Stderr, "", 0) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if flags.dbStat { | ||
s, err := dbStat(flags.db) | ||
if err != nil { | ||
cliLog.Println(err) | ||
os.Exit(1) | ||
return | ||
} | ||
fmt.Println(s) | ||
return | ||
} | ||
|
||
wayIDs, err := query(flags.db, flags.nodeIDs) | ||
if err != nil { | ||
cliLog.Println(err) | ||
os.Exit(1) | ||
return | ||
} | ||
fmt.Println(wayIDs) | ||
} | ||
|
||
func query(dbFile string, nodeIDs []int64) ([]int64, error) { | ||
|
||
db, err := nodes2wayblotdb.Open(dbFile, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer db.Close() | ||
|
||
startTime := time.Now() | ||
|
||
wayIDs, err := db.QueryWays(nodeIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
glog.Infof("Querying takes %f seconds", time.Now().Sub(startTime).Seconds()) // easy to measure querying time cost | ||
|
||
return wayIDs, nil | ||
} | ||
|
||
func dbStat(dbFile string) (string, error) { | ||
db, err := nodes2wayblotdb.Open(dbFile, true) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer db.Close() | ||
|
||
return db.Statistics(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirm:
glog.V(3).Infof
should be able to achieve the same goal. I saw the document mentioned both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally they're the same. The difference is that the first one is cheaper if logging is off because it does not evaluate its arguments, and the seconder one is shorter. See more in https://godoc.org/github.com/golang/glog#V.