Skip to content

Commit 8c6f030

Browse files
mbasmanovafacebook-github-bot
authored andcommitted
refactor: Migrate production code to ConnectorRegistry API and deprecate free functions (#16986)
Summary: 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 6580068 commit 8c6f030

20 files changed

+84
-24
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
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+
#include <utility>
24+
2025
#include <gtest/gtest.h>
2126

2227
namespace facebook::velox {
@@ -25,7 +30,7 @@ namespace {
2530
// Minimal value type for testing.
2631
class TestEntry {
2732
public:
28-
explicit TestEntry(const std::string& name) : name_{name} {}
33+
explicit TestEntry(std::string name) : name_{std::move(name)} {}
2934

3035
const std::string& name() const {
3136
return name_;
@@ -94,15 +99,17 @@ TEST(ScopedRegistryTest, snapshot) {
9499
for (const auto& [key, _] : entries) {
95100
keys.insert(key);
96101
}
97-
EXPECT_THAT(keys, testing::UnorderedElementsAre("a", "b"));
102+
EXPECT_EQ(keys.size(), 2);
103+
EXPECT_TRUE(keys.count("a"));
104+
EXPECT_TRUE(keys.count("b"));
98105
}
99106

100107
TEST(ScopedRegistryTest, parentFallback) {
101108
ScopedRegistry<std::string, TestEntry> parent;
102109
auto entry = std::make_shared<TestEntry>("from-parent");
103110
parent.insert("key", entry);
104111

105-
ScopedRegistry<std::string, TestEntry> child(&parent);
112+
const ScopedRegistry<std::string, TestEntry> child(&parent);
106113
EXPECT_EQ(child.find("key"), entry);
107114
}
108115

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
*/
1616

1717
#include "velox/connectors/Connector.h"
18-
#include "velox/common/config/Config.h"
18+
19+
#include <memory>
20+
#include <utility>
21+
22+
#include <fmt/format.h>
23+
#include <gtest/gtest.h>
24+
1925
#include "velox/common/memory/Memory.h"
2026
#include "velox/connectors/ConnectorRegistry.h"
2127
#include "velox/core/QueryCtx.h"
2228

23-
#include <gmock/gmock.h>
24-
#include <gtest/gtest.h>
25-
2629
namespace facebook::velox::connector {
2730
namespace {
2831

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)