summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2023-12-01 13:19:29 +0300
committerrobot-piglet <[email protected]>2023-12-01 15:05:05 +0300
commit078083fad75ffdcef17addfc6646e06d1c7f17d6 (patch)
tree520f19e7241c72979a0b112f056362c9877baa8f
parent84229e665d1613a00cc3faa7bb9b471f69dbe7d9 (diff)
Intermediate changes
-rw-r--r--yt/yql/plugin/bridge/interface.h1
-rw-r--r--yt/yql/plugin/bridge/plugin.cpp71
2 files changed, 62 insertions, 10 deletions
diff --git a/yt/yql/plugin/bridge/interface.h b/yt/yql/plugin/bridge/interface.h
index 4905264965d..1c3a0cd2913 100644
--- a/yt/yql/plugin/bridge/interface.h
+++ b/yt/yql/plugin/bridge/interface.h
@@ -85,6 +85,7 @@ struct TBridgeQueryFile
using TFuncBridgeFreeQueryResult = void(TBridgeQueryResult* result);
using TFuncBridgeRun = TBridgeQueryResult*(TBridgeYqlPlugin* plugin, const char* queryId, const char* impersonationUser, const char* queryText, const char* settings, const TBridgeQueryFile* files, int fileCount);
using TFuncBridgeGetProgress = TBridgeQueryResult*(TBridgeYqlPlugin* plugin, const char* queryId);
+using TFuncBridgeAbort = void(TBridgeYqlPlugin* plugin, const char* queryId);
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yql/plugin/bridge/plugin.cpp b/yt/yql/plugin/bridge/plugin.cpp
index 681b414ed73..3549779474e 100644
--- a/yt/yql/plugin/bridge/plugin.cpp
+++ b/yt/yql/plugin/bridge/plugin.cpp
@@ -6,6 +6,8 @@
#include <yt/yt/core/misc/error.h>
+#include <library/cpp/yt/misc/cast.h>
+
#include <util/system/dynlib.h>
namespace NYT::NYqlPlugin {
@@ -27,7 +29,16 @@ std::optional<TString> ToString(const char* str, size_t strLength)
////////////////////////////////////////////////////////////////////////////////
-constexpr auto RequiredAbiVersion = 0;
+// Each YQL plugin ABI change should be listed here. Either a compat should be added
+// or MinSupportedYqlPluginAbiVersion should be promoted.
+DEFINE_ENUM(EYqlPluginAbiVersion,
+ ((Invalid) (-1))
+ ((TheBigBang) (0))
+ ((AbortQuery) (1)) // gritukan: Added BridgeAbort; no breaking changes.
+);
+
+constexpr auto MinSupportedYqlPluginAbiVersion = EYqlPluginAbiVersion::TheBigBang;
+constexpr auto MaxSupportedYqlPluginAbiVersion = EYqlPluginAbiVersion::AbortQuery;
////////////////////////////////////////////////////////////////////////////////
@@ -39,24 +50,64 @@ public:
static const TString DefaultYqlPluginLibraryName = "./libyqlplugin.so";
auto sharedLibraryPath = yqlPluginSharedLibrary.value_or(DefaultYqlPluginLibraryName);
Library_.Open(sharedLibraryPath.data());
- #define XX(function) function = reinterpret_cast<TFunc ## function*>(Library_.Sym(#function));
+ #define XX(function) \
+ { \
+ if constexpr(#function == TStringBuf("BridgeAbort")) { \
+ if (AbiVersion_ < EYqlPluginAbiVersion::AbortQuery) { \
+ function = reinterpret_cast<TFunc ## function*>(AbortQueryStub); \
+ } else { \
+ function = reinterpret_cast<TFunc ## function*>(Library_.Sym(#function)); \
+ } \
+ } else { \
+ function = reinterpret_cast<TFunc ## function*>(Library_.Sym(#function)); \
+ } \
+ } \
+
+ // Firstly we need to get ABI version of the plugin to make it possible to
+ // add compats for other functions.
+ XX(BridgeGetAbiVersion);
+ GetYqlPluginAbiVersion();
+
FOR_EACH_BRIDGE_INTERFACE_FUNCTION(XX);
+ // COMPAT(gritukan): Remove after commit in YDB repository.
+ XX(BridgeAbort)
#undef XX
-
- if (RequiredAbiVersion != BridgeGetAbiVersion()) {
- THROW_ERROR_EXCEPTION(
- "YQL plugin ABI version mismatch: expected version %v, actual version %v",
- RequiredAbiVersion,
- BridgeGetAbiVersion());
- }
}
protected:
+ TDynamicLibrary Library_;
+
+ EYqlPluginAbiVersion AbiVersion_ = EYqlPluginAbiVersion::Invalid;
+
#define XX(function) TFunc ## function* function;
FOR_EACH_BRIDGE_INTERFACE_FUNCTION(XX)
+
+ // COMPAT(gritukan): Remove after commit in YDB repository.
+ XX(BridgeAbort)
#undef XX
- TDynamicLibrary Library_;
+ // COMPAT(gritukan): AbortQuery
+ static void AbortQueryStub(TBridgeYqlPlugin* /*plugin*/, const char* /*queryId*/)
+ {
+ // Just do nothing. It is not worse than in used to be before.
+ }
+
+ void GetYqlPluginAbiVersion()
+ {
+ if (!TryEnumCast(BridgeGetAbiVersion(), &AbiVersion_)) {
+ THROW_ERROR_EXCEPTION(
+ "YQL plugin ABI version %v is not supported",
+ BridgeGetAbiVersion());
+ }
+
+ if (AbiVersion_ < MinSupportedYqlPluginAbiVersion ||
+ AbiVersion_ > MaxSupportedYqlPluginAbiVersion)
+ {
+ THROW_ERROR_EXCEPTION(
+ "YQL plugin ABI version %Qv is not supported",
+ AbiVersion_);
+ }
+ }
};
////////////////////////////////////////////////////////////////////////////////