diff --git a/src/box/box.cc b/src/box/box.cc index a3348fef5202d5f0cc481b9427f435268408e751..dbcb7e8dace31e9084a6d81c875124ca10a5bb60 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1569,6 +1569,7 @@ box_process_vote(struct ballot *ballot) { ballot->is_ro = cfg_geti("read_only") != 0; vclock_copy(&ballot->vclock, &replicaset.vclock); + gc_vclock(&ballot->gc_vclock); } /** Insert a new cluster into _schema */ diff --git a/src/box/gc.c b/src/box/gc.c index 9eccf5d30136024b7b4b752870ccce3602db915a..84897dabb6c578d46fdd9c967c0a55c6dfb7daa8 100644 --- a/src/box/gc.c +++ b/src/box/gc.c @@ -164,6 +164,12 @@ gc_free(void) latch_destroy(&gc.latch); } +void +gc_vclock(struct vclock *vclock) +{ + vclock_copy(vclock, &gc.wal_vclock); +} + /** Find the consumer that uses the oldest checkpoint. */ struct gc_consumer * gc_tree_first_checkpoint(gc_tree_t *consumers) diff --git a/src/box/gc.h b/src/box/gc.h index 1bc8aedf2bcab09f2d558a87176d48cd0dc4635b..36a951bf1e307dc947a9017a742be67115643505 100644 --- a/src/box/gc.h +++ b/src/box/gc.h @@ -60,6 +60,12 @@ gc_init(void); void gc_free(void); +/** + * Get the oldest available vclock. + */ +void +gc_vclock(struct vclock *vclock); + /** * Invoke garbage collection in order to remove files left * from old checkpoints. The number of checkpoints saved by diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index d3d20f02b66c961eb78ddc355ecc0b7d24056e09..f282a0b2b1f1821a55ad61d30a5314258e3968dc 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -87,6 +87,7 @@ enum iproto_key { enum iproto_ballot_key { IPROTO_BALLOT_IS_RO = 0x01, IPROTO_BALLOT_VCLOCK = 0x02, + IPROTO_BALLOT_GC_VCLOCK = 0x03, }; #define bit(c) (1ULL<<IPROTO_##c) diff --git a/src/box/xrow.c b/src/box/xrow.c index 2a73372d1b956774354e51047e7c1e35d89982db..269a6e68020718c8fa4198671a45d0f2c64b4a98 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -344,9 +344,10 @@ iproto_reply_vote(struct obuf *out, const struct ballot *ballot, uint64_t sync, uint32_t schema_version) { size_t max_size = IPROTO_HEADER_LEN + mp_sizeof_map(1) + - mp_sizeof_uint(UINT32_MAX) + mp_sizeof_map(2) + + mp_sizeof_uint(UINT32_MAX) + mp_sizeof_map(3) + mp_sizeof_uint(UINT32_MAX) + mp_sizeof_bool(ballot->is_ro) + - mp_sizeof_uint(UINT32_MAX) + mp_sizeof_vclock(&ballot->vclock); + mp_sizeof_uint(UINT32_MAX) + mp_sizeof_vclock(&ballot->vclock) + + mp_sizeof_uint(UINT32_MAX) + mp_sizeof_vclock(&ballot->gc_vclock); char *buf = obuf_reserve(out, max_size); if (buf == NULL) { @@ -358,11 +359,13 @@ iproto_reply_vote(struct obuf *out, const struct ballot *ballot, char *data = buf + IPROTO_HEADER_LEN; data = mp_encode_map(data, 1); data = mp_encode_uint(data, IPROTO_BALLOT); - data = mp_encode_map(data, 2); + data = mp_encode_map(data, 3); data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO); data = mp_encode_bool(data, ballot->is_ro); data = mp_encode_uint(data, IPROTO_BALLOT_VCLOCK); data = mp_encode_vclock(data, &ballot->vclock); + data = mp_encode_uint(data, IPROTO_BALLOT_GC_VCLOCK); + data = mp_encode_vclock(data, &ballot->gc_vclock); size_t size = data - buf; assert(size <= max_size); @@ -933,6 +936,10 @@ xrow_decode_ballot(struct xrow_header *row, struct ballot *ballot) if (mp_decode_vclock(&data, &ballot->vclock) != 0) goto err; break; + case IPROTO_BALLOT_GC_VCLOCK: + if (mp_decode_vclock(&data, &ballot->gc_vclock) != 0) + goto err; + break; default: mp_next(&data); } diff --git a/src/box/xrow.h b/src/box/xrow.h index be2774bb19e4e2ef8d118fc56526416609536a82..9887382c7ba1be3097ca1dfa912f591c3e8a8e58 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -229,6 +229,8 @@ struct ballot { bool is_ro; /** Current instance vclock. */ struct vclock vclock; + /** Oldest vclock available on the instance. */ + struct vclock gc_vclock; }; /**