Browse Source

YT-19357: Hydra persistent read-only

danilalexeev 1 year ago
parent
commit
85912d487e

+ 17 - 0
yt/yt/client/api/admin_client.h

@@ -28,6 +28,16 @@ struct TBuildMasterSnapshotsOptions
     bool Retry = true;
 };
 
+struct TExitReadOnlyOptions
+    : public TTimeoutOptions
+{ };
+
+struct TMasterExitReadOnlyOptions
+    : public TTimeoutOptions
+{
+    bool Retry = true;
+};
+
 struct TSwitchLeaderOptions
     : public TTimeoutOptions
 { };
@@ -184,6 +194,13 @@ struct IAdminClient
     virtual TFuture<TCellIdToSnapshotIdMap> BuildMasterSnapshots(
         const TBuildMasterSnapshotsOptions& options = {}) = 0;
 
+    virtual TFuture<void> ExitReadOnly(
+        NHydra::TCellId cellId,
+        const TExitReadOnlyOptions& options = {}) = 0;
+
+    virtual TFuture<void> MasterExitReadOnly(
+        const TMasterExitReadOnlyOptions& options = {}) = 0;
+
     virtual TFuture<void> SwitchLeader(
         NHydra::TCellId cellId,
         const TString& newLeaderAddress,

+ 13 - 0
yt/yt/client/api/delegating_client.cpp

@@ -731,6 +731,19 @@ TFuture<TCellIdToSnapshotIdMap> TDelegatingClient::BuildMasterSnapshots(
     return Underlying_->BuildMasterSnapshots(options);
 }
 
+TFuture<void> TDelegatingClient::ExitReadOnly(
+    NHydra::TCellId cellId,
+    const TExitReadOnlyOptions& options)
+{
+    return Underlying_->ExitReadOnly(cellId, options);
+}
+
+TFuture<void> TDelegatingClient::MasterExitReadOnly(
+    const TMasterExitReadOnlyOptions& options)
+{
+    return Underlying_->MasterExitReadOnly(options);
+}
+
 TFuture<void> TDelegatingClient::SwitchLeader(
     NHydra::TCellId cellId,
     const TString& newLeaderAddress,

+ 7 - 0
yt/yt/client/api/delegating_client.h

@@ -462,6 +462,13 @@ public:
     TFuture<TCellIdToSnapshotIdMap> BuildMasterSnapshots(
         const TBuildMasterSnapshotsOptions& options = {}) override;
 
+    TFuture<void> ExitReadOnly(
+        NHydra::TCellId cellId,
+        const TExitReadOnlyOptions& options) override;
+
+    TFuture<void> MasterExitReadOnly(
+        const TMasterExitReadOnlyOptions& options = {}) override;
+
     TFuture<void> SwitchLeader(
         NHydra::TCellId cellId,
         const TString& newLeaderAddress,

+ 2 - 0
yt/yt/client/api/rpc_proxy/api_service_proxy.h

@@ -144,6 +144,8 @@ public:
 
     // Administration
     DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, BuildSnapshot);
+    DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, ExitReadOnly);
+    DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, MasterExitReadOnly);
     DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, GCCollect);
     DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, SuspendCoordinator);
     DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, ResumeCoordinator);

+ 22 - 0
yt/yt/client/api/rpc_proxy/client_impl.cpp

@@ -1616,6 +1616,28 @@ TFuture<TCellIdToSnapshotIdMap> TClient::BuildMasterSnapshots(const TBuildMaster
     ThrowUnimplemented("BuildMasterSnapshots");
 }
 
