-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: change stream retention to create and update table #1823
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a28c5f9
feat: add change stream retention to create table
211f4f7
Remove creating change stream enabled table in IT because we can't de…
765996e
feat: add update table with change stream retention
7a7e40d
Disable change stream at end of IT so the table can be deleted
39666df
Add change stream retention to create table IT
c2d30bc
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.bigtable.admin.v2.models; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.bigtable.admin.v2.ChangeStreamConfig; | ||
import com.google.cloud.bigtable.admin.v2.internal.NameUtil; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Objects; | ||
import org.threeten.bp.Duration; | ||
|
||
/** | ||
* Wrapper for {@link com.google.bigtable.admin.v2.UpdateTableRequest} | ||
* | ||
* <p>Allows for updating table: | ||
* | ||
* <ul> | ||
* <li>Change stream retention period. | ||
* </ul> | ||
*/ | ||
public class UpdateTableRequest { | ||
|
||
private final String tableId; | ||
|
||
private final com.google.bigtable.admin.v2.UpdateTableRequest.Builder requestBuilder = | ||
com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder(); | ||
|
||
public static UpdateTableRequest of(String tableId) { | ||
return new UpdateTableRequest(tableId); | ||
} | ||
|
||
private UpdateTableRequest(String tableId) { | ||
this.tableId = tableId; | ||
} | ||
|
||
/** Update change stream retention period between 1 day and 7 days. */ | ||
public UpdateTableRequest addChangeStreamRetention(Duration retention) { | ||
Preconditions.checkNotNull(retention); | ||
if (!retention.isZero()) { | ||
requestBuilder | ||
.getTableBuilder() | ||
.setChangeStreamConfig( | ||
ChangeStreamConfig.newBuilder() | ||
.setRetentionPeriod( | ||
com.google.protobuf.Duration.newBuilder() | ||
.setSeconds(retention.getSeconds()) | ||
.setNanos(retention.getNano()) | ||
.build()) | ||
.build()); | ||
requestBuilder.getUpdateMaskBuilder().addPaths("change_stream_config.retention_period"); | ||
} else { | ||
requestBuilder.getTableBuilder().clearChangeStreamConfig(); | ||
requestBuilder.getUpdateMaskBuilder().addPaths("change_stream_config"); | ||
} | ||
return this; | ||
} | ||
|
||
/** Disable change stream for table */ | ||
public UpdateTableRequest disableChangeStreamRetention() { | ||
return addChangeStreamRetention(Duration.ZERO); | ||
} | ||
|
||
@InternalApi | ||
public com.google.bigtable.admin.v2.UpdateTableRequest toProto( | ||
String projectId, String instanceId) { | ||
requestBuilder | ||
.getTableBuilder() | ||
.setName(NameUtil.formatTableName(projectId, instanceId, tableId)); | ||
return requestBuilder.build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof UpdateTableRequest)) return false; | ||
UpdateTableRequest that = (UpdateTableRequest) o; | ||
return Objects.equals(requestBuilder, that.requestBuilder); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(requestBuilder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add precondition to check retention is between 1 and 7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what the philosophy is. Checking here would allow us to fail faster but if we widen the retention period then we have to change on the client side as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per https://google.aip.dev/client-libraries/4223, I think we should rely on the server side validation.