Skip to content

Commit bd3cdb6

Browse files
mbasmanovameta-codesync[bot]
authored andcommitted
refactor: Migrate production code to ConnectorRegistry API and deprecate free functions (#16986)
Summary: Pull Request resolved: #16986 Replace legacy free functions (registerConnector, unregisterConnector, getConnector, hasConnector) with ConnectorRegistry methods in all remaining velox/ production code: TableScan, TableWriter, IndexLookupJoin, TraceReplayRunner, PyConnectors, and experimental operators. Mark the free functions [[deprecated]] to prevent new usages. Reviewed By: jagill Differential Revision: D98963405
1 parent ade5800 commit bd3cdb6

20 files changed

+83
-23
lines changed

velox/common/ScopedRegistry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#pragma once
1818

19+
#include <memory>
20+
#include <utility>
21+
#include <vector>
22+
1923
#include "folly/Synchronized.h"
2024
#include "folly/container/F14Map.h"
2125
#include "folly/container/F14Set.h"

velox/common/tests/ScopedRegistryTest.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
#include "velox/common/ScopedRegistry.h"
1818

19-
#include <gmock/gmock.h>
19+
#include <map>
20+
#include <memory>
21+
#include <set>
22+
#include <string>
23+
2024
#include <gtest/gtest.h>
2125

2226
namespace facebook::velox {
@@ -25,7 +29,7 @@ namespace {
2529
// Minimal value type for testing.
2630
class TestEntry {
2731
public:
28-
explicit TestEntry(const std::string& name) : name_{name} {}
32+
explicit TestEntry(std::string name) : name_{std::move(name)} {}
2933

3034
const std::string& name() const {
3135
return name_;
@@ -94,15 +98,17 @@ TEST(ScopedRegistryTest, snapshot) {
9498
for (const auto& [key, _] : entries) {
9599
keys.insert(key);
96100
}
97-
EXPECT_THAT(keys, testing::UnorderedElementsAre("a", "b"));
101+
EXPECT_EQ(keys.size(), 2);
102+
EXPECT_TRUE(keys.count("a"));
103+
EXPECT_TRUE(keys.count("b"));
98104
}
99105

100106
TEST(ScopedRegistryTest, parentFallback) {
101107
ScopedRegistry<std::string, TestEntry> parent;
102108
auto entry = std::make_shared<TestEntry>("from-parent");
103109
parent.insert("key", entry);
104110

105-
ScopedRegistry<std::string, TestEntry> child(&parent);
111+
const ScopedRegistry<std::string, TestEntry> child(&parent);
106112
EXPECT_EQ(child.find("key"), entry);
107113
}
108114

velox/connectors/Connector.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616

1717
#include "velox/connectors/Connector.h"
18+
19+
#include <memory>
20+
#include <string>
21+
22+
#include "velox/common/ScopedRegistry.h"
23+
#include "velox/common/base/Exceptions.h"
1824
#include "velox/connectors/ConnectorRegistryInternal.h"
1925

2026
namespace facebook::velox::connector {
@@ -24,7 +30,7 @@ ScopedRegistry<std::string, Connector>& connectors() {
2430
return instance;
2531
}
2632

27-
bool registerConnector(std::shared_ptr<Connector> connector) {
33+
bool registerConnector(const std::shared_ptr<Connector>& connector) {
2834
connectors().insert(connector->connectorId(), connector);
2935
return true;
3036
}

velox/connectors/Connector.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,18 @@ class Connector {
768768
trackers_;
769769
};
770770

771-
// Legacy free functions. Prefer ConnectorRegistry methods for new code.
771+
/// Deprecated free functions. Use ConnectorRegistry methods instead.
772772

773-
bool registerConnector(std::shared_ptr<Connector> connector);
773+
[[deprecated("Use ConnectorRegistry::global().insert() instead.")]]
774+
bool registerConnector(const std::shared_ptr<Connector>& connector);
774775

776+
[[deprecated("Use ConnectorRegistry::tryGet() instead.")]]
775777
bool hasConnector(const std::string& connectorId);
776778

779+
[[deprecated("Use ConnectorRegistry::global().erase() instead.")]]
777780
bool unregisterConnector(const std::string& connectorId);
778781

782+
[[deprecated("Use ConnectorRegistry::tryGet() instead.")]]
779783
std::shared_ptr<Connector> getConnector(const std::string& connectorId);
780784

781785
} // namespace facebook::velox::connector

velox/connectors/ConnectorRegistry.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
*/
1616

1717
#include "velox/connectors/ConnectorRegistry.h"
18-
#include "velox/connectors/ConnectorRegistryInternal.h"
1918

19+
#include <memory>
20+
#include <string>
21+
#include <utility>
22+
#include <vector>
23+
24+
#include "velox/connectors/Connector.h"
25+
#include "velox/connectors/ConnectorRegistryInternal.h"
2026
#include "velox/core/QueryCtx.h"
2127

2228
namespace facebook::velox::connector {

velox/connectors/ConnectorRegistry.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
#pragma once
1818

19+
#include <memory>
20+
#include <string>
21+
#include <string_view>
22+
#include <utility>
23+
#include <vector>
24+
1925
#include "velox/common/ScopedRegistry.h"
2026
#include "velox/connectors/Connector.h"
2127

velox/connectors/ConnectorRegistryInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#pragma once
1818

19+
#include <string>
20+
1921
#include "velox/common/ScopedRegistry.h"
2022
#include "velox/connectors/Connector.h"
2123

velox/connectors/tests/ConnectorTest.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
*/
1616

1717
#include "velox/connectors/Connector.h"
18+
19+
#include <memory>
20+
#include <utility>
21+
22+
#include <fmt/format.h>
23+
#include <gtest/gtest.h>
24+
1825
#include "velox/common/config/Config.h"
1926
#include "velox/common/memory/Memory.h"
2027
#include "velox/connectors/ConnectorRegistry.h"
2128
#include "velox/core/QueryCtx.h"
2229

23-
#include <gmock/gmock.h>
24-
#include <gtest/gtest.h>
25-
2630
namespace facebook::velox::connector {
2731
namespace {
2832

velox/core/QueryCtx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <folly/Executor.h>
2020
#include <folly/Synchronized.h>
2121
#include <folly/container/F14Map.h>
22-
#include <folly/executors/CPUThreadPoolExecutor.h>
2322
#include <deque>
2423
#include <functional>
24+
#include <string_view>
2525
#include <typeindex>
2626
#include "velox/common/base/Exceptions.h"
2727
#include "velox/common/caching/AsyncDataCache.h"

velox/exec/IndexLookupJoin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "velox/buffer/Buffer.h"
1919
#include "velox/common/testutil/TestValue.h"
2020
#include "velox/connectors/Connector.h"
21+
#include "velox/connectors/ConnectorRegistry.h"
2122
#include "velox/core/QueryConfig.h"
2223
#include "velox/exec/OperatorTraceWriter.h"
2324
#include "velox/exec/OperatorType.h"
@@ -347,7 +348,9 @@ IndexLookupJoin::IndexLookupJoin(
347348
operatorType(),
348349
lookupTableHandle_->connectorId()),
349350
spillConfig_.has_value() ? &(spillConfig_.value()) : nullptr)},
350-
connector_(connector::getConnector(lookupTableHandle_->connectorId())),
351+
connector_(
352+
connector::ConnectorRegistry::tryGet(
353+
lookupTableHandle_->connectorId())),
351354
maxNumInputBatches_(
352355
1 + driverCtx->queryConfig().indexLookupJoinMaxPrefetchBatches()),
353356
joinNode_{joinNode} {

0 commit comments

Comments
 (0)