summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srv.go10
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvForward.go7
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvForwardEs.go7
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go2
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go45
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesStore.go10
6 files changed, 35 insertions, 46 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srv.go b/src/hub/src/spreadspace.org/sfive/s5srv.go
index a69adfe..6f5ebbb 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srv.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srv.go
@@ -25,8 +25,7 @@ type getUpdatesToken struct {
}
type getHubIdResult struct {
- id string
- err error
+ id string
}
type getHubIdToken struct {
@@ -88,8 +87,7 @@ func (self StatsSinkServer) appendActor() {
values, err := self.store.GetUpdates()
token.response <- getUpdatesResult{values, err}
case token := <-self.getHubIdChan:
- storeId, err := self.store.GetStoreId()
- token.response <- getHubIdResult{storeId, err}
+ token.response <- getHubIdResult{self.store.GetStoreId()}
case token := <-self.getLastUpdateIdChan:
lastUpdateId, err := self.store.GetLastUpdateId()
if lastUpdateId != nil {
@@ -117,12 +115,12 @@ func (self StatsSinkServer) getUpdatesInvoke() ([]StatisticsData, error) {
return res.values, res.err
}
-func (self StatsSinkServer) getHubIdInvoke() (string, error) {
+func (self StatsSinkServer) getHubIdInvoke() string {
token := getHubIdToken{response: make(chan getHubIdResult, 1)}
defer close(token.response)
self.getHubIdChan <- token
res := <-token.response
- return res.id, res.err
+ return res.id
}
func (self StatsSinkServer) getLastUpdateIdInvoke() (int, error) {
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForward.go b/src/hub/src/spreadspace.org/sfive/s5srvForward.go
index a072b2a..418d195 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvForward.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvForward.go
@@ -21,12 +21,7 @@ func findMaxId(values []StatisticsData) int {
}
func (self StatsSinkServer) getLastUpdate(baseurl string, client *http.Client) (latestId int, storeId string, err error) {
- storeId, err = self.getHubIdInvoke()
-
- if err != nil {
- s5l.Printf("fwd: failed to get own hubid: %v\n", err)
- return
- }
+ storeId = self.getHubIdInvoke()
var resp *http.Response
resp, err = client.Get(baseurl + "/lastupdate/" + storeId)
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForwardEs.go b/src/hub/src/spreadspace.org/sfive/s5srvForwardEs.go
index 19abb1e..da5ff80 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvForwardEs.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvForwardEs.go
@@ -18,12 +18,7 @@ const lastUpdateJson = `{
func (self StatsSinkServer) getLastUpdateEs(baseurl string, client *http.Client) (latestId int, storeId string, err error) {
url := baseurl + "/dataupdate/_search?search_type=count"
- storeId, err = self.getHubIdInvoke()
-
- if err != nil {
- s5l.Printf("fwd-es: failed to get own hubid: %v\n", err)
- return
- }
+ storeId = self.getHubIdInvoke()
queryJson := fmt.Sprintf(lastUpdateJson, storeId)
s5tl.Printf("fwd-es: query: %s", queryJson)
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 54daa65..6292ba8 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
@@ -14,7 +14,7 @@ import (
func (self StatsSinkServer) healthz(c web.C, w http.ResponseWriter, r *http.Request) {
// TODO: do a more sophisticated check
- fmt.Fprintf(w, "OK\n")
+ fmt.Fprintf(w, "%s\n", self.store.GetStoreId())
}
func (self StatsSinkServer) getSourcesList(c web.C, w http.ResponseWriter, r *http.Request) {
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index c4e1676..3ccc202 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -54,7 +54,7 @@ func updateFromStatisticsData(value StatisticsData) (dataUpdateDb, []ClientData,
return du, cd, src
}
-func initDbBolt(boltPath string) (boltDb *bolt.DB, err error) {
+func initDbBolt(boltPath string) (boltDb *bolt.DB, hubId string, err error) {
boltDb, err = bolt.Open(boltPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return
@@ -73,14 +73,30 @@ func initDbBolt(boltPath string) (boltDb *bolt.DB, err error) {
if _, err := tx.CreateBucketIfNotExists([]byte(userAgentsFwdBn)); err != nil {
return err
}
- _, err := tx.CreateBucketIfNotExists([]byte(userAgentsRevBn))
- return err
+ if _, err := tx.CreateBucketIfNotExists([]byte(userAgentsRevBn)); err != nil {
+ return err
+ }
+
+ b, err := tx.CreateBucketIfNotExists([]byte(hubInfoBn))
+ if err != nil {
+ return err
+ }
+ bHubId := b.Get([]byte(hubUUIDKey))
+ if bHubId == nil {
+ hubId = uuid.New()
+ if err := b.Put([]byte(hubUUIDKey), []byte(hubId)); err != nil {
+ return err
+ }
+ } else {
+ hubId = string(bHubId)
+ }
+ return nil
})
return
}
-func initDbSqlite(sqlitePath string) (dbmap *gorp.DbMap, hubId string, err error) {
+func initDbSqlite(sqlitePath string) (dbmap *gorp.DbMap, err error) {
var db *sql.DB
db, err = sql.Open("sqlite3", sqlitePath)
@@ -92,24 +108,12 @@ func initDbSqlite(sqlitePath string) (dbmap *gorp.DbMap, hubId string, err error
// dbmap.TraceOn("[gorp]", log.New(os.Stdout, "myapp:", log.Lmicroseconds))
dbmap.AddTableWithName(dataUpdateDb{}, dataUpdatesTn).SetKeys(true, "Id")
- dbmap.AddTableWithName(hubInfoDb{}, hubInfoTn).SetKeys(false, "Name")
// TODO use some real migration, yadda yadda
if err = dbmap.CreateTablesIfNotExists(); err != nil {
return
}
- hubId, err = dbmap.SelectStr("select Value from " + hubInfoTn + " where Name = 'HubUuid'")
- // TODO handle only not-found this way
- if err != nil || hubId == "" {
- hubId = uuid.New()
- _, err = db.Exec("insert into "+hubInfoTn+" values ('HubUuid', ?)", hubId)
- if err != nil {
- hubId = ""
- return
- }
- }
-
return
}
@@ -398,18 +402,17 @@ func (s sqliteStore) GetLastUpdateId() (updateId *int, err error) {
return
}
-func (s sqliteStore) GetStoreId() (uuid string, err error) {
- uuid, err = s.db.SelectStr("select Value from HubInfo where Name = ?", "HubUuid")
- return
+func (s sqliteStore) GetStoreId() string {
+ return s.hubId
}
func NewStore(sqlitePath, boltPath string) (sqliteStore, error) {
- boltDb, err := initDbBolt(boltPath)
+ boltDb, hubid, err := initDbBolt(boltPath)
if err != nil {
return sqliteStore{}, err
}
- db, hubid, err := initDbSqlite(sqlitePath)
+ db, err := initDbSqlite(sqlitePath)
if err != nil {
boltDb.Close()
return sqliteStore{}, err
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesStore.go b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
index a6ac3a9..fd21337 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesStore.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
@@ -18,20 +18,18 @@ var (
const (
// sqlite table names
dataUpdatesTn = "DataUpdates"
- hubInfoTn = "HubInfo"
// bolt bucket names
+ hubInfoBn = "HubInfo"
sourcesFwdBn = "SourcesFwd"
sourcesRevBn = "SourcesRev"
clientDataBn = "ClientData"
userAgentsFwdBn = "UserAgentsFwd"
userAgentsRevBn = "UserAgentsRev"
-)
-type hubInfoDb struct {
- Name string
- Value string
-}
+ // well-known keys
+ hubUUIDKey = "HubUUID"
+)
// stored in sourcesRevBn
type streamIdDb struct {