| OLD | NEW |
| 1 package buildbot | 1 package buildbot |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "bytes" | 4 "bytes" |
| 5 "encoding/binary" | 5 "encoding/binary" |
| 6 "encoding/gob" | 6 "encoding/gob" |
| 7 "fmt" | 7 "fmt" |
| 8 "net/http" | 8 "net/http" |
| 9 "strconv" | 9 "strconv" |
| 10 "strings" | 10 "strings" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 // NewLocalDB returns a local DB instance. | 183 // NewLocalDB returns a local DB instance. |
| 184 func NewLocalDB(filename string) (DB, error) { | 184 func NewLocalDB(filename string) (DB, error) { |
| 185 d, err := bolt.Open(filename, 0600, nil) | 185 d, err := bolt.Open(filename, 0600, nil) |
| 186 if err != nil { | 186 if err != nil { |
| 187 return nil, err | 187 return nil, err |
| 188 } | 188 } |
| 189 db := &localDB{ | 189 db := &localDB{ |
| 190 db: d, | 190 db: d, |
| 191 » » txCount: metrics2.NewCounter("db-active-tx", map[string]string{ | 191 » » txCount: metrics2.GetCounter("db-active-tx", map[string]string{ |
| 192 "database": "buildbot", | 192 "database": "buildbot", |
| 193 }), | 193 }), |
| 194 txNextId: 0, | 194 txNextId: 0, |
| 195 txActive: map[int64]string{}, | 195 txActive: map[int64]string{}, |
| 196 txMutex: sync.RWMutex{}, | 196 txMutex: sync.RWMutex{}, |
| 197 } | 197 } |
| 198 go func() { | 198 go func() { |
| 199 for _ = range time.Tick(time.Minute) { | 199 for _ = range time.Tick(time.Minute) { |
| 200 db.reportActiveTx() | 200 db.reportActiveTx() |
| 201 } | 201 } |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 w.Header().Set("Content-Length", strconv.Itoa(int(tx.Siz
e()))) | 987 w.Header().Set("Content-Length", strconv.Itoa(int(tx.Siz
e()))) |
| 988 _, err := tx.WriteTo(w) | 988 _, err := tx.WriteTo(w) |
| 989 return err | 989 return err |
| 990 }); err != nil { | 990 }); err != nil { |
| 991 httputils.ReportError(w, r, err, fmt.Sprintf("Failed to
create DB backup: %s", err)) | 991 httputils.ReportError(w, r, err, fmt.Sprintf("Failed to
create DB backup: %s", err)) |
| 992 } | 992 } |
| 993 }) | 993 }) |
| 994 http.Handle("/", httputils.LoggingGzipRequestResponse(r)) | 994 http.Handle("/", httputils.LoggingGzipRequestResponse(r)) |
| 995 return http.ListenAndServe(port, nil) | 995 return http.ListenAndServe(port, nil) |
| 996 } | 996 } |
| OLD | NEW |