You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A useful aspect of the dummy protocol is that it offers simple sets and gets and an unusual region type, and we don't have to worry so much about the data storage implementation being correct or incorrect.
A useful aspect of the memcache protocol is that we have some stress client or serial_mix tests that use this protocol.
Another useful aspect of templatization is that it helps enforce separation of concerns pretty harshly.
I think all but the last useful aspect are now no longer present. The rdb_protocol is quite stable when it comes to dumb gets and sets, which is what the dummy and memcache protocols get us. The dummy protocol's unusual region type failed to catch recent bugs in region logic (where sharding created empty write operations). We now have a python stress client for the rdb protocol, or will soon. Separation of concerns can be enforced by code review.
The advantage of removing these protocols is that you can make changes to the "protocol API" without having to update three different things. We can get rid of the memcache port that's baked in. There may be less obstacles to the question of how automatic consistent hashing based sharding should be mapped to memcache or dummy protocol region types. Optimization to types like region_map_t or other generic types' performance becomes more feasible.
I would be in favor of removing this templatization; as someone less familiar with this code, it makes it much harder to see at a glance what's actually going on.
I don't work with the code (so take my opinion with a grain of salt), but from a 10k foot view, I'd also like the templatization and dummy/memcached protocols removed. IMO complexity is death because linear increases in complexity cause nonlinear increases in development time. So, I think any complexity increase needs to have really good justification. In this specific case, it seems to me that the justification for increased complexity doesn't outweigh the development burden.
@coffeemug The templatization here does not create complexity. It merely describes existing complexity. Removing two protocols doesn't make anything substantively simpler.
So I'm not quite sure I agree that the dummy protocol's failure to catch the empty write problem is an indication that its different sharding structure isn't useful. Did we even have batched writes implemented in the dummy protocol?
@coffeemug could you describe to cognitive burden you're talking about then? Sam's argument seems to be that this cognitive burden is exclusively things that you need to understand anyways. Which parts of the cognitive burden are only present because of templatization?
Here's an example of how complicated code is with protocol_t templatization:
template <classprotocol_t>
listener_t<protocol_t>::listener_t(constbase_path_t &base_path,
io_backender_t *io_backender,
mailbox_manager_t *mm,
clone_ptr_t<watchable_t<boost::optional<boost::optional<broadcaster_business_card_t<protocol_t> > > > > broadcaster_metadata,
branch_history_manager_t<protocol_t> *branch_history_manager,
store_view_t<protocol_t> *svs,
clone_ptr_t<watchable_t<boost::optional<boost::optional<replier_business_card_t<protocol_t> > > > > replier,
backfill_session_id_t backfill_session_id,
perfmon_collection_t *backfill_stats_parent,
signal_t *interruptor,
order_source_t *order_source)
THROWS_ONLY(interrupted_exc_t, backfiller_lost_exc_t, broadcaster_lost_exc_t) :
mailbox_manager_(mm),
svs_(svs),
uuid_(generate_uuid()),
perfmon_collection_(),
perfmon_collection_membership_(backfill_stats_parent, &perfmon_collection_, "backfill-serialization-" + uuid_to_str(uuid_)),
/* TODO: Put the file in the data directory, not here */
write_queue_(io_backender,
serializer_filepath_t(base_path, "backfill-serialization-" + uuid_to_str(uuid_)),
&perfmon_collection_),
write_queue_semaphore_(SEMAPHORE_NO_LIMIT,
WRITE_QUEUE_SEMAPHORE_TRICKLE_FRACTION),
enforce_max_outstanding_writes_from_broadcaster_(MAX_OUTSTANDING_WRITES_FROM_BROADCASTER),
write_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_write, this, _1, _2, _3, _4, _5),
mailbox_callback_mode_inline),
writeread_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_writeread, this, _1, _2, _3, _4, _5, _6),
mailbox_callback_mode_inline),
read_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_read, this, _1, _2, _3, _4, _5),
mailbox_callback_mode_inline)
{
boost::optional<boost::optional<broadcaster_business_card_t<protocol_t> > > business_card =
broadcaster_metadata->get();
if (!business_card || !business_card.get()) {
throwbroadcaster_lost_exc_t();
}
branch_id_ = business_card.get().get().branch_id;
branch_birth_certificate_t<protocol_t> this_branch_history;
{
cross_thread_signal_tct_interruptor(interruptor, branch_history_manager->home_thread());
on_thread_tth(branch_history_manager->home_thread());
branch_history_manager->import_branch_history(business_card.get().get().branch_id_associated_branch_history, interruptor);
this_branch_history = branch_history_manager->get_branch(branch_id_);
}
our_branch_region_ = this_branch_history.region;
#ifndef NDEBUG
/* Sanity-check to make sure we're on the same timeline as the thing we're trying to join. The backfiller will perform an equivalent check, but if there's an error it would be nice to catch it where the action was initiated. */rassert(region_is_superset(our_branch_region_, svs_->get_region()));
object_buffer_t<fifo_enforcer_sink_t::exit_read_t> read_token;
svs_->new_read_token(&read_token);
region_map_t<protocol_t, binary_blob_t> start_point_blob;
svs_->do_get_metainfo(order_source->check_in("listener_t(A)").with_read_mode(), &read_token, interruptor, &start_point_blob);
region_map_t<protocol_t, version_range_t> start_point = to_version_range_map(start_point_blob);
{
on_thread_tth(branch_history_manager->home_thread());
for (typenameregion_map_t<protocol_t, version_range_t>::const_iterator it = start_point.begin();
it != start_point.end();
++it) {
version_t version = it->second.latest;
rassert(version.branch == branch_id_ ||
version_is_ancestor(branch_history_manager,
version,
version_t(branch_id_, this_branch_history.initial_timestamp),
it->first));
}
}
#endif/* Attempt to register for reads and writes */try_start_receiving_writes(broadcaster_metadata, interruptor);
listener_intro_t<protocol_t> listener_intro;
bool registration_is_done = registration_done_cond_.try_get_value(&listener_intro);
guarantee(registration_is_done);
state_timestamp_t streaming_begin_point = listener_intro.broadcaster_begin_timestamp;
try {
/* Go through a little song and dance to make sure that the * backfiller will at least get us to the point that we will being * live streaming from. */cond_t backfiller_is_up_to_date;
mailbox_t<void()> ack_mbox(
mailbox_manager_,
boost::bind(&cond_t::pulse, &backfiller_is_up_to_date),
mailbox_callback_mode_inline);
resource_access_t<replier_business_card_t<protocol_t> > replier_access(replier);
send(mailbox_manager_, replier_access.access().synchronize_mailbox, streaming_begin_point, ack_mbox.get_address());
wait_any_tinterruptor2(interruptor, replier_access.get_failed_signal());
wait_interruptible(&backfiller_is_up_to_date, &interruptor2);
/* Backfill */
backfillee<protocol_t>(mailbox_manager_,
branch_history_manager,
svs_,
svs_->get_region(),
replier->subview(&listener_t<protocol_t>::get_backfiller_from_replier_bcard),
backfill_session_id,
interruptor);
} catch (constresource_lost_exc_t &) {
throwbackfiller_lost_exc_t();
}
object_buffer_t<fifo_enforcer_sink_t::exit_read_t> read_token2;
svs_->new_read_token(&read_token2);
region_map_t<protocol_t, binary_blob_t> backfill_end_point_blob;
svs_->do_get_metainfo(order_source->check_in("listener_t(B)").with_read_mode(), &read_token2, interruptor, &backfill_end_point_blob);
region_map_t<protocol_t, version_range_t> backfill_end_point = to_version_range_map(backfill_end_point_blob);
/* Sanity checking. *//* Make sure the region is not empty. */guarantee(backfill_end_point.begin() != backfill_end_point.end());
/* The end timestamp is the maximum of the timestamps we've seen. If you've been following closely (which you probably haven't because this is confusing) you should be thinking "How is that correct? If the region map says that we're at timestamp 900 on region A and 901 on region B, then that means we're missing the updates for the write with timestamp 900->901 on region A. If the region map has different timestamps for different regions, then it's not possible to boil down the current timestamp to a single number, right?" But this is wrong. Our backfill was, in fact, serialized with respect to all the writes. In fact, the reason why region A has timestamp 900 is that the write with timestamp 900->901 didn't touch any keys in region A. We didn't update the timestamp for region A because regions A and B were on separate threads, and we didn't want to send the operation to region A unnecessarily if we weren't actually updating any keys there. That's why it's OK to just take the maximum of all the timestamps that we see. TODO: If we change the way we shard such that each listener_t maps to a single B-tree on the same machine, then replace this loop with a strict assertion that requires everything to be at the same timestamp. */state_timestamp_t backfill_end_timestamp = backfill_end_point.begin()->second.earliest.timestamp;
for (typenameregion_map_t<protocol_t, version_range_t>::const_iterator it = backfill_end_point.begin();
it != backfill_end_point.end();
++it) {
guarantee(it->second.is_coherent());
guarantee(it->second.earliest.branch == branch_id_);
backfill_end_timestamp = std::max(backfill_end_timestamp, it->second.earliest.timestamp);
}
guarantee(backfill_end_timestamp >= streaming_begin_point);
current_timestamp_ = backfill_end_timestamp;
write_queue_coro_pool_callback_.init(newboost_function_callback_t<write_queue_entry_t>(
boost::bind(&listener_t<protocol_t>::perform_enqueued_write, this, _1, backfill_end_timestamp, _2)));
write_queue_coro_pool_.init(newcoro_pool_t<write_queue_entry_t>(
WRITE_QUEUE_CORO_POOL_SIZE, &write_queue_, write_queue_coro_pool_callback_.get()));
write_queue_semaphore_.set_capacity(WRITE_QUEUE_SEMAPHORE_LONG_TERM_CAPACITY);
if (write_queue_.size() <= WRITE_QUEUE_SEMAPHORE_LONG_TERM_CAPACITY) {
write_queue_has_drained_.pulse_if_not_already_pulsed();
}
wait_interruptible(&write_queue_has_drained_, interruptor);
}
Here's the "simplified" code that isn't templated:
listener_t::listener_t(constbase_path_t &base_path,
io_backender_t *io_backender,
mailbox_manager_t *mm,
clone_ptr_t<watchable_t<boost::optional<boost::optional<broadcaster_business_card_t > > > > broadcaster_metadata,
branch_history_manager_t *branch_history_manager,
store_view_t *svs,
clone_ptr_t<watchable_t<boost::optional<boost::optional<replier_business_card_t> > > > replier,
backfill_session_id_t backfill_session_id,
perfmon_collection_t *backfill_stats_parent,
signal_t *interruptor,
order_source_t *order_source)
THROWS_ONLY(interrupted_exc_t, backfiller_lost_exc_t, broadcaster_lost_exc_t) :
mailbox_manager_(mm),
svs_(svs),
uuid_(generate_uuid()),
perfmon_collection_(),
perfmon_collection_membership_(backfill_stats_parent, &perfmon_collection_, "backfill-serialization-" + uuid_to_str(uuid_)),
/* TODO: Put the file in the data directory, not here */
write_queue_(io_backender,
serializer_filepath_t(base_path, "backfill-serialization-" + uuid_to_str(uuid_)),
&perfmon_collection_),
write_queue_semaphore_(SEMAPHORE_NO_LIMIT,
WRITE_QUEUE_SEMAPHORE_TRICKLE_FRACTION),
enforce_max_outstanding_writes_from_broadcaster_(MAX_OUTSTANDING_WRITES_FROM_BROADCASTER),
write_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_write, this, _1, _2, _3, _4, _5),
mailbox_callback_mode_inline),
writeread_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_writeread, this, _1, _2, _3, _4, _5, _6),
mailbox_callback_mode_inline),
read_mailbox_(mailbox_manager_,
boost::bind(&listener_t::on_read, this, _1, _2, _3, _4, _5),
mailbox_callback_mode_inline)
{
boost::optional<boost::optional<broadcaster_business_card_t> > business_card =
broadcaster_metadata->get();
if (!business_card || !business_card.get()) {
throwbroadcaster_lost_exc_t();
}
branch_id_ = business_card.get().get().branch_id;
branch_birth_certificate_t this_branch_history;
{
cross_thread_signal_tct_interruptor(interruptor, branch_history_manager->home_thread());
on_thread_tth(branch_history_manager->home_thread());
branch_history_manager->import_branch_history(business_card.get().get().branch_id_associated_branch_history, interruptor);
this_branch_history = branch_history_manager->get_branch(branch_id_);
}
our_branch_region_ = this_branch_history.region;
#ifndef NDEBUG
/* Sanity-check to make sure we're on the same timeline as the thing we're trying to join. The backfiller will perform an equivalent check, but if there's an error it would be nice to catch it where the action was initiated. */rassert(region_is_superset(our_branch_region_, svs_->get_region()));
object_buffer_t<fifo_enforcer_sink_t::exit_read_t> read_token;
svs_->new_read_token(&read_token);
region_map_t<binary_blob_t> start_point_blob;
svs_->do_get_metainfo(order_source->check_in("listener_t(A)").with_read_mode(), &read_token, interruptor, &start_point_blob);
region_map_t<version_range_t> start_point = to_version_range_map(start_point_blob);
{
on_thread_tth(branch_history_manager->home_thread());
for (typenameregion_map_t<version_range_t>::const_iterator it = start_point.begin();
it != start_point.end();
++it) {
version_t version = it->second.latest;
rassert(version.branch == branch_id_ ||
version_is_ancestor(branch_history_manager,
version,
version_t(branch_id_, this_branch_history.initial_timestamp),
it->first));
}
}
#endif/* Attempt to register for reads and writes */try_start_receiving_writes(broadcaster_metadata, interruptor);
listener_intro_t listener_intro;
bool registration_is_done = registration_done_cond_.try_get_value(&listener_intro);
guarantee(registration_is_done);
state_timestamp_t streaming_begin_point = listener_intro.broadcaster_begin_timestamp;
try {
/* Go through a little song and dance to make sure that the * backfiller will at least get us to the point that we will being * live streaming from. */cond_t backfiller_is_up_to_date;
mailbox_t<void()> ack_mbox(
mailbox_manager_,
boost::bind(&cond_t::pulse, &backfiller_is_up_to_date),
mailbox_callback_mode_inline);
resource_access_t<replier_business_card_t> replier_access(replier);
send(mailbox_manager_, replier_access.access().synchronize_mailbox, streaming_begin_point, ack_mbox.get_address());
wait_any_tinterruptor2(interruptor, replier_access.get_failed_signal());
wait_interruptible(&backfiller_is_up_to_date, &interruptor2);
/* Backfill */backfillee(mailbox_manager_,
branch_history_manager,
svs_,
svs_->get_region(),
replier->subview(&listener_t::get_backfiller_from_replier_bcard),
backfill_session_id,
interruptor);
} catch (constresource_lost_exc_t &) {
throwbackfiller_lost_exc_t();
}
object_buffer_t<fifo_enforcer_sink_t::exit_read_t> read_token2;
svs_->new_read_token(&read_token2);
region_map_t<binary_blob_t> backfill_end_point_blob;
svs_->do_get_metainfo(order_source->check_in("listener_t(B)").with_read_mode(), &read_token2, interruptor, &backfill_end_point_blob);
region_map_t<version_range_t> backfill_end_point = to_version_range_map(backfill_end_point_blob);
/* Sanity checking. *//* Make sure the region is not empty. */guarantee(backfill_end_point.begin() != backfill_end_point.end());
/* The end timestamp is the maximum of the timestamps we've seen. If you've been following closely (which you probably haven't because this is confusing) you should be thinking "How is that correct? If the region map says that we're at timestamp 900 on region A and 901 on region B, then that means we're missing the updates for the write with timestamp 900->901 on region A. If the region map has different timestamps for different regions, then it's not possible to boil down the current timestamp to a single number, right?" But this is wrong. Our backfill was, in fact, serialized with respect to all the writes. In fact, the reason why region A has timestamp 900 is that the write with timestamp 900->901 didn't touch any keys in region A. We didn't update the timestamp for region A because regions A and B were on separate threads, and we didn't want to send the operation to region A unnecessarily if we weren't actually updating any keys there. That's why it's OK to just take the maximum of all the timestamps that we see. TODO: If we change the way we shard such that each listener_t maps to a single B-tree on the same machine, then replace this loop with a strict assertion that requires everything to be at the same timestamp. */state_timestamp_t backfill_end_timestamp = backfill_end_point.begin()->second.earliest.timestamp;
for (typenameregion_map_t<version_range_t>::const_iterator it = backfill_end_point.begin();
it != backfill_end_point.end();
++it) {
guarantee(it->second.is_coherent());
guarantee(it->second.earliest.branch == branch_id_);
backfill_end_timestamp = std::max(backfill_end_timestamp, it->second.earliest.timestamp);
}
guarantee(backfill_end_timestamp >= streaming_begin_point);
current_timestamp_ = backfill_end_timestamp;
write_queue_coro_pool_callback_.init(newboost_function_callback_t<write_queue_entry_t>(
boost::bind(&listener_t::perform_enqueued_write, this, _1, backfill_end_timestamp, _2)));
write_queue_coro_pool_.init(newcoro_pool_t<write_queue_entry_t>(
WRITE_QUEUE_CORO_POOL_SIZE, &write_queue_, write_queue_coro_pool_callback_.get()));
write_queue_semaphore_.set_capacity(WRITE_QUEUE_SEMAPHORE_LONG_TERM_CAPACITY);
if (write_queue_.size() <= WRITE_QUEUE_SEMAPHORE_LONG_TERM_CAPACITY) {
write_queue_has_drained_.pulse_if_not_already_pulsed();
}
wait_interruptible(&write_queue_has_drained_, interruptor);
}
Removing protocol_t doesn't make the clustering layer substantially simpler.
I don't think it's productive to take an emotional reaction to a stylistic matter and make sophisticated technical arguments to justify this reaction. All of us are smart enough to argue this either way, if we wanted to. The bottom line here is that we have a lot code that most people don't like for their own reasons, and we have a clear path to remove it.
Of all the examples to come up with, this is one of the most benign possible.
It may me benign, but Mike's point is that it's unnecessary code that makes everything harder for humans to read for dubious benefit.
This change will be divided into different phases with different code reviews (certain individual changes won't be merged to next until others are done -- removing memcache from the server won't be merged until removing the memcache integration tests is done).
Removing memcache from the server (next -> sam_803) (review 1372) merged to next
Removing the dummy protocol (sam_803 -> sam_803_dummy) (review 1391) merged to next
Removing protocol_t templatization from the server (sam_803_dummy -> sam_803_detemplatize) (review 1397) merged to next
Removing the unnecessary "port" field and flags (sam_803_detemplatize -> sam_803_flags) (review 1399) merged to next
Removing other unnecessary fields and flags (like "protocol") wherever they might be found (sam_803_flags -> sam_803_moreflags) (review 1400) merged to next
Some general cleanup (sam_803_moreflags -> sam_803_deinline) (review 1402) merged to next
Combine store_t and btree_store_t back together (sam_803_deinline -> sam_803_store) (review 1405) merged to next
check_style.sh fixes (sam_803_store -> sam_803_style) (some review) merged to next
Remove or fix RSI comments that have made it to next (next -> sam_803_rsi) (review 1412) merged to next
Some build times (after a git clean -fxd and ./configure CXX=clang++ --enable-drivers, running make -j9 DEBUG=1 on a T520):
v1.12.x: 4m14s
sam_803 (memcache removal): 3m23s
sam_803_dummy (dummy protocol removal): 3m1s
sam_803_detemplatize (remove <protocol_t> templatization): 3m8s
sam_803_deinline (move some stuff from headers): 2m57s (the last two differences are just noise)
Activity
mlucy commentedon May 14, 2013
I would be in favor of removing this templatization; as someone less familiar with this code, it makes it much harder to see at a glance what's actually going on.
srh commentedon May 14, 2013
How does it do that?
coffeemug commentedon May 14, 2013
I don't work with the code (so take my opinion with a grain of salt), but from a 10k foot view, I'd also like the templatization and dummy/memcached protocols removed. IMO complexity is death because linear increases in complexity cause nonlinear increases in development time. So, I think any complexity increase needs to have really good justification. In this specific case, it seems to me that the justification for increased complexity doesn't outweigh the development burden.
Tryneus commentedon May 14, 2013
Right, let's do this! Death to dead code!
srh commentedon May 14, 2013
@coffeemug The templatization here does not create complexity. It merely describes existing complexity. Removing two protocols doesn't make anything substantively simpler.
jdoliner commentedon May 14, 2013
So I'm not quite sure I agree that the dummy protocol's failure to catch the empty write problem is an indication that its different sharding structure isn't useful. Did we even have batched writes implemented in the dummy protocol?
coffeemug commentedon May 14, 2013
I disagree, I think there is a significant cognitive burden for people trying to understand the code (which is the complexity I'm talking about).
srh commentedon May 14, 2013
We didn't, but even if we did, it wouldn't have caught the problem anyway (since the dummy protocol's regions allow holes).
I don't think its failure in that circumstance means it's not useful either, but I'm not sure how it's particularly useful.
jdoliner commentedon May 14, 2013
@coffeemug could you describe to cognitive burden you're talking about then? Sam's argument seems to be that this cognitive burden is exclusively things that you need to understand anyways. Which parts of the cognitive burden are only present because of templatization?
mlucy commentedon May 14, 2013
A handful of things, off the top of my head:
protocol_t::point_replace_response_trather thanDatum.srh commentedon May 14, 2013
That has nothing to do with this issue at all.
Fix "tags" then.
Of all the examples to come up with, this is one of the most benign possible.
mlucy commentedon May 14, 2013
How would you "fix" tags to be able to figure out which class we use as the template parameter 99% of the time and jump to that?
srh commentedon May 14, 2013
Maybe
s/typename protocol_t::/rdb_protocol_t::/gbefore feeding tags? I don't know.srh commentedon May 14, 2013
Here's an example of how complicated code is with protocol_t templatization:
Here's the "simplified" code that isn't templated:
Removing protocol_t doesn't make the clustering layer substantially simpler.
coffeemug commentedon May 14, 2013
I don't think it's productive to take an emotional reaction to a stylistic matter and make sophisticated technical arguments to justify this reaction. All of us are smart enough to argue this either way, if we wanted to. The bottom line here is that we have a lot code that most people don't like for their own reasons, and we have a clear path to remove it.
It may me benign, but Mike's point is that it's unnecessary code that makes everything harder for humans to read for dubious benefit.
9 remaining items
srh commentedon Mar 25, 2014
Assigning to myself, la la la.
srh commentedon Mar 26, 2014
This change will be divided into different phases with different code reviews (certain individual changes won't be merged to next until others are done -- removing memcache from the server won't be merged until removing the memcache integration tests is done).
srh commentedon Apr 3, 2014
Some build times (after a
git clean -fxdand./configure CXX=clang++ --enable-drivers, runningmake -j9 DEBUG=1on a T520):v1.12.x: 4m14s
sam_803 (memcache removal): 3m23s
sam_803_dummy (dummy protocol removal): 3m1s
sam_803_detemplatize (remove <protocol_t> templatization): 3m8s
sam_803_deinline (move some stuff from headers): 2m57s (the last two differences are just noise)
danielmewes commentedon Apr 3, 2014
We should templatize more of our code.
mlucy commentedon Apr 4, 2014
I think we'd get faster gains if we just removed a few more dummy protocols.
danielmewes commentedon Apr 4, 2014
@mlucy I worry that we might exhaust our natural supply of dummy protocols too quickly if we keep on removing them.
Also sorry for the off-topic. 25% faster builds are really cool! @srh
srh commentedon Apr 9, 2014
The current list of TODO items is:
Reassigning to @AtnNn.