-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue-2137: filestore-client forcedcompaction command (#2383)
* issue-2137: filestore-client forcedcompaction command * issue-2137: filestore-client forcedcompaction command - forgot canondata
- Loading branch information
Showing
8 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include "command.h" | ||
|
||
#include <cloud/filestore/private/api/protos/tablet.pb.h> | ||
|
||
#include <library/cpp/json/json_reader.h> | ||
|
||
#include <google/protobuf/util/json_util.h> | ||
|
||
namespace NCloud::NFileStore::NClient { | ||
|
||
namespace { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class TForcedCompactionCommand final | ||
: public TFileStoreCommand | ||
{ | ||
private: | ||
ui32 MinRangeId = 0; | ||
|
||
private: | ||
template <typename TRequest, typename TResponse> | ||
void ExecuteAction( | ||
const TString& action, | ||
const TRequest& requestProto, | ||
TResponse* responseProto) | ||
{ | ||
auto callContext = PrepareCallContext(); | ||
|
||
TString input; | ||
google::protobuf::util::MessageToJsonString(requestProto, &input); | ||
|
||
STORAGE_DEBUG("Reading ExecuteAction request"); | ||
auto request = std::make_shared<NProto::TExecuteActionRequest>(); | ||
request->SetAction(action); | ||
request->SetInput(std::move(input)); | ||
|
||
STORAGE_DEBUG("Sending ExecuteAction request"); | ||
const auto requestId = GetRequestId(*request); | ||
auto result = WaitFor(Client->ExecuteAction( | ||
MakeIntrusive<TCallContext>(requestId), | ||
std::move(request))); | ||
|
||
STORAGE_DEBUG("Received ExecuteAction response"); | ||
|
||
if (HasError(result)) { | ||
responseProto->MutableError()->CopyFrom(result.GetError()); | ||
return; | ||
} | ||
|
||
auto parsed = google::protobuf::util::JsonStringToMessage( | ||
result.GetOutput(), | ||
responseProto).ok(); | ||
|
||
if (!parsed) { | ||
responseProto->MutableError()->CopyFrom(MakeError( | ||
E_FAIL, | ||
TStringBuilder() << "failed to parse response json: " | ||
<< result.GetOutput())); | ||
} | ||
} | ||
|
||
public: | ||
TForcedCompactionCommand() | ||
{ | ||
Opts.AddLongOption("min-range-id", "initial compaction range id") | ||
.RequiredArgument("NUM") | ||
.StoreResult(&MinRangeId); | ||
} | ||
|
||
public: | ||
bool Execute() override | ||
{ | ||
auto callContext = PrepareCallContext(); | ||
|
||
NProtoPrivate::TForcedOperationRequest request; | ||
request.SetFileSystemId(FileSystemId); | ||
request.SetOpType(NProtoPrivate::TForcedOperationRequest::E_COMPACTION); | ||
request.SetMinRangeId(MinRangeId); | ||
NProtoPrivate::TForcedOperationResponse response; | ||
ExecuteAction("forcedoperation", request, &response); | ||
CheckResponse(response); | ||
|
||
while (true) { | ||
NProtoPrivate::TForcedOperationStatusRequest statusRequest; | ||
statusRequest.SetFileSystemId(FileSystemId); | ||
statusRequest.SetOperationId(response.GetOperationId()); | ||
NProtoPrivate::TForcedOperationStatusResponse statusResponse; | ||
ExecuteAction( | ||
"forcedoperationstatus", | ||
statusRequest, | ||
&statusResponse); | ||
|
||
if (statusResponse.GetError().GetCode() == E_NOT_FOUND) { | ||
// TODO: distinguish between finished operations and tablet | ||
// restarts | ||
Cout << "finished" << Endl; | ||
break; | ||
} | ||
|
||
CheckResponse(statusResponse); | ||
|
||
Cout << "progress: " << statusResponse.GetProcessedRangeCount() | ||
<< "/" << statusResponse.GetRangeCount() << ", last=" | ||
<< statusResponse.GetLastProcessedRangeId() << Endl; | ||
|
||
Sleep(TDuration::Seconds(1)); | ||
} | ||
|
||
return true; | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
TCommandPtr NewForcedCompactionCommand() | ||
{ | ||
return std::make_shared<TForcedCompactionCommand>(); | ||
} | ||
|
||
} // namespace NCloud::NFileStore::NClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
cloud/filestore/tests/client/canondata/test.test_forced_compaction/results.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
progress: 0/64, last=1177944064 | ||
finished |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters