OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package bigtable | 5 package bigtable |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "time" | 9 "time" |
10 | 10 |
11 "cloud.google.com/go/bigtable" | 11 "cloud.google.com/go/bigtable" |
12 "github.com/luci/luci-go/common/data/stringset" | 12 "github.com/luci/luci-go/common/data/stringset" |
13 "github.com/luci/luci-go/common/errors" | 13 "github.com/luci/luci-go/common/errors" |
14 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
15 "github.com/luci/luci-go/common/retry" | 15 "github.com/luci/luci-go/common/retry" |
| 16 "github.com/luci/luci-go/common/retry/transient" |
16 "github.com/luci/luci-go/logdog/common/storage" | 17 "github.com/luci/luci-go/logdog/common/storage" |
17 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
18 ) | 19 ) |
19 | 20 |
20 // DefaultMaxLogAge is the maximum age of a log (7 days). | 21 // DefaultMaxLogAge is the maximum age of a log (7 days). |
21 const DefaultMaxLogAge = time.Duration(7 * 24 * time.Hour) | 22 const DefaultMaxLogAge = time.Duration(7 * 24 * time.Hour) |
22 | 23 |
23 // InitializeScopes is the set of OAuth scopes needed to use the Initialize | 24 // InitializeScopes is the set of OAuth scopes needed to use the Initialize |
24 // functionality. | 25 // functionality. |
25 var InitializeScopes = []string{ | 26 var InitializeScopes = []string{ |
26 bigtable.AdminScope, | 27 bigtable.AdminScope, |
27 } | 28 } |
28 | 29 |
29 func tableExists(ctx context.Context, c *bigtable.AdminClient, name string) (boo
l, error) { | 30 func tableExists(ctx context.Context, c *bigtable.AdminClient, name string) (boo
l, error) { |
30 tables, err := c.Tables(ctx) | 31 tables, err := c.Tables(ctx) |
31 if err != nil { | 32 if err != nil { |
32 return false, err | 33 return false, err |
33 } | 34 } |
34 | 35 |
35 for _, t := range tables { | 36 for _, t := range tables { |
36 if t == name { | 37 if t == name { |
37 return true, nil | 38 return true, nil |
38 } | 39 } |
39 } | 40 } |
40 return false, nil | 41 return false, nil |
41 } | 42 } |
42 | 43 |
43 func waitForTable(ctx context.Context, c *bigtable.AdminClient, name string) err
or { | 44 func waitForTable(ctx context.Context, c *bigtable.AdminClient, name string) err
or { |
44 » return retry.Retry(ctx, retry.TransientOnly(retry.Default), func() error
{ | 45 » return retry.Retry(ctx, transient.Only(retry.Default), func() error { |
45 exists, err := tableExists(ctx, c, name) | 46 exists, err := tableExists(ctx, c, name) |
46 if err != nil { | 47 if err != nil { |
47 return err | 48 return err |
48 } | 49 } |
49 if !exists { | 50 if !exists { |
50 » » » return errors.WrapTransient(errors.New("table does not e
xist")) | 51 » » » return errors.New("table does not exist", transient.Tag) |
51 } | 52 } |
52 return nil | 53 return nil |
53 }, func(err error, delay time.Duration) { | 54 }, func(err error, delay time.Duration) { |
54 log.Fields{ | 55 log.Fields{ |
55 log.ErrorKey: err, | 56 log.ErrorKey: err, |
56 "delay": delay, | 57 "delay": delay, |
57 }.Warningf(ctx, "Table does not exist yet; retrying.") | 58 }.Warningf(ctx, "Table does not exist yet; retrying.") |
58 }) | 59 }) |
59 } | 60 } |
60 | 61 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 cfg := storage.Config{ | 127 cfg := storage.Config{ |
127 MaxLogAge: DefaultMaxLogAge, | 128 MaxLogAge: DefaultMaxLogAge, |
128 } | 129 } |
129 if err := st.Config(cfg); err != nil { | 130 if err := st.Config(cfg); err != nil { |
130 log.WithError(err).Errorf(ctx, "Failed to push default configura
tion.") | 131 log.WithError(err).Errorf(ctx, "Failed to push default configura
tion.") |
131 return err | 132 return err |
132 } | 133 } |
133 | 134 |
134 return nil | 135 return nil |
135 } | 136 } |
OLD | NEW |