forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: migrate-tools support pila3.5.0
- Loading branch information
Showing
13 changed files
with
1,149 additions
and
0 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
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,66 @@ | ||
#ifndef MIGRATOR_THREAD_H_ | ||
#define MIGRATOR_THREAD_H_ | ||
|
||
#include <iostream> | ||
#include <mutex> | ||
|
||
#include "storage/storage.h" | ||
#include "net/include/redis_cli.h" | ||
|
||
#include "include/pika_sender.h" | ||
|
||
class MigratorThread : public net::Thread { | ||
public: | ||
MigratorThread(std::shared_ptr<storage::Storage> storage_, std::vector<PikaSender *> *senders, int type, int thread_num) : | ||
storage_(storage_), | ||
should_exit_(false), | ||
senders_(senders), | ||
type_(type), | ||
thread_num_(thread_num), | ||
thread_index_(0), | ||
num_(0) { | ||
} | ||
|
||
virtual ~ MigratorThread(); | ||
|
||
int64_t num() { | ||
std::lock_guard<std::mutex> l(num_mutex_); | ||
return num_; | ||
} | ||
|
||
void Stop() { | ||
should_exit_ = true; | ||
} | ||
|
||
private: | ||
void PlusNum() { | ||
std::lock_guard<std::mutex> l(num_mutex_); | ||
++num_; | ||
} | ||
|
||
void DispatchKey(const std::string &command, const std::string& key = ""); | ||
|
||
void MigrateDB(); | ||
void MigrateStringsDB(); | ||
void MigrateListsDB(); | ||
void MigrateHashesDB(); | ||
void MigrateSetsDB(); | ||
void MigrateZsetsDB(); | ||
|
||
virtual void *ThreadMain(); | ||
|
||
private: | ||
std::shared_ptr<storage::Storage> storage_; | ||
bool should_exit_; | ||
|
||
std::vector<PikaSender *> *senders_; | ||
int type_; | ||
int thread_num_; | ||
int thread_index_; | ||
|
||
int64_t num_; | ||
std::mutex num_mutex_; | ||
}; | ||
|
||
#endif | ||
|
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,43 @@ | ||
#ifndef PIKA_SENDER_H_ | ||
#define PIKA_SENDER_H_ | ||
|
||
#include <atomic> | ||
#include <thread> | ||
#include <chrono> | ||
#include <iostream> | ||
#include <queue> | ||
|
||
#include "net/include/bg_thread.h" | ||
#include "net/include/net_cli.h" | ||
#include "net/include/redis_cli.h" | ||
|
||
class PikaSender : public net::Thread { | ||
public: | ||
PikaSender(std::string ip, int64_t port, std::string password); | ||
virtual ~PikaSender(); | ||
void LoadKey(const std::string &cmd); | ||
void Set_should_stop(); | ||
bool Should_stop() { return should_exit_.load(); } | ||
|
||
int64_t elements() { return elements_; } | ||
|
||
void SendCommand(std::string &command, const std::string &key); | ||
int QueueSize(); | ||
void ConnectRedis(); | ||
|
||
private: | ||
net::NetCli *cli_; | ||
pstd::CondVar wsignal_; | ||
pstd::CondVar rsignal_; | ||
std::mutex keys_mutex_; | ||
std::queue<std::string> keys_queue_; | ||
std::string ip_; | ||
int port_; | ||
std::string password_; | ||
std::atomic<bool> should_exit_; | ||
int64_t elements_; | ||
|
||
virtual void *ThreadMain(); | ||
}; | ||
|
||
#endif |
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,47 @@ | ||
#ifndef REDIS_SENDER_H_ | ||
#define REDIS_SENDER_H_ | ||
|
||
#include <atomic> | ||
#include <thread> | ||
#include <chrono> | ||
#include <iostream> | ||
#include <queue> | ||
|
||
#include "pika_repl_bgworker.h" | ||
#include "net/include/net_cli.h" | ||
#include "net/include/redis_cli.h" | ||
|
||
class RedisSender : public net::Thread { | ||
public: | ||
RedisSender(int id, std::string ip, int64_t port, std::string password); | ||
virtual ~RedisSender(); | ||
void Stop(void); | ||
int64_t elements() { | ||
return elements_; | ||
} | ||
|
||
void SendRedisCommand(const std::string &command); | ||
|
||
private: | ||
int SendCommand(std::string &command); | ||
void ConnectRedis(); | ||
|
||
private: | ||
int id_; | ||
net::NetCli *cli_; | ||
pstd::CondVar rsignal_; | ||
pstd::CondVar wsignal_; | ||
pstd::Mutex commands_mutex_; | ||
std::queue<std::string> commands_queue_; | ||
std::string ip_; | ||
int port_; | ||
std::string password_; | ||
bool should_exit_; | ||
int32_t cnt_; | ||
int64_t elements_; | ||
std::atomic<time_t> last_write_time_; | ||
|
||
virtual void *ThreadMain(); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.