MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / flushData

Method flushData

src/replication.cpp:1026–1071  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1024 bool isActive() const { return !replicas.empty(); }
1025
1026 void flushData() {
1027 if (reply == nullptr)
1028 return;
1029 size_t written = reply->used;
1030
1031 for (auto replica : replicas) {
1032 std::unique_lock<fastlock> ul(replica->lock);
1033 while (checkClientOutputBufferLimits(replica)
1034 && (replica->flags.load(std::memory_order_relaxed) & CLIENT_CLOSE_ASAP) == 0) {
1035 ul.unlock();
1036 usleep(0);
1037 ul.lock();
1038 }
1039 }
1040
1041 aeAcquireLock();
1042 for (size_t ireplica = 0; ireplica < replicas.size(); ++ireplica) {
1043 auto replica = replicas[ireplica];
1044 if (replica->flags.load(std::memory_order_relaxed) & CLIENT_CLOSE_ASAP) {
1045 replica->replstate = REPL_STATE_NONE;
1046 continue;
1047 }
1048
1049 std::unique_lock<fastlock> lock(replica->lock);
1050 if (ireplica == (replicas.size()-1) && replica->replyAsync == nullptr) {
1051 replica->replyAsync = reply;
1052 reply = nullptr;
1053 if (!(replica->fPendingAsyncWrite)) clientInstallAsyncWriteHandler(replica);
1054 } else {
1055 addReplyProto(replica, reply->buf(), reply->used);
1056 }
1057 }
1058 ProcessPendingAsyncWrites();
1059 for (auto c : replicas) {
1060 if (c->flags & CLIENT_CLOSE_ASAP) {
1061 std::unique_lock<fastlock> ul(c->lock);
1062 c->replstate = REPL_STATE_NONE; // otherwise the client can't be free'd
1063 }
1064 }
1065 replicas.erase(std::remove_if(replicas.begin(), replicas.end(), [](const client *c)->bool{ return c->flags.load(std::memory_order_relaxed) & CLIENT_CLOSE_ASAP;}), replicas.end());
1066 aeReleaseLock();
1067 if (reply != nullptr) {
1068 reply->used = 0;
1069 }
1070 writtenBytesTracker += written;
1071 }
1072
1073 void addData(const char *data, unsigned long size) {
1074 if (reply != nullptr && (size + reply->used) > reply->size)

Callers

nothing calls this directly

Calls 13

aeAcquireLockFunction · 0.85
addReplyProtoFunction · 0.85
aeReleaseLockFunction · 0.85
unlockMethod · 0.45
lockMethod · 0.45
sizeMethod · 0.45
bufMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected