@@ -38,7 +38,9 @@ import (
38
38
"google.golang.org/api/option"
39
39
gtransport "google.golang.org/api/transport/grpc"
40
40
"google.golang.org/genproto/googleapis/rpc/status"
41
+ "google.golang.org/grpc/codes"
41
42
"google.golang.org/grpc/metadata"
43
+ grpcstatus "google.golang.org/grpc/status"
42
44
"google.golang.org/protobuf/types/known/durationpb"
43
45
field_mask "google.golang.org/protobuf/types/known/fieldmaskpb"
44
46
"google.golang.org/protobuf/types/known/timestamppb"
@@ -47,7 +49,42 @@ import (
47
49
const adminAddr = "bigtableadmin.googleapis.com:443"
48
50
const mtlsAdminAddr = "bigtableadmin.mtls.googleapis.com:443"
49
51
50
- var errExpiryMissing = errors .New ("WithExpiry is a required option" )
52
+ var (
53
+ errExpiryMissing = errors .New ("WithExpiry is a required option" )
54
+ adminRetryOptions = []gax.CallOption {
55
+ gax .WithRetry (func () gax.Retryer {
56
+ return & bigtableAdminRetryer {
57
+ Backoff : defaultBackoff ,
58
+ }
59
+ }),
60
+ }
61
+ )
62
+
63
+ // bigtableAdminRetryer extends the generic gax Retryer, but also checks
64
+ // error messages to check if operation can be retried
65
+ //
66
+ // Retry is made if :
67
+ // - error code is one of the `idempotentRetryCodes` OR
68
+ // - error code is internal and error message is one of the `retryableInternalErrMsgs`
69
+ type bigtableAdminRetryer struct {
70
+ gax.Backoff
71
+ }
72
+
73
+ func (r * bigtableAdminRetryer ) Retry (err error ) (time.Duration , bool ) {
74
+ // Similar to gax.OnCodes but shares the backoff with INTERNAL retry messages check
75
+ st , ok := grpcstatus .FromError (err )
76
+ if ! ok {
77
+ return 0 , false
78
+ }
79
+ c := st .Code ()
80
+ _ , isIdempotent := isIdempotentRetryCode [c ]
81
+ if isIdempotent ||
82
+ (grpcstatus .Code (err ) == codes .Internal && containsAny (err .Error (), retryableInternalErrMsgs )) {
83
+ pause := r .Backoff .Pause ()
84
+ return pause , true
85
+ }
86
+ return 0 , false
87
+ }
51
88
52
89
// ErrPartiallyUnavailable is returned when some locations (clusters) are
53
90
// unavailable. Both partial results (retrieved from available locations)
@@ -221,7 +258,7 @@ func (ac *AdminClient) Tables(ctx context.Context) ([]string, error) {
221
258
var err error
222
259
res , err = ac .tClient .ListTables (ctx , req )
223
260
return err
224
- }, retryOptions ... )
261
+ }, adminRetryOptions ... )
225
262
if err != nil {
226
263
return nil , err
227
264
}
@@ -660,7 +697,7 @@ func (ac *AdminClient) getTable(ctx context.Context, table string, view btapb.Ta
660
697
var err error
661
698
res , err = ac .tClient .GetTable (ctx , req )
662
699
return err
663
- }, retryOptions ... )
700
+ }, adminRetryOptions ... )
664
701
if err != nil {
665
702
return nil , err
666
703
}
@@ -913,7 +950,7 @@ func (ac *AdminClient) Snapshots(ctx context.Context, cluster string) *SnapshotI
913
950
var err error
914
951
resp , err = ac .tClient .ListSnapshots (ctx , req )
915
952
return err
916
- }, retryOptions ... )
953
+ }, adminRetryOptions ... )
917
954
if err != nil {
918
955
return "" , err
919
956
}
@@ -1018,7 +1055,7 @@ func (ac *AdminClient) SnapshotInfo(ctx context.Context, cluster, snapshot strin
1018
1055
var err error
1019
1056
resp , err = ac .tClient .GetSnapshot (ctx , req )
1020
1057
return err
1021
- }, retryOptions ... )
1058
+ }, adminRetryOptions ... )
1022
1059
if err != nil {
1023
1060
return nil , err
1024
1061
}
@@ -1070,7 +1107,7 @@ func (ac *AdminClient) isConsistent(ctx context.Context, tableName, token string
1070
1107
var err error
1071
1108
resp , err = ac .tClient .CheckConsistency (ctx , req )
1072
1109
return err
1073
- }, retryOptions ... )
1110
+ }, adminRetryOptions ... )
1074
1111
if err != nil {
1075
1112
return false , err
1076
1113
}
@@ -1430,7 +1467,7 @@ func (iac *InstanceAdminClient) Instances(ctx context.Context) ([]*InstanceInfo,
1430
1467
var err error
1431
1468
res , err = iac .iClient .ListInstances (ctx , req )
1432
1469
return err
1433
- }, retryOptions ... )
1470
+ }, adminRetryOptions ... )
1434
1471
if err != nil {
1435
1472
return nil , err
1436
1473
}
@@ -1468,7 +1505,7 @@ func (iac *InstanceAdminClient) InstanceInfo(ctx context.Context, instanceID str
1468
1505
var err error
1469
1506
res , err = iac .iClient .GetInstance (ctx , req )
1470
1507
return err
1471
- }, retryOptions ... )
1508
+ }, adminRetryOptions ... )
1472
1509
if err != nil {
1473
1510
return nil , err
1474
1511
}
@@ -1744,7 +1781,7 @@ func (iac *InstanceAdminClient) Clusters(ctx context.Context, instanceID string)
1744
1781
var err error
1745
1782
res , err = iac .iClient .ListClusters (ctx , req )
1746
1783
return err
1747
- }, retryOptions ... )
1784
+ }, adminRetryOptions ... )
1748
1785
if err != nil {
1749
1786
return nil , err
1750
1787
}
@@ -1792,7 +1829,7 @@ func (iac *InstanceAdminClient) GetCluster(ctx context.Context, instanceID, clus
1792
1829
var err error
1793
1830
c , err = iac .iClient .GetCluster (ctx , req )
1794
1831
return err
1795
- }, retryOptions ... )
1832
+ }, adminRetryOptions ... )
1796
1833
if err != nil {
1797
1834
return nil , err
1798
1835
}
@@ -2187,7 +2224,7 @@ func (iac *InstanceAdminClient) GetAppProfile(ctx context.Context, instanceID, n
2187
2224
var err error
2188
2225
ap , err = iac .iClient .GetAppProfile (ctx , profileRequest )
2189
2226
return err
2190
- }, retryOptions ... )
2227
+ }, adminRetryOptions ... )
2191
2228
if err != nil {
2192
2229
return nil , err
2193
2230
}
@@ -2209,7 +2246,7 @@ func (iac *InstanceAdminClient) ListAppProfiles(ctx context.Context, instanceID
2209
2246
var err error
2210
2247
profileRes , err = iac .iClient .ListAppProfiles (ctx , listRequest )
2211
2248
return err
2212
- }, retryOptions ... )
2249
+ }, adminRetryOptions ... )
2213
2250
if err != nil {
2214
2251
return "" , err
2215
2252
}
@@ -2228,7 +2265,6 @@ func (iac *InstanceAdminClient) ListAppProfiles(ctx context.Context, instanceID
2228
2265
// UpdateAppProfile updates an app profile within an instance.
2229
2266
// updateAttrs should be set. If unset, all fields will be replaced.
2230
2267
func (iac * InstanceAdminClient ) UpdateAppProfile (ctx context.Context , instanceID , profileID string , updateAttrs ProfileAttrsToUpdate ) error {
2231
- fmt .Println ("Entering UpdateAppProfile" )
2232
2268
ctx = mergeOutgoingMetadata (ctx , iac .md )
2233
2269
2234
2270
profile := & btapb.AppProfile {
@@ -2595,7 +2631,7 @@ func (ac *AdminClient) Backups(ctx context.Context, cluster string) *BackupItera
2595
2631
var err error
2596
2632
resp , err = ac .tClient .ListBackups (ctx , req )
2597
2633
return err
2598
- }, retryOptions ... )
2634
+ }, adminRetryOptions ... )
2599
2635
if err != nil {
2600
2636
return "" , err
2601
2637
}
@@ -2744,7 +2780,7 @@ func (ac *AdminClient) BackupInfo(ctx context.Context, cluster, backup string) (
2744
2780
var err error
2745
2781
resp , err = ac .tClient .GetBackup (ctx , req )
2746
2782
return err
2747
- }, retryOptions ... )
2783
+ }, adminRetryOptions ... )
2748
2784
if err != nil {
2749
2785
return nil , err
2750
2786
}
@@ -2983,7 +3019,7 @@ func (ac *AdminClient) AuthorizedViewInfo(ctx context.Context, tableID, authoriz
2983
3019
var err error
2984
3020
res , err = ac .tClient .GetAuthorizedView (ctx , req )
2985
3021
return err
2986
- }, retryOptions ... )
3022
+ }, adminRetryOptions ... )
2987
3023
2988
3024
if err != nil {
2989
3025
return nil , err
@@ -3017,7 +3053,7 @@ func (ac *AdminClient) AuthorizedViews(ctx context.Context, tableID string) ([]s
3017
3053
var err error
3018
3054
res , err = ac .tClient .ListAuthorizedViews (ctx , req )
3019
3055
return err
3020
- }, retryOptions ... )
3056
+ }, adminRetryOptions ... )
3021
3057
if err != nil {
3022
3058
return nil , err
3023
3059
}
@@ -3124,7 +3160,7 @@ func (iac *InstanceAdminClient) LogicalViewInfo(ctx context.Context, instanceID,
3124
3160
var err error
3125
3161
res , err = iac .iClient .GetLogicalView (ctx , req )
3126
3162
return err
3127
- }, retryOptions ... )
3163
+ }, adminRetryOptions ... )
3128
3164
3129
3165
if err != nil {
3130
3166
return nil , err
@@ -3144,7 +3180,7 @@ func (iac *InstanceAdminClient) LogicalViews(ctx context.Context, instanceID str
3144
3180
var err error
3145
3181
res , err = iac .iClient .ListLogicalViews (ctx , req )
3146
3182
return err
3147
- }, retryOptions ... )
3183
+ }, adminRetryOptions ... )
3148
3184
if err != nil {
3149
3185
return nil , err
3150
3186
}
@@ -3253,7 +3289,7 @@ func (iac *InstanceAdminClient) MaterializedViewInfo(ctx context.Context, instan
3253
3289
var err error
3254
3290
res , err = iac .iClient .GetMaterializedView (ctx , req )
3255
3291
return err
3256
- }, retryOptions ... )
3292
+ }, adminRetryOptions ... )
3257
3293
3258
3294
if err != nil {
3259
3295
return nil , err
@@ -3279,7 +3315,7 @@ func (iac *InstanceAdminClient) MaterializedViews(ctx context.Context, instanceI
3279
3315
var err error
3280
3316
res , err = iac .iClient .ListMaterializedViews (ctx , req )
3281
3317
return err
3282
- }, retryOptions ... )
3318
+ }, adminRetryOptions ... )
3283
3319
if err != nil {
3284
3320
return nil , err
3285
3321
}
0 commit comments