-
Notifications
You must be signed in to change notification settings - Fork 70
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: add soft delete feature #2403
Changes from 1 commit
26326a4
407af36
22ae88d
bd4bb67
d77aa58
a888e80
2a85a65
4f1b6de
fd22008
7142bcb
0f837d3
c2884aa
ac6022e
1c363ff
dbe0d92
fb88608
04975fc
1de29b8
c98d8c7
3a4a00f
b3d70db
7986f9c
a93e162
5a744ca
0b8fe3f
be3e975
5e65c40
938e00c
8f38221
68ce8c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ | |
import com.google.storage.v2.Object; | ||
import com.google.storage.v2.ObjectAccessControl; | ||
import com.google.storage.v2.ReadObjectRequest; | ||
import com.google.storage.v2.RestoreObjectRequest; | ||
import com.google.storage.v2.RewriteObjectRequest; | ||
import com.google.storage.v2.RewriteResponse; | ||
import com.google.storage.v2.StorageClient; | ||
|
@@ -402,6 +403,33 @@ public Blob get(BlobId blob) { | |
return get(blob, new BlobGetOption[0]); | ||
} | ||
|
||
@Override | ||
public Blob restore(BlobId blob, BlobRestoreOption... options) { | ||
Opts<ObjectSourceOpt> unwrap = Opts.unwrap(options); | ||
return internalObjectRestore(blob, unwrap); | ||
} | ||
|
||
private Blob internalObjectRestore(BlobId blobId, Opts<ObjectSourceOpt> opts) { | ||
Opts<ObjectSourceOpt> finalOpts = opts.prepend(defaultOpts).prepend(ALL_BLOB_FIELDS); | ||
GrpcCallContext grpcCallContext = | ||
finalOpts.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); | ||
RestoreObjectRequest.Builder builder = | ||
RestoreObjectRequest.newBuilder() | ||
.setBucket(bucketNameCodec.encode(blobId.getBucket())) | ||
.setObject(blobId.getName()); | ||
ifNonNull(blobId.getGeneration(), builder::setGeneration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the API failure helpful when generation isn't supplied? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it says "you must specify a generation" |
||
RestoreObjectRequest req = finalOpts.restoreObjectRequest().apply(builder).build(); | ||
GrpcCallContext merge = Utils.merge(grpcCallContext, Retrying.newCallContext()); | ||
return Retrying.run( | ||
getOptions(), | ||
retryAlgorithmManager.getFor(req), | ||
() -> storageClient.restoreObjectCallable().call(req, merge), | ||
resp -> { | ||
BlobInfo tmp = codecs.blobInfo().decode(resp); | ||
return finalOpts.clearBlobFields().decode(tmp).asBlob(this); | ||
}); | ||
} | ||
|
||
@Override | ||
public Page<Bucket> list(BucketListOption... options) { | ||
Opts<BucketListOpt> opts = Opts.unwrap(options).prepend(defaultOpts).prepend(ALL_BUCKET_FIELDS); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,10 @@ public ResultRetryAlgorithm<?> getForObjectsGet( | |
return retryStrategy.getIdempotentHandler(); | ||
} | ||
|
||
public ResultRetryAlgorithm<?> getForObjectsRestore(StorageObject pb, Map<StorageRpc.Option, ?> optionsMap) { | ||
return retryStrategy.getIdempotentHandler(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed this on first pass; ObjectRestore is idempotent because it can only succeed once which is similar to Bucket; is that your understanding as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, restore has the same idempotency as Copy and similar operations |
||
} | ||
|
||
public ResultRetryAlgorithm<?> getForObjectsUpdate( | ||
StorageObject pb, Map<StorageRpc.Option, ?> optionsMap) { | ||
return optionsMap.containsKey(StorageRpc.Option.IF_METAGENERATION_MATCH) | ||
|
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.
debug code