Skip to content

Commit

Permalink
Merge pull request #338 from Mixficsol/delete_slot
Browse files Browse the repository at this point in the history
fix: delete slot
  • Loading branch information
Mixficsol authored Dec 11, 2023
2 parents 559efc7 + e1030fc commit e2c6f92
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 457 deletions.
18 changes: 9 additions & 9 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "pstd/include/pstd_string.h"

#include "include/pika_slot.h"
#include "include/pika_db.h"
#include "net/src/dispatch_thread.h"

class SyncMasterSlot;
Expand Down Expand Up @@ -481,15 +482,14 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
virtual std::vector<std::string> current_key() const;
virtual void Execute();
virtual void ProcessSingleSlotCmd();
virtual void ProcessMultiSlotCmd();
virtual void Do(std::shared_ptr<Slot> slot = nullptr) = 0;
virtual void DoThroughDB(std::shared_ptr<Slot> slot = nullptr) {}
virtual void DoUpdateCache(std::shared_ptr<Slot> slot = nullptr) {}
virtual void ReadCache(std::shared_ptr<Slot> slot = nullptr) {}
virtual void Do(std::shared_ptr<DB> db) = 0;
virtual void DoThroughDB(std::shared_ptr<DB> db) {}
virtual void DoUpdateCache(std::shared_ptr<DB> db) {}
virtual void ReadCache(std::shared_ptr<DB> db) {}
rocksdb::Status CmdStatus() { return s_; };
virtual Cmd* Clone() = 0;
// used for execute multikey command into different slots
virtual void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) = 0;
virtual void Split(std::shared_ptr<DB> db, const HintKeys& hint_keys) = 0;
virtual void Merge() = 0;

void Initial(const PikaCmdArgsType& argv, const std::string& db_name);
Expand Down Expand Up @@ -531,11 +531,11 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
protected:
// enable copy, used default copy
// Cmd(const Cmd&);
void ProcessCommand(const std::shared_ptr<Slot>& slot, const std::shared_ptr<SyncMasterSlot>& sync_slot,
void ProcessCommand(const std::shared_ptr<DB>& db, const std::shared_ptr<SyncMasterSlot>& sync_slot,
const HintKeys& hint_key = HintKeys());
void InternalProcessCommand(const std::shared_ptr<Slot>& slot, const std::shared_ptr<SyncMasterSlot>& sync_slot,
void InternalProcessCommand(const std::shared_ptr<DB>& db, const std::shared_ptr<SyncMasterSlot>& sync_slot,
const HintKeys& hint_key);
void DoCommand(const std::shared_ptr<Slot>& slot, const HintKeys& hint_key);
void DoCommand(const std::shared_ptr<DB>& db, const HintKeys& hint_key);
bool CheckArg(uint64_t num) const;
void LogCommand() const;

Expand Down
10 changes: 9 additions & 1 deletion include/pika_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DB : public std::enable_shared_from_this<DB>, public pstd::noncopyable {
friend class PikaServer;

std::string GetDBName();
std::shared_ptr<storage::Storage> storage() const;
void BgSaveDB();
void CompactDB(const storage::DataType& type);
bool FlushSlotDB();
Expand All @@ -33,6 +34,7 @@ class DB : public std::enable_shared_from_this<DB>, public pstd::noncopyable {
bool IsBinlogIoError();
uint32_t SlotNum();
void GetAllSlots(std::set<uint32_t>& slot_ids);
std::shared_ptr<PikaCache> cache() const;
std::shared_mutex& GetSlotLock() {
return slots_rw_;
}
Expand Down Expand Up @@ -76,12 +78,18 @@ class DB : public std::enable_shared_from_this<DB>, public pstd::noncopyable {
std::map<uint32_t, std::shared_ptr<Slot>> GetSlots() {
return slots_;
}
std::shared_ptr<pstd::lock::LockMgr> LockMgr();
void DbRWLockReader();
void DbRWUnLock();
private:
std::string db_name_;
uint32_t slot_num_ = 0;
std::string db_path_;
std::string log_path_;

std::shared_ptr<pstd::lock::LockMgr> lock_mgr_;
std::shared_mutex db_rwlock_;
std::shared_ptr<storage::Storage> storage_;
std::shared_ptr<PikaCache> cache_;
std::atomic<bool> binlog_io_error_;
// lock order
// slots_rw_ > key_scan_protector_
Expand Down
Loading

0 comments on commit e2c6f92

Please sign in to comment.