Skip to content

Commit 5dc6829

Browse files
authored
fix: fix automated backup (#2844)
Change-Id: I5fff06ee77bb2565d0c1478ad18ff9324c26b984 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent f7894c0 commit 5dc6829

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

  • google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.Map.Entry;
2929
import javax.annotation.Nonnull;
30+
import javax.annotation.Nullable;
3031
import org.threeten.bp.Duration;
3132

3233
/** Wrapper for {@link Table} protocol buffer object */
@@ -111,6 +112,7 @@ public static class AutomatedBackupPolicy {
111112
@InternalApi
112113
public static AutomatedBackupPolicy fromProto(
113114
com.google.bigtable.admin.v2.Table.AutomatedBackupPolicy proto) {
115+
Preconditions.checkNotNull(proto);
114116
return new AutomatedBackupPolicy(proto);
115117
}
116118

@@ -143,7 +145,7 @@ public String viewConfig() {
143145

144146
private final Duration changeStreamRetention;
145147
private final boolean deletionProtection;
146-
private static AutomatedBackupPolicy automatedBackupPolicy;
148+
@Nullable private final AutomatedBackupPolicy automatedBackupPolicy;
147149

148150
@InternalApi
149151
public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) {
@@ -170,10 +172,9 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto)
170172
proto.getChangeStreamConfig().getRetentionPeriod().getNanos());
171173
}
172174

175+
AutomatedBackupPolicy automatedBackupPolicy = null;
173176
if (proto.hasAutomatedBackupPolicy()) {
174177
automatedBackupPolicy = AutomatedBackupPolicy.fromProto(proto.getAutomatedBackupPolicy());
175-
} else {
176-
automatedBackupPolicy = null;
177178
}
178179

179180
return new Table(
@@ -191,14 +192,14 @@ private Table(
191192
List<ColumnFamily> columnFamilies,
192193
Duration changeStreamRetention,
193194
boolean deletionProtection,
194-
AutomatedBackupPolicy automatedBackupPolicy) {
195+
@Nullable AutomatedBackupPolicy automatedBackupPolicy) {
195196
this.instanceId = tableName.getInstance();
196197
this.id = tableName.getTable();
197198
this.replicationStatesByClusterId = replicationStatesByClusterId;
198199
this.columnFamilies = columnFamilies;
199200
this.changeStreamRetention = changeStreamRetention;
200201
this.deletionProtection = deletionProtection;
201-
Table.automatedBackupPolicy = automatedBackupPolicy;
202+
this.automatedBackupPolicy = automatedBackupPolicy;
202203
}
203204

204205
/** Gets the table's id. */
@@ -230,10 +231,11 @@ public boolean isDeletionProtected() {
230231

231232
/** Returns whether this table has automated backups enabled. */
232233
public boolean isAutomatedBackupEnabled() {
233-
return automatedBackupPolicy == null ? false : true;
234+
return automatedBackupPolicy != null;
234235
}
235236

236237
/** Returns the automated backup policy config. */
238+
@Nullable
237239
public AutomatedBackupPolicy getAutomatedBackupPolicy() {
238240
return automatedBackupPolicy;
239241
}
@@ -253,7 +255,7 @@ public boolean equals(Object o) {
253255
&& Objects.equal(columnFamilies, table.columnFamilies)
254256
&& Objects.equal(changeStreamRetention, table.changeStreamRetention)
255257
&& Objects.equal(deletionProtection, table.deletionProtection)
256-
&& Objects.equal(automatedBackupPolicy, Table.automatedBackupPolicy);
258+
&& Objects.equal(automatedBackupPolicy, table.automatedBackupPolicy);
257259
}
258260

259261
@Override

0 commit comments

Comments
 (0)