Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package bigtable | 5 package bigtable |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "strings" | 9 "strings" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 // | 45 // |
| 46 // rk is the starting row key. | 46 // rk is the starting row key. |
| 47 // | 47 // |
| 48 // If the supplied limit is nonzero, no more than limit rows will be | 48 // If the supplied limit is nonzero, no more than limit rows will be |
| 49 // retrieved. | 49 // retrieved. |
| 50 // | 50 // |
| 51 // If keysOnly is true, then the callback will return nil row data. | 51 // If keysOnly is true, then the callback will return nil row data. |
| 52 getLogData(c context.Context, rk *rowKey, limit int, keysOnly bool, cb b tGetCallback) error | 52 getLogData(c context.Context, rk *rowKey, limit int, keysOnly bool, cb b tGetCallback) error |
| 53 } | 53 } |
| 54 | 54 |
| 55 // btTransientSubstrings is the set of known error substrings returned by | |
| 56 // BigTable that indicate failures that aren't related to the specific data | |
| 57 // content. | |
| 58 var btTransientSubstrings = []string{ | |
| 59 "Internal error encountered", | |
| 60 "interactive login is required", | |
|
dnj (Google)
2016/01/21 04:36:25
Learning as we go.
| |
| 61 } | |
| 62 | |
| 55 // btTableProd is an implementation of the btTable interface that uses a real | 63 // btTableProd is an implementation of the btTable interface that uses a real |
| 56 // production BigTable connection. | 64 // production BigTable connection. |
| 57 type btTableProd struct { | 65 type btTableProd struct { |
| 58 *bigtable.Table | 66 *bigtable.Table |
| 59 } | 67 } |
| 60 | 68 |
| 61 func (t *btTableProd) putLogData(c context.Context, rk *rowKey, data []byte) err or { | 69 func (t *btTableProd) putLogData(c context.Context, rk *rowKey, data []byte) err or { |
| 62 m := bigtable.NewMutation() | 70 m := bigtable.NewMutation() |
| 63 m.Set("log", "data", bigtable.ServerTime, data) | 71 m.Set("log", "data", bigtable.ServerTime, data) |
| 64 cm := bigtable.NewCondMutation(bigtable.RowKeyFilter(rk.encode()), nil, m) | 72 cm := bigtable.NewCondMutation(bigtable.RowKeyFilter(rk.encode()), nil, m) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 // Since the BigTable API doesn't give us this information, we will identify | 151 // Since the BigTable API doesn't give us this information, we will identify |
| 144 // transient errors by parsing their error string :( | 152 // transient errors by parsing their error string :( |
| 145 // | 153 // |
| 146 // TODO(dnj): File issue to add error qualifier functions to BigTable API. | 154 // TODO(dnj): File issue to add error qualifier functions to BigTable API. |
| 147 func isTransient(err error) bool { | 155 func isTransient(err error) bool { |
| 148 if err == nil { | 156 if err == nil { |
| 149 return false | 157 return false |
| 150 } | 158 } |
| 151 | 159 |
| 152 msg := err.Error() | 160 msg := err.Error() |
| 153 » if strings.Contains(msg, "Internal error encountered") { | 161 » for _, s := range btTransientSubstrings { |
| 154 » » return true | 162 » » if strings.Contains(msg, s) { |
| 163 » » » return true | |
| 164 » » } | |
| 155 } | 165 } |
| 156 return false | 166 return false |
| 157 } | 167 } |
| 158 | 168 |
| 159 // getLogData loads the "data" column from the "log" column family and returns | 169 // getLogData loads the "data" column from the "log" column family and returns |
| 160 // its []byte contents. | 170 // its []byte contents. |
| 161 // | 171 // |
| 162 // If the row doesn't exist, storage.ErrDoesNotExist will be returned. | 172 // If the row doesn't exist, storage.ErrDoesNotExist will be returned. |
| 163 func getLogData(row bigtable.Row) ([]byte, error) { | 173 func getLogData(row bigtable.Row) ([]byte, error) { |
| 164 ri := getReadItem(row, "log", "data") | 174 ri := getReadItem(row, "log", "data") |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 178 | 188 |
| 179 // Get the specific ReadItem for our column | 189 // Get the specific ReadItem for our column |
| 180 colName := fmt.Sprintf("%s:%s", family, column) | 190 colName := fmt.Sprintf("%s:%s", family, column) |
| 181 for _, item := range items { | 191 for _, item := range items { |
| 182 if item.Column == colName { | 192 if item.Column == colName { |
| 183 return &item | 193 return &item |
| 184 } | 194 } |
| 185 } | 195 } |
| 186 return nil | 196 return nil |
| 187 } | 197 } |
| OLD | NEW |