| 176 | } |
| 177 | |
| 178 | void StorageRunner::setupStorage() |
| 179 | { |
| 180 | auto settings = std::make_shared<DB::CoordinationSettings>(); |
| 181 | settings->loadFromConfig("storage.coordination_settings", *config_ptr); |
| 182 | keeper_context = std::make_shared<DB::KeeperContext>(/*standalone_keeper=*/true, settings); |
| 183 | keeper_context->setLocalLogsPreprocessed(); |
| 184 | keeper_context->setRocksDBOptions(); |
| 185 | keeper_context->setServerState(DB::KeeperContext::Phase::RUNNING); |
| 186 | |
| 187 | storage = std::make_unique<Storage>(tick_time_ms, /*superdigest=*/"", keeper_context); |
| 188 | |
| 189 | /// Allocate one session for setup and one per generator thread. |
| 190 | /// All subsequent requests from a generator use its dedicated session. |
| 191 | const int64_t setup_timeout_ms = std::max<int64_t>(60'000, tick_time_ms * 1000); |
| 192 | setup_session_id = storage->getSessionID(setup_timeout_ms); |
| 193 | for (size_t i = 0; i < concurrency; ++i) |
| 194 | generator_session_ids.push_back(storage->getSessionID(setup_timeout_ms)); |
| 195 | |
| 196 | /// Recursively create the setup tree. The real `BenchmarkContext::startup` uses a |
| 197 | /// ZooKeeper client, so we walk the node tree here and issue preprocess+commit |
| 198 | /// directly against the storage, populating `tagged_paths` as we go. |
| 199 | std::function<void(const BenchmarkContext::Node &, const std::string &)> create_subtree; |
| 200 | auto & tagged = benchmark_context.getTaggedPaths(); |
| 201 | const Coordination::ACLs & default_acls = benchmark_context.getDefaultAcls(); |
| 202 | |
| 203 | create_subtree = [&](const BenchmarkContext::Node & node, const std::string & parent_path) |
| 204 | { |
| 205 | std::string path = parent_path == "/" ? "/" + node.name.getString() : parent_path + "/" + node.name.getString(); |
| 206 | |
| 207 | auto request = std::make_shared<Coordination::ZooKeeperCreateRequest>(); |
| 208 | request->path = path; |
| 209 | request->data = node.data ? node.data->getString() : ""; |
| 210 | request->acls = default_acls; |
| 211 | |
| 212 | int64_t zxid = next_zxid.fetch_add(1); |
| 213 | try |
| 214 | { |
| 215 | storage->preprocessRequest(request, setup_session_id, 0, zxid); |
| 216 | auto responses = storage->processRequest(request, setup_session_id, zxid); |
| 217 | for (const auto & response : responses) |
| 218 | { |
| 219 | if (response.response->error != Coordination::Error::ZOK) |
| 220 | throw zkutil::KeeperException::fromPath(response.response->error, path); |
| 221 | } |
| 222 | } |
| 223 | catch (...) |
| 224 | { |
| 225 | std::cerr << "Setup request failed for path " << path << ": " |
| 226 | << DB::getCurrentExceptionMessage(false) << std::endl; |
| 227 | throw; |
| 228 | } |
| 229 | |
| 230 | if (node.tag) |
| 231 | tagged[*node.tag].push_back(path); |
| 232 | |
| 233 | for (const auto & child : node.children) |
| 234 | create_subtree(*child, path); |
| 235 | }; |
nothing calls this directly
no test coverage detected