| 456 | } |
| 457 | |
| 458 | void dumpNodes(const DB::KeeperMemoryStorage & storage, const std::string & output_file, const std::string & output_format, bool parallel_output, bool with_acl) |
| 459 | { |
| 460 | SharedContextHolder shared_context; |
| 461 | ContextMutablePtr global_context; |
| 462 | |
| 463 | using PrintFunction = std::function<void(const std::string & key, const DB::KeeperMemoryStorage::Node & value)>; |
| 464 | |
| 465 | const auto print_nodes = [&](const PrintFunction print_function) |
| 466 | { |
| 467 | std::queue<std::string> keys; |
| 468 | keys.push("/"); |
| 469 | while (!keys.empty()) |
| 470 | { |
| 471 | auto key = keys.front(); |
| 472 | keys.pop(); |
| 473 | auto value = storage.container.getValue(key); |
| 474 | print_function(key, value); |
| 475 | for (const auto & child : value.getChildren()) |
| 476 | { |
| 477 | if (key == "/") |
| 478 | keys.push(fmt::format("/{}", child)); |
| 479 | else |
| 480 | keys.push(fmt::format("{}/{}", key, child)); |
| 481 | } |
| 482 | } |
| 483 | }; |
| 484 | |
| 485 | PrintFunction print_function; |
| 486 | if (!output_file.empty()) |
| 487 | { |
| 488 | LOG_INFO(getLogger("keeper-utils"), "Writing nodes to {}", output_file); |
| 489 | |
| 490 | shared_context = DB::Context::createShared(); |
| 491 | global_context = DB::Context::createGlobal(shared_context.get()); |
| 492 | global_context->makeGlobalContext(); |
| 493 | DB::registerFormats(); |
| 494 | |
| 495 | ColumnsWithTypeAndName columns |
| 496 | { |
| 497 | {std::make_shared<DataTypeString>(), "path"}, |
| 498 | {std::make_shared<DataTypeInt64>(), "czxid"}, |
| 499 | {std::make_shared<DataTypeInt64>(), "mzxid"}, |
| 500 | {std::make_shared<DataTypeDateTime>(), "ctime"}, |
| 501 | {std::make_shared<DataTypeDateTime>(), "mtime"}, |
| 502 | {std::make_shared<DataTypeInt32>(), "version"}, |
| 503 | {std::make_shared<DataTypeInt32>(), "cversion"}, |
| 504 | {std::make_shared<DataTypeInt32>(), "aversion"}, |
| 505 | {std::make_shared<DataTypeInt64>(), "ephemeralOwner"}, |
| 506 | {std::make_shared<DataTypeInt32>(), "dataLength"}, |
| 507 | {std::make_shared<DataTypeInt32>(), "numChildren"}, |
| 508 | {std::make_shared<DataTypeInt64>(), "pzxid"}, |
| 509 | {std::make_shared<DataTypeString>(), "data"}, |
| 510 | }; |
| 511 | |
| 512 | if (with_acl) |
| 513 | columns.emplace_back(std::make_shared<DataTypeString>(), "acl"); |
| 514 | |
| 515 | Block data(columns); |
no test coverage detected