Skip to content

Commit 680cf42

Browse files
committed
Remove remaining traces of local_data
I've preserved is_local since it's still potentially useful. Signed-off-by: Cole Miller <[email protected]>
1 parent 4d462c5 commit 680cf42

File tree

18 files changed

+38
-105
lines changed

18 files changed

+38
-105
lines changed

src/leader.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ static void leaderMaybeCheckpointLegacy(struct leader *l)
224224
tracef("raft_malloc - no mem");
225225
goto err_after_buf_alloc;
226226
}
227-
#ifdef USE_SYSTEM_RAFT
228227
rv = raft_apply(l->raft, apply, &buf, 1, leaderCheckpointApplyCb);
229-
#else
230-
rv = raft_apply(l->raft, apply, &buf, NULL, 1, leaderCheckpointApplyCb);
231-
#endif
232228
if (rv != 0) {
233229
tracef("raft_apply failed %d", rv);
234230
raft_free(apply);
@@ -336,13 +332,7 @@ static int leaderApplyFrames(struct exec *req,
336332
apply->type = COMMAND_FRAMES;
337333
idSet(apply->req.req_id, req->id);
338334

339-
#ifdef USE_SYSTEM_RAFT
340335
rv = raft_apply(l->raft, &apply->req, &buf, 1, leaderApplyFramesCb);
341-
#else
342-
/* TODO actual WAL slice goes here */
343-
struct raft_entry_local_data local_data = {};
344-
rv = raft_apply(l->raft, &apply->req, &buf, &local_data, 1, leaderApplyFramesCb);
345-
#endif
346336
if (rv != 0) {
347337
tracef("raft apply failed %d", rv);
348338
goto err_after_command_encode;

src/raft.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,6 @@ enum {
198198
RAFT_CHANGE /* Raft configuration change. */
199199
};
200200

201-
/**
202-
* A small fixed-size inline buffer that stores extra data for a raft_entry
203-
* that is different for each node in the cluster.
204-
*
205-
* A leader initializes the local data for an entry before passing it into
206-
* raft_apply. This local data is stored in the volatile raft log and also
207-
* in the persistent raft log on the leader. AppendEntries messages sent by
208-
* the leader never contain the local data for entries.
209-
*
210-
* When a follower accepts an AppendEntries request, it invokes a callback
211-
* provided by the FSM to fill out the local data for each new entry before
212-
* appending the entries to its log (volatile and persistent). This local
213-
* data doesn't have to be the same as the local data that the leader computed.
214-
*
215-
* When starting up, a raft node reads the local data for each entry for its
216-
* persistent log as part of populating the volatile log.
217-
*/
218-
struct raft_entry_local_data {
219-
/* Must be the only member of this struct. */
220-
uint8_t buf[16];
221-
};
222-
223201
/**
224202
* A single entry in the raft log.
225203
*
@@ -250,20 +228,13 @@ struct raft_entry_local_data {
250228
* message or in the persistent log. This field can be used by the FSM's `apply`
251229
* callback to handle a COMMAND entry differently depending on whether it
252230
* originated locally.
253-
*
254-
* Note: The @local_data and @is_local fields do not exist when we use an external
255-
* libraft, because the last separate release of libraft predates their addition.
256-
* The ifdef at the very top of this file ensures that we use the system raft headers
257-
* when we build against an external libraft, so there will be no ABI mismatch as
258-
* a result of incompatible struct layouts.
259231
*/
260232
struct raft_entry
261233
{
262234
raft_term term; /* Term in which the entry was created. */
263235
unsigned short type; /* Type (FSM command, barrier, config change). */
264236
bool is_local; /* Placed here so it goes in the padding after @type. */
265237
struct raft_buffer buf; /* Entry data. */
266-
struct raft_entry_local_data local_data;
267238
void *batch; /* Batch that buf's memory points to, if any. */
268239
};
269240

@@ -1244,7 +1215,6 @@ struct raft_apply
12441215
RAFT_API int raft_apply(struct raft *r,
12451216
struct raft_apply *req,
12461217
const struct raft_buffer bufs[],
1247-
const struct raft_entry_local_data local_data[],
12481218
const unsigned n,
12491219
raft_apply_cb cb);
12501220

src/raft/client.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
int raft_apply(struct raft *r,
1515
struct raft_apply *req,
1616
const struct raft_buffer bufs[],
17-
const struct raft_entry_local_data local_data[],
1817
const unsigned n,
1918
raft_apply_cb cb)
2019
{
@@ -42,7 +41,7 @@ int raft_apply(struct raft *r,
4241
req->cb = cb;
4342

4443
/* Append the new entries to the log. */
45-
rv = logAppendCommands(r->log, r->current_term, bufs, local_data, n);
44+
rv = logAppendCommands(r->log, r->current_term, bufs, n);
4645
if (rv != 0) {
4746
goto err;
4847
}
@@ -91,7 +90,7 @@ int raft_barrier(struct raft *r, struct raft_barrier *req, raft_barrier_cb cb)
9190
req->index = index;
9291
req->cb = cb;
9392

94-
rv = logAppend(r->log, r->current_term, RAFT_BARRIER, buf, (struct raft_entry_local_data){}, true, NULL);
93+
rv = logAppend(r->log, r->current_term, RAFT_BARRIER, buf, true, NULL);
9594
if (rv != 0) {
9695
goto err_after_buf_alloc;
9796
}

src/raft/fixture.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ static void copyLeaderLog(struct raft_fixture *f)
13171317
assert(buf.base != NULL);
13181318
memcpy(buf.base, entry->buf.base, buf.len);
13191319
/* FIXME(cole) what to do here for is_local? */
1320-
rv = logAppend(f->log, entry->term, entry->type, buf, (struct raft_entry_local_data){}, false, NULL);
1320+
rv = logAppend(f->log, entry->term, entry->type, buf, false, NULL);
13211321
assert(rv == 0);
13221322
}
13231323
logRelease(raft->log, 1, entries, n);

src/raft/log.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ int logAppend(struct raft_log *l,
546546
const raft_term term,
547547
const unsigned short type,
548548
struct raft_buffer buf,
549-
struct raft_entry_local_data local_data,
550549
bool is_local,
551550
void *batch)
552551
{
@@ -576,7 +575,6 @@ int logAppend(struct raft_log *l,
576575
entry->type = type;
577576
entry->buf = buf;
578577
entry->batch = batch;
579-
entry->local_data = local_data;
580578
entry->is_local = is_local;
581579

582580
l->back += 1;
@@ -588,7 +586,6 @@ int logAppend(struct raft_log *l,
588586
int logAppendCommands(struct raft_log *l,
589587
const raft_term term,
590588
const struct raft_buffer bufs[],
591-
const struct raft_entry_local_data local_data[],
592589
const unsigned n)
593590
{
594591
unsigned i;
@@ -600,8 +597,7 @@ int logAppendCommands(struct raft_log *l,
600597
assert(n > 0);
601598

602599
for (i = 0; i < n; i++) {
603-
struct raft_entry_local_data loc = (local_data != NULL) ? local_data[i] : (struct raft_entry_local_data){};
604-
rv = logAppend(l, term, RAFT_COMMAND, bufs[i], loc, true, NULL);
600+
rv = logAppend(l, term, RAFT_COMMAND, bufs[i], true, NULL);
605601
if (rv != 0) {
606602
return rv;
607603
}
@@ -628,7 +624,7 @@ int logAppendConfiguration(struct raft_log *l,
628624
}
629625

630626
/* Append the new entry to the log. */
631-
rv = logAppend(l, term, RAFT_CHANGE, buf, (struct raft_entry_local_data){}, true, NULL);
627+
rv = logAppend(l, term, RAFT_CHANGE, buf, true, NULL);
632628
if (rv != 0) {
633629
goto err_after_encode;
634630
}

src/raft/log.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ int logAppend(struct raft_log *l,
114114
raft_term term,
115115
unsigned short type,
116116
struct raft_buffer buf,
117-
struct raft_entry_local_data local_data,
118117
bool is_local,
119118
void *batch);
120119

121120
/* Convenience to append a series of #RAFT_COMMAND entries. */
122121
int logAppendCommands(struct raft_log *l,
123122
const raft_term term,
124123
const struct raft_buffer bufs[],
125-
const struct raft_entry_local_data local_data[],
126124
const unsigned n);
127125

128126
/* Convenience to encode and append a single #RAFT_CHANGE entry. */

src/raft/replication.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ int replicationAppend(struct raft *r,
12351235
goto err_after_request_alloc;
12361236
}
12371237

1238-
rv = logAppend(r->log, copy.term, copy.type, copy.buf, (struct raft_entry_local_data){}, false, NULL);
1238+
rv = logAppend(r->log, copy.term, copy.type, copy.buf, false, NULL);
12391239
if (rv != 0) {
12401240
goto err_after_request_alloc;
12411241
}

src/raft/start.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int restoreEntries(struct raft *r,
7272
for (i = 0; i < n; i++) {
7373
struct raft_entry *entry = &entries[i];
7474
rv = logAppend(r->log, entry->term, entry->type, entry->buf,
75-
entry->local_data, entry->is_local, entry->batch);
75+
entry->is_local, entry->batch);
7676
if (rv != 0) {
7777
goto err;
7878
}

src/raft/uv_append.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static size_t uvAppendSize(struct uvAppend *a)
597597
{
598598
size_t size = sizeof(uint32_t) * 2; /* CRC checksums */
599599
unsigned i;
600-
size += uvSizeofBatchHeader(a->n, true); /* Batch header */
600+
size += uvSizeofBatchHeader(a->n); /* Batch header */
601601
for (i = 0; i < a->n; i++) { /* Entries data */
602602
size += bytePad64(a->entries[i].buf.len);
603603
}

src/raft/uv_encoding.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ static size_t sizeofTimeoutNow(void)
8686
sizeof(uint64_t) /* Last log term. */;
8787
}
8888

89-
size_t uvSizeofBatchHeader(size_t n, bool with_local_data)
89+
size_t uvSizeofBatchHeader(size_t n)
9090
{
9191
size_t res = 8 + /* Number of entries in the batch, little endian */
9292
16 * n; /* One header per entry */;
93-
(void)with_local_data;
9493
return res;
9594
}
9695

@@ -139,7 +138,7 @@ static void encodeAppendEntries(const struct raft_append_entries *p, void *buf)
139138
bytePut64(&cursor, p->prev_log_term); /* Previous term. */
140139
bytePut64(&cursor, p->leader_commit); /* Commit index. */
141140

142-
uvEncodeBatchHeader(p->entries, p->n_entries, cursor, false /* no local data */);
141+
uvEncodeBatchHeader(p->entries, p->n_entries, cursor);
143142
}
144143

145144
static void encodeAppendEntriesResult(
@@ -297,17 +296,14 @@ int uvEncodeMessage(const struct raft_message *message,
297296

298297
void uvEncodeBatchHeader(const struct raft_entry *entries,
299298
unsigned n,
300-
void *buf,
301-
bool with_local_data)
299+
void *buf)
302300
{
303301
unsigned i;
304302
void *cursor = buf;
305303

306304
/* Number of entries in the batch, little endian */
307305
bytePut64(&cursor, n);
308306

309-
(void)with_local_data;
310-
311307
for (i = 0; i < n; i++) {
312308
const struct raft_entry *entry = &entries[i];
313309

@@ -368,8 +364,7 @@ static void decodeRequestVoteResult(const uv_buf_t *buf,
368364

369365
int uvDecodeBatchHeader(const void *batch,
370366
struct raft_entry **entries,
371-
unsigned *n,
372-
uint64_t *local_data_size)
367+
unsigned *n)
373368
{
374369
const void *cursor = batch;
375370
size_t i;
@@ -382,8 +377,6 @@ int uvDecodeBatchHeader(const void *batch,
382377
return 0;
383378
}
384379

385-
(void)local_data_size;
386-
387380
*entries = raft_malloc(*n * sizeof **entries);
388381

389382
if (*entries == NULL) {
@@ -438,7 +431,7 @@ static int decodeAppendEntries(const uv_buf_t *buf,
438431
args->prev_log_term = byteGet64(&cursor);
439432
args->leader_commit = byteGet64(&cursor);
440433

441-
rv = uvDecodeBatchHeader(cursor, &args->entries, &args->n_entries, false);
434+
rv = uvDecodeBatchHeader(cursor, &args->entries, &args->n_entries);
442435
if (rv != 0) {
443436
return rv;
444437
}
@@ -560,8 +553,7 @@ int uvDecodeMessage(uint16_t type,
560553
int uvDecodeEntriesBatch(uint8_t *batch,
561554
size_t offset,
562555
struct raft_entry *entries,
563-
unsigned n,
564-
uint64_t local_data_size)
556+
unsigned n)
565557
{
566558
uint8_t *cursor;
567559

@@ -581,10 +573,6 @@ int uvDecodeEntriesBatch(uint8_t *batch,
581573
}
582574

583575
entry->is_local = false;
584-
585-
entry->local_data = (struct raft_entry_local_data){};
586-
assert(local_data_size <= sizeof(entry->local_data.buf));
587-
assert(local_data_size % 8 == 0);
588576
}
589577
return 0;
590578
}

0 commit comments

Comments
 (0)