Skip to content

Commit

Permalink
feat: Only RAPID supports appendable objects. (#30)
Browse files Browse the repository at this point in the history
* feat: Only RAPID supports appendable objects.

This restriction is subject to change.

* address lint issues
  • Loading branch information
cjc25 authored Nov 4, 2024
1 parent 7b50966 commit 47c63fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions gcs/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def process_bidi_write_object_grpc(cls, db, request_iterator, context):
).metadata
upload = cls.__init_first_write_grpc(first_msg, bucket, context)
if first_msg.write_object_spec.appendable:
if bucket.storage_class != "RAPID":
testbench.error.invalid(
f"Appendable object in {bucket.storage_class} storage class",
context,
)
is_appendable = True
appendable_metadata_in_first_response = True
db.insert_upload(upload)
Expand Down
36 changes: 33 additions & 3 deletions tests/test_grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,19 +1859,47 @@ def test_bidi_write_object_resumable(self):
self.assertEqual(blob.name, "object-name")
self.assertEqual(blob.bucket, "projects/_/buckets/bucket-name")

def test_bidi_write_object_appendable_unsupported(self):
# The code depends on `context.abort()` raising an exception.
context = self.mock_context()
context.abort.side_effect = grpc.RpcError()
req = storage_pb2.BidiWriteObjectRequest(
write_object_spec=storage_pb2.WriteObjectSpec(
resource=storage_pb2.Object(
name="object-name", bucket="projects/_/buckets/bucket-name"
),
appendable=True,
),
)
with self.assertRaises(grpc.RpcError):
streamer = self.grpc.BidiWriteObject([req], context=context)
responses = list(streamer)

def test_bidi_write_object_appendable(self):
# The code depends on `context.abort()` raising an exception.
context = self.mock_context()
context.abort.side_effect = grpc.RpcError()

# Only the RAPID storage class supports appendable objects at this time.
self.grpc.CreateBucket(
storage_pb2.CreateBucketRequest(
parent="projects/test-project",
bucket_id="rapid-bucket",
bucket=storage_pb2.Bucket(
storage_class="RAPID",
),
),
context,
)

QUANTUM = 256 * 1024
media = TestGrpc._create_block(2 * QUANTUM + QUANTUM / 2).encode("utf-8")
offset = 0
content = media[0:QUANTUM]
r1 = storage_pb2.BidiWriteObjectRequest(
write_object_spec=storage_pb2.WriteObjectSpec(
resource=storage_pb2.Object(
name="object-name", bucket="projects/_/buckets/bucket-name"
name="object-name", bucket="projects/_/buckets/rapid-bucket"
),
appendable=True,
),
Expand Down Expand Up @@ -1899,7 +1927,9 @@ def test_bidi_write_object_appendable(self):
# For appendable objects, we expect the object metadata in the first
# response rather than the persisted_size.
self.assertEqual(responses[0].resource.size, 2 * QUANTUM)
self.assertEqual(responses[0].resource.bucket, "projects/_/buckets/bucket-name")
self.assertEqual(
responses[0].resource.bucket, "projects/_/buckets/rapid-bucket"
)
self.assertEqual(responses[0].resource.name, "object-name")

bucket = responses[0].resource.bucket
Expand Down Expand Up @@ -1939,7 +1969,7 @@ def test_bidi_write_object_appendable(self):
blob = responses[1].resource
self.assertEqual(responses[1].resource.size, 2 * QUANTUM + QUANTUM / 2)
self.assertEqual(blob.name, "object-name")
self.assertEqual(blob.bucket, "projects/_/buckets/bucket-name")
self.assertEqual(blob.bucket, "projects/_/buckets/rapid-bucket")

def test_bidi_write_object_no_requests(self):
# The code depends on `context.abort()` raising an exception.
Expand Down

0 comments on commit 47c63fa

Please sign in to comment.