forked from OpenAtomFoundation/pikiwidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_cache_load_thread.h
56 lines (45 loc) · 2.01 KB
/
pika_cache_load_thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2023-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// 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.
#ifndef PIKA_CACHE_LOAD_THREAD_H_
#define PIKA_CACHE_LOAD_THREAD_H_
#include <atomic>
#include <string>
#include <unordered_map>
#include <vector>
#include "include/pika_cache.h"
#include "include/pika_slot.h"
#include "include/pika_define.h"
#include "net/include/net_thread.h"
#include "storage/storage.h"
class PikaCacheLoadThread : public net::Thread {
public:
PikaCacheLoadThread(int zset_cache_start_pos, int zset_cache_field_num_per_key);
~PikaCacheLoadThread();
uint64_t AsyncLoadKeysNum(void) { return async_load_keys_num_; }
uint32_t WaittingLoadKeysNum(void) { return waitting_load_keys_num_; }
void Push(const char key_type, std::string& key, const std::shared_ptr<Slot> &slot);
private:
bool LoadKV(std::string& key, const std::shared_ptr<Slot>& slot);
bool LoadHash(std::string& key, const std::shared_ptr<Slot>& slot);
bool LoadList(std::string& key, const std::shared_ptr<Slot>& slot);
bool LoadSet(std::string& key, const std::shared_ptr<Slot>& slot);
bool LoadZset(std::string& key, const std::shared_ptr<Slot>& slot);
bool LoadKey(const char key_type, std::string& key, const std::shared_ptr<Slot>& slot);
virtual void* ThreadMain();
private:
std::atomic_bool should_exit_;
std::deque<std::tuple<const char, std::string, const std::shared_ptr<Slot>>> loadkeys_queue_;
pstd::CondVar loadkeys_cond_;
pstd::Mutex loadkeys_mutex_;
std::unordered_map<std::string, std::string> loadkeys_map_;
pstd::Mutex loadkeys_map_mutex_;
std::atomic_uint64_t async_load_keys_num_;
std::atomic_uint32_t waitting_load_keys_num_;
// currently only take effects to zset
int zset_cache_start_pos_;
int zset_cache_field_num_per_key_;
std::shared_ptr<PikaCache> cache_;
};
#endif // PIKA_CACHE_LOAD_THREAD_H_