-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: JaySon-Huang <[email protected]>
- Loading branch information
1 parent
73cb457
commit c5d057c
Showing
15 changed files
with
227 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2023 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Flash/Disaggregated/S3LockClient.h> | ||
#include <Storages/S3/S3Common.h> | ||
#include <Storages/S3/S3Filename.h> | ||
|
||
namespace DB::S3 | ||
{ | ||
|
||
class MockS3LockClient : public IS3LockClient | ||
{ | ||
public: | ||
explicit MockS3LockClient(std::shared_ptr<TiFlashS3Client> c) | ||
: s3_client(std::move(c)) | ||
{ | ||
} | ||
|
||
std::pair<bool, String> | ||
sendTryAddLockRequest(const String & data_file_key, UInt32 lock_store_id, UInt32 lock_seq, Int64) override | ||
{ | ||
auto view = S3FilenameView::fromKey(data_file_key); | ||
if (!objectExists(*s3_client, s3_client->bucket(), data_file_key)) | ||
{ | ||
return {false, ""}; | ||
} | ||
auto delmark_key = view.getDelMarkKey(); | ||
if (objectExists(*s3_client, s3_client->bucket(), delmark_key)) | ||
{ | ||
return {false, ""}; | ||
} | ||
uploadEmptyFile(*s3_client, s3_client->bucket(), view.getLockKey(lock_store_id, lock_seq)); | ||
return {true, ""}; | ||
} | ||
|
||
std::pair<bool, String> | ||
sendTryMarkDeleteRequest(const String & data_file_key, Int64) override | ||
{ | ||
auto view = S3FilenameView::fromKey(data_file_key); | ||
auto lock_prefix = view.getLockPrefix(); | ||
bool any_lock_exist = false; | ||
listPrefix(*s3_client, s3_client->bucket(), lock_prefix, [&any_lock_exist](const Aws::S3::Model::ListObjectsV2Result & result) -> S3::PageResult { | ||
if (!result.GetContents().empty()) | ||
any_lock_exist = true; | ||
return S3::PageResult{.num_keys = result.GetContents().size(), .more = false}; | ||
}); | ||
if (any_lock_exist) | ||
{ | ||
return {false, ""}; | ||
} | ||
uploadEmptyFile(*s3_client, s3_client->bucket(), view.getDelMarkKey()); | ||
return {true, ""}; | ||
} | ||
|
||
private: | ||
std::shared_ptr<TiFlashS3Client> s3_client; | ||
}; | ||
|
||
} // namespace DB::S3 |
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,56 @@ | ||
// Copyright 2023 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Storages/Transaction/Types.h> | ||
#include <common/types.h> | ||
|
||
namespace DB | ||
{ | ||
class Logger; | ||
using LoggerPtr = std::shared_ptr<Logger>; | ||
} // namespace DB | ||
|
||
namespace DB::S3 | ||
{ | ||
|
||
class IS3LockClient; | ||
using S3LockClientPtr = std::shared_ptr<IS3LockClient>; | ||
|
||
class IS3LockClient | ||
{ | ||
public: | ||
virtual ~IS3LockClient() = default; | ||
|
||
// Try add lock to the `data_file_key` by `lock_store_id` and `lock_seq` | ||
// If the file is locked successfully, return <true, ""> | ||
// Otherwise return <false, conflict_message> | ||
// This method will update the owner info when owner changed. | ||
// If deadline exceed or failed to get the owner info within | ||
// `timeour_s`, it will throw exception. | ||
virtual std::pair<bool, String> | ||
sendTryAddLockRequest(const String & data_file_key, UInt32 lock_store_id, UInt32 lock_seq, Int64 timeout_s) = 0; | ||
|
||
// Try mark the `data_file_key` as deleted | ||
// If the file is marked as deleted, return <true, ""> | ||
// Otherwise return <false, conflict_message> | ||
// This method will update the owner info when owner changed. | ||
// If deadline exceed or failed to get the owner info within | ||
// `timeour_s`, it will throw exception. | ||
virtual std::pair<bool, String> | ||
sendTryMarkDeleteRequest(const String & data_file_key, Int64 timeout_s) = 0; | ||
}; | ||
|
||
} // namespace DB::S3 |
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ struct RemoteDataLocation | |
UInt64 size_in_file; | ||
}; | ||
|
||
} // namespace DB::PS::V3::Remote | ||
} // namespace DB::Remote |
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
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
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
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