Skip to content

Commit 0d96c96

Browse files
committed
write_pending for each stream
1 parent c64402d commit 0d96c96

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

google/cloud/storage/internal/async/object_descriptor_impl.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ ObjectDescriptorImpl::Read(ReadParams p) {
108108
}
109109

110110
void ObjectDescriptorImpl::Flush(std::unique_lock<std::mutex> lk) {
111-
if (write_pending_ || next_request_.read_ranges().empty()) return;
112-
write_pending_ = true;
111+
if (streams_.back().write_pending || next_request_.read_ranges().empty()) {
112+
return;
113+
}
114+
streams_.back().write_pending = true;
113115
google::storage::v2::BidiReadObjectRequest request;
114116
request.Swap(&next_request_);
115117

@@ -125,7 +127,7 @@ void ObjectDescriptorImpl::Flush(std::unique_lock<std::mutex> lk) {
125127
void ObjectDescriptorImpl::OnWrite(bool ok) {
126128
std::unique_lock<std::mutex> lk(mu_);
127129
if (!ok) return DoFinish(std::move(lk));
128-
write_pending_ = false;
130+
streams_.back().write_pending = false;
129131
Flush(std::move(lk));
130132
}
131133

@@ -215,7 +217,7 @@ void ObjectDescriptorImpl::Resume(google::rpc::Status const& proto_status) {
215217
if (!range) continue;
216218
*request.add_read_ranges() = *std::move(range);
217219
}
218-
write_pending_ = true;
220+
streams_.back().write_pending = true;
219221
lk.unlock();
220222
make_stream_(std::move(request)).then([w = WeakFromThis()](auto f) {
221223
if (auto self = w.lock()) self->OnResume(f.get());

google/cloud/storage/internal/async/object_descriptor_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ObjectDescriptorImpl
4343
std::shared_ptr<OpenStream> stream;
4444
std::unordered_map<std::int64_t, std::shared_ptr<ReadRange>> active_ranges;
4545
std::unique_ptr<storage_experimental::ResumePolicy> resume_policy;
46+
bool write_pending = false;
4647
};
4748

4849
public:
@@ -110,7 +111,6 @@ class ObjectDescriptorImpl
110111
google::storage::v2::BidiReadObjectSpec read_object_spec_;
111112
absl::optional<google::storage::v2::Object> metadata_;
112113
std::int64_t read_id_generator_ = 0;
113-
bool write_pending_ = false;
114114
google::storage::v2::BidiReadObjectRequest next_request_;
115115

116116
Options options_;

0 commit comments

Comments
 (0)