void Inode::NotifyBytesRead(size_t bytes) { // notify writer, if something can be written now size_t writable = fBuffer.Writable(); if (bytes > 0) { // notify select()ors only, if nothing was writable before if (writable == bytes) { if (fWriteSelectSyncPool) notify_select_event_pool(fWriteSelectSyncPool, B_SELECT_WRITE); } // If any of the waiting writers has a minimal write count that has // now become satisfied, we notify all of them (condition variables // don't support doing that selectively). WriteRequest* request; WriteRequestList::Iterator iterator = fWriteRequests.GetIterator(); while ((request = iterator.Next()) != NULL) { size_t minWriteCount = request->MinimalWriteCount(); if (minWriteCount > 0 && minWriteCount <= writable && minWriteCount > writable - bytes) { fWriteCondition.NotifyAll(); break; } } } }
void OnLog(const std::string &target, const std::string &module, const std::string &source, const std::string &action, const std::string &data) { for (unsigned j = this->configurations.size(); j > 0; --j) { FlatfileConfiguration *c = this->configurations[j - 1]; if (c->name == target) { this->Clean(); std::string message = ctime(&Sinkhole::curtime); Sinkhole::strip(message); message += " [" + module + "] " + source + ": " + action + " " + data; WriteRequest *req = new WriteRequest(c, message); try { req->Dispatch(); c->requests.push_back(req); } catch (const Sinkhole::Exception &ex) { Sinkhole::Log(Sinkhole::LOG_ERROR) << "Error queing log message: " << ex.GetReason(); } break; } } }
WriteResponse WriteFile(const string &path, string &buf, size_t size, off_t offset) { WriteRequest request; request.set_path(path); request.set_buf(buf); request.set_size(size); request.set_offset(offset); WriteResponse response; ClientContext context; Status status = stub_->WriteFile(&context, request, &response); if (status.ok()) { return response; } // TODO: Do something on failure here return response; }
// This test verifies that a non-VOTING replica does not reply to // promise or write requests. TEST_F(ReplicaTest, NonVoting) { const string path = os::getcwd() + "/.log"; Replica replica(path); PromiseRequest promiseRequest; promiseRequest.set_proposal(2); Future<PromiseResponse> promiseResponse = protocol::promise(replica.pid(), promiseRequest); // Flush the event queue to make sure that if the replica could // reply to the promise request, the future 'promiseResponse' would // be satisfied before the pending check below. Clock::pause(); Clock::settle(); Clock::resume(); EXPECT_TRUE(promiseResponse.isPending()); WriteRequest writeRequest; writeRequest.set_proposal(3); writeRequest.set_position(1); writeRequest.set_type(Action::APPEND); writeRequest.mutable_append()->set_bytes("hello world"); Future<WriteResponse> writeResponse = protocol::write(replica.pid(), writeRequest); // Flush the event queue to make sure that if the replica could // reply to the write request, the future 'writeResponse' would be // satisfied before the pending check below. Clock::pause(); Clock::settle(); Clock::resume(); EXPECT_TRUE(writeResponse.isPending()); }
Error uv11::write(WriteRequest& req, Stream& stream, Buffer const bufs[], unsigned int nbufs, WriteCb const& write_cb) { req.write_cb = write_cb; int s = uv_write( &req.Get(), &stream.GetStream(), bufs, nbufs, [] (uv_write_t* r, int status) { WriteRequest* w = reinterpret_cast<WriteRequest*>(r->data); auto w_cb = w->write_cb; w->write_cb = nullptr; w_cb(*w, make_error(status)); } ); if (s) req.write_cb = nullptr; return make_error(s); }
WriteRequest MessageUtils::create_write_request(const vfs::Object& obj, const uint64_t size, const uint64_t offset) { WriteRequest msg; msg.set_object_id(obj.id.str()); msg.set_object_type(static_cast<uint32_t>(obj.type)); msg.set_size(size); msg.set_offset(offset); msg.CheckInitialized(); return msg; }