22
22
#include "rifl.h"
23
23
#include "timeTrace.h"
24
24
#include "udp.h"
25
+ #include "witnesscmd.h"
25
26
26
27
/* functions from aof.c */
27
28
struct client * createFakeClient ();
@@ -41,7 +42,7 @@ struct WitnessGcInfo {
41
42
42
43
/* 0th index is not used. */
43
44
struct WitnessGcInfo unsyncedRpcs [WITNESS_BATCH_SIZE ] = {{0 ,0 ,0 }, };
44
- int unsyncedRpcsSize = 0 ;
45
+ uint32_t unsyncedRpcsSize = 0 ;
45
46
46
47
struct WitnessGcBioContext {
47
48
long long maxOpNum ;
@@ -51,37 +52,23 @@ struct WitnessGcBioContext {
51
52
/*================================= Functions =============================== */
52
53
void scheduleFsyncAndWitnessGc () {
53
54
record ("start constructing gc RPC." , 0 , 0 , 0 , 0 );
54
- // TODO: Construct GC packet
55
- char * masterIdxStr = "1" ;
56
- int s = createSocket ();
57
- sds cmdstr = sdscatprintf (sdsempty (), "*%d\r\n$3\r\nWGC\r\n$%d\r\n%s\r\n" ,
58
- 2 + 3 * unsyncedRpcsSize , (int )strlen (masterIdxStr ), masterIdxStr );
59
- for (int i = 0 ; i < unsyncedRpcsSize ; ++ i ) {
60
- int hashIndex_len , clientId_len , requestId_len ;
61
- char hashIndex_str [LONG_STR_SIZE ];
62
- char clientId_str [LONG_STR_SIZE ];
63
- char requestId_str [LONG_STR_SIZE ];
64
-
65
- hashIndex_len = ulltoa64 (hashIndex_str , sizeof (hashIndex_str ),
66
- unsyncedRpcs [i ].hashIndex );
67
- clientId_len = ulltoa64 (clientId_str , sizeof (clientId_str ),
68
- unsyncedRpcs [i ].clientId );
69
- requestId_len = ulltoa64 (requestId_str , sizeof (requestId_str ),
70
- unsyncedRpcs [i ].requestId );
71
- // hashIndex_len = ll2string(hashIndex_str, sizeof(hashIndex_str),
72
- // unsyncedRpcs[i].hashIndex);
73
- // clientId_len = ll2string(clientId_str, sizeof(clientId_str),
74
- // unsyncedRpcs[i].clientId);
75
- // requestId_len = ll2string(requestId_str, sizeof(requestId_str),
76
- // unsyncedRpcs[i].requestId);
77
- cmdstr = sdscatprintf (cmdstr , "$%d\r\n%s\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n" ,
78
- hashIndex_len , hashIndex_str , clientId_len , clientId_str , requestId_len , requestId_str );
55
+ /* Create a set of GC Cmds */
56
+ witnesscmd_t * cmds =
57
+ (witnesscmd_t * ) zmalloc (unsyncedRpcsSize * sizeof (witnesscmd_t ));
58
+ for (uint32_t i = 0 ; i < unsyncedRpcsSize ; ++ i ) {
59
+ init_witnesscmd (cmds , "D" , unsyncedRpcs [i ].clientId ,
60
+ unsyncedRpcs [i ].requestId ,
61
+ unsyncedRpcs [i ].hashIndex , "" , 0 );
62
+ cmds ++ ;
79
63
}
80
64
unsyncedRpcsSize = 0 ;
81
- close (s );
82
65
record ("constructed gc RPC." , 0 , 0 , 0 , 0 );
83
- bioCreateBackgroundJob (BIO_FSYNC_AND_GC_WITNESS , (void * )cmdstr ,
84
- (void * )(long )server .aof_fd , server .currentOpNum );
66
+
67
+ /* Submit the GC job to the background thread */
68
+ bioCreateBackgroundJob (BIO_FSYNC_AND_GC_WITNESS ,
69
+ cmds ,
70
+ (void * )(long )server .aof_fd , server .currentOpNum ,
71
+ unsyncedRpcsSize );
85
72
record ("bioBackgroundJob Created." , 0 , 0 , 0 , 0 );
86
73
}
87
74
0 commit comments