| 128 | } |
| 129 | |
| 130 | void SnapshotPayloadParseState::flushQueuedKeys() { |
| 131 | if (vecqueuedKeys.empty()) |
| 132 | return; |
| 133 | serverAssert(current_database >= 0); |
| 134 | |
| 135 | // TODO: We can't finish parse until all the work functions finish |
| 136 | int idb = current_database; |
| 137 | serverAssert(vecqueuedKeys.size() == vecqueuedVals.size()); |
| 138 | auto sizePrev = vecqueuedKeys.size(); |
| 139 | if (current_database < cserver.dbnum) { |
| 140 | if (g_pserver->m_pstorageFactory) { |
| 141 | (*insertsInFlight)++; |
| 142 | std::weak_ptr<std::atomic<int>> insertsInFlightTmp = insertsInFlight; // C++ GRRRRRRRRRRRRRRRR, we don't want to capute "this" because that's dangerous |
| 143 | g_pserver->asyncworkqueue->AddWorkFunction([idb, vecqueuedKeys = std::move(this->vecqueuedKeys), vecqueuedKeysCb = std::move(this->vecqueuedKeysCb), vecqueuedVals = std::move(this->vecqueuedVals), vecqueuedValsCb = std::move(this->vecqueuedValsCb), insertsInFlightTmp, pallocator = m_spallocator.release()]() mutable { |
| 144 | g_pserver->db[idb]->bulkDirectStorageInsert(vecqueuedKeys.data(), vecqueuedKeysCb.data(), vecqueuedVals.data(), vecqueuedValsCb.data(), vecqueuedKeys.size()); |
| 145 | (*(insertsInFlightTmp.lock()))--; |
| 146 | delete pallocator; |
| 147 | }); |
| 148 | } else { |
| 149 | for (size_t ival = 0; ival < vecqueuedKeys.size(); ++ival) { |
| 150 | size_t offset = 0; |
| 151 | auto spexpire = deserializeExpire(vecqueuedVals[ival], vecqueuedValsCb[ival], &offset); |
| 152 | auto o = deserializeStoredObject(vecqueuedVals[ival] + offset, vecqueuedValsCb[ival] - offset); |
| 153 | sds sdsKey = sdsnewlen(vecqueuedKeys[ival], -static_cast<ssize_t>(vecqueuedKeysCb[ival])); |
| 154 | if (dbMerge(g_pserver->db[idb], sdsKey, o, false)) { |
| 155 | if (spexpire != nullptr) |
| 156 | g_pserver->db[idb]->setExpire(sdsKey, std::move(*spexpire)); |
| 157 | } else { |
| 158 | sdsfree(sdsKey); |
| 159 | } |
| 160 | } |
| 161 | vecqueuedKeys.clear(); |
| 162 | vecqueuedKeysCb.clear(); |
| 163 | vecqueuedVals.clear(); |
| 164 | vecqueuedValsCb.clear(); |
| 165 | } |
| 166 | } else { |
| 167 | // else drop the data |
| 168 | vecqueuedKeys.clear(); |
| 169 | vecqueuedKeysCb.clear(); |
| 170 | vecqueuedVals.clear(); |
| 171 | vecqueuedValsCb.clear(); |
| 172 | // Note: m_spallocator will get free'd when overwritten below |
| 173 | } |
| 174 | m_spallocator = std::make_unique<SlabAllocator>(); |
| 175 | cbQueued = 0; |
| 176 | vecqueuedKeys.reserve(sizePrev); |
| 177 | vecqueuedKeysCb.reserve(sizePrev); |
| 178 | vecqueuedVals.reserve(sizePrev); |
| 179 | vecqueuedValsCb.reserve(sizePrev); |
| 180 | serverAssert(vecqueuedKeys.empty()); |
| 181 | serverAssert(vecqueuedVals.empty()); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | SnapshotPayloadParseState::SnapshotPayloadParseState() { |
nothing calls this directly
no test coverage detected