-
Notifications
You must be signed in to change notification settings - Fork 5
/
lock_server_cache_rsm.h
88 lines (69 loc) · 2.1 KB
/
lock_server_cache_rsm.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef lock_server_cache_rsm_h
#define lock_server_cache_rsm_h
#include <string>
#include <queue>
#include "lock_protocol.h"
#include "rpc.h"
#include "rsm_state_transfer.h"
#include "rsm.h"
#include "uqueue.h"
#include "fifo.h"
class lock_server_cache_rsm : public rsm_state_transfer {
private:
class rsm *rsm;
enum lock_status {
free, // server has the free lock
lent, // lock is lent to some client @owner
revoked, // lock is lent but being revoked
};
struct acquire_reply_t {
lock_protocol::status status;
int ret;
std::string revoke;
};
struct release_reply_t {
lock_protocol::status status;
};
struct client_context_t {
lock_protocol::xid_t last_xid;
acquire_reply_t acquire_reply;
release_reply_t release_reply;
client_context_t() : last_xid(0) { }
friend inline marshall& operator<<(marshall &m, client_context_t ctx) {
m << ctx.last_xid;
m << ctx.acquire_reply.status << ctx.acquire_reply.ret << ctx.acquire_reply.revoke;
m << ctx.release_reply.status;
return m;
}
friend inline unmarshall& operator>>(unmarshall &u, client_context_t &ctx) {
u >> ctx.last_xid;
u >> ctx.acquire_reply.status >> ctx.acquire_reply.ret >> ctx.acquire_reply.revoke;
u >> ctx.release_reply.status;
return u;
}
};
struct lock_t {
lock_status status;
std::string owner;
uqueue<std::string> wait_q; // waiting list
std::map<std::string, client_context_t> client_ctx;
lock_t() : status(lock_status::free) { }
};
std::map<lock_protocol::lockid_t, lock_t> locks;
struct task_t {
lock_protocol::lockid_t lid;
std::string client;
};
fifo<task_t> revoke_tasks;
fifo<task_t> retry_tasks;
pthread_mutex_t m;
public:
lock_server_cache_rsm(class rsm *rsm = 0);
void revoker();
void retryer();
std::string marshal_state();
void unmarshal_state(std::string state);
lock_protocol::status acquire(lock_protocol::lockid_t, std::string, lock_protocol::xid_t, int &);
lock_protocol::status release(lock_protocol::lockid_t, std::string, lock_protocol::xid_t, int &);
};
#endif