Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: sync all snapshot data in Pika process without rsync subprocess #1805

Merged
merged 44 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
73dc198
define rsync related header file and proto
Jul 7, 2023
4b92d87
Merge branch 'OpenAtomFoundation:unstable' into optimize-rsync
luky116 Jul 10, 2023
c93f5d6
feat:add throttle (#167)
chejinge Jul 12, 2023
8ba038f
feat: implement rsync network tansform (#169)
wangshao1 Jul 12, 2023
dd51cde
fix action (#171)
luky116 Jul 12, 2023
4bbd2e6
merge unstable code
luky116 Jul 12, 2023
d23e398
fix
luky116 Jul 12, 2023
7785b42
feat: add load local meta file (#175)
luky116 Jul 13, 2023
e4aa948
[feat] add rsync client/server code (#177)
wangshao1 Jul 13, 2023
26d4db8
add rsyncclient to syncslaveslot (#182)
wangshao1 Jul 14, 2023
547530c
feat: add read meta file and data (#179)
luky116 Jul 14, 2023
7bac336
fix compile error (#183)
wangshao1 Jul 14, 2023
b2f4091
fix compile error (#184)
wangshao1 Jul 14, 2023
1b4b979
optimize: add_throttle (#189)
chejinge Jul 14, 2023
fa96b9d
rsyncclient periodically flush meta table (#192)
wangshao1 Jul 14, 2023
84e69da
change rsync response (#190)
luky116 Jul 17, 2023
3fe94e4
add debug log for test
Jul 18, 2023
0d35c3b
fix rsync client/server bugs
wangshao1 Jul 18, 2023
1130130
fix bugs
wangshao1 Jul 18, 2023
612f5e4
add debug log for test
Jul 18, 2023
63c4a7e
fix bugs
wangshao1 Jul 19, 2023
dc86779
fix bugs
Jul 19, 2023
002d34d
fix bugs
wangshao1 Jul 19, 2023
1918b90
rix rsync bugs (#194)
wangshao1 Jul 20, 2023
9583007
fix bugs
wangshao1 Jul 20, 2023
852b8d6
fix bugs
Jul 20, 2023
f39a024
fix bugs 1
wangshao1 Jul 21, 2023
ce861f7
Merge branch 'optimize-rsync' into optimize-rsync-wsy
Jul 22, 2023
bbf6585
fix bugs
Jul 22, 2023
17217ac
fix rsync bugs (#195)
wangshao1 Jul 22, 2023
44c57ed
remove unused code
Jul 23, 2023
5983379
Merge branch 'optimize-rsync' into optimize-rsync-wsy
Jul 23, 2023
fe25080
remove unused code
Jul 23, 2023
6fa3717
Merge branch 'unstable' into optimize-rsync-wsy
Jul 24, 2023
f48726b
remove unused code
Jul 24, 2023
1e7750b
Merge pull request #211 from wangshao1/optimize-rsync-wangsy
chejinge Jul 24, 2023
c5936b2
remove unused code
Jul 24, 2023
afd133a
add copyright
Jul 24, 2023
4a54423
Merge pull request #212 from wangshao1/optimize-rsync-wangsy
chejinge Jul 24, 2023
bbd489c
fix by review comments (#213)
wangshao1 Jul 25, 2023
17095de
fix by review comments (#214)
wangshao1 Jul 26, 2023
2090367
fix by review comments (#216)
wangshao1 Jul 26, 2023
2be71f4
Optimize rsync wangsy (#217)
wangshao1 Jul 26, 2023
01b6a22
fix by review comments (#218)
wangshao1 Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/pika_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class PikaServer;
/* Port shift */
const int kPortShiftRSync = 1000;
const int kPortShiftReplServer = 2000;
// todo 待移除,使用 kPortShiftRSync
//TODO: Temporarily used for rsync server port shift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: Temporarily used for rsync server port shift. will be deleted.

const int kPortShiftRsync2 = 10001;

const std::string kPikaPidFile = "pika.pid";
const std::string kPikaSecretFile = "rsync.secret";
const std::string kDefaultRsyncAuth = "default";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the provided code patch, here is a brief code review:

  1. The addition of a new constant kPortShiftRsync2 and the accompanying comment suggest that it is temporarily used for rsync server port shifting. Ensure that this temporary usage is properly communicated and documented to prevent confusion.

  2. Overall, the code change seems to be straightforward and doesn't introduce any obvious bug risks.

Improvement suggestions:

  1. Consider using more descriptive names for constants, such as kPortShiftRsyncTemporary, instead of kPortShiftRsync2. This will make the code more readable and maintainable.

  2. Ensure that the use of this temporary variable kPortShiftRsync2 is properly removed or updated once its temporary usage is complete, to avoid leaving unused or misleading code in the system.

  3. It's always good practice to include a comment explaining the reason behind certain code changes, especially when introducing temporary variables/constants or making non-obvious modifications that deviate from the existing codebase.

Remember to thoroughly test the code after making these changes to ensure proper functionality.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the code patch you provided, here are some observations:

  1. The addition of kPortShiftRsync2 suggests a new port shift value for the rsync server. However, the comment mentions that it is temporary and will be deleted. Make sure to update or remove this code appropriately once it is no longer needed.

  2. The variable name kPortShiftRsync2 could be improved for better clarity. Consider using a more descriptive name based on its purpose.

  3. Ensure that there are no conflicts or issues arising from the new port shift values (kPortShiftRSync, kPortShiftReplServer, and kPortShiftRsync2) being used in the code elsewhere.

  4. Review the usage of other constants (kPikaPidFile, kPikaSecretFile, and kDefaultRsyncAuth) to ensure they are accurate and consistent throughout the codebase.

  5. It's important to review the surrounding code affected by the changes to confirm that the modifications align with the intended functionality.

Overall, without further context or the complete code, it is difficult to identify any potential bugs or suggest additional improvements beyond what has been mentioned. A comprehensive code review requires examining the broader codebase and understanding the overall architecture and requirements.

Expand Down
19 changes: 7 additions & 12 deletions include/rsync_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@
#include <thread>
#include <condition_variable>

#include "include/rsync_client_thread.h"
#include "net/include/bg_thread.h"
#include "pstd/include/pstd_status.h"
#include "include/rsync_client_thread.h"
#include "net/include/net_cli.h"
#include "pstd/include/env.h"
#include "pstd/include/pstd_status.h"
#include "pstd/include/pstd_hash.h"
#include "pstd/include/pstd_string.h"
#include "pstd/include/pstd_status.h"
#include "rsync_service.pb.h"
#include "include/rsync_client_thread.h"
#include "include/throttle.h"

using namespace pstd;
using namespace net;
using namespace RsyncService;
#include "rsync_service.pb.h"

const std::string kDumpMetaFileName = "DUMP_META_DATA";
const std::string kUuidPrefix = "snapshot-uuid:";
Expand All @@ -57,19 +52,19 @@ class RsyncClient : public net::Thread {
return state_.load() == RUNNING;
}
bool IsIdle() { return state_.load() == IDLE;}
void OnReceive(RsyncResponse* resp);
void OnReceive(RsyncService::RsyncResponse* resp);

private:
bool Recover();
Status Wait(RsyncResponse*& resp);
Status Wait(RsyncService::RsyncResponse*& resp);
Status CopyRemoteFile(const std::string& filename);
Status CopyRemoteMeta(std::string* snapshot_uuid, std::set<std::string>* file_set);
Status LoadLocalMeta(std::string* snapshot_uuid, std::map<std::string, std::string>* file_map);
std::string GetLocalMetaFilePath();
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
Status FlushMetaTable();
Status CleanUpExpiredFiles(bool need_reset_path, const std::set<std::string>& files);
Status UpdateLocalMeta(const std::string& snapshot_uuid, const std::set<std::string>& expired_files, std::map<std::string, std::string>* localFileMap);
void HandleRsyncMetaResponse(RsyncResponse* response);
void HandleRsyncMetaResponse(RsyncService::RsyncResponse* response);

private:
std::map<std::string, std::string> meta_table_;
Expand Down Expand Up @@ -149,7 +144,7 @@ class WaitObject {
std::string filename_;
RsyncService::Type type_;
wangshao1 marked this conversation as resolved.
Show resolved Hide resolved
size_t offset_ = 0xFFFFFFFF;
RsyncResponse* resp_ = nullptr;
RsyncService::RsyncResponse* resp_ = nullptr;
};

} // end namespace rsync
Expand Down
6 changes: 2 additions & 4 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

#include "include/pika_server.h"

#include <arpa/inet.h>
#include <ifaddrs.h>
#include <netinet/in.h>
Expand All @@ -25,10 +23,10 @@

#include "include/pika_cmd_table_manager.h"
#include "include/pika_dispatch_thread.h"
#include "include/pika_rm.h"
#include "pstd_hash.h"
#include "include/pika_monotonic_time.h"
#include "include/pika_instant.h"
#include "include/pika_server.h"
#include "include/pika_rm.h"

using pstd::Status;
extern PikaServer* g_pika_server;
Expand Down
7 changes: 2 additions & 5 deletions src/pika_slot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

#include "include/pika_slot.h"

#include <fstream>
#include <memory>

#include "include/pika_conf.h"
#include "include/pika_rm.h"
#include "include/pika_server.h"
#include "include/pika_slot.h"

#include "pstd/include/mutex_impl.h"
#include "pstd_hash.h"
#include "pstd/include/pstd_hash.h"

using pstd::Status;

Expand Down Expand Up @@ -143,7 +142,6 @@ void Slot::PrepareRsync() {
// 3, Update master offset, and the PikaAuxiliaryThread cron will connect and do slaveof task with master
bool Slot::TryUpdateMasterOffset() {
std::string info_path = dbsync_path_ + kBgsaveInfoFile;
// todo 这里要改动,定期向 master 发送 meta_rsync 的请求
if (!pstd::FileExists(info_path)) {
LOG(WARNING) << "info path: " << info_path << " not exist";
return false;
Expand Down Expand Up @@ -331,7 +329,6 @@ Status Slot::GetBgSaveUUID(std::string* snapshot_uuid) {
if (snapshot_uuid_.empty()) {
std::string info_data;
const std::string infoPath = bgsave_info().path + "/info";
// todo 这里待替换
rocksdb::Status s = rocksdb::ReadFileToString(rocksdb::Env::Default(), infoPath, &info_data);
if (!s.ok()) {
LOG(WARNING) << "read dump meta info failed! error:" << s.ToString();
Expand Down
1 change: 0 additions & 1 deletion src/rsync_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using namespace net;
using namespace pstd;
using namespace RsyncService;
using namespace pstd;

extern PikaServer* g_pika_server;

Expand Down
1 change: 1 addition & 0 deletions src/rsync_client_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ RsyncClientThread::RsyncClientThread(int cron_interval, int keepalive_timeout, v

RsyncClientThread::~RsyncClientThread() {}
} //end namespace rsync
wangshao1 marked this conversation as resolved.
Show resolved Hide resolved

1 change: 1 addition & 0 deletions src/rsync_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ message RsyncResponse {
optional MetaResponse meta_resp = 6;
optional FileResponse file_resp = 7;
}