Skip to content

Commit 3a5c633

Browse files
committed
memory mode: remove deprecated client hold mode.
1 parent e3950cf commit 3a5c633

9 files changed

+18
-35
lines changed

src/ctrip_swap.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ list *clientRenewLocks(client *c) {
3838
void clientGotLock(client *c, swapCtx *ctx, void *lock) {
3939
serverAssert(ctx->swap_lock == NULL);
4040
ctx->swap_lock = lock;
41-
switch (c->client_hold_mode) {
42-
case CLIENT_HOLD_MODE_CMD:
43-
case CLIENT_HOLD_MODE_REPL:
41+
switch (c->swap_lock_mode) {
42+
case SWAP_LOCK_UNIQUE:
4443
serverAssert(c->swap_locks != NULL);
4544
listAddNodeTail(c->swap_locks,lock);
4645
break;
47-
case CLIENT_HOLD_MODE_EVICT:
46+
case SWAP_LOCK_SHARED:
4847
default:
4948
break;
5049
}
@@ -60,17 +59,16 @@ void clientReleaseLocks(client *c, swapCtx *ctx) {
6059
listNode *ln;
6160
listIter li;
6261

63-
switch (c->client_hold_mode) {
64-
case CLIENT_HOLD_MODE_CMD:
65-
case CLIENT_HOLD_MODE_REPL:
62+
switch (c->swap_lock_mode) {
63+
case SWAP_LOCK_UNIQUE:
6664
locks = clientRenewLocks(c);
6765
listRewind(locks,&li);
6866
while ((ln = listNext(&li))) {
6967
lockUnlock(listNodeValue(ln));
7068
}
7169
listRelease(locks);
7270
break;
73-
case CLIENT_HOLD_MODE_EVICT:
71+
case SWAP_LOCK_SHARED:
7472
if (ctx->swap_lock) {
7573
lockUnlock(ctx->swap_lock);
7674
}
@@ -247,8 +245,6 @@ void continueProcessCommand(client *c) {
247245
handleClientsBlockedOnKeys();
248246
}
249247

250-
/* unhold keys for current command. */
251-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_CMD);
252248
/* post command */
253249
commandProcessed(c);
254250
c->flags |= CLIENT_SWAP_UNLOCKING;

src/ctrip_swap_blocked.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ swapUnblockCtx* createSwapUnblockCtx() {
8484
client *c = createClient(NULL);
8585
c->cmd = lookupCommandByCString("brpoplpush");
8686
c->db = server.db+i;
87-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
87+
c->swap_lock_mode = SWAP_LOCK_SHARED;
8888
swap_dependency_block_ctx->mock_clients[i] = c;
8989
}
9090
return swap_dependency_block_ctx;

src/ctrip_swap_evict.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ void evictClientKeyRequestFinished(client *c, swapCtx *ctx) {
3838
if (ctx->errcode) clientSwapError(c,ctx->errcode);
3939
incrRefCount(key);
4040
c->keyrequests_count--;
41-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_EVICT);
4241

4342
if (persist_version != SWAP_PERSIST_VERSION_NO) {
4443
swapPersistKeyRequestFinished(server.swap_persist_ctx,

src/ctrip_swap_expire.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ void expireClientKeyRequestFinished(client *c, swapCtx *ctx) {
3434
if (ctx->errcode) clientSwapError(c,ctx->errcode);
3535
incrRefCount(key);
3636
c->keyrequests_count--;
37-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_EVICT);
3837
clientReleaseLocks(c,ctx);
3938
decrRefCount(key);
4039
}
@@ -206,7 +205,6 @@ void metaScan4ScanExpireRequestFinished(client *c, swapCtx *ctx) {
206205
if (ctx->errcode) clientSwapError(c,ctx->errcode);
207206
incrRefCount(key);
208207
c->keyrequests_count--;
209-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_EVICT);
210208
clientReleaseLocks(c,ctx);
211209
decrRefCount(key);
212210
}
@@ -465,7 +463,6 @@ void slaveExpireClientKeyRequestFinished(client *c, swapCtx *ctx) {
465463
incrRefCount(key);
466464
if (ctx->errcode) clientSwapError(c,ctx->errcode);
467465
c->keyrequests_count--;
468-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_EVICT);
469466
clientReleaseLocks(c,ctx);
470467
decrRefCount(key);
471468
}

src/ctrip_swap_load.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ void loadClientKeyRequestFinished(client *c, swapCtx *ctx) {
4444
}
4545
incrRefCount(key);
4646
c->keyrequests_count--;
47-
serverAssert(c->client_hold_mode == CLIENT_HOLD_MODE_EVICT);
4847
clientReleaseLocks(c,ctx);
4948
decrRefCount(key);
5049

src/ctrip_swap_repl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ static void processFinishedReplCommands() {
202202

203203
commandProcessed(wc);
204204

205-
serverAssert(wc->client_hold_mode == CLIENT_HOLD_MODE_REPL);
206-
207205
long long prev_offset = c->reploff;
208206
/* update reploff */
209207
if (c->flags&CLIENT_MASTER) {

src/ctrip_swap_server.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void swapInitServer(void) {
166166
client *c = createClient(NULL);
167167
c->cmd = lookupCommandByCString("SWAP.EVICT");
168168
c->db = server.db+i;
169-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
169+
c->swap_lock_mode = SWAP_LOCK_SHARED;
170170
server.swap_evict_clients[i] = c;
171171
}
172172

@@ -175,7 +175,7 @@ void swapInitServer(void) {
175175
client *c = createClient(NULL);
176176
c->cmd = lookupCommandByCString("SWAP.LOAD");
177177
c->db = server.db+i;
178-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
178+
c->swap_lock_mode = SWAP_LOCK_SHARED;
179179
server.swap_load_clients[i] = c;
180180
}
181181

@@ -184,7 +184,7 @@ void swapInitServer(void) {
184184
client *c = createClient(NULL);
185185
c->db = server.db+i;
186186
c->cmd = lookupCommandByCString("SWAP.EXPIRED");
187-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
187+
c->swap_lock_mode = SWAP_LOCK_SHARED;
188188
server.swap_expire_clients[i] = c;
189189
}
190190

@@ -193,7 +193,7 @@ void swapInitServer(void) {
193193
client *c = createClient(NULL);
194194
c->db = server.db+i;
195195
c->cmd = lookupCommandByCString("SWAP.SCANEXPIRE");
196-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
196+
c->swap_lock_mode = SWAP_LOCK_SHARED;
197197
server.swap_scan_expire_clients[i] = c;
198198
}
199199

@@ -202,21 +202,21 @@ void swapInitServer(void) {
202202
client *c = createClient(NULL);
203203
c->db = server.db+i;
204204
c->cmd = lookupCommandByCString("ttl");
205-
c->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
205+
c->swap_lock_mode = SWAP_LOCK_SHARED;
206206
server.swap_ttl_clients[i] = c;
207207
}
208208

209209
server.swap_mutex_client = createClient(NULL);
210210
server.swap_mutex_client->cmd = lookupCommandByCString("SWAP.MUTEXOP");
211-
server.swap_mutex_client->client_hold_mode = CLIENT_HOLD_MODE_EVICT;
211+
server.swap_mutex_client->swap_lock_mode = SWAP_LOCK_SHARED;
212212

213213
server.swap_repl_workers = 256;
214214
server.swap_repl_swapping_clients = listCreate();
215215
server.swap_repl_worker_clients_free = listCreate();
216216
server.swap_repl_worker_clients_used = listCreate();
217217
for (i = 0; i < server.swap_repl_workers; i++) {
218218
client *c = createClient(NULL);
219-
c->client_hold_mode = CLIENT_HOLD_MODE_REPL;
219+
c->swap_lock_mode = SWAP_LOCK_UNIQUE;
220220
listAddNodeTail(server.swap_repl_worker_clients_free, c);
221221
}
222222

src/ctrip_swap_server.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,15 @@ typedef void (*dataSwapFinishedCallback)(void *ctx, int action, char *rawkey, ch
7373
struct scanExpire *scan_expire; /* scan expire related */ \
7474
struct coldFilter *cold_filter; /* cold keys filter: absent cache & cuckoo filter. */
7575

76-
/* TODO: remove */
77-
#define CLIENT_HOLD_MODE_CMD 0 /* Hold all key in cmd if any key in cmd needs swap. */
78-
#define CLIENT_HOLD_MODE_EVICT 1 /* Hold key if needs swap. */
79-
#define CLIENT_HOLD_MODE_REPL 2 /* Hold all key no matter what. */
80-
81-
typedef void (*voidfuncptr)(void);
76+
#define SWAP_LOCK_UNIQUE 0 /* Client will submit/lock/proceed/unlock one tx at a time, typically used by normal and repl worker client. */
77+
#define SWAP_LOCK_SHARED 1 /* Client may submit another tx event if previous tx is in flight, typicall used by evict client. */
8278

8379
#define SWAP_CLIENT \
8480
int keyrequests_count; \
8581
struct swapCmdTrace *swap_cmd; \
8682
long swap_duration; /* microseconds used in swap */ \
8783
int swap_result; \
88-
voidfuncptr client_swap_finished_cb; \
89-
void *client_swap_finished_pd; \
90-
int client_hold_mode; /* indicates how client should hold key */ \
84+
int swap_lock_mode; /* indicates whether client will submit submit multiple tx simutaneously. */ \
9185
int CLIENT_DEFERED_CLOSING; \
9286
int CLIENT_REPL_SWAPPING; \
9387
long long swap_cmd_reploff; /* Command replication offset when dispatch if this is a repl worker */ \

src/networking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ client *createClient(connection *conn) {
202202
c->swap_result = 0;
203203
c->swap_cmd_reploff = -1;
204204
c->swap_repl_client = NULL;
205-
c->client_hold_mode = CLIENT_HOLD_MODE_CMD;
205+
c->swap_lock_mode = SWAP_LOCK_UNIQUE;
206206
c->CLIENT_DEFERED_CLOSING = 0;
207207
c->CLIENT_REPL_SWAPPING = 0;
208208
c->swap_locks = listCreate();

0 commit comments

Comments
 (0)