@@ -789,6 +789,7 @@ class TBaseEtcdRequest {
789
789
virtual std::string ParseGrpcRequest () = 0;
790
790
virtual void MakeQueryWithParams (std::ostream& sql, NYdb::TParamsBuilder& params) = 0;
791
791
virtual void ReplyWith (const NYdb::TResultSets& results, const TActorContext& ctx) = 0;
792
+ virtual bool ExecuteAsync () const { return false ; }
792
793
793
794
i64 Revision = 0LL ;
794
795
};
@@ -812,7 +813,7 @@ class TEtcdRequestGrpc
812
813
this ->Die (ctx);
813
814
} else {
814
815
this ->Become (&TEtcdRequestGrpc::StateFunc);
815
- SendDatabaseRequest ();
816
+ SendDatabaseRequest (ctx );
816
817
}
817
818
}
818
819
private:
@@ -822,7 +823,7 @@ class TEtcdRequestGrpc
822
823
823
824
virtual std::ostream& Dump (std::ostream& out) const = 0;
824
825
825
- void SendDatabaseRequest () {
826
+ void SendDatabaseRequest (const TActorContext& ctx ) {
826
827
std::ostringstream sql;
827
828
NYdb::TParamsBuilder params;
828
829
sql << " -- " << GetRequestName () << " >>>>" << std::endl;
@@ -834,14 +835,24 @@ class TEtcdRequestGrpc
834
835
TQueryClient::TQueryResultFunc callback = [query = sql.str (), args = params.Build ()](TQueryClient::TSession session) -> TAsyncExecuteQueryResult {
835
836
return session.ExecuteQuery (query, TTxControl::BeginTx ().CommitTx (), args);
836
837
};
837
- Stuff-> Client -> RetryQuery ( std::move (callback)). Subscribe ([my = this ->SelfId (), stuff = TSharedStuff::TWeakPtr (Stuff)]( const auto & future ) {
838
- if ( const auto lock = stuff. lock () ) {
838
+ if ( this ->ExecuteAsync () ) {
839
+ Stuff-> Client -> RetryQuery ( std::move (callback)). Subscribe ([name = GetRequestName ()]( const auto & future ) {
839
840
if (const auto res = future.GetValueSync (); res.IsSuccess ())
840
- lock-> ActorSystem -> Send (my, new NEtcd::TEvQueryResult (res. GetResultSets ())) ;
841
+ std::cout << name << " finished succesfully. " << std::endl ;
841
842
else
842
- lock->ActorSystem ->Send (my, new NEtcd::TEvQueryError (res.GetIssues ()));
843
- }
844
- });
843
+ std::cout << name << " finished with errors: " << res.GetIssues ().ToString () << std::endl;
844
+ });
845
+ ctx.Send (this ->SelfId (), new NEtcd::TEvQueryResult);
846
+ } else {
847
+ Stuff->Client ->RetryQuery (std::move (callback)).Subscribe ([my = this ->SelfId (), stuff = TSharedStuff::TWeakPtr (Stuff)](const auto & future) {
848
+ if (const auto lock = stuff.lock ()) {
849
+ if (const auto res = future.GetValueSync (); res.IsSuccess ())
850
+ lock->ActorSystem ->Send (my, new NEtcd::TEvQueryResult (res.GetResultSets ()));
851
+ else
852
+ lock->ActorSystem ->Send (my, new NEtcd::TEvQueryError (res.GetIssues ()));
853
+ }
854
+ });
855
+ }
845
856
}
846
857
847
858
STFUNC (StateFunc) {
@@ -1076,37 +1087,54 @@ class TCompactRequest
1076
1087
1077
1088
const auto &rec = *GetProtoRequest ();
1078
1089
KeyRevision = rec.revision ();
1090
+ Physical = rec.physical ();
1079
1091
if (KeyRevision <= 0LL | KeyRevision >= Revision)
1080
1092
return std::string (" invalid revision:" ) += std::to_string (KeyRevision);
1081
1093
return {};
1082
1094
}
1083
1095
1096
+ bool ExecuteAsync () const final {
1097
+ return !Physical;
1098
+ }
1099
+
1084
1100
void MakeQueryWithParams (std::ostream& sql, NYdb::TParamsBuilder& params) final {
1085
1101
sql << " $Trash = select c.key as key, c.modified as modified from `history` as c inner join (" << std::endl;
1086
1102
sql << " select max_by((`key`, `modified`), `modified`) as pair from `history`" << std::endl;
1087
1103
sql << " where `modified` < " << AddParam (" Revision" , params, KeyRevision) << " and 0L = `version` group by `key`" << std::endl;
1088
1104
sql << " ) as keys on keys.pair.0 = c.key where c.modified <= keys.pair.1;" << std::endl;
1089
- sql << " select count(*) from $Trash;" << std::endl;
1090
1105
sql << " delete from `history` on select * from $Trash;" << std::endl;
1106
+ if (Physical) {
1107
+ sql << " select count(*) from $Trash;" << std::endl;
1108
+ }
1091
1109
}
1092
1110
1093
1111
void ReplyWith (const NYdb::TResultSets& results, const TActorContext& ctx) final {
1094
- auto parser = NYdb::TResultSetParser (results.front ());
1095
- const auto erased = parser.TryNextRow () ? NYdb::TValueParser (parser.GetValue (0 )).GetUint64 () : 0ULL ;
1096
- if (!erased)
1097
- TryToRollbackRevision ();
1112
+ Dump (std::cout);
1113
+ if (Physical) {
1114
+ auto parser = NYdb::TResultSetParser (results.front ());
1115
+ const auto erased = parser.TryNextRow () ? NYdb::TValueParser (parser.GetValue (0 )).GetUint64 () : 0ULL ;
1116
+ if (!erased)
1117
+ TryToRollbackRevision ();
1118
+
1119
+ std::cout << ' =' << erased << std::endl;
1120
+ } else {
1121
+ std::cout << " is executing asynchronously." << std::endl;
1122
+ }
1098
1123
1099
1124
etcdserverpb::CompactionResponse response;
1100
1125
response.mutable_header ()->set_revision (Revision);
1101
- Dump (std::cout) << ' =' << erased << std::endl;
1102
1126
return Reply (response, ctx);
1103
1127
}
1104
1128
1105
1129
std::ostream& Dump (std::ostream& out) const final {
1106
- return out << " Compact(" << KeyRevision << ' )' ;
1130
+ out << " Compact(" << KeyRevision;
1131
+ if (Physical)
1132
+ out << " ,physical" ;
1133
+ return out << ' )' ;
1107
1134
}
1108
1135
1109
1136
i64 KeyRevision;
1137
+ bool Physical;
1110
1138
};
1111
1139
1112
1140
class TLeaseGrantRequest
0 commit comments