Skip to content

Commit 4dc0c1e

Browse files
committed
relay: move gc subscriber creation out of it
GC consumer creation and destroy seemed to only happen in box.cc with one exception in relay_subscribe(). Lets move it out for consistency. Now relay can only notify GC consumers, but can't manage them. That also makes it harder to misuse the GC by passing some wrong vclock to it, similar to what was happening in tarantool#10047. In scope of tarantool#10047 NO_TEST=refactoring NO_CHANGELOG=refactoring NO_DOC=refactoring
1 parent b846396 commit 4dc0c1e

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/box/box.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4713,6 +4713,26 @@ box_process_subscribe(struct iostream *io, const struct xrow_header *header)
47134713
}
47144714
struct vclock start_vclock;
47154715
box_localize_vclock(&req.vclock, &start_vclock);
4716+
/*
4717+
* Register the replica with the garbage collector.
4718+
* In case some of the replica's WAL files were deleted, it might
4719+
* subscribe with a smaller vclock than the master remembers, so
4720+
* recreate the gc consumer unconditionally to make sure it holds
4721+
* the correct vclock.
4722+
*/
4723+
if (!replica->anon) {
4724+
bool had_gc = false;
4725+
if (replica->gc != NULL) {
4726+
gc_consumer_unregister(replica->gc);
4727+
had_gc = true;
4728+
}
4729+
replica->gc = gc_consumer_register(&start_vclock, "replica %s",
4730+
tt_uuid_str(&replica->uuid));
4731+
if (replica->gc == NULL)
4732+
diag_raise();
4733+
if (!had_gc)
4734+
gc_delay_unref();
4735+
}
47164736
/*
47174737
* Send a response to SUBSCRIBE request, tell
47184738
* the replica how many rows we have in stock for it,

src/box/relay.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,27 +1098,6 @@ relay_subscribe(struct replica *replica, struct iostream *io, uint64_t sync,
10981098
assert(replica->anon || replica->id != REPLICA_ID_NIL);
10991099
struct relay *relay = replica->relay;
11001100
assert(relay->state != RELAY_FOLLOW);
1101-
/*
1102-
* Register the replica with the garbage collector.
1103-
* In case some of the replica's WAL files were deleted, it might
1104-
* subscribe with a smaller vclock than the master remembers, so
1105-
* recreate the gc consumer unconditionally to make sure it holds
1106-
* the correct vclock.
1107-
*/
1108-
if (!replica->anon) {
1109-
bool had_gc = false;
1110-
if (replica->gc != NULL) {
1111-
gc_consumer_unregister(replica->gc);
1112-
had_gc = true;
1113-
}
1114-
replica->gc = gc_consumer_register(replica_clock, "replica %s",
1115-
tt_uuid_str(&replica->uuid));
1116-
if (replica->gc == NULL)
1117-
diag_raise();
1118-
if (!had_gc)
1119-
gc_delay_unref();
1120-
}
1121-
11221101
if (replica_version_id < version_id(2, 6, 0) || replica->anon)
11231102
sent_raft_term = UINT64_MAX;
11241103
relay_start(relay, io, sync, relay_process_row,

0 commit comments

Comments
 (0)