+TFuture<void> TClient::ExitReadOnly(
+    NHydra::TCellId cellId,
+    const TExitReadOnlyOptions& /*options*/)
+{
+    auto proxy = CreateApiServiceProxy();
+
+    auto req = proxy.ExitReadOnly();
+    ToProto(req->mutable_cell_id(), cellId);
+
+    return req->Invoke().As<void>();
+}
+
+TFuture<void> TClient::MasterExitReadOnly(const TMasterExitReadOnlyOptions& options)
+{
+    auto proxy = CreateApiServiceProxy();
+
+    auto req = proxy.MasterExitReadOnly();
+    req->set_retry(options.Retry);
+
+    return req->Invoke().As<void>();
+}
+
 TFuture<void> TClient::SwitchLeader(
     NHydra::TCellId /*cellId*/,
     const TString& /*newLeaderAddress*/,

+ 7 - 0
yt/yt/client/api/rpc_proxy/client_impl.h

@@ -323,6 +323,13 @@ public:
     TFuture<TCellIdToSnapshotIdMap> BuildMasterSnapshots(
         const TBuildMasterSnapshotsOptions& options) override;
 
+    TFuture<void> ExitReadOnly(
+        NHydra::TCellId cellId,
+        const TExitReadOnlyOptions& options) override;
+
+    TFuture<void> MasterExitReadOnly(
+        const TMasterExitReadOnlyOptions& options) override;
+
     TFuture<void> SwitchLeader(
         NHydra::TCellId cellId,
         const TString& newLeaderAddress,

+ 31 - 0
yt/yt/client/driver/admin_commands.cpp

@@ -69,6 +69,37 @@ void TBuildMasterSnapshotsCommand::DoExecute(ICommandContextPtr context)
 
 ////////////////////////////////////////////////////////////////////////////////
 
+TExitReadOnlyCommand::TExitReadOnlyCommand()
+{
+    RegisterParameter("cell_id", CellId_);
+}
+
+void TExitReadOnlyCommand::DoExecute(ICommandContextPtr context)
+{
+    WaitFor(context->GetClient()->ExitReadOnly(CellId_, Options))
+        .ThrowOnError();
+
+    ProduceEmptyOutput(context);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+TMasterExitReadOnlyCommand::TMasterExitReadOnlyCommand()
+{
+    RegisterParameter("retry", Options.Retry)
+        .Optional();
+}
+
+void TMasterExitReadOnlyCommand::DoExecute(ICommandContextPtr context)
+{
+    WaitFor(context->GetClient()->MasterExitReadOnly(Options))
+        .ThrowOnError();
+
+    ProduceEmptyOutput(context);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
 TSwitchLeaderCommand::TSwitchLeaderCommand()
 {
     RegisterParameter("cell_id", CellId_);

+ 26 - 0
yt/yt/client/driver/admin_commands.h

@@ -30,6 +30,32 @@ private:
 
 ////////////////////////////////////////////////////////////////////////////////
 
+class TExitReadOnlyCommand
+    : public TTypedCommand<NApi::TExitReadOnlyOptions>
+{
+public:
+    TExitReadOnlyCommand();
+
+private:
+    NHydra::TCellId CellId_;
+
+    void DoExecute(ICommandContextPtr context) override;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TMasterExitReadOnlyCommand
+    : public TTypedCommand<NApi::TMasterExitReadOnlyOptions>
+{
+public:
+    TMasterExitReadOnlyCommand();
+
+private:
+    void DoExecute(ICommandContextPtr context) override;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
 class TSwitchLeaderCommand
     : public TTypedCommand<NApi::TSwitchLeaderOptions>
 {

+ 2 - 0
yt/yt/client/driver/driver.cpp

@@ -314,6 +314,8 @@ public:
 
         REGISTER_ALL(TBuildSnapshotCommand,                "build_snapshot",                  Null,       Structured, true,  false);
         REGISTER_ALL(TBuildMasterSnapshotsCommand,         "build_master_snapshots",          Null,       Structured, true,  false);
+        REGISTER_ALL(TExitReadOnlyCommand,                 "exit_read_only",                  Null,       Structured, true,  false);
+        REGISTER_ALL(TMasterExitReadOnlyCommand,           "master_exit_read_only",           Null,       Structured, true,  false);
         REGISTER_ALL(TSwitchLeaderCommand,                 "switch_leader",                   Null,       Structured, true,  false);
         REGISTER_ALL(TResetStateHashCommand,               "reset_state_hash",                Null,       Structured, true,  false);
         REGISTER_ALL(THealExecNodeCommand,                 "heal_exec_node",                  Null,       Structured, true,  false);

+ 2 - 0
yt/yt/client/federated/client.cpp

@@ -372,6 +372,8 @@ public:
     UNIMPLEMENTED_METHOD(TFuture<void>, CheckClusterLiveness, (const TCheckClusterLivenessOptions&));
     UNIMPLEMENTED_METHOD(TFuture<int>, BuildSnapshot, (const TBuildSnapshotOptions&));
     UNIMPLEMENTED_METHOD(TFuture<TCellIdToSnapshotIdMap>, BuildMasterSnapshots, (const TBuildMasterSnapshotsOptions&));
+    UNIMPLEMENTED_METHOD(TFuture<void>, ExitReadOnly, (NObjectClient::TCellId, const TExitReadOnlyOptions&));
+    UNIMPLEMENTED_METHOD(TFuture<void>, MasterExitReadOnly, (const TMasterExitReadOnlyOptions&));
     UNIMPLEMENTED_METHOD(TFuture<void>, SwitchLeader, (NObjectClient::TCellId, const TString&, const TSwitchLeaderOptions&));
     UNIMPLEMENTED_METHOD(TFuture<void>, ResetStateHash, (NObjectClient::TCellId, const TResetStateHashOptions&));
     UNIMPLEMENTED_METHOD(TFuture<void>, GCCollect, (const TGCCollectOptions&));

Some files were not shown because too many files changed in this diff