From dd0e77000862b067bd4455135dc4f5060a924ed0 Mon Sep 17 00:00:00 2001 From: Dave Peterson Date: Sat, 20 Jun 2020 22:56:20 -0700 Subject: [PATCH] code cleanup: remove all instances of assert(this); --- doc/status_monitoring.md | 1 - src/base/backoff_rate_limiter.cc | 3 - src/base/backoff_rate_limiter.h | 1 - src/base/blocking_asset.h | 5 -- src/base/buf.h | 22 ----- src/base/code_location.cc | 2 - src/base/code_location.h | 1 - src/base/convert.h | 18 ---- src/base/counter.h | 5 -- src/base/demangle.cc | 2 - src/base/dir_iter.cc | 4 - src/base/dir_iter.h | 6 -- src/base/dynamic_lib.h | 3 - src/base/error.cc | 4 - src/base/error.h | 2 - src/base/error_util.h | 5 -- src/base/event_semaphore.cc | 4 - src/base/event_semaphore.h | 1 - src/base/exclusive_lock.h | 2 - src/base/fd.cc | 2 - src/base/fd.h | 10 --- src/base/file_reader.cc | 9 -- src/base/file_reader.h | 2 - src/base/hex_dump_writer.cc | 2 - src/base/hex_dump_writer.h | 21 ----- src/base/indent.h | 5 -- src/base/on_destroy.h | 1 - src/base/opt.h | 34 -------- src/base/opt.test.cc | 7 -- src/base/os_error.h | 1 - src/base/piece.h | 65 -------------- src/base/pos.h | 5 -- src/base/random_exp_backoff.cc | 1 - src/base/random_exp_backoff.h | 6 -- src/base/safe_global.h | 8 -- src/base/shared_lock.h | 2 - src/base/sig_handler_installer.h | 2 - src/base/sig_masker.h | 2 - src/base/sig_set.h | 9 -- src/base/slice.h | 9 -- src/base/spin_lock.h | 2 - src/base/stream_msg_reader.cc | 12 --- src/base/stream_msg_reader.h | 8 -- src/base/stream_msg_reader.test.cc | 12 --- src/base/stream_msg_with_size_reader.cc | 4 - src/base/stream_msg_with_size_reader.h | 9 -- src/base/stream_msg_with_size_reader.test.cc | 4 - src/base/thread_safe_rate_limiter.h | 1 - src/base/thrower.h | 5 -- src/base/timer_fd.cc | 1 - src/base/timer_fd.h | 1 - src/base/tmp_dir.h | 2 - src/base/tmp_file.cc | 3 - src/base/tmp_file.h | 5 -- src/base/to_integer.h | 2 - src/capped/blob.cc | 2 - src/capped/blob.h | 11 --- src/capped/pool.cc | 9 -- src/capped/pool.h | 4 - src/capped/reader.cc | 2 - src/capped/reader.h | 5 -- src/capped/writer.cc | 5 -- src/dory/anomaly_tracker.cc | 16 ---- src/dory/anomaly_tracker.h | 7 -- src/dory/anomaly_tracker.test.cc | 4 - src/dory/batch/batch_config.h | 1 - src/dory/batch/batch_config_builder.cc | 13 --- src/dory/batch/batcher_core.cc | 13 --- src/dory/batch/batcher_core.h | 6 -- src/dory/batch/combined_topics_batcher.cc | 5 -- src/dory/batch/combined_topics_batcher.h | 3 - src/dory/batch/global_batch_config.h | 5 -- src/dory/batch/per_topic_batcher.cc | 8 -- src/dory/batch/per_topic_batcher.h | 8 -- src/dory/batch/single_topic_batcher.cc | 1 - src/dory/batch/single_topic_batcher.h | 6 -- src/dory/client/client_sender_base.h | 3 - src/dory/client/tcp_sender.cc | 3 - src/dory/client/unix_dg_sender.cc | 4 - src/dory/client/unix_stream_sender.cc | 3 - src/dory/compress/compression_codec_api.cc | 1 - src/dory/compress/compression_codec_api.h | 3 - src/dory/compress/gzip/gzip_codec.cc | 7 -- src/dory/compress/lz4/lz4_codec.cc | 6 -- src/dory/compress/snappy/snappy_codec.cc | 6 -- src/dory/conf/batch_conf.cc | 10 --- src/dory/conf/batch_conf.h | 1 - src/dory/conf/compression_conf.cc | 10 --- src/dory/conf/compression_conf.h | 2 - src/dory/conf/conf.cc | 21 ----- src/dory/conf/conf.h | 1 - src/dory/conf/conf_error.h | 1 - src/dory/conf/discard_logging_conf.cc | 2 - src/dory/conf/http_interface_conf.cc | 4 - src/dory/conf/input_sources_conf.cc | 6 -- src/dory/conf/kafka_config_conf.cc | 2 - src/dory/conf/logging_conf.cc | 2 - src/dory/conf/msg_debug_conf.cc | 2 - src/dory/conf/topic_rate_conf.cc | 9 -- src/dory/conf/topic_rate_conf.h | 1 - src/dory/debug/debug_logger.cc | 6 -- src/dory/debug/debug_logger.h | 2 - src/dory/debug/debug_setup.cc | 11 --- src/dory/debug/debug_setup.h | 13 --- src/dory/discard_file_logger.cc | 36 -------- src/dory/discard_file_logger.h | 7 -- src/dory/dory.test.cc | 13 +-- src/dory/dory_server.cc | 11 --- src/dory/dory_server.h | 7 -- .../any_partition/v0/v0_input_dg_reader.cc | 1 - .../partition_key/v0/v0_input_dg_reader.cc | 1 - .../kafka_proto/metadata/v0/metadata_proto.cc | 4 - .../metadata/v0/metadata_request_reader.cc | 2 - .../metadata/v0/metadata_request_reader.h | 2 - .../metadata/v0/metadata_request_writer.cc | 5 -- .../metadata/v0/metadata_response_reader.cc | 47 ---------- .../metadata/v0/metadata_response_writer.cc | 22 ----- .../metadata/v0/metadata_response_writer.h | 3 - .../kafka_proto/produce/produce_protocol.h | 1 - .../kafka_proto/produce/v0/msg_set_reader.cc | 11 --- .../kafka_proto/produce/v0/msg_set_writer.cc | 11 --- .../kafka_proto/produce/v0/msg_set_writer.h | 10 --- .../kafka_proto/produce/v0/produce_proto.cc | 5 -- .../produce/v0/produce_request_reader.cc | 26 ------ .../produce/v0/produce_request_writer.cc | 15 ---- .../produce/v0/produce_request_writer.h | 10 --- .../produce/v0/produce_response_reader.cc | 17 ---- .../produce/v0/produce_response_writer.cc | 7 -- src/dory/metadata.cc | 34 -------- src/dory/metadata.h | 20 ----- src/dory/metadata_fetcher.cc | 7 -- src/dory/metadata_fetcher.h | 2 - src/dory/metadata_timestamp.cc | 3 - src/dory/mock_kafka_server/cmd_bucket.cc | 3 - src/dory/mock_kafka_server/cmd_handler.cc | 1 - src/dory/mock_kafka_server/cmd_worker.cc | 4 - src/dory/mock_kafka_server/connect_handler.cc | 1 - .../mock_kafka_server/connect_handler_base.cc | 5 -- src/dory/mock_kafka_server/error_injector.cc | 3 - src/dory/mock_kafka_server/error_injector.h | 8 -- src/dory/mock_kafka_server/main_thread.cc | 3 - src/dory/mock_kafka_server/main_thread.h | 7 -- .../mock_kafka_server/mock_kafka_worker.cc | 2 - src/dory/mock_kafka_server/port_map.cc | 3 - src/dory/mock_kafka_server/prod_req/msg.h | 3 - src/dory/mock_kafka_server/prod_req/msg_set.h | 7 -- .../mock_kafka_server/prod_req/prod_req.h | 7 -- .../prod_req/prod_req_builder.cc | 9 -- .../mock_kafka_server/prod_req/topic_group.h | 4 - .../received_request_tracker.h | 3 - src/dory/mock_kafka_server/server.cc | 8 -- src/dory/mock_kafka_server/server.h | 6 -- src/dory/mock_kafka_server/setup.cc | 11 --- .../single_client_handler_base.cc | 17 ---- .../single_client_handler_base.h | 1 - .../thread_terminate_handler.cc | 3 - .../mock_kafka_server/v0_client_handler.cc | 5 -- .../v0_client_handler_factory.cc | 1 - src/dory/msg.cc | 1 - src/dory/msg.h | 15 ---- .../msg_dispatch/any_partition_chooser.cc | 1 - src/dory/msg_dispatch/any_partition_chooser.h | 4 - src/dory/msg_dispatch/broker_msg_queue.cc | 14 --- src/dory/msg_dispatch/broker_msg_queue.h | 3 - src/dory/msg_dispatch/connector.cc | 19 ----- src/dory/msg_dispatch/connector.h | 9 -- .../msg_dispatch/dispatcher_shared_state.cc | 7 -- .../msg_dispatch/dispatcher_shared_state.h | 4 - src/dory/msg_dispatch/kafka_dispatcher.cc | 16 ---- .../msg_dispatch/produce_request_factory.cc | 13 --- .../msg_dispatch/produce_request_factory.h | 6 -- .../produce_response_processor.cc | 12 --- .../msg_dispatch/produce_response_processor.h | 3 - src/dory/msg_rate_limiter.cc | 3 - src/dory/msg_state_tracker.cc | 29 ------- src/dory/msg_state_tracker.h | 4 - src/dory/router_thread.cc | 57 ------------- src/dory/router_thread.h | 8 -- src/dory/stream_client_handler.cc | 2 - src/dory/stream_client_handler.test.cc | 1 - src/dory/stream_client_work_fn.cc | 6 -- src/dory/test_util/misc_util.cc | 1 - src/dory/test_util/mock_kafka_dispatcher.cc | 16 ---- src/dory/unix_dg_input_agent.cc | 6 -- src/dory/util/dory_rate_limiter.h | 2 - src/dory/util/invalid_arg_error.h | 2 - src/dory/util/pause_button.cc | 2 - src/dory/util/pause_button.h | 1 - src/dory/util/poll_array.h | 13 --- src/dory/util/topic_map.cc | 8 -- src/dory/util/topic_map.h | 2 - src/dory/web_interface.cc | 5 -- src/dory/web_interface.h | 6 -- src/dory/web_request_handler.cc | 21 ----- src/fiber/dispatcher.cc | 16 ---- src/fiber/dispatcher.h | 9 +- src/fiber/dispatcher.test.broken.cc | 85 ++++++++----------- src/log/array_ostream_base.h | 6 -- src/log/array_ostream_base.test.cc | 2 - src/log/combined_log_writer.cc | 2 - src/log/combined_log_writer.h | 5 -- src/log/file_log_writer.cc | 4 - src/log/file_log_writer.h | 5 -- src/log/log_entry.h | 9 -- src/log/log_entry.test.cc | 7 -- src/log/log_entry_access_api.h | 1 - src/log/stdout_stderr_log_writer.cc | 4 - src/log/stdout_stderr_log_writer.h | 1 - src/log/syslog_log_writer.cc | 4 - src/log/syslog_log_writer.h | 1 - src/rpc/transceiver.cc | 8 -- src/server/signal_handler_thread.cc | 6 -- src/server/signal_handler_thread.h | 2 - src/server/stream_server_base.cc | 11 --- src/server/stream_server_base.h | 2 - src/server/stream_servers.test.cc | 4 - src/server/tcp_ipv4_server.cc | 3 - src/server/tcp_ipv4_server.h | 3 - src/server/tcp_ipv6_server.cc | 3 - src/server/tcp_ipv6_server.h | 4 - src/server/unix_stream_server.cc | 4 - src/server/unix_stream_server.h | 3 - src/server/url_decode.h | 1 - src/socket/address.cc | 10 --- src/socket/address.h | 15 ---- src/socket/db/cursor.cc | 4 - src/socket/db/cursor.h | 6 -- src/socket/named_unix_socket.cc | 1 - src/socket/named_unix_socket.h | 6 -- src/socket/option.h | 5 -- src/third_party/mongoose/mongoose.h | 3 - src/thread/fd_managed_thread.cc | 14 --- src/thread/fd_managed_thread.h | 4 - src/thread/gate.h | 7 -- src/thread/managed_thread_pool.h | 9 -- src/thread/managed_thread_pool.test.cc | 11 --- src/thread/managed_thread_pool_base.cc | 33 ------- src/thread/managed_thread_pool_base.h | 19 ----- src/thread/managed_thread_pool_config.cc | 9 -- src/thread/managed_thread_pool_config.h | 9 -- src/thread/segmented_list.h | 33 ------- src/xml/config/config_errors.h | 14 +-- src/xml/dom_parser_with_line_info.cc | 5 -- src/xml/dom_parser_with_line_info.h | 1 - src/xml/test/xml_test_initializer.cc | 5 -- src/xml/xml_initializer.h | 1 - src/xml/xml_input_line_info.h | 4 - 247 files changed, 40 insertions(+), 1831 deletions(-) diff --git a/doc/status_monitoring.md b/doc/status_monitoring.md index c9a2dc51..bcb2844b 100644 --- a/doc/status_monitoring.md +++ b/doc/status_monitoring.md @@ -71,7 +71,6 @@ for class `TMsg`, which represents a single message: ```C++ TMsg::~TMsg() { - assert(this); MsgDestroy.Increment(); if (State != TState::Processed) { diff --git a/src/base/backoff_rate_limiter.cc b/src/base/backoff_rate_limiter.cc index bd8ef100..05720aa0 100644 --- a/src/base/backoff_rate_limiter.cc +++ b/src/base/backoff_rate_limiter.cc @@ -57,7 +57,6 @@ TBackoffRateLimiter::TBackoffRateLimiter( } size_t TBackoffRateLimiter::ComputeDelay() { - assert(this); struct timespec now; GetCurrentTime(now); @@ -79,8 +78,6 @@ size_t TBackoffRateLimiter::ComputeDelay() { bool TBackoffRateLimiter::InBackoffWindow(const struct timespec &now) noexcept { - assert(this); - if (FirstTime) { FirstTime = false; return false; diff --git a/src/base/backoff_rate_limiter.h b/src/base/backoff_rate_limiter.h index 19fa6ecf..0ed66dac 100644 --- a/src/base/backoff_rate_limiter.h +++ b/src/base/backoff_rate_limiter.h @@ -60,7 +60,6 @@ namespace Base { the internal state of the rate limiter so it will correctly compute the next delay value. */ void OnAction() noexcept { - assert(this); GetCurrentTime(LastEventTime); } diff --git a/src/base/blocking_asset.h b/src/base/blocking_asset.h index 4bbc07b3..9ff55403 100644 --- a/src/base/blocking_asset.h +++ b/src/base/blocking_asset.h @@ -45,27 +45,22 @@ namespace Base { The target must not currently be locked by any thread. Destroying a locked target has undefined results. */ ~TBlockingAsset() { - assert(this); Wr::pthread_rwlock_destroy(&RwLock); } void AcquireExclusive() const noexcept { - assert(this); Wr::pthread_rwlock_wrlock(&RwLock); } void AcquireShared() const noexcept { - assert(this); Wr::pthread_rwlock_rdlock(&RwLock); } void ReleaseExclusive() const noexcept { - assert(this); Wr::pthread_rwlock_unlock(&RwLock); } void ReleaseShared() const noexcept { - assert(this); Wr::pthread_rwlock_unlock(&RwLock); } diff --git a/src/base/buf.h b/src/base/buf.h index c1459b4b..deefbe2a 100644 --- a/src/base/buf.h +++ b/src/base/buf.h @@ -74,8 +74,6 @@ namespace Base { /* Move assignment operator leaves 'that' empty. */ TBuf &operator=(TBuf &&that) noexcept { - assert(this); - if (&that != this) { Storage = std::move(that.Storage); ItemOffset = that.ItemOffset; @@ -90,7 +88,6 @@ namespace Base { /* Move-assign 'items' into buffer, making 'items' its new contents. May be used in combination with TakeStorage() to refill buffer. */ TBuf &operator=(TStorage &&items) { - assert(this); Storage = std::move(items); ItemOffset = 0; ItemCount = Storage.size(); @@ -99,9 +96,6 @@ namespace Base { /* Swap contents with contents of 'that'. */ void Swap(TBuf &that) noexcept { - assert(this); - assert(&that); - if (&that != this) { Storage.swap(that.Storage); std::swap(ItemOffset, that.ItemOffset); @@ -111,7 +105,6 @@ namespace Base { /* Mark all data as consumed, leaving nothing but empty space. */ void Clear() noexcept { - assert(this); MarkDataConsumed(ItemCount); } @@ -122,7 +115,6 @@ namespace Base { by routines that take as input a vector to fill with data. It allows underlying memory allocated for storage to be reused. */ TStorage TakeStorage() noexcept { - assert(this); ItemOffset = 0; ItemCount = 0; return std::move(Storage); @@ -131,7 +123,6 @@ namespace Base { /* Return pointer to start location where additional items are expected to be deposited. Do not call unless SpaceSize() returns a value > 0. */ T *Space() noexcept { - assert(this); assert(ItemOffset < Storage.size()); assert(ItemCount < (Storage.size() - ItemOffset)); assert(SpaceSize() > 0); @@ -140,7 +131,6 @@ namespace Base { /* Return number of items the region returned by Space() can hold. */ size_t SpaceSize() const noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); return Storage.size() - ItemOffset - ItemCount; @@ -149,7 +139,6 @@ namespace Base { /* Return true if buffer currently has no space where additional items can be deposited, or false otherwise. */ bool SpaceIsEmpty() const noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); return (SpaceSize() == 0); @@ -158,7 +147,6 @@ namespace Base { /* Return pointer to start location of received items that are ready to be consumed. Do not call unless DataSize() returns a value > 0. */ T *Data() noexcept { - assert(this); assert(ItemOffset < Storage.size()); assert(ItemCount <= (Storage.size() - ItemOffset)); assert(DataSize() > 0); @@ -168,7 +156,6 @@ namespace Base { /* Return const pointer to start location of received items that are ready to be consumed. Do not call unless DataSize() returns a value > 0. */ const T *Data() const noexcept { - assert(this); assert(ItemOffset < Storage.size()); assert(ItemCount <= (Storage.size() - ItemOffset)); assert(DataSize() > 0); @@ -177,7 +164,6 @@ namespace Base { /* Return number of items the region returned by Data() holds. */ size_t DataSize() const noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); return ItemCount; @@ -186,7 +172,6 @@ namespace Base { /* Return true if buffer currently has no received items that are ready to be consumed, or false otherwise. */ bool DataIsEmpty() const noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); return (DataSize() == 0); @@ -196,7 +181,6 @@ namespace Base { without allocating memory. This method is a no-op if the buffer is empty or its items are already at the front. */ void MoveDataToFront() noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); @@ -215,7 +199,6 @@ namespace Base { 'min_to_add' items. Note that moving the items to the front may make more than 'min_to_add' extra space available. */ void AddSpace(size_t min_to_add) { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); @@ -228,7 +211,6 @@ namespace Base { necessary, move items to front of buffer and possibly allocate additional storage. */ void EnsureSpace(size_t min_size) { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); size_t actual = SpaceSize(); @@ -242,7 +224,6 @@ namespace Base { items the buffer can hold is at least 'min_size'. If necessary, move items to front of buffer and possibly allocate additional storage. */ void EnsureDataPlusSpace(size_t min_size) { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); size_t actual = Storage.size() - ItemOffset; @@ -257,7 +238,6 @@ namespace Base { consumed. This increases the value returned by DataSize() and decreases the value returned by SpaceSize(). */ void MarkSpaceConsumed(size_t size) noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); assert(size <= SpaceSize()); @@ -270,7 +250,6 @@ namespace Base { available space indicated by SpaceSize() follows the unconsumed items, and consuming items makes space available at the front. */ void MarkDataConsumed(size_t size) noexcept { - assert(this); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); assert(size <= DataSize()); @@ -284,7 +263,6 @@ namespace Base { private: void DoAddSpace(size_t min_to_add) { - assert(this); assert(min_to_add); assert(Storage.empty() || (ItemOffset < Storage.size())); assert(ItemCount <= (Storage.size() - ItemOffset)); diff --git a/src/base/code_location.cc b/src/base/code_location.cc index 61d09da5..2e6b7ef9 100644 --- a/src/base/code_location.cc +++ b/src/base/code_location.cc @@ -26,13 +26,11 @@ using namespace Base; const char *TCodeLocation::GetFile() const noexcept { - assert(this); return File + ((std::strncmp(File, SrcRoot, SrcRootLen) == 0) ? (SrcRootLen) : 0); } void TCodeLocation::Write(std::ostream &strm) const { - assert(this); strm << '[' << GetFile() << ", " << LineNumber << ']'; } diff --git a/src/base/code_location.h b/src/base/code_location.h index 046b3a9e..109aaff7 100644 --- a/src/base/code_location.h +++ b/src/base/code_location.h @@ -67,7 +67,6 @@ namespace Base { /* Returns the line number. Always returns > 0. */ unsigned GetLineNumber() const { - assert(this); return LineNumber; } diff --git a/src/base/convert.h b/src/base/convert.h index 884b509a..aecfde27 100644 --- a/src/base/convert.h +++ b/src/base/convert.h @@ -38,8 +38,6 @@ namespace Base { the next character at the head of the input stream, it returns TOpt::Unknown. */ TOpt TryReadSign() { - assert(this); - if(!(*this)) { return *TOpt::Unknown; } @@ -60,7 +58,6 @@ namespace Base { /* TryReadSign wrapper that asserts that a sign is read or throws. */ bool ReadSign() { - assert(this); TOpt ret = TryReadSign(); if (ret) { @@ -73,20 +70,16 @@ namespace Base { /* Returns true if there is a next character in the input stream and it is a digit, false otherwise. */ bool HasDigit() { - assert(this); return ((*this) && isdigit(*(*this))); } void ConsumeWhitespace() { - assert(this); while(isspace(**this)) { ++(*this); } } /* Reads in a character from Input and converts it to it's decimal value. */ template bool TryReadDigit(TVal &output) { - assert(this); - assert(&output); assert(std::numeric_limits::is_exact); assert(std::numeric_limits::min() <= 0); assert(std::numeric_limits::max() >= 9); @@ -109,8 +102,6 @@ namespace Base { bounds checking. */ template bool TryReadUnsignedInt(TVal &output, bool positive = true) { - assert(this); - assert(&output); assert(std::numeric_limits::is_integer); assert(std::numeric_limits::is_exact); assert(positive || std::numeric_limits::is_signed); @@ -165,8 +156,6 @@ namespace Base { read or an exception thrown. */ template TConverter &ReadUnsignedInt(TVal &output, bool positive=true) { - assert(this); - if (!TryReadUnsignedInt(output, positive)) { throw TSyntaxError(HERE, "No integer exists at current location in stream."); @@ -187,8 +176,6 @@ namespace Base { support hexadecimal and octal. */ template bool TryReadInt(TVal &output, bool sign_required = false) { - assert(this); - assert(&output); assert(std::numeric_limits::is_integer); assert(std::numeric_limits::is_exact); assert(sign_required ? std::numeric_limits::is_signed : true); @@ -219,8 +206,6 @@ namespace Base { at the current stream head, then an exception should be thrown. */ template TConverter &ReadInt(TVal &output, bool sign_required = false) { - assert(this); - if (!TryReadInt(output, sign_required)) { throw TSyntaxError(HERE, "No integer exists at current location."); } @@ -241,7 +226,6 @@ namespace Base { void ReadDouble(double &output, bool sign_required=false); operator bool() const { - assert(this); return Working; } @@ -267,8 +251,6 @@ namespace Base { } TConverter &operator++() { - assert(this); - if (!Working) { throw TSyntaxError(HERE, "unexpectedly out of text"); } diff --git a/src/base/counter.h b/src/base/counter.h index e18d5146..c4971edd 100644 --- a/src/base/counter.h +++ b/src/base/counter.h @@ -100,33 +100,28 @@ namespace Base { /* The code location at which the counter was declared. */ const Base::TCodeLocation &GetCodeLocation() const noexcept { - assert(this); return CodeLocation; } /* The count as of the last time the counters were sampled. */ uint32_t GetCount() const noexcept { - assert(this); return SampledCount; } /* The name of this counter. This should be unique within its module. Never null. */ const char *GetName() const noexcept { - assert(this); return Name; } /* The next counter in the program, if any. */ const TCounter *GetNextCounter() const noexcept { - assert(this); return NextCounter; } /* Increment the counter. This will not change the current frozen value, but will be reflected in the next frozen value. */ void Increment(uint32_t delta = 1) noexcept { - assert(this); Base::TSharedLock lock(Asset); __sync_add_and_fetch(&UnsampledCount, delta); } diff --git a/src/base/demangle.cc b/src/base/demangle.cc index 47d86379..a4f23e17 100644 --- a/src/base/demangle.cc +++ b/src/base/demangle.cc @@ -36,13 +36,11 @@ TDemangle::TDemangle(const char *mangled) : Buf(nullptr) { } TDemangle::~TDemangle() { - assert(this); assert(Buf); free(Buf); //The gcc man pages use free, so we use free. } const char *TDemangle::Get() const { - assert(this); assert(Buf); return Buf; } diff --git a/src/base/dir_iter.cc b/src/base/dir_iter.cc index 7e8a0f2b..194f5154 100644 --- a/src/base/dir_iter.cc +++ b/src/base/dir_iter.cc @@ -36,19 +36,15 @@ TDirIter::TDirIter(const char *dir) } TDirIter::~TDirIter() { - assert(this); Wr::closedir(Handle); } void TDirIter::Rewind() noexcept { - assert(this); rewinddir(Handle); Pos = NotFresh; } bool TDirIter::TryRefresh() const noexcept { - assert(this); - while (Pos == NotFresh) { dirent *const ptr = Wr::readdir(Handle); diff --git a/src/base/dir_iter.h b/src/base/dir_iter.h index 29d00114..42d44488 100644 --- a/src/base/dir_iter.h +++ b/src/base/dir_iter.h @@ -78,7 +78,6 @@ namespace Base { /* True until we reach then end of the directory. */ operator bool() const noexcept { - assert(this); return TryRefresh(); } @@ -86,7 +85,6 @@ namespace Base { Calling this function when we've already reached the end of the directory is a logic error. */ TDirIter &operator++() { - assert(this); Refresh(); Pos = NotFresh; return *this; @@ -97,7 +95,6 @@ namespace Base { Calling this function when we've already reached the end of the directory is a logic error. */ TKind GetKind() const { - assert(this); Refresh(); return static_cast(DirEnt.d_type); } @@ -106,7 +103,6 @@ namespace Base { Calling this function when we've already reached the end of the directory is a logic error. */ const char *GetName() const { - assert(this); Refresh(); return DirEnt.d_name; } @@ -131,8 +127,6 @@ namespace Base { /* Like TryRefresh(), but die if we're at the end. */ void Refresh() const noexcept { - assert(this); - if (!TryRefresh()) { Die("Past end of directory"); } diff --git a/src/base/dynamic_lib.h b/src/base/dynamic_lib.h index 746c9e6d..7afb374b 100644 --- a/src/base/dynamic_lib.h +++ b/src/base/dynamic_lib.h @@ -40,7 +40,6 @@ namespace Base { class TErrorBase : public std::runtime_error { public: virtual const char *what() const noexcept { - assert(this); return Msg.c_str(); } @@ -93,7 +92,6 @@ namespace Base { function signature. */ template T LoadSymNoexcept(const char *symname) noexcept { - assert(this); return reinterpret_cast(dlsym(Handle, symname)); } @@ -101,7 +99,6 @@ namespace Base { */ template T LoadSym(const char *symname) { - assert(this); T sym = reinterpret_cast(dlsym(Handle, symname)); if (sym == nullptr) { diff --git a/src/base/error.cc b/src/base/error.cc index 5b748758..02fffc70 100644 --- a/src/base/error.cc +++ b/src/base/error.cc @@ -38,8 +38,6 @@ TError::TError() : WhatPtr("PostCtor() was not called") {} void TError::PostCtor(const TCodeLocation &code_location, const char *details) { - assert(this); - try { CodeLocation = code_location; std::stringstream out_strm; @@ -66,8 +64,6 @@ void TError::PostCtor(const TCodeLocation &code_location, void TError::PostCtor(const TCodeLocation &code_location, const char *details_start, const char* details_end) { - assert(this); - try { CodeLocation = code_location; std::stringstream out_strm; diff --git a/src/base/error.h b/src/base/error.h index a0ad3da5..427f410c 100644 --- a/src/base/error.h +++ b/src/base/error.h @@ -72,7 +72,6 @@ namespace Base { /* Returns a human-readable description of what went wrong. This message has the following pattern: (,),[,
] */ const char *what() const noexcept override { - assert(this); return WhatPtr; } @@ -83,7 +82,6 @@ namespace Base { /* Returns the location at which the exception was thrown. */ const TCodeLocation &GetCodeLocation() const noexcept { - assert(this); return CodeLocation; } diff --git a/src/base/error_util.h b/src/base/error_util.h index 711b1a95..ec18b849 100644 --- a/src/base/error_util.h +++ b/src/base/error_util.h @@ -112,8 +112,6 @@ namespace Base { } TBacktraceSymbols &operator=(TBacktraceSymbols &&other) noexcept { - assert(this); - if (&other != this) { Clear(); Buf = other.Buf; @@ -128,19 +126,16 @@ namespace Base { void Clear() noexcept { /* As specified by the man page for backtrace_symbols(), free Buf, but not the individual pointers in the array it points to. */ - assert(this); free(Buf); Buf = nullptr; BufSize = 0; } size_t Size() const noexcept { - assert(this); return BufSize; } const char *operator[](size_t index) const noexcept { - assert(this); assert(index < BufSize); return Buf[index]; } diff --git a/src/base/event_semaphore.cc b/src/base/event_semaphore.cc index c942cc11..60437f01 100644 --- a/src/base/event_semaphore.cc +++ b/src/base/event_semaphore.cc @@ -48,7 +48,6 @@ TEventSemaphore::TEventSemaphore(int initial_count, bool nonblocking) noexcept } void TEventSemaphore::Reset(int initial_count) noexcept { - assert(this); int flags = Wr::fcntl(Fd, F_GETFL, 0); TFd new_fd = Wr::eventfd(initial_count, EFD_SEMAPHORE); @@ -73,7 +72,6 @@ void TEventSemaphore::Reset(int initial_count) noexcept { } bool TEventSemaphore::Pop() noexcept { - assert(this); uint64_t dummy; ssize_t ret = Wr::read(Wr::TDisp::AddFatal, {EIO, EISDIR}, Fd, &dummy, sizeof(dummy)); @@ -109,7 +107,6 @@ bool TEventSemaphore::Pop() noexcept { } bool TEventSemaphore::PopIntr() { - assert(this); uint64_t dummy; ssize_t ret = Wr::read(Wr::TDisp::AddFatal, {EIO, EISDIR}, Fd, &dummy, sizeof(dummy)); @@ -129,6 +126,5 @@ bool TEventSemaphore::PopIntr() { } void TEventSemaphore::Push(int count) noexcept { - assert(this); Wr::eventfd_write(Fd, static_cast(count)); } diff --git a/src/base/event_semaphore.h b/src/base/event_semaphore.h index 912cd46c..9c58c597 100644 --- a/src/base/event_semaphore.h +++ b/src/base/event_semaphore.h @@ -38,7 +38,6 @@ namespace Base { bool nonblocking = false) noexcept; const TFd &GetFd() const noexcept { - assert(this); return Fd; } diff --git a/src/base/exclusive_lock.h b/src/base/exclusive_lock.h index af8a37c8..cb95f255 100644 --- a/src/base/exclusive_lock.h +++ b/src/base/exclusive_lock.h @@ -37,13 +37,11 @@ namespace Base { TExclusiveLock(const TAsset &asset) noexcept(noexcept(asset.AcquireExclusive())) : Asset(asset) { - assert(&asset); asset.AcquireExclusive(); } /* Releases the lock. */ ~TExclusiveLock() { - assert(this); Asset.ReleaseExclusive(); } diff --git a/src/base/fd.cc b/src/base/fd.cc index cf6ddeb5..0f3668cf 100644 --- a/src/base/fd.cc +++ b/src/base/fd.cc @@ -49,7 +49,6 @@ static void PreparePoll(int fd, int timeout, timespec *&tsp, } bool TFd::IsReadable(int timeout) const noexcept { - assert(this); timespec ts; timespec *tsp = &ts; pollfd p; @@ -63,7 +62,6 @@ bool TFd::IsReadable(int timeout) const noexcept { } bool TFd::IsReadableIntr(int timeout) const { - assert(this); timespec ts; timespec *tsp = &ts; pollfd p; diff --git a/src/base/fd.h b/src/base/fd.h index 36f05380..f7900f57 100644 --- a/src/base/fd.h +++ b/src/base/fd.h @@ -86,21 +86,17 @@ namespace Base { /* Close the file descriptor we own, if any. If the descriptor is in the stdio range (0-2), then don't close it. */ ~TFd() { - assert(this); - if (OsHandle >= 3) { Wr::close(OsHandle); } } void Swap(TFd &that) noexcept { - assert(this); std::swap(OsHandle, that.OsHandle); } /* Swaperator. */ TFd &operator=(TFd &&that) noexcept { - assert(this); Swap(that); return *this; } @@ -108,7 +104,6 @@ namespace Base { /* Assignment. This will duplicate the file descriptor, if any, using the OS function dup(). */ TFd &operator=(const TFd &that) noexcept { - assert(this); return *this = TFd(that); } @@ -118,19 +113,16 @@ namespace Base { legal file descriptor, this function will throw the appropriate error. */ TFd &operator=(int os_handle) { - assert(this); return *this = TFd(os_handle); } /* Returns the naked file descriptor, which may be -1. */ operator int() const noexcept { - assert(this); return OsHandle; } /* True iff. this handle is open. */ bool IsOpen() const noexcept { - assert(this); return OsHandle >= 0; } @@ -148,7 +140,6 @@ namespace Base { default-constructed state. This is how to get the naked file desciptor away from the object without the object attempting to close it. */ int Release() noexcept { - assert(this); int result = OsHandle; OsHandle = -1; return result; @@ -156,7 +147,6 @@ namespace Base { /* Return to the default-constructed state. */ TFd &Reset() noexcept { - assert(this); return *this = TFd(); } diff --git a/src/base/file_reader.cc b/src/base/file_reader.cc index 9d7facb7..c7f7bc07 100644 --- a/src/base/file_reader.cc +++ b/src/base/file_reader.cc @@ -27,7 +27,6 @@ using namespace Base; size_t Base::TFileReader::GetSize() { - assert(this); Open(); size_t size = 0; @@ -43,7 +42,6 @@ size_t Base::TFileReader::GetSize() { } size_t Base::TFileReader::ReadIntoBuf(void *buf, size_t buf_size) { - assert(this); assert(buf); PrepareForRead(); @@ -61,7 +59,6 @@ size_t Base::TFileReader::ReadIntoBuf(void *buf, size_t buf_size) { } void Base::TFileReader::ReadIntoString(std::string &dst) { - assert(this); dst.reserve(GetSize()); PrepareForRead(); @@ -74,14 +71,12 @@ void Base::TFileReader::ReadIntoString(std::string &dst) { } std::string Base::TFileReader::ReadIntoString() { - assert(this); std::string contents; ReadIntoString(contents); return contents; } void Base::TFileReader::ThrowFileOpenError() const { - assert(this); const char *sys_msg = std::strerror(errno); std::string msg("Cannot open file ["); msg += Filename; @@ -91,7 +86,6 @@ void Base::TFileReader::ThrowFileOpenError() const { } void Base::TFileReader::ThrowFileReadError() const { - assert(this); const char *sys_msg = std::strerror(errno); std::string msg("Cannot read file ["); msg += Filename; @@ -101,8 +95,6 @@ void Base::TFileReader::ThrowFileReadError() const { } void Base::TFileReader::Open() { - assert(this); - try { /* Clear any errors remaining from a previous operation. */ Stream.clear(); @@ -117,7 +109,6 @@ void Base::TFileReader::Open() { } void Base::TFileReader::PrepareForRead() { - assert(this); Open(); try { diff --git a/src/base/file_reader.h b/src/base/file_reader.h index 589cb0b6..5953bd6e 100644 --- a/src/base/file_reader.h +++ b/src/base/file_reader.h @@ -70,7 +70,6 @@ namespace Base { /* Assign to 'dst' the entire contents of the file. */ template void ReadIntoBuf(std::vector &dst) { - assert(this); static_assert( std::is_integral::value && (sizeof(T) == sizeof(uint8_t)), "Destination vector type parameter must be single-byte integral"); @@ -88,7 +87,6 @@ namespace Base { /* Return entire file contents. */ template std::vector ReadIntoBuf() { - assert(this); std::vector result; ReadIntoBuf(result); return result; diff --git a/src/base/hex_dump_writer.cc b/src/base/hex_dump_writer.cc index 6eddebbc..e2e88c19 100644 --- a/src/base/hex_dump_writer.cc +++ b/src/base/hex_dump_writer.cc @@ -112,7 +112,6 @@ static void AppendHexByteToString(std::string &dst, uint8_t byte) { void THexDumpWriter::Write(const void *mem, size_t bytes, uint64_t start_addr) const { - assert(this); auto *p = static_cast(mem); size_t index = 0; size_t bytes_left = bytes; @@ -199,7 +198,6 @@ void THexDumpWriter::Write(const void *mem, size_t bytes, /* Append to string 'dst' the character representation of 'byte'. */ void THexDumpWriter::AppendByteCharToString(std::string &dst, uint8_t byte) const { - assert(this); dst += Format.IsPrintableFn(byte) ? static_cast(byte) : Format.Nonprintable; } diff --git a/src/base/hex_dump_writer.h b/src/base/hex_dump_writer.h index 1747969b..93db5166 100644 --- a/src/base/hex_dump_writer.h +++ b/src/base/hex_dump_writer.h @@ -67,120 +67,99 @@ namespace Base { const TIsPrintableFn &is_printable_fn); size_t GetBytesPerLine() const noexcept { - assert(this); return BytesPerLine; } TFormat &SetBytesPerLine(size_t bytes_per_line) noexcept { - assert(this); BytesPerLine = bytes_per_line; return *this; } size_t GetAddrPrintWidth() const noexcept { - assert(this); return AddrPrintWidth; } TFormat &SetAddrPrintWidth(size_t addr_print_width) noexcept { - assert(this); AddrPrintWidth = addr_print_width; return *this; } const std::string &GetIndent() const noexcept { - assert(this); return Indent; } TFormat &SetIndent(const std::string &indent) { - assert(this); Indent = indent; return *this; } TFormat &SetIndent(std::string &&indent) noexcept { - assert(this); Indent = std::move(indent); return *this; } const std::string &GetSep1() const noexcept { - assert(this); return Sep1; } TFormat &SetSep1(const std::string &sep1) { - assert(this); Sep1 = sep1; return *this; } TFormat &SetSep1(std::string &&sep1) noexcept { - assert(this); Sep1 = std::move(sep1); return *this; } const std::string &GetSep2() const noexcept { - assert(this); return Sep2; } TFormat &SetSep2(const std::string &sep2) { - assert(this); Sep2 = sep2; return *this; } TFormat &SetSep2(std::string &&sep2) noexcept { - assert(this); Sep2 = std::move(sep2); return *this; } const std::string &GetSep3() const noexcept { - assert(this); return Sep3; } TFormat &SetSep3(const std::string &sep3) { - assert(this); Sep3 = sep3; return *this; } TFormat &SetSep3(std::string &&sep3) noexcept { - assert(this); Sep3 = std::move(sep3); return *this; } char GetNonprintable() const noexcept { - assert(this); return Nonprintable; } TFormat &SetNonprintable(char nonprintable) noexcept { - assert(this); Nonprintable = nonprintable; return *this; } const TIsPrintableFn &GetIsPrintableFn() const noexcept { - assert(this); return IsPrintableFn; } TFormat &SetIsPrintableFn( const TIsPrintableFn &is_printable_fn) { - assert(this); IsPrintableFn = is_printable_fn; return *this; } TFormat &SetIsPrintableFn(TIsPrintableFn &&is_printable_fn) { - assert(this); IsPrintableFn = std::move(is_printable_fn); return *this; } diff --git a/src/base/indent.h b/src/base/indent.h index 6e261502..08dffec4 100644 --- a/src/base/indent.h +++ b/src/base/indent.h @@ -64,28 +64,23 @@ namespace Base { TIndent& operator=(const TIndent &) = delete; ~TIndent() { - assert(this); IndentStr.resize(InitialIndentSize); } void AddOnce(size_t count = DEFAULT_INDENT_COUNT, char indent_char = DEFAULT_INDENT_CHAR) { - assert(this); IndentStr.append(count, indent_char); } void AddOnce(const char *extra_indent) { - assert(this); IndentStr += extra_indent; } void AddOnce(const std::string &extra_indent) { - assert(this); AddOnce(extra_indent.c_str()); } const std::string &Get() const { - assert(this); return IndentStr; } diff --git a/src/base/on_destroy.h b/src/base/on_destroy.h index e7d87c9e..3efe1377 100644 --- a/src/base/on_destroy.h +++ b/src/base/on_destroy.h @@ -77,7 +77,6 @@ namespace Base { } void Cancel() noexcept { - assert(this); Active = false; } diff --git a/src/base/opt.h b/src/base/opt.h index 36f52452..20698144 100644 --- a/src/base/opt.h +++ b/src/base/opt.h @@ -97,16 +97,12 @@ namespace Base { /* If we're known, destroy our value as we go. Implicitly noexcept if Reset() is noexcept. */ ~TOpt() { - assert(this); Reset(); } TOpt &operator=(TOpt &&that) noexcept(std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value) { - assert(this); - assert(&that); - if (this != &that) { if (Val) { if (that.Val) { @@ -125,9 +121,6 @@ namespace Base { TOpt &operator=(const TOpt &that) noexcept(std::is_nothrow_copy_constructible::value && std::is_nothrow_copy_assignable::value) { - assert(this); - assert(&that); - if (this != &that) { if (Val) { if (that.Val) { @@ -146,9 +139,6 @@ namespace Base { TOpt &operator=(TVal &&that) noexcept(std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value) { - assert(this); - assert(&that); - if (Val != &that) { if (Val) { *Val = std::move(that); @@ -165,9 +155,6 @@ namespace Base { TOpt &operator=(const TVal &that) noexcept(std::is_nothrow_copy_constructible::value && std::is_nothrow_copy_assignable::value) { - assert(this); - assert(&that); - if (Val != &that) { if (Val) { *Val = that; @@ -181,61 +168,52 @@ namespace Base { /* True iff. we're known. */ operator bool() const noexcept { - assert(this); return IsKnown(); } /* Our value. We must already be known. */ const TVal &operator*() const noexcept { - assert(this); assert(Val); return *Val; } /* Our value. We must already be known. */ TVal &operator*() noexcept { - assert(this); assert(Val); return *Val; } /* Our value. We must already be known. */ const TVal *operator->() const noexcept { - assert(this); assert(Val); return Val; } /* Our value. We must already be known. */ TVal *operator->() noexcept { - assert(this); assert(Val); return Val; } /* A pointer to our value. We must already be known. */ const TVal *Get() const noexcept { - assert(this); assert(Val); return Val; } /* A pointer to our value. We must already be known. */ TVal *Get() noexcept { - assert(this); assert(Val); return Val; } /* True iff. we're known. */ bool IsKnown() const noexcept { - assert(this); return Val != nullptr; } /* True iff. we're not known. */ bool IsUnknown() const noexcept { - assert(this); return !IsKnown(); } @@ -245,8 +223,6 @@ namespace Base { template TVal &MakeKnown(TArgs &&... args) noexcept( noexcept(TVal(std::forward(args)...))) { - assert(this); - if (!Val) { Val = new (Storage) TVal(std::forward(args)...); } @@ -256,8 +232,6 @@ namespace Base { /* Reset to the unknown state. */ TOpt &Reset() noexcept(std::is_nothrow_destructible::value) { - assert(this); - if (Val) { Val->~TVal(); Val = nullptr; @@ -268,13 +242,11 @@ namespace Base { /* A pointer to our value. If we're not known, return nullptr. */ const TVal *TryGet() const noexcept { - assert(this); return Val; } /* A pointer to our value. If we're not known, return nullptr. */ TVal *TryGet() noexcept { - assert(this); return Val; } @@ -303,9 +275,6 @@ namespace Base { this function inserts nothing. */ template std::ostream &operator<<(std::ostream &strm, const Base::TOpt &that) { - assert(&strm); - assert(&that); - if (that) { strm << *that; } @@ -316,9 +285,6 @@ namespace Base { /* A std stream extractor for Base::TOpt<>. */ template std::istream &operator>>(std::istream &strm, Base::TOpt &that) { - assert(&strm); - assert(&that); - if (!strm.eof()) { strm >> that.MakeKnown(); } else { diff --git a/src/base/opt.test.cc b/src/base/opt.test.cc index ca85c662..27f98546 100644 --- a/src/base/opt.test.cc +++ b/src/base/opt.test.cc @@ -100,8 +100,6 @@ namespace { } ~THolder() { - assert(this); - if (DtorFlag) { *DtorFlag = true; } @@ -110,7 +108,6 @@ namespace { THolder &operator=(const THolder &) = default; THolder &operator=(THolder &&other) noexcept { - assert(this); Value = std::move(other.Value); /* Explicitly clear other.Value to make it obvious that other.Value was @@ -121,23 +118,19 @@ namespace { } void SetDtorFlag(bool &flag) noexcept { - assert(this); DtorFlag = &flag; *DtorFlag = false; } const std::string &GetValue() const noexcept { - assert(this); return Value; } std::string &GetValue() noexcept { - assert(this); return Value; } bool IsEmpty() const noexcept { - assert(this); return Value.empty(); } diff --git a/src/base/os_error.h b/src/base/os_error.h index e4a446b2..85e58409 100644 --- a/src/base/os_error.h +++ b/src/base/os_error.h @@ -43,7 +43,6 @@ namespace Base { } int GetErrorCode() const { - assert(this); return ErrorCode; } diff --git a/src/base/piece.h b/src/base/piece.h index ce401692..bcc0dbcc 100644 --- a/src/base/piece.h +++ b/src/base/piece.h @@ -87,7 +87,6 @@ namespace Base { library and built-in types appear at the end of this file. */ template inline size_t GetHashHelper(const TVal &val) { - assert(&val); return val.GetHash(); } @@ -165,7 +164,6 @@ namespace Base { /* Construct as a copy of a piece of compatible type. */ template TPiece(const TPiece &that) { - assert(&that); Start = that.GetStart(); Limit = that.GetLimit(); } @@ -194,8 +192,6 @@ namespace Base { /* Assign as a copy of a piece of compatible type. */ template TPiece &operator=(const TPiece &that) { - assert(this); - assert(&that); Start = that.GetStart(); Limit = that.GetLimit(); return *this; @@ -203,7 +199,6 @@ namespace Base { /* Assign so as to span a single value. */ TPiece &operator=(TVal &that) { - assert(this); Start = &that; Limit = Start + 1; return *this; @@ -211,13 +206,11 @@ namespace Base { /* Return true iff. the piece is non-empty. */ operator bool() const { - assert(this); return (Start != Limit); } /* Return the given element of the piece. */ TVal &operator[](const TPos &pos) const { - assert(this); size_t size = GetSize(); ptrdiff_t offset = pos.GetAbsOffset(size); assert(offset >= 0 && static_cast(offset) < size); @@ -226,8 +219,6 @@ namespace Base { /* Return a slice of the piece. */ TPiece operator[](const TSlice &slice) const { - assert(this); - assert(&slice); size_t start, limit; slice.GetAbsPair(GetSize(), start, limit); assert(start <= limit); @@ -238,8 +229,6 @@ namespace Base { true iff. they are equal. */ template bool operator==(const TPiece &that) const { - assert(this); - assert(&that); TVal *cursor = Start; TCompatVal *that_cursor = that.GetStart(); @@ -258,8 +247,6 @@ namespace Base { true iff. they are not equal. */ template bool operator!=(const TPiece &that) const { - assert(this); - assert(&that); TVal *cursor = Start; TCompatVal *that_cursor = that.GetStart(); @@ -278,7 +265,6 @@ namespace Base { true iff. this one is less than that one. */ template bool operator<(const TPiece &that) const { - assert(this); return (Compare(that) < 0); } @@ -286,7 +272,6 @@ namespace Base { true iff. this one is less than or equal to that one. */ template bool operator<=(const TPiece &that) const { - assert(this); return (Compare(that) <= 0); } @@ -294,7 +279,6 @@ namespace Base { true iff. this one is greater than that one. */ template bool operator>(const TPiece &that) const { - assert(this); return (Compare(that) > 0); } @@ -302,14 +286,12 @@ namespace Base { true iff. this one is greater than or equal to that one. */ template bool operator>=(const TPiece &that) const { - assert(this); return (Compare(that) >= 0); } /* Apply a delta to the limit of the piece. The result must not place the limit before the start. */ TPiece &AdjustLimit(ptrdiff_t delta) { - assert(this); Limit += delta; assert(Start <= Limit); return *this; @@ -318,7 +300,6 @@ namespace Base { /* Adjust the limit of the piece such that the piece ends up with the given size. The start remains unchanged. */ TPiece &AdjustLimitToSize(size_t size) { - assert(this); Limit = Start + size; return *this; } @@ -326,7 +307,6 @@ namespace Base { /* Apply a delta to the start of the piece. The result must not place the limit before the start. */ TPiece &AdjustStart(ptrdiff_t delta) { - assert(this); Start += delta; assert(Start <= Limit); return *this; @@ -335,7 +315,6 @@ namespace Base { /* Adjust the start of the piece such that the piece ends up with the given size. The limit remains unchanged. */ TPiece &AdjustStartToSize(size_t size) { - assert(this); Start = Limit - size; return *this; } @@ -345,7 +324,6 @@ namespace Base { can be equal. One or both can be null. */ template TPiece &Assign(TCompatVal *start, TCompatVal *limit) { - assert(this); assert(start <= limit); Start = start; Limit = limit; @@ -356,7 +334,6 @@ namespace Base { size of zero is ok here, as is a null pointer. */ template TPiece &Assign(TCompatVal *start, size_t size) { - assert(this); Start = start; Limit = start + size; return *this; @@ -364,8 +341,6 @@ namespace Base { /* Returns true if the given slice can be made. */ bool CanSlice(const TSlice &slice) const { - assert(this); - assert(&slice); return slice.CanGetAbsPair(GetSize()); } @@ -376,8 +351,6 @@ namespace Base { operator<. */ template int Compare(const TPiece &that) const { - assert(this); - assert(&that); TVal *cursor = Start; TCompatVal *that_cursor = that.GetStart(); @@ -398,8 +371,6 @@ namespace Base { /* Redefines the piece to just the given slice. */ TPiece &Constrain(const TSlice &slice) { - assert(this); - assert(&slice); size_t start, limit; slice.GetAbsPair(GetSize(), start, limit); Limit = Start + limit; @@ -413,7 +384,6 @@ namespace Base { is not. */ template bool Contains(TCompatVal *ptr) { - assert(this); return (ptr >= Start) && (ptr < Limit); } @@ -421,49 +391,41 @@ namespace Base { one. */ template bool Contains(const TPiece &that) { - assert(this); - assert(&that); return (Start <= that.Start) && (that.Limit <= Limit); } /* Return the first element in the piece. The piece must not be empty. (Compare with GetRest().) */ const TVal &GetHead() const { - assert(this); assert(*this); return *Start; } /* Return the limiting pointer of the piece. This can be null. */ TVal *GetLimit() const { - assert(this); return Limit; } /* Return a new piece which spans all but the first element of this piece. This piece must not be empty. (Compare with GetHead().) */ TPiece GetRest() const { - assert(this); assert(*this); return TPiece(Start + 1, Limit); } /* Return the number of elements in the piece. This can be zero. */ size_t GetSize() const { - assert(this); return Limit - Start; } /* Return the starting pointer of the piece. */ TVal *GetStart() const { - assert(this); return Start; } /* Compute a hash of the contents of the piece. (TVal must be hashable.) */ size_t GetHash() const { - assert(this); size_t result = 0; for (TVal *csr = Start; csr < Limit; ++csr) { @@ -474,14 +436,12 @@ namespace Base { } const TVal &GetTail() const { - assert(this); assert(*this); return *(Limit - 1); } /* Reset to the default-constructed (empty) state. */ TPiece &Reset() { - assert(this); Start = 0; Limit = 0; return *this; @@ -490,7 +450,6 @@ namespace Base { /* Set the limiting pointer of the piece. The new limit must not be less than the existing start. */ TPiece &SetLimit(TVal *limit) { - assert(this); assert(Start <= limit); Limit = limit; return *this; @@ -499,7 +458,6 @@ namespace Base { /* Set the starting pointer of the piece. The existing limit must not be less than the new start. */ TPiece &SetStart(TVal *start) { - assert(this); assert(start <= Limit); Start = start; return *this; @@ -508,8 +466,6 @@ namespace Base { /* Exchange the states of this piece with that one. This is a guranteed no-throw. */ TPiece &Swap(TPiece &that) { - assert(this); - assert(&that); std::swap(Start, that.Start); std::swap(Limit, that.Limit); return *this; @@ -518,9 +474,6 @@ namespace Base { /* Return a pointer to the instance of val, if possible. */ template TVal *Find(const TCompatVal &val) const { - assert(this); - assert(&val); - for (auto cur = Start; cur < Limit; ++cur) { if (*cur == val) { return cur; @@ -535,9 +488,6 @@ namespace Base { */ template TVal *Find(const std::unordered_set &val_set) const { - assert(this); - assert(&val_set); - for (auto cur = Start; cur < Limit; ++cur) { if (Base::Contains(val_set, *cur)) { return cur; @@ -550,9 +500,6 @@ namespace Base { /* Return a slice of the piece (by out-param), if possible. */ bool TrySlice(const TSlice &slice, TPiece &out) const { - assert(this); - assert(&slice); - assert(&out); size_t start, limit; bool success = slice.TryGetAbsPair(GetSize(), start, limit); @@ -593,8 +540,6 @@ namespace Base { template const TPiece &ShallowCopy(const TPiece &dest, const TPiece &src, size_t size) { - assert(&dest); - assert(&src); assert(dest.GetSize() >= size); assert(src.GetSize() >= size); assert(sizeof(TDestVal) == sizeof(TSrcVal)); @@ -606,8 +551,6 @@ namespace Base { template const TPiece &ShallowCopy(const TPiece &dest, const TPiece &src) { - assert(&dest); - assert(&src); return ShallowCopy(dest, src, std::min(dest.GetSize(), src.GetSize())); } @@ -622,8 +565,6 @@ namespace Base { template const TPiece &Copy(const TPiece &dest, const TPiece &src, size_t size) { - assert(&dest); - assert(&src); assert(dest.GetSize() >= size); assert(src.GetSize() >= size); TSrcVal *src_val = src.GetStart(); @@ -640,8 +581,6 @@ namespace Base { template const TPiece &Copy(const TPiece &dest, const TPiece &src) { - assert(&dest); - assert(&src); return Copy(dest, src, std::min(dest.GetSize(), src.GetSize())); } @@ -771,14 +710,12 @@ namespace Base { same type. */ template TPiece AsPiece(const std::vector &that) { - assert(&that); return TPiece(&that[0], that.size()); } /* Constructs a TPiece spanning a standard vector of the same type. */ template TPiece AsPiece(std::vector &that) { - assert(&that); return TPiece(&that[0], that.size()); } @@ -787,7 +724,6 @@ namespace Base { template TPiece AsPiece( const std::basic_string &that) { - assert(&that); return TPiece(that.data(), that.size()); } @@ -795,7 +731,6 @@ namespace Base { type. */ template TPiece AsPiece(std::basic_string &that) { - assert(&that); return TPiece(const_cast(that.data()), that.size()); } diff --git a/src/base/pos.h b/src/base/pos.h index 6a7a3f0f..c45cd007 100644 --- a/src/base/pos.h +++ b/src/base/pos.h @@ -80,13 +80,11 @@ namespace Base { /* Returns true iff. this pos is the same as that one. */ bool operator==(const TPos &that) const { - assert(this); return Offset == that.Offset && Dir == that.Dir; } /* Returns true iff. this pos is not the same as that one. */ bool operator!=(const TPos &that) const { - assert(this); return Offset != that.Offset || Dir != that.Dir; } @@ -94,7 +92,6 @@ namespace Base { a sequence of the given size. The absolute offset is always relative to the start of the sequence. */ ptrdiff_t GetAbsOffset(size_t size) const { - assert(this); ptrdiff_t result; switch (Dir) { @@ -114,7 +111,6 @@ namespace Base { /* Return to the default constructed state. */ TPos &Reset() { - assert(this); Offset = 0; Dir = Forward; return *this; @@ -122,7 +118,6 @@ namespace Base { /* Swap this pos with that one. */ TPos &Swap(TPos &that) { - assert(this); std::swap(Offset, that.Offset); std::swap(Dir, that.Dir); return *this; diff --git a/src/base/random_exp_backoff.cc b/src/base/random_exp_backoff.cc index 9d982ccf..012f85d7 100644 --- a/src/base/random_exp_backoff.cc +++ b/src/base/random_exp_backoff.cc @@ -25,7 +25,6 @@ using namespace Base; size_t TRandomExpBackoff::NextValue() { - assert(this); size_t half_base = BaseCount / 2; size_t min_result = half_base; size_t max_result = BaseCount + half_base; diff --git a/src/base/random_exp_backoff.h b/src/base/random_exp_backoff.h index 814d0630..ad50f5e1 100644 --- a/src/base/random_exp_backoff.h +++ b/src/base/random_exp_backoff.h @@ -44,22 +44,18 @@ namespace Base { {} size_t GetInitialCount() const noexcept { - assert(this); return InitialCount; } size_t GetMaxDouble() const noexcept { - assert(this); return MaxDouble; } size_t GetCurrentBaseCount() const noexcept { - assert(this); return BaseCount; } size_t GetCurrentDoubleTimesLeft() const noexcept { - assert(this); return DoubleTimesLeft; } @@ -78,8 +74,6 @@ namespace Base { /* This reinitializes the object to its initially constructed state, allowing it to generate a new sequence of values. */ void Reset() noexcept { - assert(this); - BaseCount = InitialCount; DoubleTimesLeft = MaxDouble; } diff --git a/src/base/safe_global.h b/src/base/safe_global.h index b8d32032..b2dd7f56 100644 --- a/src/base/safe_global.h +++ b/src/base/safe_global.h @@ -41,49 +41,41 @@ namespace Base { : Factory(factory), Val(0), Constructing(false) {} ~TSafeGlobal() { - assert(this); delete Val; } const TVal &operator*() const { - assert(this); Freshen(); return *AssertTrue(Val); } TVal &operator*() { - assert(this); Freshen(); return *AssertTrue(Val); } const TVal *operator->() const { - assert(this); Freshen(); return AssertTrue(Val); } TVal *operator->() { - assert(this); Freshen(); return AssertTrue(Val); } const TVal *GetObj() const { - assert(this); Freshen(); return AssertTrue(Val); } TVal *GetObj() { - assert(this); Freshen(); return AssertTrue(Val); } private: void Freshen() const { - assert(this); TSpinLock::TLock lock(SpinLock); if (!Val) { assert(!Constructing); diff --git a/src/base/shared_lock.h b/src/base/shared_lock.h index 6f0e34cd..30b860c4 100644 --- a/src/base/shared_lock.h +++ b/src/base/shared_lock.h @@ -36,13 +36,11 @@ namespace Base { /* Will not return until the lock is granted. */ TSharedLock(const TAsset &asset) : Asset(asset) { - assert(&asset); asset.AcquireShared(); } /* Releases the lock. */ ~TSharedLock() { - assert(this); Asset.ReleaseShared(); } diff --git a/src/base/sig_handler_installer.h b/src/base/sig_handler_installer.h index 49ada61e..2794e95e 100644 --- a/src/base/sig_handler_installer.h +++ b/src/base/sig_handler_installer.h @@ -52,13 +52,11 @@ namespace Base { /* Restore the old action. */ ~TSigHandlerInstaller() { - assert(this); Wr::sigaction(SignalNumber, &OldAct, nullptr); } /* The signal we handle. */ int GetSignalNumber() const noexcept { - assert(this); return SignalNumber; } diff --git a/src/base/sig_masker.h b/src/base/sig_masker.h index 07319c2f..fb31a643 100644 --- a/src/base/sig_masker.h +++ b/src/base/sig_masker.h @@ -48,12 +48,10 @@ namespace Base { /* Restore the mask. */ ~TSigMasker() { - assert(this); Wr::pthread_sigmask(SIG_SETMASK, &OldSet, nullptr); } const sigset_t &GetOldSet() const noexcept { - assert(this); return OldSet; } diff --git a/src/base/sig_set.h b/src/base/sig_set.h index 4481ee8f..9c214726 100644 --- a/src/base/sig_set.h +++ b/src/base/sig_set.h @@ -96,59 +96,50 @@ namespace Base { /* Assignment operator. */ TSigSet &operator=(const TSigSet &that) noexcept { - assert(this); std::memcpy(&OsObj, &that.OsObj, sizeof(OsObj)); return *this; } /* Assignment operator from sigset_t. */ TSigSet &operator=(const sigset_t &sigset) noexcept { - assert(this); std::memcpy(&OsObj, &sigset, sizeof(OsObj)); return *this; } /* Add the signal to the set. */ TSigSet &operator+=(int sig) noexcept { - assert(this); Wr::sigaddset(&OsObj, sig); return *this; } /* Remove the signal from the set. */ TSigSet &operator-=(int sig) noexcept { - assert(this); Wr::sigdelset(&OsObj, sig); return *this; } /* Construct a new set with the signal added. */ TSigSet operator+(int sig) noexcept { - assert(this); return TSigSet(*this) += sig; } /* Construct a new set with the signal removed. */ TSigSet operator-(int sig) noexcept { - assert(this); return TSigSet(*this) -= sig; } /* True iff. the signal is in the set. */ bool operator[](int sig) const noexcept { - assert(this); return Wr::sigismember(&OsObj, sig); } /* Access the OS object. */ const sigset_t &operator*() const noexcept { - assert(this); return OsObj; } /* Access the OS object. */ const sigset_t *Get() const noexcept { - assert(this); return &OsObj; } diff --git a/src/base/slice.h b/src/base/slice.h index a226d85d..6fd977ec 100644 --- a/src/base/slice.h +++ b/src/base/slice.h @@ -61,20 +61,17 @@ namespace Base { /* Returns true iff. this slice is the same as that one. */ bool operator==(const TSlice &that) const { - assert(this); return Start == that.Start && Limit == that.Limit; } /* Returns true iff. this slice is not the same as that one. */ bool operator!=(const TSlice &that) const { - assert(this); return Start != that.Start || Limit != that.Limit; } /* Converts a slice based on a non-char sequence into a slice of a char sequence. */ TSlice AsByteSlice(size_t seq_size, size_t elem_size) const { - assert(this); size_t start, limit; GetAbsPair(seq_size / elem_size, start, limit); start *= elem_size; @@ -85,7 +82,6 @@ namespace Base { /* Returns true iff. this slice is valid when applied to a sequence of the given size. */ bool CanGetAbsPair(size_t size) const { - assert(this); size_t dummy1, dummy2; return TryGetAbsPair(size, dummy1, dummy2); } @@ -94,7 +90,6 @@ namespace Base { given size specified by this slice. The size must be large enough to accomodate the slice. */ void GetAbsPair(size_t size, size_t &start, size_t &limit) const { - assert(this); bool success = TryGetAbsPair(size, start, limit); assert(success); } @@ -105,7 +100,6 @@ namespace Base { position. You'll need to use same variation on GetAbsPair() for that. */ bool IsPos() const { - assert(this); return Start == Limit; } @@ -115,7 +109,6 @@ namespace Base { otherwise, this function leaves the out-parameters alone and the returns false. */ bool TryGetAbsPair(size_t size, size_t &start, size_t &limit) const { - assert(this); ptrdiff_t start_offset = Start.GetAbsOffset(size), limit_offset = Limit.GetAbsOffset(size); bool success = @@ -133,7 +126,6 @@ namespace Base { /* The default (everything) slice. */ TSlice &Reset() { - assert(this); Start = *TPos::Start; Limit = *TPos::Limit; return *this; @@ -141,7 +133,6 @@ namespace Base { /* Swap this slice with that one. */ TSlice &Swap(TSlice &that) { - assert(this); std::swap(Start, that.Start); std::swap(Limit, that.Limit); return *this; diff --git a/src/base/spin_lock.h b/src/base/spin_lock.h index ccd20bfd..bb38bc1c 100644 --- a/src/base/spin_lock.h +++ b/src/base/spin_lock.h @@ -43,7 +43,6 @@ namespace Base { } ~TLock() { - assert(this); SpinLock.Lock.clear(std::memory_order_release); } @@ -69,7 +68,6 @@ namespace Base { } ~TSoftLock() { - assert(this); SpinLock.Lock.clear(std::memory_order_release); } diff --git a/src/base/stream_msg_reader.cc b/src/base/stream_msg_reader.cc index ad70ee04..42a05008 100644 --- a/src/base/stream_msg_reader.cc +++ b/src/base/stream_msg_reader.cc @@ -33,7 +33,6 @@ using namespace Base; TStreamMsgReader::TState TStreamMsgReader::Read() { - assert(this); const size_t read_size = PrepareForRead(); /* In case we get a read size of 0, return here so we don't get a return @@ -49,8 +48,6 @@ TStreamMsgReader::TState TStreamMsgReader::Read() { } TStreamMsgReader::TState TStreamMsgReader::ConsumeReadyMsg() noexcept { - assert(this); - if (Impl.State != TState::MsgReady) { Die("Invalid call to TStreamMsgReader::ConsumeReadyMsg()"); } @@ -73,7 +70,6 @@ TStreamMsgReader::TState TStreamMsgReader::ConsumeReadyMsg() noexcept { } const uint8_t *TStreamMsgReader::GetReadyMsg() const noexcept { - assert(this); static const uint8_t empty_data = 0; /* We use a lot of defensive programming below to prevent buggy code from @@ -110,14 +106,11 @@ const uint8_t *TStreamMsgReader::GetReadyMsg() const noexcept { } const uint8_t *TStreamMsgReader::GetData() const noexcept { - assert(this); static const uint8_t empty_data = 0; return Impl.Buf.DataIsEmpty() ? &empty_data : Impl.Buf.Data(); } void TStreamMsgReader::Reset(int fd) noexcept { - assert(this); - /* Give subclass code a chance to reset its state before we reset ours. */ Impl.RestrictReadyMsgCalls = true; HandleReset(); @@ -132,7 +125,6 @@ TStreamMsgReader::TStreamMsgReader(int fd) } TStreamMsgReader::TState TStreamMsgReader::TryAdvanceToNextMsg() noexcept { - assert(this); Impl.RestrictReadyMsgCalls = true; TGetMsgResult result = GetNextMsg(); Impl.RestrictReadyMsgCalls = false; @@ -170,8 +162,6 @@ TStreamMsgReader::TState TStreamMsgReader::TryAdvanceToNextMsg() noexcept { } size_t TStreamMsgReader::PrepareForRead() { - assert(this); - if (Impl.State != TState::ReadNeeded) { Die("Invalid call to TStreamMsgReader::Read()"); } @@ -187,8 +177,6 @@ size_t TStreamMsgReader::PrepareForRead() { TStreamMsgReader::TState TStreamMsgReader::ProcessReadResult( ssize_t read_result) { - assert(this); - if (read_result < 0) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wlogical-op" diff --git a/src/base/stream_msg_reader.h b/src/base/stream_msg_reader.h index f11469f7..11b29d1d 100644 --- a/src/base/stream_msg_reader.h +++ b/src/base/stream_msg_reader.h @@ -79,7 +79,6 @@ namespace Base { handling strategy. */ template TState Read(TReadFn read_fn) noexcept(noexcept(read_fn(0, nullptr, 0))) { - assert(this); const size_t read_size = PrepareForRead(); /* In case we get a read size of 0, return here so we don't get a return @@ -97,7 +96,6 @@ namespace Base { /* Returns current state of reader. */ TState GetState() const noexcept { - assert(this); return Impl.State; } @@ -111,7 +109,6 @@ namespace Base { message. Must not be called from within any subclass-implemented method except BeforeConsumeReadyMsg(). */ size_t GetReadyMsgSize() const noexcept { - assert(this); assert(Impl.State == TState::MsgReady); assert(!Impl.RestrictReadyMsgCalls); assert(Impl.Fd >= 0); @@ -144,14 +141,12 @@ namespace Base { multiple messages along with extra data such as size fields or message terminators. */ size_t GetDataSize() const noexcept { - assert(this); return Impl.Buf.DataSize(); } /* Returns the file descriptor that the reader is reading from, or -1 if it currently has no associated file descriptor. */ int GetFd() const noexcept { - assert(this); return Impl.Fd; } @@ -165,7 +160,6 @@ namespace Base { constructor. Specifically, no file descriptor is associated with the reader. */ void Reset() noexcept { - assert(this); Reset(-1); } @@ -245,7 +239,6 @@ namespace Base { /* GetNextMsg() may call this to determine whether the end of input has been reached. */ bool AtEndOfInput() const noexcept { - assert(this); return Impl.EndOfInput; } @@ -254,7 +247,6 @@ namespace Base { (GetReadyMsg() - GetData()). Must not be called from within any subclass-implemented method except BeforeConsumeReadyMsg(). */ size_t GetReadyMsgOffset() const noexcept { - assert(this); assert(Impl.State == TState::MsgReady); assert(!Impl.RestrictReadyMsgCalls); assert(Impl.Fd >= 0); diff --git a/src/base/stream_msg_reader.test.cc b/src/base/stream_msg_reader.test.cc index afe2b953..6a0c5621 100644 --- a/src/base/stream_msg_reader.test.cc +++ b/src/base/stream_msg_reader.test.cc @@ -110,25 +110,21 @@ namespace { }; // TTestReader size_t TTestReader::GetNextReadSize() noexcept { - assert(this); TakeStateSnapshot(OnGetNextReadSize); return GetNextReadSizeReturnValue; } TStreamMsgReader::TGetMsgResult TTestReader::GetNextMsg() noexcept { - assert(this); TakeStateSnapshot(OnGetNextMsg); return *GetNextMsgReturnValue; } void TTestReader::HandleReset() noexcept { - assert(this); TakeStateSnapshot(OnHandleReset); } void TTestReader::BeforeConsumeReadyMsg() noexcept { - assert(this); TakeStateSnapshot(OnBeforeConsumeReadyMsg); size_t size = GetReadyMsgSize(); @@ -143,7 +139,6 @@ namespace { } void TTestReader::TakeStateSnapshot(TStateSnapshot &snapshot) noexcept { - assert(this); snapshot.State = GetState(); size_t size = GetDataSize(); @@ -166,20 +161,17 @@ namespace { void TTestReader::SetMsgReady(size_t offset, size_t size, size_t trailing_data_size) { - assert(this); GetNextMsgReturnValue.Reset(); GetNextMsgReturnValue.MakeKnown(TGetMsgResult::MsgReady(offset, size, trailing_data_size)); } void TTestReader::SetNoMsgReady() { - assert(this); GetNextMsgReturnValue.Reset(); GetNextMsgReturnValue.MakeKnown(TGetMsgResult::NoMsgReady()); } void TTestReader::SetInvalid() { - assert(this); GetNextMsgReturnValue.Reset(); GetNextMsgReturnValue.MakeKnown(TGetMsgResult::Invalid()); } @@ -195,8 +187,6 @@ namespace { } void CloseRead() { - assert(this); - if (Read >= 0) { close(Read); Read = -1; @@ -204,8 +194,6 @@ namespace { } void CloseWrite() { - assert(this); - if (Write >= 0) { close(Write); Write = -1; diff --git a/src/base/stream_msg_with_size_reader.cc b/src/base/stream_msg_with_size_reader.cc index 162d7b90..4671d51b 100644 --- a/src/base/stream_msg_with_size_reader.cc +++ b/src/base/stream_msg_with_size_reader.cc @@ -99,13 +99,11 @@ TStreamMsgWithSizeReaderBase::TStreamMsgWithSizeReaderBase( } size_t TStreamMsgWithSizeReaderBase::GetNextReadSize() noexcept { - assert(this); return PreferredReadSize; } TStreamMsgReader::TGetMsgResult TStreamMsgWithSizeReaderBase::GetNextMsg() noexcept { - assert(this); size_t data_size = GetDataSize(); if (data_size < SizeFieldSize) { @@ -159,13 +157,11 @@ TStreamMsgWithSizeReaderBase::GetNextMsg() noexcept { } void TStreamMsgWithSizeReaderBase::HandleReset() noexcept { - assert(this); OptMsgBodySize.Reset(); OptDataInvalidReason.Reset(); } void TStreamMsgWithSizeReaderBase::BeforeConsumeReadyMsg() noexcept { - assert(this); OptMsgBodySize.Reset(); } diff --git a/src/base/stream_msg_with_size_reader.h b/src/base/stream_msg_with_size_reader.h index ddcbdd6f..b85ff586 100644 --- a/src/base/stream_msg_with_size_reader.h +++ b/src/base/stream_msg_with_size_reader.h @@ -77,47 +77,38 @@ namespace Base { }; // TDataInvalidReason size_t GetSizeFieldSize() const noexcept { - assert(this); return SizeFieldSize; } bool GetSizeFieldIsSigned() const noexcept { - assert(this); return SizeFieldIsSigned; } bool GetSizeIncludesSizeField() const noexcept { - assert(this); return SizeIncludesSizeField; } bool GetIncludeSizeFieldInMsg() const noexcept { - assert(this); return IncludeSizeFieldInMsg; } size_t GetMaxMsgBodySize() const noexcept { - assert(this); return MaxMsgBodySize; } void SetMaxMsgBodySize(size_t size) noexcept { - assert(this); MaxMsgBodySize = size; } size_t GetPreferredReadSize() const noexcept { - assert(this); return PreferredReadSize; } void SetPreferredReadSize(size_t size) noexcept { - assert(this); PreferredReadSize = size; } TOpt GetDataInvalidReason() const noexcept { - assert(this); return OptDataInvalidReason; } diff --git a/src/base/stream_msg_with_size_reader.test.cc b/src/base/stream_msg_with_size_reader.test.cc index 3fb92be4..898a0443 100644 --- a/src/base/stream_msg_with_size_reader.test.cc +++ b/src/base/stream_msg_with_size_reader.test.cc @@ -49,8 +49,6 @@ namespace { } void CloseRead() { - assert(this); - if (Read >= 0) { Wr::close(Read); Read = -1; @@ -58,8 +56,6 @@ namespace { } void CloseWrite() { - assert(this); - if (Write >= 0) { Wr::close(Write); Write = -1; diff --git a/src/base/thread_safe_rate_limiter.h b/src/base/thread_safe_rate_limiter.h index b063b665..9017ffa2 100644 --- a/src/base/thread_safe_rate_limiter.h +++ b/src/base/thread_safe_rate_limiter.h @@ -42,7 +42,6 @@ namespace Base { } bool Test() noexcept { - assert(this); std::lock_guard lock(Mutex); return Limiter.Test(); } diff --git a/src/base/thrower.h b/src/base/thrower.h index 46e91922..bc08bc4a 100644 --- a/src/base/thrower.h +++ b/src/base/thrower.h @@ -86,7 +86,6 @@ namespace Base { /* Boom goes the dynamite. */ [[ noreturn ]] ~TThrower() noexcept(false) { - assert(this); throw TError(Strm.str().c_str()); } @@ -95,8 +94,6 @@ namespace Base { delimiter before the value. */ template void Write(const TVal &val) { - assert(this); - if (AtEndOfPart) { Strm << PartDelimiter; AtEndOfPart = false; @@ -109,7 +106,6 @@ namespace Base { This doesn't actually add anything to the message, it just marks the position as being the end of a part. */ void Write(const TEndOfPart &) { - assert(this); AtEndOfPart = true; } @@ -139,7 +135,6 @@ namespace Base { template Base::TThrower &&operator<<(Base::TThrower &&thrower, const TVal &val) { - assert(&thrower); thrower.Write(val); return std::move(thrower); } diff --git a/src/base/timer_fd.cc b/src/base/timer_fd.cc index a3660658..073cd090 100644 --- a/src/base/timer_fd.cc +++ b/src/base/timer_fd.cc @@ -45,7 +45,6 @@ TTimerFd::TTimerFd(size_t milliseconds) noexcept } uint64_t TTimerFd::Pop() { - assert(this); uint64_t count = 0; IfLt0(Wr::read(Wr::TDisp::Nonfatal, {EINTR}, Fd, &count, sizeof(count))); return count; diff --git a/src/base/timer_fd.h b/src/base/timer_fd.h index 1138bceb..942299d6 100644 --- a/src/base/timer_fd.h +++ b/src/base/timer_fd.h @@ -38,7 +38,6 @@ namespace Base { explicit TTimerFd(size_t milliseconds) noexcept; const TFd &GetFd() const { - assert(this); return Fd; } diff --git a/src/base/tmp_dir.h b/src/base/tmp_dir.h index 282cf08d..3dbc6240 100644 --- a/src/base/tmp_dir.h +++ b/src/base/tmp_dir.h @@ -38,12 +38,10 @@ namespace Base { ~TTmpDir(); const std::string &GetName() const noexcept { - assert(this); return Name; } void SetDeleteOnDestroy(bool delete_on_destroy) noexcept { - assert(this); DeleteOnDestroy = delete_on_destroy; } diff --git a/src/base/tmp_file.cc b/src/base/tmp_file.cc index 62dd5b54..279ff7e0 100644 --- a/src/base/tmp_file.cc +++ b/src/base/tmp_file.cc @@ -97,8 +97,6 @@ void TTmpFile::Reset() noexcept { } TTmpFile &TTmpFile::operator=(TTmpFile &&that) noexcept { - assert(this); - if (&that != this) { Reset(); Name = std::move(that.Name); @@ -113,7 +111,6 @@ TTmpFile &TTmpFile::operator=(TTmpFile &&that) noexcept { } void TTmpFile::Swap(TTmpFile &that) noexcept { - assert(this); Name.swap(that.Name); std::swap(DeleteOnDestroy, that.DeleteOnDestroy); Fd.Swap(that.Fd); diff --git a/src/base/tmp_file.h b/src/base/tmp_file.h index e31ac9b2..b4e19f0b 100644 --- a/src/base/tmp_file.h +++ b/src/base/tmp_file.h @@ -47,7 +47,6 @@ namespace Base { ~TTmpFile(); bool IsEmpty() const noexcept { - assert(this); return Name.empty(); } @@ -62,22 +61,18 @@ namespace Base { void Swap(TTmpFile &that) noexcept; const std::string &GetName() const { - assert(this); return Name; } const TFd &GetFd() const { - assert(this); return Fd; } bool GetDeleteOnDestroy() const noexcept { - assert(this); return DeleteOnDestroy; } void SetDeleteOnDestroy(bool delete_on_destroy) { - assert(this); DeleteOnDestroy = delete_on_destroy; } diff --git a/src/base/to_integer.h b/src/base/to_integer.h index e2e80593..c32312b7 100644 --- a/src/base/to_integer.h +++ b/src/base/to_integer.h @@ -86,12 +86,10 @@ namespace Base { TWrongBase(TBase found, unsigned int allowed); TBase GetFound() const noexcept { - assert(this); return Found; } unsigned int GetAllowed() const noexcept { - assert(this); return Allowed; } diff --git a/src/capped/blob.cc b/src/capped/blob.cc index a63fd280..14fb43ec 100644 --- a/src/capped/blob.cc +++ b/src/capped/blob.cc @@ -24,8 +24,6 @@ using namespace Capped; size_t TBlob::DoGetDataInFirstBlock(char *&data) const noexcept { - assert(this); - if (FirstBlock == nullptr) { data = nullptr; return 0; diff --git a/src/capped/blob.h b/src/capped/blob.h index feb3295b..3579d102 100644 --- a/src/capped/blob.h +++ b/src/capped/blob.h @@ -51,8 +51,6 @@ namespace Capped { /* Return our blocks to the pool, if we have any. */ ~TBlob() { - assert(this); - if (Pool) { Pool->FreeList(FirstBlock); } @@ -60,7 +58,6 @@ namespace Capped { /* Move the data from that blob into this one, leaving that blob empty. */ TBlob &operator=(TBlob &&that) noexcept { - assert(this); TBlob temp(std::move(*this)); return Swap(that); } @@ -71,20 +68,17 @@ namespace Capped { /* Return the number of bytes in a (full) block. All blocks except for possibly the last block are full. */ size_t GetBlockSize() const noexcept { - assert(this); assert(Pool); return Pool->GetDataSize(); } /* True iff. this blob is non-empty. */ operator bool() const noexcept { - assert(this); return FirstBlock; } /* Return the total size in bytes of the data contained. */ size_t Size() const noexcept { - assert(this); return NumBytes; } @@ -92,7 +86,6 @@ namespace Capped { first block, or will be set to nullptr if blob is empty. Returned value is size in bytes of first block, or 0 if blob is empty. */ size_t GetDataInFirstBlock(const char *&data) const noexcept { - assert(this); char *block_data = nullptr; size_t ret = DoGetDataInFirstBlock(block_data); data = block_data; @@ -103,7 +96,6 @@ namespace Capped { first block, or will be set to nullptr if blob is empty. Returned value is size in bytes of first block, or 0 if blob is empty. */ size_t GetDataInFirstBlock(char *&data) noexcept { - assert(this); return DoGetDataInFirstBlock(data); } @@ -112,7 +104,6 @@ namespace Capped { template bool ForEachBlock(bool (*cb)(const void *, size_t, TContext), TContext context) const { - assert(this); assert(cb); for (TBlock *block = FirstBlock; block; block = block->NextBlock) { @@ -128,7 +119,6 @@ namespace Capped { /* Return this blob to the default-constructed state; that is, empty, but still connected to the buffer pool. */ TBlob &Reset() noexcept { - assert(this); TBlob temp(std::move(*this)); return *this; } @@ -137,7 +127,6 @@ namespace Capped { one). The two blobs can be connected to different pools; those connections are swapped, too. */ TBlob &Swap(TBlob &that) noexcept { - assert(this); std::swap(Pool, that.Pool); std::swap(FirstBlock, that.FirstBlock); std::swap(LastBlockSize, that.LastBlockSize); diff --git a/src/capped/pool.cc b/src/capped/pool.cc index 2a1e90fc..6b55751d 100644 --- a/src/capped/pool.cc +++ b/src/capped/pool.cc @@ -43,12 +43,10 @@ TPool::TPool(size_t block_size, size_t block_count, TSync sync_policy) } TPool::~TPool() { - assert(this); delete [] Storage; } void *TPool::Alloc() { - assert(this); TOpt> opt_lock; if (Guarded) { @@ -65,7 +63,6 @@ void *TPool::Alloc() { } TPool::TBlock *TPool::AllocList(size_t block_count) { - assert(this); TBlock *first_block = nullptr; if (block_count) { @@ -92,8 +89,6 @@ TPool::TBlock *TPool::AllocList(size_t block_count) { } void TPool::Free(void *ptr) noexcept { - assert(this); - if (ptr) { TOpt> opt_lock; @@ -106,8 +101,6 @@ void TPool::Free(void *ptr) noexcept { } void TPool::FreeList(TBlock *first_block) noexcept { - assert(this); - if (first_block == nullptr) { return; } @@ -122,7 +115,6 @@ void TPool::FreeList(TBlock *first_block) noexcept { } void TPool::DoFree(void *ptr) noexcept { - assert(this); assert(ptr); assert(Storage <= ptr); assert(ptr < Storage + BlockSize * BlockCount); @@ -130,7 +122,6 @@ void TPool::DoFree(void *ptr) noexcept { } void TPool::DoFreeList(TBlock *first_block) noexcept { - assert(this); assert(first_block); do { diff --git a/src/capped/pool.h b/src/capped/pool.h index a76e12f1..6b53d9ab 100644 --- a/src/capped/pool.h +++ b/src/capped/pool.h @@ -52,7 +52,6 @@ namespace Capped { /* Link this block to the head of the given list. The previous linkage of this block is ignored and overwritten. */ void Link(TBlock *&first_block) noexcept { - assert(this); NextBlock = first_block; first_block = this; } @@ -110,19 +109,16 @@ namespace Capped { /* The size of the data field in each block. */ size_t GetDataSize() const noexcept { - assert(this); return BlockSize - GetBlockOverhead();; } /* The number of blocks in the whole pool, free and allocated. */ size_t GetBlockCount() const noexcept { - assert(this); return BlockCount; } /* The size of each block, in bytes. */ size_t GetBlockSize() const noexcept { - assert(this); return BlockSize; } diff --git a/src/capped/reader.cc b/src/capped/reader.cc index 20bf8569..640e26fc 100644 --- a/src/capped/reader.cc +++ b/src/capped/reader.cc @@ -30,8 +30,6 @@ using namespace Base; using namespace Capped; TReader &TReader::Advance(void *data, size_t size) { - assert(this); - /* Getting the block size will fail in the case where the blob is empty, so we first protect ourselves. */ diff --git a/src/capped/reader.h b/src/capped/reader.h index d7894d0d..9f2f2e90 100644 --- a/src/capped/reader.h +++ b/src/capped/reader.h @@ -56,7 +56,6 @@ namespace Capped { /* True iff. we have not yet reached the end of the blob. */ operator bool() const noexcept { - assert(this); assert((Cursor == nullptr) == (BytesRemaining == 0)); return Cursor; } @@ -65,7 +64,6 @@ namespace Capped { read past the end of the blob, this function throws TMemoryCapReached. Note that a read of zero bytes is always safe. */ TReader &Read(void *data, size_t size) { - assert(this); assert(data || (size == 0)); return Advance(data, size); } @@ -73,17 +71,14 @@ namespace Capped { /* Same as Read(), except data is skipped over rather than copied to caller-supplied buffer. */ TReader &Skip(size_t size) { - assert(this); return Advance(nullptr, size); } size_t GetBytesRemaining() const noexcept { - assert(this); return BytesRemaining; } size_t GetBytesConsumed() const noexcept { - assert(this); size_t total = Blob->Size(); assert(BytesRemaining <= total); return total - BytesRemaining; diff --git a/src/capped/writer.cc b/src/capped/writer.cc index 4a129a75..5f32683f 100644 --- a/src/capped/writer.cc +++ b/src/capped/writer.cc @@ -33,18 +33,15 @@ TWriter::TWriter(TPool *pool) noexcept } TWriter::~TWriter() { - assert(this); CancelBlob(); } void TWriter::CancelBlob() noexcept { - assert(this); Pool->FreeList(FirstBlock); Init(); } TBlob TWriter::DraftBlob() noexcept { - assert(this); TBlob result; if (FirstBlock) { @@ -56,7 +53,6 @@ TBlob TWriter::DraftBlob() noexcept { } TWriter &TWriter::Write(const void *data, size_t size) { - assert(this); assert(data || !size); /* Determine if we need to allocate more blocks and, if so, where we'll link them on to our list. */ @@ -115,7 +111,6 @@ TWriter &TWriter::Write(const void *data, size_t size) { } void TWriter::Init() noexcept { - assert(this); FirstBlock = nullptr; LastBlock = nullptr; Cursor = nullptr; diff --git a/src/dory/anomaly_tracker.cc b/src/dory/anomaly_tracker.cc index 52f1317c..120412e4 100644 --- a/src/dory/anomaly_tracker.cc +++ b/src/dory/anomaly_tracker.cc @@ -72,7 +72,6 @@ size_t TAnomalyTracker::GetNoDiscardQueryCount() { } void TAnomalyTracker::TrackDiscard(TMsg &msg, TDiscardReason reason) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogDiscard(msg, reason); const std::string &msg_topic = msg.GetTopic(); @@ -97,7 +96,6 @@ void TAnomalyTracker::TrackDiscard(TMsg &msg, TDiscardReason reason) { } void TAnomalyTracker::TrackDuplicate(const TMsg &msg) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogDuplicate(msg); std::string topic(msg.GetTopic()); @@ -111,7 +109,6 @@ void TAnomalyTracker::TrackDuplicate(const TMsg &msg) { void TAnomalyTracker::TrackNoMemDiscard(TMsg::TTimestamp timestamp, const char *topic_begin, const char *topic_end, const void *key_begin, const void *key_end, const void *value_begin, const void *value_end) { - assert(this); assert(topic_begin); assert(topic_end >= topic_begin); assert(key_begin || (key_end == key_begin)); @@ -130,7 +127,6 @@ void TAnomalyTracker::TrackNoMemDiscard(TMsg::TTimestamp timestamp, void TAnomalyTracker::TrackMalformedMsgDiscard(const void *prefix_begin, const void *prefix_end) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogMalformedMsgDiscard(prefix_begin, prefix_end); prefix_end = EnforceMaxPrefixLen(prefix_begin, prefix_end); @@ -146,7 +142,6 @@ void TAnomalyTracker::TrackMalformedMsgDiscard(const void *prefix_begin, void TAnomalyTracker::TrackStreamClientUncleanDisconnect(bool is_tcp, const void *prefix_begin, const void *prefix_end) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogUncleanDisconnectMsgDiscard(is_tcp, prefix_begin, prefix_end); @@ -171,7 +166,6 @@ void TAnomalyTracker::TrackStreamClientUncleanDisconnect(bool is_tcp, void TAnomalyTracker::TrackUnsupportedApiKeyDiscard( const void *prefix_begin, const void *prefix_end, int api_key) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogUnsupportedApiKeyDiscard(prefix_begin, prefix_end, api_key); @@ -183,7 +177,6 @@ void TAnomalyTracker::TrackUnsupportedApiKeyDiscard( void TAnomalyTracker::TrackUnsupportedMsgVersionDiscard( const void *prefix_begin, const void *prefix_end, int version) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogUnsupportedMsgVersionDiscard(prefix_begin, prefix_end, version); @@ -202,7 +195,6 @@ void TAnomalyTracker::TrackUnsupportedMsgVersionDiscard( void TAnomalyTracker::TrackBadTopicDiscard(TMsg::TTimestamp timestamp, const char *topic_begin, const char *topic_end, const void *key_begin, const void *key_end, const void *value_begin, const void *value_end) { - assert(this); assert(topic_begin); assert(topic_end >= topic_begin); assert(key_begin || (key_end == key_begin)); @@ -221,7 +213,6 @@ void TAnomalyTracker::TrackBadTopicDiscard(TMsg::TTimestamp timestamp, } void TAnomalyTracker::TrackBadTopicDiscard(TMsg &msg) { - assert(this); uint64_t now = ClockFn(); DiscardFileLogger.LogBadTopicDiscard(msg); std::string topic(msg.GetTopic()); @@ -233,8 +224,6 @@ void TAnomalyTracker::TrackBadTopicDiscard(TMsg &msg) { } void TAnomalyTracker::TrackLongMsgDiscard(TMsg &msg) { - assert(this); - std::string topic(msg.GetTopic()); size_t value_size = msg.GetValueSize(); std::vector tmp_buf(topic.size() + 1 + value_size); @@ -263,7 +252,6 @@ void TAnomalyTracker::TrackLongMsgDiscard(TMsg &msg) { std::shared_ptr TAnomalyTracker::GetInfo(TInfo &filling_report_copy) const { - assert(this); uint64_t now = ClockFn(); LastGetInfoTime.store(now); @@ -274,7 +262,6 @@ TAnomalyTracker::GetInfo(TInfo &filling_report_copy) const { } void TAnomalyTracker::CheckGetInfoRate() const { - assert(this); uint64_t now = ClockFn(); uint64_t last_get_info_time = LastGetInfoTime.load(); @@ -291,7 +278,6 @@ void TAnomalyTracker::CheckGetInfoRate() const { const uint8_t *TAnomalyTracker::EnforceMaxPrefixLen(const void *msg_begin, const void *msg_end) { - assert(this); assert(msg_end >= msg_begin); const auto *begin = reinterpret_cast(msg_begin); const auto *end = reinterpret_cast(msg_end); @@ -300,7 +286,6 @@ const uint8_t *TAnomalyTracker::EnforceMaxPrefixLen(const void *msg_begin, } void TAnomalyTracker::AdvanceReportPeriod(uint64_t now) const { - assert(this); assert(FillingReport); assert((FillingReport->GetReportId() == 0) || LastFullReport); @@ -355,7 +340,6 @@ void TAnomalyTracker::AdvanceReportPeriod(uint64_t now) const { void TAnomalyTracker::UpdateTopicMap(TMap &topic_map, std::string &&topic, TMsg::TTimestamp timestamp) { - assert(this); auto result = topic_map.insert( std::make_pair(std::move(topic), TTopicInfo(timestamp))); diff --git a/src/dory/anomaly_tracker.h b/src/dory/anomaly_tracker.h index 3abce7eb..16cfe844 100644 --- a/src/dory/anomaly_tracker.h +++ b/src/dory/anomaly_tracker.h @@ -125,12 +125,10 @@ namespace Dory { public: size_t GetReportId() const { - assert(this); return ReportId; } uint64_t GetStartTime() const { - assert(this); return StartTime; } @@ -229,7 +227,6 @@ namespace Dory { /* Same as above, except the message is passed by smart pointer. */ void TrackDiscard(const TMsg::TPtr &msg_ptr, TDiscardReason reason) { - assert(this); TrackDiscard(*msg_ptr, reason); } @@ -240,7 +237,6 @@ namespace Dory { /* Same as above, except the message is passed by smart pointer. */ void TrackDuplicate(const TMsg::TPtr &msg_ptr) { - assert(this); TrackDuplicate(*msg_ptr); } @@ -290,7 +286,6 @@ namespace Dory { /* Same as above, but takes TMsg::TPtr as parameter. */ void TrackBadTopicDiscard(const TMsg::TPtr &msg_ptr) { - assert(this); TrackBadTopicDiscard(*msg_ptr); } @@ -300,7 +295,6 @@ namespace Dory { /* Same as above, except the message is passed by smart pointer. */ void TrackLongMsgDiscard(const TMsg::TPtr &msg_ptr) { - assert(this); TrackLongMsgDiscard(*msg_ptr); } @@ -319,7 +313,6 @@ namespace Dory { /* Return the reporting interval length in seconds. */ size_t GetReportInterval() const { - assert(this); return ReportInterval; } diff --git a/src/dory/anomaly_tracker.test.cc b/src/dory/anomaly_tracker.test.cc index 81689223..ce1da972 100644 --- a/src/dory/anomaly_tracker.test.cc +++ b/src/dory/anomaly_tracker.test.cc @@ -65,13 +65,10 @@ namespace { TMockClock(const TMockClock &) = default; uint64_t operator()() const { - assert(this); return *ValueStore; } TMockClock &operator=(const TMockClock &that) { - assert(this); - if (this != &that) { *ValueStore = *that.ValueStore; } @@ -80,7 +77,6 @@ namespace { } TMockClock &operator=(uint64_t timestamp) { - assert(this); *ValueStore = timestamp; return *this; } diff --git a/src/dory/batch/batch_config.h b/src/dory/batch/batch_config.h index 05d64a25..fb7ba213 100644 --- a/src/dory/batch/batch_config.h +++ b/src/dory/batch/batch_config.h @@ -43,7 +43,6 @@ namespace Dory { TBatchConfig& operator=(const TBatchConfig &) noexcept = default; void Clear() noexcept { - assert(this); *this = TBatchConfig(); } diff --git a/src/dory/batch/batch_config_builder.cc b/src/dory/batch/batch_config_builder.cc index 849c798b..11fa09dc 100644 --- a/src/dory/batch/batch_config_builder.cc +++ b/src/dory/batch/batch_config_builder.cc @@ -29,8 +29,6 @@ using namespace Dory::Conf; bool TBatchConfigBuilder::AddTopic(const std::string &topic, const TBatchConfig *config) { - assert(this); - if (PerTopicMap.find(topic) != PerTopicMap.end()) { return false; } @@ -57,8 +55,6 @@ bool TBatchConfigBuilder::AddTopic(const std::string &topic, } bool TBatchConfigBuilder::SetDefaultTopic(const TBatchConfig *config) { - assert(this); - if (DefaultTopicConfigSpecified) { return false; } @@ -70,8 +66,6 @@ bool TBatchConfigBuilder::SetDefaultTopic(const TBatchConfig *config) { } bool TBatchConfigBuilder::SetBrokerConfig(const TBatchConfig *config) { - assert(this); - if (BrokerBatchConfigSpecified) { return false; } @@ -82,8 +76,6 @@ bool TBatchConfigBuilder::SetBrokerConfig(const TBatchConfig *config) { } bool TBatchConfigBuilder::SetProduceRequestDataLimit(size_t limit) { - assert(this); - if (ProduceRequestDataLimitSpecified) { return false; } @@ -94,8 +86,6 @@ bool TBatchConfigBuilder::SetProduceRequestDataLimit(size_t limit) { } bool TBatchConfigBuilder::SetMessageMaxBytes(size_t limit) { - assert(this); - if (MessageMaxBytesSpecified) { return false; } @@ -106,7 +96,6 @@ bool TBatchConfigBuilder::SetMessageMaxBytes(size_t limit) { } TGlobalBatchConfig TBatchConfigBuilder::Build() { - assert(this); auto per_topic_config = std::make_shared( DefaultTopicConfig, std::move(PerTopicMap)); std::unordered_set topic_filter; @@ -144,7 +133,6 @@ static TBatchConfig ToBatchConfig(const TBatchConf::TBatchValues &values) { } TGlobalBatchConfig TBatchConfigBuilder::BuildFromConf(const TBatchConf &conf) { - assert(this); SetProduceRequestDataLimit(conf.ProduceRequestDataLimit); SetMessageMaxBytes(conf.MessageMaxBytes); TBatchConfig config = ToBatchConfig(conf.CombinedTopicsConfig); @@ -196,7 +184,6 @@ TGlobalBatchConfig TBatchConfigBuilder::BuildFromConf(const TBatchConf &conf) { } void TBatchConfigBuilder::Clear() { - assert(this); PerTopicMap.clear(); DefaultTopicConfigSpecified = false; DefaultTopicConfig = TBatchConfig(); diff --git a/src/dory/batch/batcher_core.cc b/src/dory/batch/batcher_core.cc index 98a0be64..2623e75c 100644 --- a/src/dory/batch/batcher_core.cc +++ b/src/dory/batch/batcher_core.cc @@ -28,8 +28,6 @@ using namespace Dory; using namespace Dory::Batch; TOpt TBatcherCore::GetNextCompleteTime() const noexcept { - assert(this); - if (IsEmpty() || !TimeLimitIsEnabled(Config)) { return TOpt(); } @@ -40,7 +38,6 @@ TOpt TBatcherCore::GetNextCompleteTime() const noexcept { TBatcherCore::TAction TBatcherCore::ProcessNewMsg(TMsg::TTimestamp now, const TMsg::TPtr &msg) noexcept { - assert(this); assert(msg); if (!Dory::Batch::BatchingIsEnabled(Config)) { @@ -81,7 +78,6 @@ TBatcherCore::ProcessNewMsg(TMsg::TTimestamp now, } void TBatcherCore::ClearState() noexcept { - assert(this); MinTimestamp = std::numeric_limits::max(); MsgCount = 0; ByteCount = 0; @@ -89,8 +85,6 @@ void TBatcherCore::ClearState() noexcept { bool TBatcherCore::TestTimeLimit(TMsg::TTimestamp now, TMsg::TTimestamp new_msg_timestamp) const noexcept { - assert(this); - if (!TimeLimitIsEnabled(Config)) { return false; } @@ -100,8 +94,6 @@ bool TBatcherCore::TestTimeLimit(TMsg::TTimestamp now, } bool TBatcherCore::TestMsgCount(bool adding_msg) const noexcept { - assert(this); - if (!MsgCountLimitIsEnabled(Config)) { return false; } @@ -111,8 +103,6 @@ bool TBatcherCore::TestMsgCount(bool adding_msg) const noexcept { } bool TBatcherCore::TestByteCount(size_t bytes_to_add) const noexcept { - assert(this); - if (!ByteCountLimitIsEnabled(Config)) { return false; } @@ -121,8 +111,6 @@ bool TBatcherCore::TestByteCount(size_t bytes_to_add) const noexcept { } bool TBatcherCore::TestByteCountExceeded(size_t bytes_to_add) const noexcept { - assert(this); - if (!ByteCountLimitIsEnabled(Config)) { return false; } @@ -132,7 +120,6 @@ bool TBatcherCore::TestByteCountExceeded(size_t bytes_to_add) const noexcept { void TBatcherCore::UpdateState(TMsg::TTimestamp timestamp, size_t body_size) noexcept { - assert(this); MinTimestamp = std::min(MinTimestamp, timestamp); ++MsgCount; ByteCount += body_size; diff --git a/src/dory/batch/batcher_core.h b/src/dory/batch/batcher_core.h index ba6b46e0..ad5cb4fa 100644 --- a/src/dory/batch/batcher_core.h +++ b/src/dory/batch/batcher_core.h @@ -53,27 +53,22 @@ namespace Dory { TBatcherCore &operator=(const TBatcherCore &) noexcept = default; bool BatchingIsEnabled() const noexcept { - assert(this); return Dory::Batch::BatchingIsEnabled(Config); } const TBatchConfig &GetConfig() const noexcept { - assert(this); return Config; } bool IsEmpty() const noexcept { - assert(this); return (MsgCount == 0); } size_t GetMsgCount() const noexcept { - assert(this); return MsgCount; } size_t GetByteCount() const noexcept { - assert(this); return ByteCount; } @@ -96,7 +91,6 @@ namespace Dory { bool TestByteCountExceeded(size_t bytes_to_add) const noexcept; bool TestAllLimits(TMsg::TTimestamp now) const noexcept { - assert(this); return TestTimeLimit(now) || TestMsgCount() || TestByteCount(); } diff --git a/src/dory/batch/combined_topics_batcher.cc b/src/dory/batch/combined_topics_batcher.cc index 39685d2d..35ed44e0 100644 --- a/src/dory/batch/combined_topics_batcher.cc +++ b/src/dory/batch/combined_topics_batcher.cc @@ -39,15 +39,12 @@ TCombinedTopicsBatcher::TCombinedTopicsBatcher(const TConfig &config) } bool TCombinedTopicsBatcher::BatchingIsEnabled() const noexcept { - assert(this); return (ExcludeTopicFilter || !TopicFilter->empty()) && CoreState.BatchingIsEnabled(); } bool TCombinedTopicsBatcher::BatchingIsEnabled( const std::string &topic) const noexcept { - assert(this); - if (!CoreState.BatchingIsEnabled()) { return false; } @@ -62,7 +59,6 @@ bool TCombinedTopicsBatcher::BatchingIsEnabled( std::list> TCombinedTopicsBatcher::AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { - assert(this); assert(msg); const std::string &topic = msg->GetTopic(); @@ -101,7 +97,6 @@ TCombinedTopicsBatcher::AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { std::list> TCombinedTopicsBatcher::TakeBatch() { - assert(this); std::list> result = TopicMap.Get(); CoreState.ClearState(); return result; diff --git a/src/dory/batch/combined_topics_batcher.h b/src/dory/batch/combined_topics_batcher.h index 5afac8b0..ca5419a2 100644 --- a/src/dory/batch/combined_topics_batcher.h +++ b/src/dory/batch/combined_topics_batcher.h @@ -91,12 +91,10 @@ namespace Dory { explicit TCombinedTopicsBatcher(const TConfig &config); TConfig GetConfig() const noexcept { - assert(this); return TConfig(CoreState.GetConfig(), TopicFilter, ExcludeTopicFilter); } bool IsEmpty() const noexcept { - assert(this); assert(CoreState.IsEmpty() == TopicMap.IsEmpty()); return CoreState.IsEmpty(); } @@ -112,7 +110,6 @@ namespace Dory { AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now); Base::TOpt GetNextCompleteTime() const noexcept { - assert(this); return CoreState.GetNextCompleteTime(); } diff --git a/src/dory/batch/global_batch_config.h b/src/dory/batch/global_batch_config.h index 0e871635..7622114d 100644 --- a/src/dory/batch/global_batch_config.h +++ b/src/dory/batch/global_batch_config.h @@ -55,29 +55,24 @@ namespace Dory { TGlobalBatchConfig &operator=(TGlobalBatchConfig &&) = default; void Clear() { - assert(this); *this = TGlobalBatchConfig(); } const std::shared_ptr & GetPerTopicConfig() const noexcept { - assert(this); return PerTopicConfig; } const TCombinedTopicsBatcher::TConfig & GetCombinedTopicsConfig() const noexcept { - assert(this); return CombinedTopicsConfig; } size_t GetProduceRequestDataLimit() const noexcept { - assert(this); return ProduceRequestDataLimit; } size_t GetMessageMaxBytes() const noexcept { - assert(this); return MessageMaxBytes; } diff --git a/src/dory/batch/per_topic_batcher.cc b/src/dory/batch/per_topic_batcher.cc index d8787de6..786e9a4b 100644 --- a/src/dory/batch/per_topic_batcher.cc +++ b/src/dory/batch/per_topic_batcher.cc @@ -41,7 +41,6 @@ TPerTopicBatcher::TPerTopicBatcher(std::shared_ptr &&config) std::list> TPerTopicBatcher::AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { - assert(this); assert(msg); const std::string &topic = msg->GetTopic(); auto iter = BatchMap.find(topic); @@ -133,7 +132,6 @@ TPerTopicBatcher::AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { std::list> TPerTopicBatcher::GetCompleteBatches(TMsg::TTimestamp now) { - assert(this); std::list> result; for (TExpiryRef iter = ExpiryTracker.begin(); @@ -168,8 +166,6 @@ TPerTopicBatcher::GetCompleteBatches(TMsg::TTimestamp now) { } TOpt TPerTopicBatcher::GetNextCompleteTime() const noexcept { - assert(this); - if (ExpiryTracker.empty()) { return TOpt(); } @@ -178,7 +174,6 @@ TOpt TPerTopicBatcher::GetNextCompleteTime() const noexcept { } std::list> TPerTopicBatcher::GetAllBatches() { - assert(this); std::list> result; std::list batch; @@ -198,7 +193,6 @@ std::list> TPerTopicBatcher::GetAllBatches() { } std::list TPerTopicBatcher::DeleteTopic(const std::string &topic) { - assert(this); auto iter = BatchMap.find(topic); if (iter == BatchMap.end()) { @@ -220,8 +214,6 @@ std::list TPerTopicBatcher::DeleteTopic(const std::string &topic) { } bool TPerTopicBatcher::SanityCheck() const { - assert(this); - for (const auto &map_item : BatchMap) { const std::string &topic = map_item.first; const TBatchMapEntry &entry = map_item.second; diff --git a/src/dory/batch/per_topic_batcher.h b/src/dory/batch/per_topic_batcher.h index 777d2adb..a1cc670c 100644 --- a/src/dory/batch/per_topic_batcher.h +++ b/src/dory/batch/per_topic_batcher.h @@ -60,7 +60,6 @@ namespace Dory { TConfig& operator=(TConfig &&) = default; const TBatchConfig &Get(const std::string &topic) const noexcept { - assert(this); auto iter = PerTopic.find(topic); return (iter == PerTopic.end()) ? DefaultTopic : iter->second; } @@ -77,12 +76,10 @@ namespace Dory { /* TODO: Eliminate need for clients to call this method. */ bool IsEnabled() const noexcept { - assert(this); return bool(Config); } const std::shared_ptr &GetConfig() const noexcept { - assert(this); return Config; } @@ -134,8 +131,6 @@ namespace Dory { } TBatchExpiryRecord &operator=(TBatchExpiryRecord &&that) noexcept { - assert(this); - if (this != &that) { Expiry = that.Expiry; Topic = std::move(that.Topic); @@ -145,17 +140,14 @@ namespace Dory { } bool operator<(const TBatchExpiryRecord &that) const noexcept { - assert(this); return (Expiry < that.Expiry); } TMsg::TTimestamp GetExpiry() const noexcept { - assert(this); return Expiry; } const std::string &GetTopic() const noexcept { - assert(this); return Topic; } diff --git a/src/dory/batch/single_topic_batcher.cc b/src/dory/batch/single_topic_batcher.cc index 32310627..70ef18b5 100644 --- a/src/dory/batch/single_topic_batcher.cc +++ b/src/dory/batch/single_topic_batcher.cc @@ -28,7 +28,6 @@ using namespace Dory::Batch; std::list TSingleTopicBatcher::DoAddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { - assert(this); assert(msg); std::list result; diff --git a/src/dory/batch/single_topic_batcher.h b/src/dory/batch/single_topic_batcher.h index 74e248f2..fd3e6a04 100644 --- a/src/dory/batch/single_topic_batcher.h +++ b/src/dory/batch/single_topic_batcher.h @@ -50,36 +50,30 @@ namespace Dory { TSingleTopicBatcher &operator=(TSingleTopicBatcher &&) = default; bool IsEmpty() const noexcept { - assert(this); return CoreState.IsEmpty(); } const TBatchConfig &GetConfig() const noexcept { - assert(this); return CoreState.GetConfig(); } bool BatchingIsEnabled() const noexcept { - assert(this); return CoreState.BatchingIsEnabled(); } std::list AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) { - assert(this); std::list result = DoAddMsg(std::move(msg), now); assert(MsgList.size() == CoreState.GetMsgCount()); return result; } Base::TOpt GetNextCompleteTime() const noexcept { - assert(this); return CoreState.GetNextCompleteTime(); } /* Empty out the batcher, and return all messages it contained. */ std::list TakeBatch() { - assert(this); CoreState.ClearState(); assert(CoreState.GetMsgCount() == 0); return std::move(MsgList); diff --git a/src/dory/client/client_sender_base.h b/src/dory/client/client_sender_base.h index d5903760..6b1f215c 100644 --- a/src/dory/client/client_sender_base.h +++ b/src/dory/client/client_sender_base.h @@ -38,17 +38,14 @@ namespace Dory { virtual ~TClientSenderBase() = default; void PrepareToSend() { - assert(this); DoPrepareToSend(); } void Send(const void *msg, size_t msg_size) { - assert(this); DoSend(reinterpret_cast(msg), msg_size); } void Reset() { - assert(this); DoReset(); } diff --git a/src/dory/client/tcp_sender.cc b/src/dory/client/tcp_sender.cc index 6eba5092..b43899fe 100644 --- a/src/dory/client/tcp_sender.cc +++ b/src/dory/client/tcp_sender.cc @@ -35,7 +35,6 @@ using namespace Dory; using namespace Dory::Client; void TTcpSender::DoPrepareToSend() { - assert(this); Sock = IfLt0(socket(AF_INET, SOCK_STREAM, 0)); struct sockaddr_in servaddr; std::memset(&servaddr, 0, sizeof(servaddr)); @@ -47,11 +46,9 @@ void TTcpSender::DoPrepareToSend() { } void TTcpSender::DoSend(const uint8_t *msg, size_t msg_size) { - assert(this); IfLt0(send(Sock, msg, msg_size, MSG_NOSIGNAL)); } void TTcpSender::DoReset() { - assert(this); Sock.Reset(); } diff --git a/src/dory/client/unix_dg_sender.cc b/src/dory/client/unix_dg_sender.cc index 622df8ef..2533e096 100644 --- a/src/dory/client/unix_dg_sender.cc +++ b/src/dory/client/unix_dg_sender.cc @@ -32,8 +32,6 @@ using namespace Dory; using namespace Dory::Client; void TUnixDgSender::DoPrepareToSend() { - assert(this); - switch (Sock.Bind(Path.c_str())) { case DORY_OK: { break; @@ -52,7 +50,6 @@ void TUnixDgSender::DoPrepareToSend() { } void TUnixDgSender::DoSend(const uint8_t *msg, size_t msg_size) { - assert(this); int ret = Sock.Send(msg, msg_size); if (ret != DORY_OK) { @@ -62,6 +59,5 @@ void TUnixDgSender::DoSend(const uint8_t *msg, size_t msg_size) { } void TUnixDgSender::DoReset() { - assert(this); Sock.Close(); } diff --git a/src/dory/client/unix_stream_sender.cc b/src/dory/client/unix_stream_sender.cc index 9b944c38..3f781ef6 100644 --- a/src/dory/client/unix_stream_sender.cc +++ b/src/dory/client/unix_stream_sender.cc @@ -36,7 +36,6 @@ using namespace Dory; using namespace Dory::Client; void TUnixStreamSender::DoPrepareToSend() { - assert(this); Sock = IfLt0(socket(AF_LOCAL, SOCK_STREAM, 0)); struct sockaddr_un servaddr; std::memset(&servaddr, 0, sizeof(servaddr)); @@ -53,11 +52,9 @@ void TUnixStreamSender::DoPrepareToSend() { } void TUnixStreamSender::DoSend(const uint8_t *msg, size_t msg_size) { - assert(this); IfLt0(send(Sock, msg, msg_size, MSG_NOSIGNAL)); } void TUnixStreamSender::DoReset() { - assert(this); Sock.Reset(); } diff --git a/src/dory/compress/compression_codec_api.cc b/src/dory/compress/compression_codec_api.cc index 8a695b7b..60c85d15 100644 --- a/src/dory/compress/compression_codec_api.cc +++ b/src/dory/compress/compression_codec_api.cc @@ -27,7 +27,6 @@ using namespace Dory::Compress; int TCompressionCodecApi::CompressionLevelParam( const TOpt &requested_level) const noexcept { - assert(this); auto real_level = GetRealCompressionLevel(requested_level); return (real_level.IsKnown()) ? *real_level : 0; } diff --git a/src/dory/compress/compression_codec_api.h b/src/dory/compress/compression_codec_api.h index aeace2ec..a70700f6 100644 --- a/src/dory/compress/compression_codec_api.h +++ b/src/dory/compress/compression_codec_api.h @@ -73,7 +73,6 @@ namespace Dory { /* Return true if the algorithm supports compression levels, or false otherwise. */ bool SupportsCompressionLevels() const noexcept { - assert(this); return GetRealCompressionLevel(Base::TOpt()).IsKnown(); } @@ -84,7 +83,6 @@ namespace Dory { size_t ComputeCompressedResultBufSpace(const void *uncompressed_data, size_t uncompressed_size, const Base::TOpt &compression_level) const { - assert(this); return DoComputeCompressedResultBufSpace(uncompressed_data, uncompressed_size, CompressionLevelParam(compression_level)); } @@ -99,7 +97,6 @@ namespace Dory { virtual size_t Compress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size, const Base::TOpt &compression_level) const { - assert(this); return DoCompress(input_buf, input_buf_size, output_buf, output_buf_size, CompressionLevelParam(compression_level)); } diff --git a/src/dory/compress/gzip/gzip_codec.cc b/src/dory/compress/gzip/gzip_codec.cc index b5cb7988..c20c7059 100644 --- a/src/dory/compress/gzip/gzip_codec.cc +++ b/src/dory/compress/gzip/gzip_codec.cc @@ -136,8 +136,6 @@ static const int MAX_LEVEL = Z_BEST_COMPRESSION; TOpt TGzipCodec::GetRealCompressionLevel( const TOpt &requested_level) const noexcept { - assert(this); - if (requested_level.IsUnknown()) { return TOpt(DEFAULT_LEVEL); } @@ -210,7 +208,6 @@ static size_t DoUncompress(const void *compressed_data, size_t compressed_size, size_t TGzipCodec::ComputeUncompressedResultBufSpace( const void *compressed_data, size_t compressed_size) const { - assert(this); uint8_t discard_buf[512]; return DoUncompress(compressed_data, compressed_size, discard_buf, sizeof(discard_buf), false); @@ -218,7 +215,6 @@ size_t TGzipCodec::ComputeUncompressedResultBufSpace( size_t TGzipCodec::Uncompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size) const { - assert(this); return DoUncompress(input_buf, input_buf_size, output_buf, output_buf_size, true); } @@ -241,7 +237,6 @@ namespace { } size_t ComputeCompressedResultBufSpace(size_t uncompressed_size) { - assert(this); uLong max_size = deflateBound(&Strm, uncompressed_size); auto result = static_cast(max_size); @@ -263,7 +258,6 @@ namespace { size_t TGzipCodec::DoComputeCompressedResultBufSpace( const void * /*uncompressed_data*/, size_t uncompressed_size, int compression_level) const { - assert(this); z_stream strm; return TDeflateInitializer(strm, compression_level) .ComputeCompressedResultBufSpace(uncompressed_size); @@ -272,7 +266,6 @@ size_t TGzipCodec::DoComputeCompressedResultBufSpace( size_t TGzipCodec::DoCompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size, int compression_level) const { - assert(this); z_stream strm; TDeflateInitializer init(strm, compression_level); size_t min_result_size = diff --git a/src/dory/compress/lz4/lz4_codec.cc b/src/dory/compress/lz4/lz4_codec.cc index 5a33241f..8a224420 100644 --- a/src/dory/compress/lz4/lz4_codec.cc +++ b/src/dory/compress/lz4/lz4_codec.cc @@ -80,8 +80,6 @@ static const int MAX_LEVEL = 16; TOpt TLz4Codec::GetRealCompressionLevel( const TOpt &requested_level) const noexcept { - assert(this); - if (requested_level.IsUnknown()) { return TOpt(DEFAULT_LEVEL); } @@ -94,7 +92,6 @@ TOpt TLz4Codec::GetRealCompressionLevel( size_t TLz4Codec::ComputeUncompressedResultBufSpace( const void *compressed_data, size_t compressed_size) const { - assert(this); LZ4F_decompressionContext_t dctx = nullptr; CheckLz4Status(LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION), "LZ4F_createDecompressionContext"); @@ -172,7 +169,6 @@ static void CheckWriteBufferOverflow(size_t bytes_written, size_t capacity, size_t TLz4Codec::Uncompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size) const { - assert(this); LZ4F_decompressionContext_t dctx = nullptr; CheckLz4Status(LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION), "LZ4F_createDecompressionContext"); @@ -234,14 +230,12 @@ size_t TLz4Codec::Uncompress(const void *input_buf, size_t input_buf_size, size_t TLz4Codec::DoComputeCompressedResultBufSpace( const void * /*uncompressed_data*/, size_t uncompressed_size, int /*compression_level*/) const { - assert(this); return CheckLz4Status(LZ4F_compressBound(uncompressed_size, nullptr), "LZ4F_compressBound"); } size_t TLz4Codec::DoCompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size, int compression_level) const { - assert(this); assert((compression_level >= MIN_LEVEL) && (compression_level <= MAX_LEVEL)); auto *out_buf = reinterpret_cast(output_buf); LZ4F_compressionContext_t cctx = nullptr; diff --git a/src/dory/compress/snappy/snappy_codec.cc b/src/dory/compress/snappy/snappy_codec.cc index d3880a0c..84a5c30f 100644 --- a/src/dory/compress/snappy/snappy_codec.cc +++ b/src/dory/compress/snappy/snappy_codec.cc @@ -91,15 +91,12 @@ const TSnappyCodec &TSnappyCodec::The() { TOpt TSnappyCodec::GetRealCompressionLevel( const TOpt & /*requested_level*/) const noexcept { - assert(this); - /* This algorithm does not support compression levels. */ return TOpt(); } size_t TSnappyCodec::ComputeUncompressedResultBufSpace( const void *compressed_data, size_t compressed_size) const { - assert(this); size_t result = 0; CheckSnappyStatus(Lib.snappy_uncompressed_length( reinterpret_cast(compressed_data), compressed_size, @@ -110,7 +107,6 @@ size_t TSnappyCodec::ComputeUncompressedResultBufSpace( size_t TSnappyCodec::Uncompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size) const { - assert(this); CheckSnappyStatus(Lib.snappy_uncompress( reinterpret_cast(input_buf), input_buf_size, reinterpret_cast(output_buf), &output_buf_size), @@ -123,14 +119,12 @@ size_t TSnappyCodec::Uncompress(const void *input_buf, size_t input_buf_size, size_t TSnappyCodec::DoComputeCompressedResultBufSpace( const void * /*uncompressed_data*/, size_t uncompressed_size, int /*compression_level*/) const { - assert(this); return Lib.snappy_max_compressed_length(uncompressed_size); } size_t TSnappyCodec::DoCompress(const void *input_buf, size_t input_buf_size, void *output_buf, size_t output_buf_size, int /*compression_level*/) const { - assert(this); CheckSnappyStatus(Lib.snappy_compress( reinterpret_cast(input_buf), input_buf_size, reinterpret_cast(output_buf), &output_buf_size), diff --git a/src/dory/conf/batch_conf.cc b/src/dory/conf/batch_conf.cc index 06005d17..17b5f50c 100644 --- a/src/dory/conf/batch_conf.cc +++ b/src/dory/conf/batch_conf.cc @@ -96,7 +96,6 @@ std::string TBatchUnknownTopicConfig::CreateMsg( void TBatchConf::TBuilder::AddNamedConfig(const std::string &name, const TBatchValues &values) { - assert(this); const auto result = NamedConfigs.insert(std::make_pair(name, values)); if (!result.second) { @@ -105,8 +104,6 @@ void TBatchConf::TBuilder::AddNamedConfig(const std::string &name, } void TBatchConf::TBuilder::SetProduceRequestDataLimit(size_t limit) { - assert(this); - if (GotProduceRequestDataLimit) { throw TBatchDuplicateProduceRequestDataLimit(); } @@ -116,8 +113,6 @@ void TBatchConf::TBuilder::SetProduceRequestDataLimit(size_t limit) { } void TBatchConf::TBuilder::SetMessageMaxBytes(size_t message_max_bytes) { - assert(this); - if (GotMessageMaxBytes) { throw TBatchDuplicateMessageMaxBytes(); } @@ -128,7 +123,6 @@ void TBatchConf::TBuilder::SetMessageMaxBytes(size_t message_max_bytes) { void TBatchConf::TBuilder::SetCombinedTopicsConfig(bool enabled, const std::string *config_name) { - assert(this); assert(!enabled || config_name); if (GotCombinedTopics) { @@ -152,7 +146,6 @@ void TBatchConf::TBuilder::SetCombinedTopicsConfig(bool enabled, void TBatchConf::TBuilder::SetDefaultTopicConfig(TTopicAction action, const std::string *config_name) { - assert(this); assert((action != TTopicAction::PerTopic) || config_name); if (GotDefaultTopic) { @@ -176,7 +169,6 @@ void TBatchConf::TBuilder::SetDefaultTopicConfig(TTopicAction action, void TBatchConf::TBuilder::SetTopicConfig(const std::string &topic, TTopicAction action, const std::string *config_name) { - assert(this); assert((action != TTopicAction::PerTopic) || config_name); if (BuildResult.TopicConfigs.find(topic) != BuildResult.TopicConfigs.end()) { @@ -200,8 +192,6 @@ void TBatchConf::TBuilder::SetTopicConfig(const std::string &topic, } TBatchConf TBatchConf::TBuilder::Build() { - assert(this); - if (!GotProduceRequestDataLimit) { throw TBatchMissingProduceRequestDataLimit(); } diff --git a/src/dory/conf/batch_conf.h b/src/dory/conf/batch_conf.h index b88e7189..383742ce 100644 --- a/src/dory/conf/batch_conf.h +++ b/src/dory/conf/batch_conf.h @@ -230,7 +230,6 @@ namespace Dory { TBuilder() = default; void Reset() { - assert(this); *this = TBuilder(); } diff --git a/src/dory/conf/compression_conf.cc b/src/dory/conf/compression_conf.cc index 88a4e27c..3cdf842f 100644 --- a/src/dory/conf/compression_conf.cc +++ b/src/dory/conf/compression_conf.cc @@ -95,8 +95,6 @@ std::string TCompressionUnknownTopicConfig::CreateMsg(const std::string &topic, void TCompressionConf::TBuilder::AddNamedConfig(const std::string &name, TCompressionType type, size_t min_size, const TOpt &level) { - assert(this); - if (type == TCompressionType::None) { min_size = 0; } @@ -111,8 +109,6 @@ void TCompressionConf::TBuilder::AddNamedConfig(const std::string &name, void TCompressionConf::TBuilder::SetSizeThresholdPercent( size_t size_threshold_percent) { - assert(this); - if (GotSizeThresholdPercent) { throw TCompressionDuplicateSizeThresholdPercent(); } @@ -127,8 +123,6 @@ void TCompressionConf::TBuilder::SetSizeThresholdPercent( void TCompressionConf::TBuilder::SetDefaultTopicConfig( const std::string &config_name) { - assert(this); - if (GotDefaultTopic) { throw TCompressionDuplicateDefaultTopicConfig(); } @@ -145,8 +139,6 @@ void TCompressionConf::TBuilder::SetDefaultTopicConfig( void TCompressionConf::TBuilder::SetTopicConfig(const std::string &topic, const std::string &config_name) { - assert(this); - if (BuildResult.TopicConfigs.find(topic) != BuildResult.TopicConfigs.end()) { throw TCompressionDuplicateTopicConfig(topic); } @@ -161,8 +153,6 @@ void TCompressionConf::TBuilder::SetTopicConfig(const std::string &topic, } TCompressionConf TCompressionConf::TBuilder::Build() { - assert(this); - if (!GotDefaultTopic) { throw TCompressionMissingDefaultTopic(); } diff --git a/src/dory/conf/compression_conf.h b/src/dory/conf/compression_conf.h index 62045771..56a7123f 100644 --- a/src/dory/conf/compression_conf.h +++ b/src/dory/conf/compression_conf.h @@ -168,7 +168,6 @@ namespace Dory { TBuilder() = default; void Reset() { - assert(this); *this = TBuilder(); } @@ -184,7 +183,6 @@ namespace Dory { const std::string &config_name); bool IsNamedConfigsEmpty() const noexcept { - assert(this); return NamedConfigs.empty(); } diff --git a/src/dory/conf/conf.cc b/src/dory/conf/conf.cc index 24ea65a5..9bc70a46 100644 --- a/src/dory/conf/conf.cc +++ b/src/dory/conf/conf.cc @@ -56,7 +56,6 @@ TConf::TBuilder::TBuilder(bool allow_input_bind_ephemeral, bool enable_lz4) } TConf TConf::TBuilder::Build(const void *buf, size_t buf_size) { - assert(this); assert(buf); Reset(); XmlDoc.reset(ParseXmlConfig(buf, buf_size, "US-ASCII")); @@ -76,7 +75,6 @@ TConf TConf::TBuilder::Build(const void *buf, size_t buf_size) { void TConf::TBuilder::ProcessSingleBatchingNamedConfig( const DOMElement &config_elem) { - assert(this); const std::string name = TAttrReader::GetString(config_elem, "name", TOpts::TRIM_WHITESPACE | TOpts::THROW_IF_EMPTY); RequireAllChildElementLeaves(config_elem); @@ -125,7 +123,6 @@ void TConf::TBuilder::ProcessSingleBatchingNamedConfig( void TConf::TBuilder::ProcessTopicBatchConfig(const DOMElement &topic_elem, TBatchConf::TTopicAction &action, std::string &config) { - assert(this); RequireLeaf(topic_elem); const std::string action_str = TAttrReader::GetString(topic_elem, "action", TOpts::TRIM_WHITESPACE | TOpts::THROW_IF_EMPTY); @@ -172,7 +169,6 @@ void TConf::TBuilder::ProcessTopicBatchConfig(const DOMElement &topic_elem, void TConf::TBuilder::ProcessBatchingTopicConfigsElem( const DOMElement &topic_configs_elem) { - assert(this); const auto item_vec = GetItemListElements(topic_configs_elem, "topic"); for (const auto &item : item_vec) { @@ -199,7 +195,6 @@ void TConf::TBuilder::ProcessBatchingTopicConfigsElem( } void TConf::TBuilder::ProcessBatchingElem(const DOMElement &batching_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(batching_elem, { {"namedConfigs", false}, {"produceRequestDataLimit", true}, @@ -295,7 +290,6 @@ void TConf::TBuilder::ProcessBatchingElem(const DOMElement &batching_elem) { void TConf::TBuilder::ProcessSingleCompressionNamedConfig( const DOMElement &config_elem) { - assert(this); const std::string name = TAttrReader::GetString(config_elem, "name", TOpts::TRIM_WHITESPACE | TOpts::THROW_IF_EMPTY); TCompressionType type = TCompressionType::None; @@ -328,7 +322,6 @@ void TConf::TBuilder::ProcessSingleCompressionNamedConfig( void TConf::TBuilder::ProcessCompressionTopicConfigsElem( const DOMElement &topic_configs_elem) { - assert(this); RequireAllChildElementLeaves(topic_configs_elem); const auto item_vec = GetItemListElements(topic_configs_elem, "topic"); @@ -356,7 +349,6 @@ void TConf::TBuilder::ProcessCompressionTopicConfigsElem( void TConf::TBuilder::ProcessCompressionElem( const DOMElement &compression_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(compression_elem, { {"namedConfigs", true}, {"sizeThresholdPercent", false}, @@ -421,7 +413,6 @@ void TConf::TBuilder::ProcessCompressionElem( void TConf::TBuilder::ProcessTopicRateTopicConfigsElem( const DOMElement &topic_configs_elem) { - assert(this); RequireAllChildElementLeaves(topic_configs_elem); const auto topic_item_vec = GetItemListElements(topic_configs_elem, "topic"); @@ -450,7 +441,6 @@ void TConf::TBuilder::ProcessTopicRateTopicConfigsElem( } void TConf::TBuilder::ProcessTopicRateElem(const DOMElement &topic_rate_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(topic_rate_elem, { {"namedConfigs", true}, {"defaultTopic", true}, {"topicConfigs", false} @@ -524,7 +514,6 @@ void TConf::TBuilder::ProcessTopicRateElem(const DOMElement &topic_rate_elem) { std::pair> TConf::TBuilder::ProcessFileSectionElem(const DOMElement &elem, std::unordered_map &subsection_map) { - assert(this); const bool enable = TAttrReader::GetBool(elem, "enable"); RequireAllChildElementLeaves(elem); subsection_map = GetSubsectionElements(elem, @@ -552,7 +541,6 @@ TConf::TBuilder::ProcessFileSectionElem(const DOMElement &elem, void TConf::TBuilder::ProcessInputSourcesElem( const DOMElement &input_sources_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(input_sources_elem, { {"unixDatagram", false}, {"unixStream", false}, {"tcp", false} @@ -643,7 +631,6 @@ void TConf::TBuilder::ProcessInputSourcesElem( void TConf::TBuilder::ProcessInputConfigElem( const DOMElement &input_config_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(input_config_elem, { {"maxBuffer", false}, {"maxDatagramMsgSize", false}, @@ -682,7 +669,6 @@ void TConf::TBuilder::ProcessInputConfigElem( void TConf::TBuilder::ProcessMsgDeliveryElem( const DOMElement &msg_delivery_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(msg_delivery_elem, { {"topicAutocreate", false}, {"maxFailedDeliveryAttempts", false}, @@ -769,7 +755,6 @@ void TConf::TBuilder::ProcessMsgDeliveryElem( void TConf::TBuilder::ProcessHttpInterfaceElem( const DOMElement &http_interface_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(http_interface_elem, { {"port", false}, {"loopbackOnly", false}, @@ -820,7 +805,6 @@ void TConf::TBuilder::ProcessHttpInterfaceElem( void TConf::TBuilder::ProcessDiscardLoggingElem( const DOMElement &discard_logging_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(discard_logging_elem, { {"path", true}, {"maxFileSize", false}, @@ -874,7 +858,6 @@ void TConf::TBuilder::ProcessDiscardLoggingElem( void TConf::TBuilder::ProcessKafkaConfigElem( const DOMElement &kafka_config_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(kafka_config_elem, { {"clientId", false}, {"replicationTimeout", false} @@ -902,7 +885,6 @@ void TConf::TBuilder::ProcessKafkaConfigElem( } void TConf::TBuilder::ProcessMsgDebugElem(const DOMElement &msg_debug_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(msg_debug_elem, { {"path", true}, {"timeLimit", false}, @@ -940,7 +922,6 @@ void TConf::TBuilder::ProcessMsgDebugElem(const DOMElement &msg_debug_elem) { } void TConf::TBuilder::ProcessLoggingElem(const DOMElement &logging_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(logging_elem, { {"level", false}, {"stdoutStderr", false}, {"syslog", false}, @@ -1004,7 +985,6 @@ void TConf::TBuilder::ProcessLoggingElem(const DOMElement &logging_elem) { void TConf::TBuilder::ProcessInitialBrokersElem( const DOMElement &initial_brokers_elem) { - assert(this); std::vector broker_vec; RequireAllChildElementLeaves(initial_brokers_elem); const auto broker_elem_vec = GetItemListElements(initial_brokers_elem, @@ -1028,7 +1008,6 @@ void TConf::TBuilder::ProcessInitialBrokersElem( } void TConf::TBuilder::ProcessRootElem(const DOMElement &root_elem) { - assert(this); const auto subsection_map = GetSubsectionElements(root_elem, { {"batching", false}, {"compression", false}, diff --git a/src/dory/conf/conf.h b/src/dory/conf/conf.h index 654d3c94..c9d89263 100644 --- a/src/dory/conf/conf.h +++ b/src/dory/conf/conf.h @@ -133,7 +133,6 @@ namespace Dory { } void Reset() { - assert(this); *this = TBuilder(AllowInputBindEphemeral, EnableLz4); } diff --git a/src/dory/conf/conf_error.h b/src/dory/conf/conf_error.h index 10a7513a..6604abe6 100644 --- a/src/dory/conf/conf_error.h +++ b/src/dory/conf/conf_error.h @@ -33,7 +33,6 @@ namespace Dory { class TConfError : public std::runtime_error { public: const char *what() const noexcept override { - assert(this); return Msg.c_str(); } diff --git a/src/dory/conf/discard_logging_conf.cc b/src/dory/conf/discard_logging_conf.cc index 4d444523..7d5f6fbe 100644 --- a/src/dory/conf/discard_logging_conf.cc +++ b/src/dory/conf/discard_logging_conf.cc @@ -27,8 +27,6 @@ using namespace Dory; using namespace Dory::Conf; void TDiscardLoggingConf::SetPath(const std::string &path) { - assert(this); - if (!path.empty() && (path[0] != '/')) { throw TDiscardLoggingRelativePath(); } diff --git a/src/dory/conf/http_interface_conf.cc b/src/dory/conf/http_interface_conf.cc index 07885717..7395afcb 100644 --- a/src/dory/conf/http_interface_conf.cc +++ b/src/dory/conf/http_interface_conf.cc @@ -27,8 +27,6 @@ using namespace Dory; using namespace Dory::Conf; void THttpInterfaceConf::SetPort(in_port_t port) { - assert(this); - if (port < 1) { throw THttpInterfaceInvalidPort(); } @@ -37,8 +35,6 @@ void THttpInterfaceConf::SetPort(in_port_t port) { } void THttpInterfaceConf::SetDiscardReportInterval(size_t value) { - assert(this); - if (value < 1) { throw THttpInterfaceInvalidDiscardReportInterval(); } diff --git a/src/dory/conf/input_sources_conf.cc b/src/dory/conf/input_sources_conf.cc index d7a08c3e..3ee8338a 100644 --- a/src/dory/conf/input_sources_conf.cc +++ b/src/dory/conf/input_sources_conf.cc @@ -27,8 +27,6 @@ using namespace Dory::Conf; void TInputSourcesConf::SetUnixDgConf(const std::string &path, const TOpt &mode) { - assert(this); - if (!path.empty() && (path[0] != '/')) { throw TInputSourcesRelativeUnixDgPath(); } @@ -43,8 +41,6 @@ void TInputSourcesConf::SetUnixDgConf(const std::string &path, void TInputSourcesConf::SetUnixStreamConf(const std::string &path, const TOpt &mode) { - assert(this); - if (!path.empty() && (path[0] != '/')) { throw TInputSourcesRelativeUnixStreamPath(); } @@ -59,8 +55,6 @@ void TInputSourcesConf::SetUnixStreamConf(const std::string &path, void TInputSourcesConf::SetTcpConf(const TOpt &port, bool allow_input_bind_ephemeral) { - assert(this); - if (!allow_input_bind_ephemeral && port.IsKnown() && (*port == 0)) { throw TInvalidTcpInputPort(); } diff --git a/src/dory/conf/kafka_config_conf.cc b/src/dory/conf/kafka_config_conf.cc index 4df556d1..f72c00b5 100644 --- a/src/dory/conf/kafka_config_conf.cc +++ b/src/dory/conf/kafka_config_conf.cc @@ -28,8 +28,6 @@ using namespace Dory; using namespace Dory::Conf; void TKafkaConfigConf::SetReplicationTimeout(size_t value) { - assert(this); - if (value > static_cast(std::numeric_limits::max())) { throw TKafkaConfigInvalidReplicationTimeout(); } diff --git a/src/dory/conf/logging_conf.cc b/src/dory/conf/logging_conf.cc index ca98b7af..0cbb8358 100644 --- a/src/dory/conf/logging_conf.cc +++ b/src/dory/conf/logging_conf.cc @@ -29,8 +29,6 @@ using namespace Dory::Conf; void TLoggingConf::SetFileConf(const std::string &path, const TOpt &mode) { - assert(this); - if (!path.empty() && (path[0] != '/')) { throw TLoggingRelativePath(); } diff --git a/src/dory/conf/msg_debug_conf.cc b/src/dory/conf/msg_debug_conf.cc index 95cfdca3..39129013 100644 --- a/src/dory/conf/msg_debug_conf.cc +++ b/src/dory/conf/msg_debug_conf.cc @@ -27,8 +27,6 @@ using namespace Dory; using namespace Dory::Conf; void TMsgDebugConf::SetPath(const std::string &path) { - assert(this); - if (!path.empty() && (path[0] != '/')) { throw TMsgDebugRelativePath(); } diff --git a/src/dory/conf/topic_rate_conf.cc b/src/dory/conf/topic_rate_conf.cc index d0c5b07f..53df0cd1 100644 --- a/src/dory/conf/topic_rate_conf.cc +++ b/src/dory/conf/topic_rate_conf.cc @@ -74,8 +74,6 @@ std::string TTopicRateUnknownTopicConfig::CreateMsg( void TTopicRateConf::TBuilder::AddBoundedNamedConfig(const std::string &name, size_t interval, size_t max_count) { - assert(this); - if (interval == 0) { throw TTopicRateZeroRateLimitInterval(name); } @@ -90,7 +88,6 @@ void TTopicRateConf::TBuilder::AddBoundedNamedConfig(const std::string &name, void TTopicRateConf::TBuilder::AddUnlimitedNamedConfig( const std::string &name) { - assert(this); const auto result = NamedConfigs.insert(std::make_pair(name, TConf())); @@ -101,8 +98,6 @@ void TTopicRateConf::TBuilder::AddUnlimitedNamedConfig( void TTopicRateConf::TBuilder::SetDefaultTopicConfig( const std::string &config_name) { - assert(this); - if (GotDefaultTopic) { throw TTopicRateDuplicateDefaultTopicConfig(); } @@ -119,8 +114,6 @@ void TTopicRateConf::TBuilder::SetDefaultTopicConfig( void TTopicRateConf::TBuilder::SetTopicConfig(const std::string &topic, const std::string &config_name) { - assert(this); - if (BuildResult.TopicConfigs.find(topic) != BuildResult.TopicConfigs.end()) { throw TTopicRateDuplicateTopicConfig(topic); } @@ -135,8 +128,6 @@ void TTopicRateConf::TBuilder::SetTopicConfig(const std::string &topic, } TTopicRateConf TTopicRateConf::TBuilder::Build() { - assert(this); - if (!GotDefaultTopic) { throw TTopicRateMissingDefaultTopic(); } diff --git a/src/dory/conf/topic_rate_conf.h b/src/dory/conf/topic_rate_conf.h index bb42e231..61bdd408 100644 --- a/src/dory/conf/topic_rate_conf.h +++ b/src/dory/conf/topic_rate_conf.h @@ -150,7 +150,6 @@ namespace Dory { TBuilder() = default; void Reset() { - assert(this); *this = TBuilder(); } diff --git a/src/dory/debug/debug_logger.cc b/src/dory/debug/debug_logger.cc index 0a0970fd..1f53016d 100644 --- a/src/dory/debug/debug_logger.cc +++ b/src/dory/debug/debug_logger.cc @@ -65,8 +65,6 @@ static const char *ToBlurb(TDebugSetup::TLogId log_id) { } void TDebugLogger::LogMsg(const TMsg &msg) { - assert(this); - if (DebugSetup.MySettingsAreOld(CachedSettingsVersion)) { Settings = DebugSetup.GetSettings(); assert(Settings); @@ -152,8 +150,6 @@ void TDebugLogger::LogMsg(const TMsg &msg) { } void TDebugLogger::LogMsgList(const std::list &msg_list) { - assert(this); - for (const TMsg::TPtr &msg_ptr : msg_list) { LogMsg(*msg_ptr); } @@ -166,13 +162,11 @@ unsigned long TDebugLogger::Now() noexcept { } void TDebugLogger::DisableLogging() noexcept { - assert(this); LogFd = -1; LoggingEnabled = false; } void TDebugLogger::EnableLogging() noexcept { - assert(this); LoggingEnabledAt = Now(); MsgCount = 0; LogFd = Settings->GetLogFileDescriptor(LogId); diff --git a/src/dory/debug/debug_logger.h b/src/dory/debug/debug_logger.h index 5d6fceb6..b027b0bd 100644 --- a/src/dory/debug/debug_logger.h +++ b/src/dory/debug/debug_logger.h @@ -56,7 +56,6 @@ namespace Dory { void LogMsg(const TMsg &msg); void LogMsg(const TMsg::TPtr &msg_ptr) { - assert(this); LogMsg(*msg_ptr); } @@ -71,7 +70,6 @@ namespace Dory { static unsigned long Now() noexcept; unsigned long SecondsSinceEnabled() const noexcept { - assert(this); unsigned long t = Now(); return (t >= LoggingEnabledAt) ? (t - LoggingEnabledAt): 0; } diff --git a/src/dory/debug/debug_setup.cc b/src/dory/debug/debug_setup.cc index 9db9d606..884713d2 100644 --- a/src/dory/debug/debug_setup.cc +++ b/src/dory/debug/debug_setup.cc @@ -77,8 +77,6 @@ TDebugSetup::TSettings::TSettings(size_t version, } bool TDebugSetup::AddDebugTopic(const char *topic) { - assert(this); - std::lock_guard lock(Mutex); assert(Settings); const std::unordered_set *tptr = Settings->GetDebugTopics(); @@ -106,8 +104,6 @@ bool TDebugSetup::AddDebugTopic(const char *topic) { } bool TDebugSetup::DelDebugTopic(const char *topic) { - assert(this); - std::lock_guard lock(Mutex); assert(Settings); const std::unordered_set *tptr = Settings->GetDebugTopics(); @@ -134,8 +130,6 @@ bool TDebugSetup::DelDebugTopic(const char *topic) { void TDebugSetup::SetDebugTopics( std::unordered_set *debug_topics) { - assert(this); - std::lock_guard lock(Mutex); assert(Settings); @@ -148,8 +142,6 @@ void TDebugSetup::SetDebugTopics( } void TDebugSetup::TruncateDebugFiles() { - assert(this); - if (Wr::truncate(GetLogPath(TLogId::MSG_RECEIVE).c_str(), 0) < 0) { LOG(TPri::ERR) << "Failed to truncate MSG_RECEIVE debug logfile"; } @@ -164,7 +156,6 @@ void TDebugSetup::TruncateDebugFiles() { } void TDebugSetup::CreateDebugDir() { - assert(this); std::string cmd("/bin/mkdir -p "); cmd += DebugDir; @@ -203,8 +194,6 @@ static void SettingsFtruncate(const TDebugSetup::TSettings &settings) { void TDebugSetup::DeleteOldDebugFiles( const std::shared_ptr &old_settings) { - assert(this); - /* Unlink the old files. When we create new files to replace them, any threads still using the old file descriptors (and debug settings) will write to the unlinked files until they see that the debug settings have diff --git a/src/dory/debug/debug_setup.h b/src/dory/debug/debug_setup.h index 4091c5a8..37067d84 100644 --- a/src/dory/debug/debug_setup.h +++ b/src/dory/debug/debug_setup.h @@ -69,28 +69,22 @@ namespace Dory { pointer to the set of enabled topics. */ const std::unordered_set * GetDebugTopics() const noexcept { - assert(this); return DebugTopics.IsKnown() ? &*DebugTopics : nullptr; } size_t GetVersion() const noexcept { - assert(this); return Version; } bool LoggingIsEnabled() const noexcept { - assert(this); return LoggingEnabled; } int GetLogFileDescriptor(TLogId log_id) const noexcept { - assert(this); return LogFds[ToIndex(log_id)]; } bool RequestLogBytes(size_t num_bytes) noexcept { - assert(this); - std::lock_guard lock(Mutex); if (BytesRemaining < num_bytes) { @@ -117,7 +111,6 @@ namespace Dory { } Base::TFd &GetLogFd(TLogId log_id) noexcept { - assert(this); return LogFds[ToIndex(log_id)]; } @@ -166,7 +159,6 @@ namespace Dory { } const std::string &GetLogPath(TLogId log_id) const noexcept { - assert(this); return LogPaths[ToIndex(log_id)]; } @@ -175,14 +167,11 @@ namespace Dory { } bool MySettingsAreOld(size_t my_version) const noexcept { - assert(this); - /* We can get away without grabbing 'Mutex' here. */ return SettingsVersion != my_version; } std::shared_ptr GetSettings() const noexcept { - assert(this); std::lock_guard lock(Mutex); assert(Settings); return Settings; @@ -198,7 +187,6 @@ namespace Dory { void SetDebugTopics(std::unordered_set *debug_topics); void ClearDebugTopics() { - assert(this); std::unordered_set no_topics; SetDebugTopics(&no_topics); } @@ -207,7 +195,6 @@ namespace Dory { private: std::string &GetLogPath(TLogId log_id) noexcept { - assert(this); return LogPaths[ToIndex(log_id)]; } diff --git a/src/dory/discard_file_logger.cc b/src/dory/discard_file_logger.cc index a8ce03ef..cecfb7db 100644 --- a/src/dory/discard_file_logger.cc +++ b/src/dory/discard_file_logger.cc @@ -95,8 +95,6 @@ static void CreateDir(const char *dir) { } TDiscardFileLogger::~TDiscardFileLogger() { - assert(this); - try { Shutdown(); } catch (const std::exception &x) { @@ -114,8 +112,6 @@ TDiscardFileLogger::~TDiscardFileLogger() { void TDiscardFileLogger::Init(const char *log_path, uint64_t max_file_size, uint64_t max_archive_size, size_t max_msg_prefix_len) { - assert(this); - /* Will contain absolute path of directory containing logfile. */ std::string log_dir; @@ -158,8 +154,6 @@ void TDiscardFileLogger::Init(const char *log_path, uint64_t max_file_size, } void TDiscardFileLogger::Shutdown() { - assert(this); - std::lock_guard lock(Mutex); DisableLogging(); @@ -193,8 +187,6 @@ static const char *ReasonToBlurb(TDiscardFileLogger::TDiscardReason reason) { } void TDiscardFileLogger::LogDiscard(const TMsg &msg, TDiscardReason reason) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -213,8 +205,6 @@ void TDiscardFileLogger::LogDiscard(const TMsg &msg, TDiscardReason reason) { } void TDiscardFileLogger::LogDuplicate(const TMsg &msg) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -235,7 +225,6 @@ void TDiscardFileLogger::LogDuplicate(const TMsg &msg) { void TDiscardFileLogger::LogNoMemDiscard(TMsg::TTimestamp timestamp, const char *topic_begin, const char *topic_end, const void *key_begin, const void *key_end, const void *value_begin, const void *value_end) { - assert(this); assert(topic_begin); assert(topic_end >= topic_begin); assert(key_begin || (key_end == key_begin)); @@ -259,8 +248,6 @@ void TDiscardFileLogger::LogNoMemDiscard(TMsg::TTimestamp timestamp, void TDiscardFileLogger::LogMalformedMsgDiscard(const void *msg_begin, const void *msg_end) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -274,8 +261,6 @@ void TDiscardFileLogger::LogMalformedMsgDiscard(const void *msg_begin, void TDiscardFileLogger::LogUncleanDisconnectMsgDiscard(bool is_tcp, const void *msg_begin, const void *msg_end) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -289,8 +274,6 @@ void TDiscardFileLogger::LogUncleanDisconnectMsgDiscard(bool is_tcp, void TDiscardFileLogger::LogUnsupportedApiKeyDiscard(const void *msg_begin, const void *msg_end, int api_key) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -307,8 +290,6 @@ void TDiscardFileLogger::LogUnsupportedApiKeyDiscard(const void *msg_begin, void TDiscardFileLogger::LogUnsupportedMsgVersionDiscard(const void *msg_begin, const void *msg_end, int version) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -326,7 +307,6 @@ void TDiscardFileLogger::LogUnsupportedMsgVersionDiscard(const void *msg_begin, void TDiscardFileLogger::LogBadTopicDiscard(TMsg::TTimestamp timestamp, const char *topic_begin, const char *topic_end, const void *key_begin, const void *key_end, const void *value_begin, const void *value_end) { - assert(this); assert(topic_begin); assert(topic_end >= topic_begin); assert(key_begin || (key_end == key_begin)); @@ -349,8 +329,6 @@ void TDiscardFileLogger::LogBadTopicDiscard(TMsg::TTimestamp timestamp, } void TDiscardFileLogger::LogBadTopicDiscard(const TMsg &msg) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -369,8 +347,6 @@ void TDiscardFileLogger::LogBadTopicDiscard(const TMsg &msg) { } void TDiscardFileLogger::LogLongMsgDiscard(const TMsg &msg) { - assert(this); - if (!Enabled) { return; // fast path for case where logging is disabled } @@ -401,7 +377,6 @@ TDiscardFileLogger::TArchiveCleaner::~TArchiveCleaner() { } void TDiscardFileLogger::TArchiveCleaner::Run() { - assert(this); int tid = static_cast(Gettid()); LOG(TPri::INFO) << "Discard log cleaner thread " << tid << " started"; bool caught_fatal_exception = false; @@ -451,8 +426,6 @@ struct TOldLogFileInfo { TOldLogFileInfo& operator=(const TOldLogFileInfo &) = default; TOldLogFileInfo& operator=(TOldLogFileInfo &&that) noexcept { - assert(this); - if (this != &that) { AbsolutePath = std::move(that.AbsolutePath); Size = that.Size; @@ -563,7 +536,6 @@ GetOldLogFileSizes(const char *log_dir, const char *log_filename) { } bool TDiscardFileLogger::TArchiveCleaner::HandleCleanRequest() { - assert(this); std::vector old_log_files; try { @@ -616,7 +588,6 @@ bool TDiscardFileLogger::TArchiveCleaner::HandleCleanRequest() { } void TDiscardFileLogger::TArchiveCleaner::DoRun() { - assert(this); std::array events; struct pollfd &shutdown_request_event = events[0]; struct pollfd &clean_request_event = events[1]; @@ -709,7 +680,6 @@ void TDiscardFileLogger::ParseLogPath(const char *log_path, const uint8_t *TDiscardFileLogger::EnforceMaxPrefixLen(const void *msg_begin, const void *msg_end) { - assert(this); const auto *p1 = reinterpret_cast(msg_begin); const auto *p2 = reinterpret_cast(msg_end); assert(p2 >= p1); @@ -718,8 +688,6 @@ const uint8_t *TDiscardFileLogger::EnforceMaxPrefixLen(const void *msg_begin, } void TDiscardFileLogger::EnforceMaxPrefixLen(std::vector &msg) { - assert(this); - if (msg.size() > MaxMsgPrefixLen) { msg.resize(MaxMsgPrefixLen); } @@ -741,7 +709,6 @@ TFd TDiscardFileLogger::OpenLogPath(const char *log_path) { } void TDiscardFileLogger::DisableLogging() { - assert(this); Enabled = false; LogFd.Reset(); } @@ -750,7 +717,6 @@ void TDiscardFileLogger::DisableLogging() { logfile size to exceed the limit. If so, rename the logfile, create a new one in its place, and return true. Otherwise return false. */ bool TDiscardFileLogger::CheckMaxFileSize(uint64_t next_entry_size) { - assert(this); assert(Enabled); assert(ArchiveCleaner); assert(LogFd.IsOpen()); @@ -790,8 +756,6 @@ bool TDiscardFileLogger::CheckMaxFileSize(uint64_t next_entry_size) { } void TDiscardFileLogger::WriteToLog(const std::string &log_entry) { - assert(this); - if (log_entry.empty()) { return; } diff --git a/src/dory/discard_file_logger.h b/src/dory/discard_file_logger.h index 304001f2..9014a79d 100644 --- a/src/dory/discard_file_logger.h +++ b/src/dory/discard_file_logger.h @@ -115,7 +115,6 @@ namespace Dory { /* Same as above, except message is passed by smart pointer. */ void LogDiscard(const TMsg::TPtr &msg_ptr, TDiscardReason reason) { - assert(this); LogDiscard(*msg_ptr, reason); } @@ -125,7 +124,6 @@ namespace Dory { /* Same as above, except message is passed by smart pointer. */ void LogDuplicate(const TMsg::TPtr &msg_ptr) { - assert(this); LogDuplicate(*msg_ptr); } @@ -179,7 +177,6 @@ namespace Dory { /* Same as above, except message is passed by smart pointer. */ void LogBadTopicDiscard(const TMsg::TPtr &msg_ptr) { - assert(this); LogBadTopicDiscard(*msg_ptr); } @@ -189,7 +186,6 @@ namespace Dory { /* Same as above, except message is passed by smart pointer. */ void LogLongMsgDiscard(const TMsg::TPtr &msg_ptr) { - assert(this); LogLongMsgDiscard(*msg_ptr); } @@ -208,16 +204,13 @@ namespace Dory { /* Awaken thread. It will then scan the log directory and delete old logfiles as necessary. */ void SendCleanRequest() { - assert(this); CleanRequestSem.Push(); } protected: - void Run() override; private: - bool HandleCleanRequest(); void DoRun(); diff --git a/src/dory/dory.test.cc b/src/dory/dory.test.cc index 1c7b0a8a..7a590aea 100644 --- a/src/dory/dory.test.cc +++ b/src/dory/dory.test.cc @@ -108,35 +108,29 @@ namespace { virtual ~TDoryTestServer(); void UseUnixDgSocket() { - assert(this); assert(!IsStarted()); UnixDgSocketName = MakeTmpFilename("/tmp/dory_test_dg_sock.XXXXXX"); } void UseUnixStreamSocket() { - assert(this); assert(!IsStarted()); UnixStreamSocketName = MakeTmpFilename("/tmp/dory_test_stream_sock.XXXXXX"); } void UseTcpInputSocket() { - assert(this); TcpInputActive = true; } const char *GetUnixDgSocketName() const { - assert(this); return UnixDgSocketName.c_str(); } const char *GetUnixStreamSocketName() const { - assert(this); return UnixStreamSocketName.c_str(); } in_port_t GetInputPort() const { - assert(this); return Dory->GetInputPort(); } @@ -147,7 +141,6 @@ namespace { pointer to dory server object, or nullptr on dory server initialization failure. */ TDoryServer *GetDory() { - assert(this); return Dory.get(); } @@ -156,7 +149,6 @@ namespace { using TFdManagedThread::Join; int GetDoryReturnValue() const { - assert(this); return DoryReturnValue; } @@ -195,7 +187,6 @@ namespace { } bool TDoryTestServer::SyncStart() { - assert(this); std::ostringstream os; const std::string produce_request_data_limit( EnableBatching ? "1024k" : "0"); @@ -351,12 +342,10 @@ namespace { } void TDoryTestServer::RequestShutdown() { - assert(this); Dory::Util::RequestShutdown(); } void TDoryTestServer::Run() { - assert(this); DoryReturnValue = EXIT_FAILURE; try { @@ -1656,7 +1645,7 @@ namespace { }; // TMsgBlaster void TMsgBlaster::Run() { - assert(this); + std::vector msg_buf; for (const std::string &msg : MsgVec) { diff --git a/src/dory/dory_server.cc b/src/dory/dory_server.cc index 51cba1dd..3fb22a47 100644 --- a/src/dory/dory_server.cc +++ b/src/dory/dory_server.cc @@ -187,7 +187,6 @@ TDoryServer::TDoryServer(TCmdLineArgs &&args, TConf &&conf, } void TDoryServer::BindStatusSocket(bool bind_ephemeral) { - assert(this); TAddress status_address( Conf.HttpInterfaceConf.LoopbackOnly ? TAddress::IPv4Loopback : TAddress::IPv4Any, @@ -209,8 +208,6 @@ void TDoryServer::BindStatusSocket(bool bind_ephemeral) { } int TDoryServer::Run() { - assert(this); - /* Regardless of what happens, we must notify test code when we have either finished initialization or are shutting down (possibly due to a fatal exception). */ @@ -260,7 +257,6 @@ int TDoryServer::Run() { std::unique_ptr TDoryServer::CreateStreamClientHandler(bool is_tcp) { - assert(this); return std::unique_ptr( new TStreamClientHandler(is_tcp, Conf, Pool, MsgStateTracker, AnomalyTracker, RouterThread.GetMsgChannel(), @@ -268,8 +264,6 @@ std::unique_ptr } bool TDoryServer::StartMsgHandlingThreads() { - assert(this); - if (!Conf.DiscardLoggingConf.Path.empty()) { /* We must do this before starting the input agents so all discards are tracked properly when discard file logging is enabled. This starts a @@ -353,8 +347,6 @@ static void ReportStreamClientWorkerErrors( } bool TDoryServer::HandleEvents() { - assert(this); - /* This is for periodically verifying that we are getting queried for discard info. */ TTimerFd discard_query_check_timer( @@ -495,8 +487,6 @@ static void ShutDownInputAgent(Thread::TFdManagedThread &agent, } void TDoryServer::DiscardFinalMsgs(std::list &msg_list) { - assert(this); - for (TMsg::TPtr &msg : msg_list) { if (msg) { if (Conf.LoggingConf.LogDiscards) { @@ -517,7 +507,6 @@ void TDoryServer::DiscardFinalMsgs(std::list &msg_list) { } bool TDoryServer::Shutdown() { - assert(this); bool shutdown_ok = true; /* We could parallelize the shutdown by first calling each agent's diff --git a/src/dory/dory_server.h b/src/dory/dory_server.h index a0ae2ec6..59077330 100644 --- a/src/dory/dory_server.h +++ b/src/dory/dory_server.h @@ -76,18 +76,15 @@ namespace Dory { const Base::TFd &shutdown_fd); const TCmdLineArgs &GetCmdLineArgs() const noexcept { - assert(this); return CmdLineArgs; } const Conf::TConf &GetConf() const noexcept { - assert(this); return Conf; } /* Used for testing. */ const TAnomalyTracker &GetAnomalyTracker() const noexcept { - assert(this); return AnomalyTracker; } @@ -95,7 +92,6 @@ namespace Dory { void BindStatusSocket(bool bind_ephemeral = false); in_port_t GetStatusPort() const noexcept { - assert(this); return StatusPort; } @@ -103,20 +99,17 @@ namespace Dory { Do not call until server has been started. This is intended for test code to use for finding the ephemeral port chosen by the kernel. */ in_port_t GetInputPort() const noexcept { - assert(this); return TcpInputAgent.IsKnown() ? TcpInputAgent->GetBindPort() : 0; } /* Return a file descriptor that becomes readable when the server has finished initialization or is shutting down. Test code calls this. */ const Base::TFd &GetInitWaitFd() const noexcept { - assert(this); return InitWaitSem.GetFd(); } /* This is called by test code. */ size_t GetAckCount() const noexcept { - assert(this); return Dispatcher.GetAckCount(); } diff --git a/src/dory/input_dg/any_partition/v0/v0_input_dg_reader.cc b/src/dory/input_dg/any_partition/v0/v0_input_dg_reader.cc index 330a31fd..474d326d 100644 --- a/src/dory/input_dg/any_partition/v0/v0_input_dg_reader.cc +++ b/src/dory/input_dg/any_partition/v0/v0_input_dg_reader.cc @@ -31,7 +31,6 @@ using namespace Dory::InputDg::AnyPartition; using namespace Dory::InputDg::AnyPartition::V0; TMsg::TPtr TV0InputDgReader::BuildMsg() { - assert(this); const uint8_t *pos = DataBegin; if ((DataEnd - pos) < INPUT_DG_ANY_P_V0_FLAGS_FIELD_SIZE) { diff --git a/src/dory/input_dg/partition_key/v0/v0_input_dg_reader.cc b/src/dory/input_dg/partition_key/v0/v0_input_dg_reader.cc index 4fd5cbbb..acff0f79 100644 --- a/src/dory/input_dg/partition_key/v0/v0_input_dg_reader.cc +++ b/src/dory/input_dg/partition_key/v0/v0_input_dg_reader.cc @@ -31,7 +31,6 @@ using namespace Dory::InputDg::PartitionKey; using namespace Dory::InputDg::PartitionKey::V0; TMsg::TPtr TV0InputDgReader::BuildMsg() { - assert(this); const uint8_t *pos = DataBegin; if ((DataEnd - pos) < INPUT_DG_P_KEY_V0_FLAGS_FIELD_SIZE) { diff --git a/src/dory/kafka_proto/metadata/v0/metadata_proto.cc b/src/dory/kafka_proto/metadata/v0/metadata_proto.cc index cdb1bf00..c7d91f5a 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_proto.cc +++ b/src/dory/kafka_proto/metadata/v0/metadata_proto.cc @@ -46,14 +46,12 @@ DEFINE_COUNTER(TopicAutocreateUnexpectedTopicInResponse); void TMetadataProto::WriteAllTopicsMetadataRequest( std::vector &result, int32_t correlation_id) const { - assert(this); TMetadataRequestWriter().WriteAllTopicsRequest(result, correlation_id); } void TMetadataProto::WriteSingleTopicMetadataRequest( std::vector &result, const char *topic, int32_t correlation_id) const { - assert(this); TMetadataRequestWriter().WriteSingleTopicRequest(result, topic, topic + std::strlen(topic), correlation_id); } @@ -67,7 +65,6 @@ static inline bool CanSendToPartition(int16_t error_code) { std::unique_ptr TMetadataProto::BuildMetadataFromResponse( const void *response_buf, size_t response_buf_size) const { - assert(this); TMetadata::TBuilder builder; TMetadataResponseReader reader(response_buf, response_buf_size); std::string name; @@ -109,7 +106,6 @@ std::unique_ptr TMetadataProto::BuildMetadataFromResponse( bool TMetadataProto::TopicAutocreateWasSuccessful(const char *topic, const void *response_buf, size_t response_buf_size) const { - assert(this); TMetadataResponseReader reader(response_buf, response_buf_size); if (!reader.NextTopic()) { diff --git a/src/dory/kafka_proto/metadata/v0/metadata_request_reader.cc b/src/dory/kafka_proto/metadata/v0/metadata_request_reader.cc index 574016bd..cfb65684 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_request_reader.cc +++ b/src/dory/kafka_proto/metadata/v0/metadata_request_reader.cc @@ -94,14 +94,12 @@ TMetadataRequestReader::TMetadataRequestReader(const void *request, } const char *TMetadataRequestReader::GetTopicBegin() const { - assert(this); return AllTopics ? nullptr : reinterpret_cast(Begin + SingleTopicHeaderSize()); } const char *TMetadataRequestReader::GetTopicEnd() const { - assert(this); return AllTopics ? nullptr : reinterpret_cast(Begin + SingleTopicHeaderSize() + diff --git a/src/dory/kafka_proto/metadata/v0/metadata_request_reader.h b/src/dory/kafka_proto/metadata/v0/metadata_request_reader.h index 2a9c708b..498a0ea3 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_request_reader.h +++ b/src/dory/kafka_proto/metadata/v0/metadata_request_reader.h @@ -111,14 +111,12 @@ namespace Dory { /* Returns the correlation ID. */ int32_t GetCorrelationId() const { - assert(this); return ReadInt32FromHeader(Begin + THdr::CORRELATION_ID_OFFSET); } /* Return true if this is an all topics request. Else return false. */ bool IsAllTopics() const { - assert(this); return AllTopics; } diff --git a/src/dory/kafka_proto/metadata/v0/metadata_request_writer.cc b/src/dory/kafka_proto/metadata/v0/metadata_request_writer.cc index cb85397b..de05093c 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_request_writer.cc +++ b/src/dory/kafka_proto/metadata/v0/metadata_request_writer.cc @@ -33,7 +33,6 @@ using namespace Dory::KafkaProto::Metadata::V0; void TMetadataRequestWriter::WriteSingleTopicRequest(struct iovec &header_iov, struct iovec &body_iov, void *header_buf, const char *topic_begin, const char *topic_end, int32_t correlation_id) { - assert(this); assert(header_buf); assert(topic_begin); assert(topic_end > topic_begin); @@ -48,7 +47,6 @@ void TMetadataRequestWriter::WriteSingleTopicRequest(struct iovec &header_iov, void TMetadataRequestWriter::WriteSingleTopicRequest( std::vector &result, const char *topic_begin, const char *topic_end, int32_t correlation_id) { - assert(this); assert(topic_begin); assert(topic_end > topic_begin); size_t topic_size = topic_end - topic_begin; @@ -59,7 +57,6 @@ void TMetadataRequestWriter::WriteSingleTopicRequest( void TMetadataRequestWriter::WriteAllTopicsRequest(struct iovec &iov, void *header_buf, int32_t correlation_id) { - assert(this); assert(header_buf); iov.iov_base = header_buf; iov.iov_len = NUM_ALL_TOPICS_HEADER_BYTES; @@ -68,14 +65,12 @@ void TMetadataRequestWriter::WriteAllTopicsRequest(struct iovec &iov, void TMetadataRequestWriter::WriteAllTopicsRequest( std::vector &result, int32_t correlation_id) { - assert(this); result.resize(NUM_ALL_TOPICS_HEADER_BYTES); WriteHeader(&result[0], 0, correlation_id); } void TMetadataRequestWriter::WriteHeader(void *header_buf, size_t topic_size, int32_t correlation_id) { - assert(this); assert(header_buf); assert(topic_size <= static_cast(std::numeric_limits::max())); diff --git a/src/dory/kafka_proto/metadata/v0/metadata_response_reader.cc b/src/dory/kafka_proto/metadata/v0/metadata_response_reader.cc index af121aa0..58247480 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_response_reader.cc +++ b/src/dory/kafka_proto/metadata/v0/metadata_response_reader.cc @@ -76,12 +76,10 @@ TMetadataResponseReader::TMetadataResponseReader(const void *buf, } int32_t TMetadataResponseReader::GetCorrelationId() const { - assert(this); return ReadInt32FromHeader(Buf + THdr::CORRELATION_ID_OFFSET); } size_t TMetadataResponseReader::GetBrokerCount() const { - assert(this); int32_t count = ReadInt32FromHeader(Buf + THdr::BROKER_COUNT_OFFSET); if (count < 0) { @@ -93,8 +91,6 @@ size_t TMetadataResponseReader::GetBrokerCount() const { } bool TMetadataResponseReader::FirstBroker() { - assert(this); - if (BufSize < MinSize()) { MetadataResponseIncomplete1.Increment(); THROW_ERROR(TIncompleteMetadataResponse); @@ -108,8 +104,6 @@ bool TMetadataResponseReader::FirstBroker() { } bool TMetadataResponseReader::NextBroker() { - assert(this); - if (State == TState::Initial) { return FirstBroker(); } @@ -123,7 +117,6 @@ bool TMetadataResponseReader::NextBroker() { } void TMetadataResponseReader::SkipRemainingBrokers() { - assert(this); assert(State <= TState::InBrokerList); if ((State == TState::Initial) && !FirstBroker()) { @@ -138,7 +131,6 @@ void TMetadataResponseReader::SkipRemainingBrokers() { } int32_t TMetadataResponseReader::GetCurrentBrokerNodeId() const { - assert(this); assert(State == TState::InBrokerList); assert(BrokersLeft); int32_t result = ReadInt32FromHeader(Buf + CurrentBrokerOffset + @@ -155,7 +147,6 @@ int32_t TMetadataResponseReader::GetCurrentBrokerNodeId() const { } const char *TMetadataResponseReader::GetCurrentBrokerHostBegin() const { - assert(this); assert(State == TState::InBrokerList); assert(BrokersLeft); return reinterpret_cast(Buf + CurrentBrokerOffset + @@ -163,14 +154,12 @@ const char *TMetadataResponseReader::GetCurrentBrokerHostBegin() const { } const char *TMetadataResponseReader::GetCurrentBrokerHostEnd() const { - assert(this); assert(State == TState::InBrokerList); assert(BrokersLeft); return GetCurrentBrokerHostBegin() + CurrentBrokerHostLength; } int32_t TMetadataResponseReader::GetCurrentBrokerPort() const { - assert(this); assert(State == TState::InBrokerList); assert(BrokersLeft); int32_t port = ReadInt32FromHeader(Buf + CurrentBrokerOffset + @@ -186,7 +175,6 @@ int32_t TMetadataResponseReader::GetCurrentBrokerPort() const { } size_t TMetadataResponseReader::GetTopicCount() const { - assert(this); assert(State >= TState::InBrokerList); assert(BrokersLeft == 0); assert(BufSize >= CurrentBrokerOffset); @@ -208,8 +196,6 @@ size_t TMetadataResponseReader::GetTopicCount() const { } bool TMetadataResponseReader::FirstTopic() { - assert(this); - if (State <= TState::InBrokerList) { SkipRemainingBrokers(); } @@ -224,8 +210,6 @@ bool TMetadataResponseReader::FirstTopic() { } bool TMetadataResponseReader::NextTopic() { - assert(this); - if (State <= TState::InBrokerList) { return FirstTopic(); } @@ -241,7 +225,6 @@ bool TMetadataResponseReader::NextTopic() { } void TMetadataResponseReader::SkipRemainingTopics() { - assert(this); assert(State >= TState::InBrokerList); assert(BrokersLeft == 0); @@ -257,7 +240,6 @@ void TMetadataResponseReader::SkipRemainingTopics() { } int16_t TMetadataResponseReader::GetCurrentTopicErrorCode() const { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); return ReadInt16FromHeader(Buf + CurrentTopicOffset + @@ -265,7 +247,6 @@ int16_t TMetadataResponseReader::GetCurrentTopicErrorCode() const { } const char *TMetadataResponseReader::GetCurrentTopicNameBegin() const { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); return reinterpret_cast(Buf + CurrentTopicOffset + @@ -273,14 +254,12 @@ const char *TMetadataResponseReader::GetCurrentTopicNameBegin() const { } const char *TMetadataResponseReader::GetCurrentTopicNameEnd() const { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); return GetCurrentTopicNameBegin() + CurrentTopicNameLength; } size_t TMetadataResponseReader::GetCurrentTopicPartitionCount() const { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); int32_t count = ReadInt32FromHeader(Buf + CurrentTopicOffset + @@ -295,7 +274,6 @@ size_t TMetadataResponseReader::GetCurrentTopicPartitionCount() const { } bool TMetadataResponseReader::FirstPartitionInTopic() { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); PartitionsLeftInTopic = GetCurrentTopicPartitionCount(); @@ -308,7 +286,6 @@ bool TMetadataResponseReader::FirstPartitionInTopic() { } bool TMetadataResponseReader::NextPartitionInTopic() { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); @@ -347,7 +324,6 @@ bool TMetadataResponseReader::NextPartitionInTopic() { } void TMetadataResponseReader::SkipRemainingPartitions() { - assert(this); assert(State >= TState::InTopicList); assert(TopicsLeft); @@ -363,7 +339,6 @@ void TMetadataResponseReader::SkipRemainingPartitions() { } int16_t TMetadataResponseReader::GetCurrentPartitionErrorCode() const { - assert(this); assert(State >= TState::InPartitionList); assert(PartitionsLeftInTopic); return ReadInt16FromHeader(Buf + CurrentPartitionOffset + @@ -371,7 +346,6 @@ int16_t TMetadataResponseReader::GetCurrentPartitionErrorCode() const { } int32_t TMetadataResponseReader::GetCurrentPartitionId() const { - assert(this); assert(State >= TState::InPartitionList); assert(PartitionsLeftInTopic); int32_t id = ReadInt32FromHeader(Buf + CurrentPartitionOffset + @@ -388,7 +362,6 @@ int32_t TMetadataResponseReader::GetCurrentPartitionId() const { } int32_t TMetadataResponseReader::GetCurrentPartitionLeaderId() const { - assert(this); assert(State >= TState::InPartitionList); assert(PartitionsLeftInTopic); int32_t id = ReadInt32FromHeader(Buf + CurrentPartitionOffset + @@ -406,7 +379,6 @@ int32_t TMetadataResponseReader::GetCurrentPartitionLeaderId() const { } size_t TMetadataResponseReader::GetCurrentPartitionReplicaCount() const { - assert(this); assert(State >= TState::InPartitionList); assert(PartitionsLeftInTopic); int32_t count = ReadInt32FromHeader(Buf + CurrentPartitionOffset + @@ -421,7 +393,6 @@ size_t TMetadataResponseReader::GetCurrentPartitionReplicaCount() const { } bool TMetadataResponseReader::FirstReplicaInPartition() { - assert(this); assert(State >= TState::InPartitionList); assert(PartitionsLeftInTopic); ReplicasLeftInPartition = GetCurrentPartitionReplicaCount(); @@ -433,7 +404,6 @@ bool TMetadataResponseReader::FirstReplicaInPartition() { } bool TMetadataResponseReader::NextReplicaInPartition() { - assert(this); assert((State == TState::InPartitionList) || (State == TState::InReplicaList)); assert(PartitionsLeftInTopic); @@ -450,7 +420,6 @@ bool TMetadataResponseReader::NextReplicaInPartition() { } void TMetadataResponseReader::SkipRemainingReplicas() { - assert(this); assert((State == TState::InPartitionList) || (State == TState::InReplicaList)); assert(PartitionsLeftInTopic); @@ -467,7 +436,6 @@ void TMetadataResponseReader::SkipRemainingReplicas() { } int32_t TMetadataResponseReader::GetCurrentReplicaNodeId() const { - assert(this); assert(State == TState::InReplicaList); assert(ReplicasLeftInPartition); int32_t id = ReadInt32FromHeader(Buf + CurrentReplicaOffset); @@ -484,7 +452,6 @@ int32_t TMetadataResponseReader::GetCurrentReplicaNodeId() const { size_t TMetadataResponseReader::GetCurrentPartitionCaughtUpReplicaCount() const { - assert(this); assert(State >= TState::InReplicaList); assert(ReplicasLeftInPartition == 0); assert(BufSize >= CurrentReplicaOffset); @@ -505,7 +472,6 @@ TMetadataResponseReader::GetCurrentPartitionCaughtUpReplicaCount() const { } bool TMetadataResponseReader::FirstCaughtUpReplicaInPartition() { - assert(this); assert(State >= TState::InPartitionList); if (State <= TState::InReplicaList) { @@ -523,7 +489,6 @@ bool TMetadataResponseReader::FirstCaughtUpReplicaInPartition() { } bool TMetadataResponseReader::NextCaughtUpReplicaInPartition() { - assert(this); assert(State >= TState::InPartitionList); if (State < TState::InCaughtUpReplicaList) { @@ -538,7 +503,6 @@ bool TMetadataResponseReader::NextCaughtUpReplicaInPartition() { } void TMetadataResponseReader::SkipRemainingCaughtUpReplicas() { - assert(this); assert((State == TState::InReplicaList) || (State == TState::InCaughtUpReplicaList)); assert(ReplicasLeftInPartition == 0); @@ -555,7 +519,6 @@ void TMetadataResponseReader::SkipRemainingCaughtUpReplicas() { } int32_t TMetadataResponseReader::GetCurrentCaughtUpReplicaNodeId() const { - assert(this); assert(State == TState::InCaughtUpReplicaList); assert(CaughtUpReplicasLeftInPartition); int32_t id = ReadInt32FromHeader(Buf + CurrentCaughtUpReplicaOffset); @@ -571,8 +534,6 @@ int32_t TMetadataResponseReader::GetCurrentCaughtUpReplicaNodeId() const { } void TMetadataResponseReader::ClearStateVariables() { - assert(this); - switch (State) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" @@ -613,7 +574,6 @@ void TMetadataResponseReader::ClearStateVariables() { } bool TMetadataResponseReader::InitBroker() { - assert(this); CurrentBrokerHostLength = 0; if (BrokersLeft == 0) { @@ -646,7 +606,6 @@ bool TMetadataResponseReader::InitBroker() { } bool TMetadataResponseReader::InitTopic() { - assert(this); CurrentTopicNameLength = 0; if (TopicsLeft == 0) { @@ -681,8 +640,6 @@ bool TMetadataResponseReader::InitTopic() { } bool TMetadataResponseReader::InitPartition() { - assert(this); - if (PartitionsLeftInTopic == 0) { return false; } @@ -700,8 +657,6 @@ bool TMetadataResponseReader::InitPartition() { } bool TMetadataResponseReader::InitReplica() { - assert(this); - if (ReplicasLeftInPartition == 0) { return false; } @@ -718,8 +673,6 @@ bool TMetadataResponseReader::InitReplica() { } bool TMetadataResponseReader::InitCaughtUpReplica() { - assert(this); - if (CaughtUpReplicasLeftInPartition == 0) { return false; } diff --git a/src/dory/kafka_proto/metadata/v0/metadata_response_writer.cc b/src/dory/kafka_proto/metadata/v0/metadata_response_writer.cc index d16a23b7..0324c0c4 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_response_writer.cc +++ b/src/dory/kafka_proto/metadata/v0/metadata_response_writer.cc @@ -50,7 +50,6 @@ TMetadataResponseWriter::TMetadataResponseWriter() void TMetadataResponseWriter::OpenResponse(std::vector &out, int32_t correlation_id) { - assert(this); assert(State == TState::Initial); assert(Result == nullptr); State = TState::InResponse; @@ -62,7 +61,6 @@ void TMetadataResponseWriter::OpenResponse(std::vector &out, } void TMetadataResponseWriter::OpenBrokerList() { - assert(this); assert(State == TState::InResponse); State = TState::InBrokerList; BrokerCount = 0; @@ -72,7 +70,6 @@ void TMetadataResponseWriter::OpenBrokerList() { void TMetadataResponseWriter::AddBroker(int32_t node_id, const char *host_begin, const char *host_end, int32_t port) { - assert(this); assert(host_begin); assert(host_end > host_begin); assert(State == TState::InBrokerList); @@ -92,14 +89,12 @@ void TMetadataResponseWriter::AddBroker(int32_t node_id, } void TMetadataResponseWriter::CloseBrokerList() { - assert(this); assert(State == TState::InBrokerList); State = TState::InResponse; WriteInt32ToHeader(Loc(THdr::BROKER_COUNT_OFFSET), BrokerCount); } void TMetadataResponseWriter::OpenTopicList() { - assert(this); assert(State == TState::InResponse); State = TState::InTopicList; GrowResult(THdr::TOPIC_COUNT_SIZE); @@ -112,7 +107,6 @@ void TMetadataResponseWriter::OpenTopicList() { void TMetadataResponseWriter::OpenTopic(int16_t topic_error_code, const char *topic_name_begin, const char *topic_name_end) { - assert(this); assert(State == TState::InTopicList); assert(topic_name_begin); assert(topic_name_end > topic_name_begin); @@ -131,7 +125,6 @@ void TMetadataResponseWriter::OpenTopic(int16_t topic_error_code, } void TMetadataResponseWriter::OpenPartitionList() { - assert(this); assert(State == TState::InTopic); State = TState::InPartitionList; PartitionCount = 0; @@ -140,7 +133,6 @@ void TMetadataResponseWriter::OpenPartitionList() { void TMetadataResponseWriter::OpenPartition(int16_t partition_error_code, int32_t partition_id, int32_t leader_node_id) { - assert(this); assert(State == TState::InPartitionList); State = TState::InPartition; size_t replica_count_delta = THdr::PARTITION_ERROR_CODE_SIZE + @@ -158,14 +150,12 @@ void TMetadataResponseWriter::OpenPartition(int16_t partition_error_code, } void TMetadataResponseWriter::OpenReplicaList() { - assert(this); assert(State == TState::InPartition); State = TState::InReplicaList; ReplicaCount = 0; } void TMetadataResponseWriter::AddReplica(int32_t replica_node_id) { - assert(this); assert(State == TState::InReplicaList); size_t offset = Size(); GrowResult(THdr::REPLICA_NODE_ID_SIZE); @@ -174,7 +164,6 @@ void TMetadataResponseWriter::AddReplica(int32_t replica_node_id) { } void TMetadataResponseWriter::CloseReplicaList() { - assert(this); assert(State == TState::InReplicaList); State = TState::InPartition; CaughtUpReplicaCountOffset = static_cast(Size()); @@ -183,14 +172,12 @@ void TMetadataResponseWriter::CloseReplicaList() { } void TMetadataResponseWriter::OpenCaughtUpReplicaList() { - assert(this); assert(State == TState::InPartition); State = TState::InCaughtUpReplicaList; CaughtUpReplicaCount = 0; } void TMetadataResponseWriter::AddCaughtUpReplica(int32_t replica_node_id) { - assert(this); assert(State == TState::InCaughtUpReplicaList); size_t offset = Size(); GrowResult(THdr::CAUGHT_UP_REPLICA_NODE_ID_SIZE); @@ -199,14 +186,12 @@ void TMetadataResponseWriter::AddCaughtUpReplica(int32_t replica_node_id) { } void TMetadataResponseWriter::CloseCaughtUpReplicaList() { - assert(this); assert(State == TState::InCaughtUpReplicaList); State = TState::InPartition; WriteInt32ToHeader(Loc(CaughtUpReplicaCountOffset), CaughtUpReplicaCount); } void TMetadataResponseWriter::ClosePartition() { - assert(this); assert(State == TState::InPartition); State = TState::InPartitionList; ++PartitionCount; @@ -214,14 +199,12 @@ void TMetadataResponseWriter::ClosePartition() { } void TMetadataResponseWriter::ClosePartitionList() { - assert(this); assert(State == TState::InPartitionList); State = TState::InTopic; WriteInt32ToHeader(Loc(PartitionCountOffset), PartitionCount); } void TMetadataResponseWriter::CloseTopic() { - assert(this); assert(State == TState::InTopic); State = TState::InTopicList; ++TopicCount; @@ -229,14 +212,12 @@ void TMetadataResponseWriter::CloseTopic() { } void TMetadataResponseWriter::CloseTopicList() { - assert(this); assert(State == TState::InTopicList); State = TState::InResponse; WriteInt32ToHeader(Loc(TopicCountOffset), TopicCount); } void TMetadataResponseWriter::CloseResponse() { - assert(this); assert(State == TState::InResponse); State = TState::Initial; assert(Size() >= REQUEST_OR_RESPONSE_SIZE_SIZE); @@ -248,7 +229,6 @@ void TMetadataResponseWriter::CloseResponse() { } void TMetadataResponseWriter::ClearBookkeepingInfo() { - assert(this); BrokerCount = 0; BrokerOffset = 0; TopicCountOffset = 0; @@ -264,13 +244,11 @@ void TMetadataResponseWriter::ClearBookkeepingInfo() { } void TMetadataResponseWriter::SetEmptyStr(size_t size_field_offset) { - assert(this); WriteInt16ToHeader(Loc(size_field_offset), THdr::EMPTY_STRING_LENGTH); } void TMetadataResponseWriter::SetStr(size_t size_field_offset, const char *str_begin, const char *str_end) { - assert(this); assert(str_begin || (str_end == str_begin)); assert(str_end >= str_begin); diff --git a/src/dory/kafka_proto/metadata/v0/metadata_response_writer.h b/src/dory/kafka_proto/metadata/v0/metadata_response_writer.h index 207f95b2..d5bd61c1 100644 --- a/src/dory/kafka_proto/metadata/v0/metadata_response_writer.h +++ b/src/dory/kafka_proto/metadata/v0/metadata_response_writer.h @@ -125,7 +125,6 @@ namespace Dory { }; void GrowResult(size_t num_bytes) { - assert(this); assert(Result); Result->resize(Result->size() + num_bytes); } @@ -134,14 +133,12 @@ namespace Dory { than &(*Result)[i]. */ template uint8_t *Loc(T i) { - assert(this); assert(Result); return &(*Result)[i]; } /* More stuff to save typing. */ size_t Size() const { - assert(this); assert(Result); return Result->size(); } diff --git a/src/dory/kafka_proto/produce/produce_protocol.h b/src/dory/kafka_proto/produce/produce_protocol.h index 9ea95dd4..407275ba 100644 --- a/src/dory/kafka_proto/produce/produce_protocol.h +++ b/src/dory/kafka_proto/produce/produce_protocol.h @@ -60,7 +60,6 @@ namespace Dory { /* Return the number of bytes in a message set containing a single empty message (i.e. empty key and value). */ size_t GetSingleMsgOverhead() const { - assert(this); return Constants.SingleMsgOverhead; } diff --git a/src/dory/kafka_proto/produce/v0/msg_set_reader.cc b/src/dory/kafka_proto/produce/v0/msg_set_reader.cc index 415b0482..ba768bb6 100644 --- a/src/dory/kafka_proto/produce/v0/msg_set_reader.cc +++ b/src/dory/kafka_proto/produce/v0/msg_set_reader.cc @@ -37,7 +37,6 @@ TMsgSetReader::TMsgSetReader() { } void TMsgSetReader::Clear() { - assert(this); Begin = nullptr; End = nullptr; Size = 0; @@ -51,7 +50,6 @@ void TMsgSetReader::Clear() { } void TMsgSetReader::SetMsgSet(const void *msg_set, size_t msg_set_size) { - assert(this); Clear(); Begin = reinterpret_cast(msg_set); End = Begin + msg_set_size; @@ -59,7 +57,6 @@ void TMsgSetReader::SetMsgSet(const void *msg_set, size_t msg_set_size) { } bool TMsgSetReader::FirstMsg() { - assert(this); assert(Begin); assert(End >= Begin); CurrentMsg = Begin; @@ -73,7 +70,6 @@ bool TMsgSetReader::FirstMsg() { } bool TMsgSetReader::NextMsg() { - assert(this); assert(Begin); assert(End >= Begin); @@ -109,13 +105,11 @@ bool TMsgSetReader::NextMsg() { } bool TMsgSetReader::CurrentMsgCrcIsOk() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); return CurrentMsgCrcOk; } TCompressionType TMsgSetReader::GetCurrentMsgCompressionType() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); uint8_t attrs = *(CurrentMsg + PRC::MSG_OFFSET_SIZE + PRC::MSG_SIZE_SIZE + PRC::CRC_SIZE + PRC::MAGIC_BYTE_SIZE); @@ -142,31 +136,26 @@ TCompressionType TMsgSetReader::GetCurrentMsgCompressionType() const { } const uint8_t *TMsgSetReader::GetCurrentMsgKeyBegin() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); return CurrentMsgKeyBegin; } const uint8_t *TMsgSetReader::GetCurrentMsgKeyEnd() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); return CurrentMsgKeyEnd; } const uint8_t *TMsgSetReader::GetCurrentMsgValueBegin() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); return CurrentMsgValueBegin; } const uint8_t *TMsgSetReader::GetCurrentMsgValueEnd() const { - assert(this); assert((CurrentMsg >= Begin) && (CurrentMsg < End)); return CurrentMsgValueEnd; } void TMsgSetReader::InitCurrentMsg() { - assert(this); assert(Begin); assert(End > Begin); assert(CurrentMsg >= Begin); diff --git a/src/dory/kafka_proto/produce/v0/msg_set_writer.cc b/src/dory/kafka_proto/produce/v0/msg_set_writer.cc index ceca5f3b..a3fa4c2d 100644 --- a/src/dory/kafka_proto/produce/v0/msg_set_writer.cc +++ b/src/dory/kafka_proto/produce/v0/msg_set_writer.cc @@ -36,7 +36,6 @@ TMsgSetWriter::TMsgSetWriter() { } void TMsgSetWriter::Reset() { - assert(this); Buf = nullptr; State = TState::Idle; AtOffset = 0; @@ -52,8 +51,6 @@ void TMsgSetWriter::Reset() { } void TMsgSetWriter::OpenMsgSet(std::vector &result_buf, bool append) { - assert(this); - /* Make sure we start in a sane state. This guards against cases where an exception previously thrown by this object leaves it in a bad state and we later reuse it for another produce request. */ @@ -99,7 +96,6 @@ static int8_t XlateCompressionType(TCompressionType compression_type) { void TMsgSetWriter::OpenMsg(TCompressionType compression_type, size_t key_size, size_t value_size) { - assert(this); assert(State == TState::InMsgSet); assert(Buf); assert(key_size <= static_cast(std::numeric_limits::max())); @@ -131,7 +127,6 @@ void TMsgSetWriter::OpenMsg(TCompressionType compression_type, } size_t TMsgSetWriter::GetCurrentMsgKeyOffset() const { - assert(this); assert(State == TState::InMsg); assert(Buf); assert(CurrentMsgKeyOffset > CurrentMsgSetItemOffset); @@ -139,7 +134,6 @@ size_t TMsgSetWriter::GetCurrentMsgKeyOffset() const { } size_t TMsgSetWriter::GetCurrentMsgValueOffset() const { - assert(this); assert(State == TState::InMsg); assert(Buf); assert(CurrentMsgValueOffset > CurrentMsgSetItemOffset); @@ -147,7 +141,6 @@ size_t TMsgSetWriter::GetCurrentMsgValueOffset() const { } void TMsgSetWriter::AdjustValueSize(size_t new_size) { - assert(this); assert(State == TState::InMsg); assert(Buf->size() > CurrentMsgValueSize); size_t size_of_buf_minus_value = Buf->size() - CurrentMsgValueSize; @@ -156,7 +149,6 @@ void TMsgSetWriter::AdjustValueSize(size_t new_size) { } void TMsgSetWriter::RollbackOpenMsg() { - assert(this); assert(State == TState::InMsg); assert(Buf); assert(CurrentMsgCrcOffset > CurrentMsgSetItemOffset); @@ -174,7 +166,6 @@ void TMsgSetWriter::RollbackOpenMsg() { } void TMsgSetWriter::CloseMsg() { - assert(this); assert(State == TState::InMsg); assert(Buf); assert(CurrentMsgCrcOffset > CurrentMsgSetItemOffset); @@ -211,7 +202,6 @@ void TMsgSetWriter::CloseMsg() { void TMsgSetWriter::AddMsg(TCompressionType compression_type, const uint8_t *key_begin, const uint8_t *key_end, const uint8_t *value_begin, const uint8_t *value_end) { - assert(this); assert(State == TState::InMsgSet); assert(Buf); assert(key_begin || (!key_begin && !key_end)); @@ -237,7 +227,6 @@ void TMsgSetWriter::AddMsg(TCompressionType compression_type, } size_t TMsgSetWriter::CloseMsgSet() { - assert(this); assert(State == TState::InMsgSet); assert(Buf); assert(AtOffset >= FirstMsgSetItemOffset); diff --git a/src/dory/kafka_proto/produce/v0/msg_set_writer.h b/src/dory/kafka_proto/produce/v0/msg_set_writer.h index edf00a2f..aaabd2f0 100644 --- a/src/dory/kafka_proto/produce/v0/msg_set_writer.h +++ b/src/dory/kafka_proto/produce/v0/msg_set_writer.h @@ -94,66 +94,56 @@ namespace Dory { } void WriteInt8(size_t offset, int8_t value) { - assert(this); assert(Buf); assert(Buf->size() > offset); (*Buf)[offset] = static_cast(value); } void WriteInt8AtOffset(int8_t value) { - assert(this); WriteInt8(AtOffset, value); ++AtOffset; } void WriteInt16(size_t offset, int16_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 1)); WriteInt16ToHeader(&(*Buf)[offset], value); } void WriteInt16AtOffset(int16_t value) { - assert(this); WriteInt16(AtOffset, value); AtOffset += 2; } void WriteInt32(size_t offset, int32_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 3)); WriteInt32ToHeader(&(*Buf)[offset], value); } void WriteInt32AtOffset(int32_t value) { - assert(this); WriteInt32(AtOffset, value); AtOffset += 4; } void WriteInt64(size_t offset, int64_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 7)); WriteInt64ToHeader(&(*Buf)[offset], value); } void WriteInt64AtOffset(int64_t value) { - assert(this); WriteInt64(AtOffset, value); AtOffset += 8; } void WriteData(size_t offset, const void *data, size_t data_size) { - assert(this); assert(Buf); assert(Buf->size() > (offset + data_size - 1)); std::memcpy(&(*Buf)[offset], data, data_size); } void WriteDataAtOffset(const void *data, size_t data_size) { - assert(this); WriteData(AtOffset, data, data_size); AtOffset += data_size; } diff --git a/src/dory/kafka_proto/produce/v0/produce_proto.cc b/src/dory/kafka_proto/produce/v0/produce_proto.cc index a70d37d7..1abeaeb3 100644 --- a/src/dory/kafka_proto/produce/v0/produce_proto.cc +++ b/src/dory/kafka_proto/produce/v0/produce_proto.cc @@ -89,27 +89,22 @@ DEFINE_COUNTER(AckOk); std::unique_ptr TProduceProto::CreateProduceRequestWriter() const { - assert(this); return std::unique_ptr(new TProduceRequestWriter); } std::unique_ptr TProduceProto::CreateMsgSetWriter() const { - assert(this); return std::unique_ptr(new TMsgSetWriter); } std::unique_ptr TProduceProto::CreateProduceResponseReader() const { - assert(this); return std::unique_ptr( new TProduceResponseReader); } TProduceProtocol::TAckResultAction TProduceProto::ProcessAck(int16_t ack_value) const { - assert(this); - /* See https://kafka.apache.org/protocol for documentation on the error codes below. */ switch (static_cast(ack_value)) { diff --git a/src/dory/kafka_proto/produce/v0/produce_request_reader.cc b/src/dory/kafka_proto/produce/v0/produce_request_reader.cc index d9e9b261..a5326248 100644 --- a/src/dory/kafka_proto/produce/v0/produce_request_reader.cc +++ b/src/dory/kafka_proto/produce/v0/produce_request_reader.cc @@ -35,7 +35,6 @@ TProduceRequestReader::TProduceRequestReader() { } void TProduceRequestReader::Clear() { - assert(this); Begin = nullptr; End = nullptr; Size = 0; @@ -55,7 +54,6 @@ void TProduceRequestReader::Clear() { void TProduceRequestReader::SetRequest(const void *request, size_t request_size) { - assert(this); Clear(); Begin = reinterpret_cast(request); End = Begin + GetRequestOrResponseSize(Begin); @@ -107,13 +105,11 @@ void TProduceRequestReader::SetRequest(const void *request, } int32_t TProduceRequestReader::GetCorrelationId() const { - assert(this); return ReadInt32FromHeader(Begin + REQUEST_OR_RESPONSE_SIZE_SIZE + PRC::API_KEY_SIZE + PRC::API_VERSION_SIZE); } const char *TProduceRequestReader::GetClientIdBegin() const { - assert(this); return reinterpret_cast(Begin) + REQUEST_OR_RESPONSE_SIZE_SIZE + PRC::API_KEY_SIZE + PRC::API_VERSION_SIZE + PRC::CORRELATION_ID_SIZE + @@ -121,27 +117,22 @@ const char *TProduceRequestReader::GetClientIdBegin() const { } const char *TProduceRequestReader::GetClientIdEnd() const { - assert(this); return GetClientIdBegin() + ClientIdLen; } int16_t TProduceRequestReader::GetRequiredAcks() const { - assert(this); return ReadInt16FromHeader(GetClientIdEnd()); } int32_t TProduceRequestReader::GetReplicationTimeout() const { - assert(this); return ReadInt32FromHeader(GetClientIdEnd() + PRC::REQUIRED_ACKS_SIZE); } size_t TProduceRequestReader::GetNumTopics() const { - assert(this); return static_cast(NumTopics); } bool TProduceRequestReader::FirstTopic() { - assert(this); assert(Begin); assert(End > Begin); assert(NumTopics >= 0); @@ -159,7 +150,6 @@ bool TProduceRequestReader::FirstTopic() { } bool TProduceRequestReader::NextTopic() { - assert(this); assert(Begin); assert(End > Begin); assert(NumTopics >= 0); @@ -200,26 +190,22 @@ bool TProduceRequestReader::NextTopic() { } const char *TProduceRequestReader::GetCurrentTopicNameBegin() const { - assert(this); assert((CurrentTopicBegin > Begin) && (CurrentTopicBegin < End)); return reinterpret_cast(CurrentTopicBegin) + PRC::TOPIC_NAME_LEN_SIZE; } const char *TProduceRequestReader::GetCurrentTopicNameEnd() const { - assert(this); assert((CurrentTopicNameEnd > Begin) && (CurrentTopicNameEnd < End)); return reinterpret_cast(CurrentTopicNameEnd); } size_t TProduceRequestReader::GetNumMsgSetsInCurrentTopic() const { - assert(this); assert((CurrentTopicNameEnd > Begin) && (CurrentTopicNameEnd < End)); return static_cast(NumPartitionsInTopic); } bool TProduceRequestReader::FirstMsgSetInTopic() { - assert(this); assert(Begin); assert(End > Begin); assert((CurrentTopicIndex >= 0) && (CurrentTopicIndex < NumTopics)); @@ -238,7 +224,6 @@ bool TProduceRequestReader::FirstMsgSetInTopic() { } bool TProduceRequestReader::NextMsgSetInTopic() { - assert(this); assert(Begin); assert(End > Begin); assert(CurrentTopicBegin > Begin); @@ -270,13 +255,11 @@ bool TProduceRequestReader::NextMsgSetInTopic() { } int32_t TProduceRequestReader::GetPartitionOfCurrentMsgSet() const { - assert(this); assert((CurrentPartitionBegin > Begin) && (CurrentPartitionBegin < End)); return ReadInt32FromHeader(CurrentPartitionBegin); } bool TProduceRequestReader::FirstMsgInMsgSet() { - assert(this); assert(Begin); assert(End > Begin); assert((CurrentTopicIndex >= 0) && (CurrentTopicIndex < NumTopics)); @@ -292,7 +275,6 @@ bool TProduceRequestReader::FirstMsgInMsgSet() { } bool TProduceRequestReader::NextMsgInMsgSet() { - assert(this); assert(Begin); assert(End > Begin); assert((CurrentTopicIndex >= 0) && (CurrentTopicIndex < NumTopics)); @@ -308,37 +290,30 @@ bool TProduceRequestReader::NextMsgInMsgSet() { } bool TProduceRequestReader::CurrentMsgCrcIsOk() const { - assert(this); return MsgSetReader.CurrentMsgCrcIsOk(); } TCompressionType TProduceRequestReader::GetCurrentMsgCompressionType() const { - assert(this); return MsgSetReader.GetCurrentMsgCompressionType(); } const uint8_t *TProduceRequestReader::GetCurrentMsgKeyBegin() const { - assert(this); return MsgSetReader.GetCurrentMsgKeyBegin(); } const uint8_t *TProduceRequestReader::GetCurrentMsgKeyEnd() const { - assert(this); return MsgSetReader.GetCurrentMsgKeyEnd(); } const uint8_t *TProduceRequestReader::GetCurrentMsgValueBegin() const { - assert(this); return MsgSetReader.GetCurrentMsgValueBegin(); } const uint8_t *TProduceRequestReader::GetCurrentMsgValueEnd() const { - assert(this); return MsgSetReader.GetCurrentMsgValueEnd(); } void TProduceRequestReader::InitCurrentTopic() { - assert(this); assert(Begin); assert(End > Begin); assert(CurrentTopicBegin > Begin); @@ -378,7 +353,6 @@ void TProduceRequestReader::InitCurrentTopic() { } void TProduceRequestReader::InitCurrentPartition() { - assert(this); assert(Begin); assert(End > Begin); assert(CurrentPartitionBegin > Begin); diff --git a/src/dory/kafka_proto/produce/v0/produce_request_writer.cc b/src/dory/kafka_proto/produce/v0/produce_request_writer.cc index 4e0fb12c..f235d652 100644 --- a/src/dory/kafka_proto/produce/v0/produce_request_writer.cc +++ b/src/dory/kafka_proto/produce/v0/produce_request_writer.cc @@ -35,7 +35,6 @@ TProduceRequestWriter::TProduceRequestWriter() { } void TProduceRequestWriter::Reset() { - assert(this); Buf = nullptr; State = TState::Idle; AtOffset = 0; @@ -53,8 +52,6 @@ void TProduceRequestWriter::Reset() { void TProduceRequestWriter::OpenRequest(std::vector &result_buf, int32_t corr_id, const char *client_id_begin, const char *client_id_end, int16_t required_acks, int32_t replication_timeout) { - assert(this); - /* Make sure we start in a sane state. */ Reset(); @@ -88,7 +85,6 @@ void TProduceRequestWriter::OpenRequest(std::vector &result_buf, void TProduceRequestWriter::OpenTopic(const char *topic_name_begin, const char *topic_name_end) { - assert(this); assert(State == TState::InRequest); assert(topic_name_begin); assert(topic_name_end > topic_name_begin); @@ -116,7 +112,6 @@ void TProduceRequestWriter::OpenTopic(const char *topic_name_begin, } void TProduceRequestWriter::OpenMsgSet(int32_t partition) { - assert(this); assert(State == TState::InTopic); assert(Buf); Buf->resize(Buf->size() + PRC::PARTITION_SIZE + PRC::MSG_SET_SIZE_SIZE); @@ -134,7 +129,6 @@ void TProduceRequestWriter::OpenMsgSet(int32_t partition) { void TProduceRequestWriter::OpenMsg(TCompressionType compression_type, size_t key_size, size_t value_size) { - assert(this); assert(State == TState::InMsgSet); assert(Buf); assert(key_size <= static_cast(std::numeric_limits::max())); @@ -144,35 +138,30 @@ void TProduceRequestWriter::OpenMsg(TCompressionType compression_type, } size_t TProduceRequestWriter::GetCurrentMsgKeyOffset() const { - assert(this); assert(State == TState::InMsgSet); assert(Buf); return MsgSetWriter.GetCurrentMsgKeyOffset(); } size_t TProduceRequestWriter::GetCurrentMsgValueOffset() const { - assert(this); assert(State == TState::InMsgSet); assert(Buf); return MsgSetWriter.GetCurrentMsgValueOffset(); } void TProduceRequestWriter::AdjustValueSize(size_t new_size) { - assert(this); assert(State == TState::InMsgSet); assert(Buf); MsgSetWriter.AdjustValueSize(new_size); } void TProduceRequestWriter::RollbackOpenMsg() { - assert(this); assert(State == TState::InMsgSet); assert(Buf); MsgSetWriter.RollbackOpenMsg(); } void TProduceRequestWriter::CloseMsg() { - assert(this); assert(State == TState::InMsgSet); assert(Buf); MsgSetWriter.CloseMsg(); @@ -181,7 +170,6 @@ void TProduceRequestWriter::CloseMsg() { void TProduceRequestWriter::AddMsg(TCompressionType compression_type, const uint8_t *key_begin, const uint8_t *key_end, const uint8_t *value_begin, const uint8_t *value_end) { - assert(this); assert(State == TState::InMsgSet); assert(Buf); MsgSetWriter.AddMsg(compression_type, key_begin, key_end, value_begin, @@ -189,7 +177,6 @@ void TProduceRequestWriter::AddMsg(TCompressionType compression_type, } void TProduceRequestWriter::CloseMsgSet() { - assert(this); assert(State == TState::InMsgSet); assert(Buf); size_t msg_set_size = MsgSetWriter.CloseMsgSet(); @@ -202,7 +189,6 @@ void TProduceRequestWriter::CloseMsgSet() { } void TProduceRequestWriter::CloseTopic() { - assert(this); assert(State == TState::InTopic); assert(Buf); WriteInt32(CurrentTopicPartitionCountOffset, @@ -212,7 +198,6 @@ void TProduceRequestWriter::CloseTopic() { } void TProduceRequestWriter::CloseRequest() { - assert(this); assert(State == TState::InRequest); assert(Buf); WriteInt32(TopicCountOffset, static_cast(TopicCount)); diff --git a/src/dory/kafka_proto/produce/v0/produce_request_writer.h b/src/dory/kafka_proto/produce/v0/produce_request_writer.h index 3cb5c641..7a07557b 100644 --- a/src/dory/kafka_proto/produce/v0/produce_request_writer.h +++ b/src/dory/kafka_proto/produce/v0/produce_request_writer.h @@ -96,66 +96,56 @@ namespace Dory { }; // TState void WriteInt8(size_t offset, int8_t value) { - assert(this); assert(Buf); assert(Buf->size() > offset); (*Buf)[offset] = static_cast(value); } void WriteInt8AtOffset(int8_t value) { - assert(this); WriteInt8(AtOffset, value); ++AtOffset; } void WriteInt16(size_t offset, int16_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 1)); WriteInt16ToHeader(&(*Buf)[offset], value); } void WriteInt16AtOffset(int16_t value) { - assert(this); WriteInt16(AtOffset, value); AtOffset += 2; } void WriteInt32(size_t offset, int32_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 3)); WriteInt32ToHeader(&(*Buf)[offset], value); } void WriteInt32AtOffset(int32_t value) { - assert(this); WriteInt32(AtOffset, value); AtOffset += 4; } void WriteInt64(size_t offset, int64_t value) { - assert(this); assert(Buf); assert(Buf->size() > (offset + 7)); WriteInt64ToHeader(&(*Buf)[offset], value); } void WriteInt64AtOffset(int64_t value) { - assert(this); WriteInt64(AtOffset, value); AtOffset += 8; } void WriteData(size_t offset, const void *data, size_t data_size) { - assert(this); assert(Buf); assert(Buf->size() > (offset + data_size - 1)); std::memcpy(&(*Buf)[offset], data, data_size); } void WriteDataAtOffset(const void *data, size_t data_size) { - assert(this); WriteData(AtOffset, data, data_size); AtOffset += data_size; } diff --git a/src/dory/kafka_proto/produce/v0/produce_response_reader.cc b/src/dory/kafka_proto/produce/v0/produce_response_reader.cc index 939598d7..94ada74b 100644 --- a/src/dory/kafka_proto/produce/v0/produce_response_reader.cc +++ b/src/dory/kafka_proto/produce/v0/produce_response_reader.cc @@ -44,7 +44,6 @@ TProduceResponseReader::TProduceResponseReader() { } void TProduceResponseReader::Clear() noexcept { - assert(this); Begin = nullptr; End = nullptr; NumTopics = 0; @@ -57,7 +56,6 @@ void TProduceResponseReader::Clear() noexcept { void TProduceResponseReader::SetResponse(const void *response, size_t response_size) { - assert(this); assert(response); Clear(); @@ -84,7 +82,6 @@ void TProduceResponseReader::SetResponse(const void *response, } int32_t TProduceResponseReader::GetCorrelationId() const { - assert(this); assert(Begin); assert(End); assert(NumTopics >= 0); @@ -92,12 +89,10 @@ int32_t TProduceResponseReader::GetCorrelationId() const { } size_t TProduceResponseReader::GetNumTopics() const { - assert(this); return static_cast(NumTopics); } bool TProduceResponseReader::FirstTopic() { - assert(this); assert(NumTopics >= 0); if (NumTopics < 1) { @@ -112,7 +107,6 @@ bool TProduceResponseReader::FirstTopic() { } bool TProduceResponseReader::NextTopic() { - assert(this); assert(NumTopics >= 0); if (CurrentTopicIndex < 0) { @@ -143,7 +137,6 @@ bool TProduceResponseReader::NextTopic() { } const char *TProduceResponseReader::GetCurrentTopicNameBegin() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd > CurrentTopicBegin); @@ -152,7 +145,6 @@ const char *TProduceResponseReader::GetCurrentTopicNameBegin() const { } const char *TProduceResponseReader::GetCurrentTopicNameEnd() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd > CurrentTopicBegin); @@ -160,7 +152,6 @@ const char *TProduceResponseReader::GetCurrentTopicNameEnd() const { } size_t TProduceResponseReader::GetNumPartitionsInCurrentTopic() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd > CurrentTopicBegin); @@ -168,7 +159,6 @@ size_t TProduceResponseReader::GetNumPartitionsInCurrentTopic() const { } bool TProduceResponseReader::FirstPartitionInTopic() { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -184,7 +174,6 @@ bool TProduceResponseReader::FirstPartitionInTopic() { } bool TProduceResponseReader::NextPartitionInTopic() { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -208,7 +197,6 @@ bool TProduceResponseReader::NextPartitionInTopic() { } int32_t TProduceResponseReader::GetCurrentPartitionNumber() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -220,7 +208,6 @@ int32_t TProduceResponseReader::GetCurrentPartitionNumber() const { } int16_t TProduceResponseReader::GetCurrentPartitionErrorCode() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -232,7 +219,6 @@ int16_t TProduceResponseReader::GetCurrentPartitionErrorCode() const { } int64_t TProduceResponseReader::GetCurrentPartitionOffset() const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -244,7 +230,6 @@ int64_t TProduceResponseReader::GetCurrentPartitionOffset() const { } const uint8_t *TProduceResponseReader::GetPartitionStart(int32_t index) const { - assert(this); assert(NumTopics >= 0); assert(CurrentTopicBegin); assert(CurrentTopicNameEnd); @@ -256,8 +241,6 @@ const uint8_t *TProduceResponseReader::GetPartitionStart(int32_t index) const { } void TProduceResponseReader::InitCurrentTopic() { - assert(this); - if ((CurrentTopicBegin + PRC::TOPIC_NAME_LEN_SIZE) > End) { ProduceResponseTruncated3.Increment(); THROW_ERROR(TResponseTruncated); diff --git a/src/dory/kafka_proto/produce/v0/produce_response_writer.cc b/src/dory/kafka_proto/produce/v0/produce_response_writer.cc index be3412d3..2acbd8c1 100644 --- a/src/dory/kafka_proto/produce/v0/produce_response_writer.cc +++ b/src/dory/kafka_proto/produce/v0/produce_response_writer.cc @@ -37,7 +37,6 @@ TProduceResponseWriter::TProduceResponseWriter() { } void TProduceResponseWriter::Reset() { - assert(this); OutBuf = nullptr; TopicStarted = false; CurrentTopicOffset = 0; @@ -49,8 +48,6 @@ void TProduceResponseWriter::Reset() { void TProduceResponseWriter::OpenResponse(std::vector &out, int32_t correlation_id) { - assert(this); - /* Make sure we start in a sane state. */ Reset(); @@ -65,7 +62,6 @@ void TProduceResponseWriter::OpenResponse(std::vector &out, void TProduceResponseWriter::OpenTopic(const char *topic_begin, const char *topic_end) { - assert(this); assert(topic_begin); assert(topic_end >= topic_begin); assert(OutBuf); @@ -91,7 +87,6 @@ void TProduceResponseWriter::OpenTopic(const char *topic_begin, void TProduceResponseWriter::AddPartition(int32_t partition, int16_t error_code, int64_t offset) { - assert(this); assert(partition >= 0); assert(offset >= 0); assert(OutBuf); @@ -111,7 +106,6 @@ void TProduceResponseWriter::AddPartition(int32_t partition, } void TProduceResponseWriter::CloseTopic() { - assert(this); assert(OutBuf); assert(TopicStarted); assert(CurrentTopicOffset >= REQUEST_OR_RESPONSE_SIZE_SIZE + @@ -131,7 +125,6 @@ void TProduceResponseWriter::CloseTopic() { } void TProduceResponseWriter::CloseResponse() { - assert(this); assert(OutBuf); assert(!TopicStarted); assert(CurrentTopicOffset >= REQUEST_OR_RESPONSE_SIZE_SIZE + diff --git a/src/dory/metadata.cc b/src/dory/metadata.cc index 0b58380d..a2818b5b 100644 --- a/src/dory/metadata.cc +++ b/src/dory/metadata.cc @@ -41,7 +41,6 @@ DEFINE_COUNTER(MetadataSanityCheckFail); DEFINE_COUNTER(MetadataSanityCheckSuccess); bool TMetadata::TBroker::operator==(const TBroker &that) const noexcept { - assert(this); return (Id == that.Id) && (Hostname == that.Hostname) && (Port == that.Port) && (InService == that.InService); } @@ -51,14 +50,12 @@ TMetadata::TBuilder::TBuilder() } void TMetadata::TBuilder::OpenBrokerList() { - assert(this); assert(State == TState::Initial); State = TState::AddingBrokers; } void TMetadata::TBuilder::AddBroker(int32_t kafka_id, std::string &&hostname, uint16_t port) { - assert(this); assert(State == TState::AddingBrokers); auto result = BrokerMap.insert(std::make_pair(kafka_id, Brokers.size())); @@ -72,13 +69,11 @@ void TMetadata::TBuilder::AddBroker(int32_t kafka_id, std::string &&hostname, } void TMetadata::TBuilder::CloseBrokerList() { - assert(this); assert(State == TState::AddingBrokers); State = TState::AddingTopics; } bool TMetadata::TBuilder::OpenTopic(const std::string &name) { - assert(this); assert(State == TState::AddingTopics); bool success = TopicNameToIndex.insert(std::make_pair(name, Topics.size())).second; @@ -101,7 +96,6 @@ bool TMetadata::TBuilder::OpenTopic(const std::string &name) { void TMetadata::TBuilder::AddPartitionToTopic(int32_t partition_id, int32_t broker_id, bool can_send_to_partition, int16_t error_code) { - assert(this); assert(State == TState::AddingOneTopic); auto iter = BrokerMap.find(broker_id); @@ -154,7 +148,6 @@ void TMetadata::TBuilder::AddPartitionToTopic(int32_t partition_id, } void TMetadata::TBuilder::CloseTopic() { - assert(this); assert(State == TState::AddingOneTopic); assert(TopicNameToIndex.size() == Topics.size()); @@ -238,7 +231,6 @@ void TMetadata::TBuilder::CloseTopic() { } std::unique_ptr TMetadata::TBuilder::Build() { - assert(this); assert((State != TState::AddingBrokers) && (State != TState::AddingOneTopic)); assert(TopicNameToIndex.size() == Topics.size()); @@ -253,8 +245,6 @@ std::unique_ptr TMetadata::TBuilder::Build() { } void TMetadata::TBuilder::GroupInServiceBrokers() { - assert(this); - /* Rearrange 'Brokers' vector so all out of service brokers are at the end. */ @@ -324,8 +314,6 @@ void TMetadata::TBuilder::GroupInServiceBrokers() { } bool TMetadata::operator==(const TMetadata &that) const { - assert(this); - if ((Brokers.size() != that.Brokers.size()) || (TopicBrokerVec.size() != that.TopicBrokerVec.size()) || (Topics.size() != that.Topics.size())) { @@ -340,7 +328,6 @@ bool TMetadata::operator==(const TMetadata &that) const { } int TMetadata::FindTopicIndex(const std::string &topic) const noexcept { - assert(this); auto iter = TopicNameToIndex.find(topic); if (iter == TopicNameToIndex.end()) { @@ -362,7 +349,6 @@ int TMetadata::FindTopicIndex(const std::string &topic) const noexcept { const int32_t *TMetadata::FindPartitionChoices(const std::string &topic, size_t broker_index, size_t &num_choices) const noexcept { - assert(this); num_choices = 0; int topic_index = FindTopicIndex(topic); @@ -427,8 +413,6 @@ bool TMetadata::SanityCheckOkPartitions(const TTopic &t, std::unordered_set &id_set_ok, std::unordered_map> &broker_partition_map) const { - assert(this); - for (const TPartition &p : t.OkPartitions) { id_set_ok.insert(p.Id); @@ -473,8 +457,6 @@ bool TMetadata::SanityCheckOkPartitions(const TTopic &t, bool TMetadata::SanityCheckOutOfServicePartitions(const TTopic &t, std::unordered_set &id_set_bad) const { - assert(this); - for (const TPartition &p : t.OutOfServicePartitions) { id_set_bad.insert(p.Id); @@ -517,8 +499,6 @@ bool TMetadata::SanityCheckBrokerPartitionMap(const TTopic &t, const std::unordered_map> &broker_partition_map, std::vector &topic_broker_vec_access) const { - assert(this); - for (const auto &map_item : broker_partition_map) { auto iter = t.PartitionChoiceMap.find(map_item.first); @@ -576,8 +556,6 @@ bool TMetadata::SanityCheckBrokerPartitionMap(const TTopic &t, bool TMetadata::SanityCheckOneTopic(const TTopic &t, std::unordered_set &in_service_broker_indexes, std::vector &topic_broker_vec_access) const { - assert(this); - if (t.AllPartitions.size() != (t.OkPartitions.size() + t.OutOfServicePartitions.size())) { LOG(TPri::ERR) @@ -629,7 +607,6 @@ bool TMetadata::SanityCheckOneTopic(const TTopic &t, bool TMetadata::SanityCheckTopics( std::unordered_set &in_service_broker_indexes) const { - assert(this); std::unordered_set topic_indexes; for (const auto &map_item : TopicNameToIndex) { @@ -679,7 +656,6 @@ bool TMetadata::SanityCheck() const { } bool TMetadata::DoSanityCheck() const { - assert(this); std::unordered_set in_service_broker_indexes; if (!SanityCheckTopics(in_service_broker_indexes)) { @@ -729,11 +705,8 @@ bool TMetadata::DoSanityCheck() const { } bool TMetadata::CompareBrokers(const TMetadata &that) const { - assert(this); - struct t_hasher { size_t operator()(const TBroker &broker) const noexcept { - assert(this); return StringHash(broker.Hostname) ^ Int32Hash(broker.Id ^ broker.Port ^ broker.InService); } @@ -757,8 +730,6 @@ bool TMetadata::CompareBrokers(const TMetadata &that) const { bool TMetadata::SingleTopicCompare(const TMetadata &that, const TTopic &this_topic, const TTopic &that_topic) const { - assert(this); - struct t_part { int32_t Id; int32_t BrokerId; @@ -774,20 +745,17 @@ bool TMetadata::SingleTopicCompare(const TMetadata &that, t_part &operator=(const t_part &) noexcept = default; bool operator==(const t_part &that) const noexcept { - assert(this); return (Id == that.Id) && (BrokerId == that.BrokerId) && (ErrorCode == that.ErrorCode); } bool operator!=(const t_part &that) const noexcept { - assert(this); return !(*this == that); } }; // t_part struct t_hasher { size_t operator()(const t_part &part) const noexcept { - assert(this); return Int32Hash(part.Id ^ part.BrokerId ^ part.ErrorCode); } @@ -836,8 +804,6 @@ bool TMetadata::SingleTopicCompare(const TMetadata &that, } bool TMetadata::CompareTopics(const TMetadata &that) const { - assert(this); - for (const auto &map_item : TopicNameToIndex) { auto iter = that.TopicNameToIndex.find(map_item.first); diff --git a/src/dory/metadata.h b/src/dory/metadata.h index 77187a22..bc499ec1 100644 --- a/src/dory/metadata.h +++ b/src/dory/metadata.h @@ -46,22 +46,18 @@ namespace Dory { class TBroker final { public: int32_t GetId() const noexcept { - assert(this); return Id; } const std::string &GetHostname() const noexcept { - assert(this); return Hostname; } uint16_t GetPort() const noexcept { - assert(this); return Port; } bool IsInService() const noexcept { - assert(this); return InService; } @@ -76,7 +72,6 @@ namespace Dory { bool operator==(const TBroker &that) const noexcept; bool operator!=(const TBroker &that) const noexcept { - assert(this); return !(*this == that); } @@ -88,7 +83,6 @@ namespace Dory { } void MarkInService() noexcept { - assert(this); InService = true; } @@ -111,17 +105,14 @@ namespace Dory { class TPartition final { public: int32_t GetId() const noexcept { - assert(this); return Id; } size_t GetBrokerIndex() const noexcept { - assert(this); return BrokerIndex; } int16_t GetErrorCode() const noexcept { - assert(this); return ErrorCode; } @@ -152,12 +143,10 @@ namespace Dory { class TPartitionChoices final { public: size_t GetTopicBrokerVecIndex() const noexcept { - assert(this); return TopicBrokerVecIndex; } size_t GetTopicBrokerVecNumItems() const noexcept { - assert(this); return TopicBrokerVecNumItems; } @@ -186,18 +175,15 @@ namespace Dory { class TTopic final { public: const std::vector &GetOkPartitions() const noexcept { - assert(this); return OkPartitions; } const std::vector & GetOutOfServicePartitions() const noexcept { - assert(this); return OutOfServicePartitions; } const std::vector &GetAllPartitions() const noexcept { - assert(this); return AllPartitions; } @@ -258,7 +244,6 @@ namespace Dory { std::unique_ptr Build(); void Reset() { - assert(this); *this = TBuilder(); } @@ -305,28 +290,23 @@ namespace Dory { bool operator==(const TMetadata &that) const; bool operator!=(const TMetadata &that) const { - assert(this); return !(*this == that); } const std::vector &GetBrokers() const noexcept { - assert(this); return Brokers; } size_t NumInServiceBrokers() const noexcept { - assert(this); return InServiceBrokerCount; } const std::vector &GetTopics() const noexcept { - assert(this); return Topics; } const std::unordered_map & GetTopicNameMap() const noexcept { - assert(this); return TopicNameToIndex; } diff --git a/src/dory/metadata_fetcher.cc b/src/dory/metadata_fetcher.cc index 7a1fa954..040f8428 100644 --- a/src/dory/metadata_fetcher.cc +++ b/src/dory/metadata_fetcher.cc @@ -79,7 +79,6 @@ TMetadataFetcher::TMetadataFetcher(const TMetadataProtocol *metadata_protocol) } bool TMetadataFetcher::Connect(const char *host_name, in_port_t port) { - assert(this); Disconnect(); try { @@ -105,8 +104,6 @@ bool TMetadataFetcher::Connect(const char *host_name, in_port_t port) { } std::unique_ptr TMetadataFetcher::Fetch(int timeout_ms) { - assert(this); - if (!Sock.IsOpen()) { Die("Must connect to host before getting metadata"); } @@ -168,8 +165,6 @@ std::unique_ptr TMetadataFetcher::Fetch(int timeout_ms) { TMetadataFetcher::TTopicAutocreateResult TMetadataFetcher::TopicAutocreate(const char *topic, int timeout_ms) { - assert(this); - if (!Sock.IsOpen()) { Die("Must connect to host before getting metadata"); } @@ -211,7 +206,6 @@ TMetadataFetcher::TopicAutocreate(const char *topic, int timeout_ms) { bool TMetadataFetcher::SendRequest(const std::vector &request, int timeout_ms) { - assert(this); StartSendMetadataRequest.Increment(); try { @@ -247,7 +241,6 @@ enum class TReadResponsePollItem { }; // TReadResponsePollItem bool TMetadataFetcher::ReadResponse(int timeout_ms) { - assert(this); TPollArray poll_array; struct pollfd &sock_item = poll_array[TReadResponsePollItem::SockIo]; sock_item.events = POLLIN; diff --git a/src/dory/metadata_fetcher.h b/src/dory/metadata_fetcher.h index 84bd6361..229e9a6f 100644 --- a/src/dory/metadata_fetcher.h +++ b/src/dory/metadata_fetcher.h @@ -65,12 +65,10 @@ namespace Dory { /* Return true on success or false on failure. */ bool Connect(const std::string &host_name, in_port_t port) { - assert(this); return Connect(host_name.c_str(), port); } void Disconnect() noexcept { - assert(this); Sock.Reset(); } diff --git a/src/dory/metadata_timestamp.cc b/src/dory/metadata_timestamp.cc index a12a27a2..f60a93fc 100644 --- a/src/dory/metadata_timestamp.cc +++ b/src/dory/metadata_timestamp.cc @@ -29,7 +29,6 @@ using namespace Base; using namespace Dory; void TMetadataTimestamp::RecordUpdate(bool modified) noexcept { - assert(this); uint64_t now = GetEpochMilliseconds(); std::lock_guard lock(Mutex); @@ -42,8 +41,6 @@ void TMetadataTimestamp::RecordUpdate(bool modified) noexcept { void TMetadataTimestamp::GetTimes(uint64_t &last_update_time, uint64_t &last_modified_time) const noexcept { - assert(this); - std::lock_guard lock(Mutex); last_update_time = LastUpdateTime; last_modified_time = LastModifiedTime; diff --git a/src/dory/mock_kafka_server/cmd_bucket.cc b/src/dory/mock_kafka_server/cmd_bucket.cc index f67ca3bc..c80b877f 100644 --- a/src/dory/mock_kafka_server/cmd_bucket.cc +++ b/src/dory/mock_kafka_server/cmd_bucket.cc @@ -30,14 +30,12 @@ using namespace Dory::MockKafkaServer; using namespace Log; void TCmdBucket::Put(const TCmd &cmd) { - assert(this); LOG(TPri::DEBUG) << "append cmd to queue"; std::lock_guard lock(Mutex); CmdQueue.emplace_back(std::make_pair(++SequenceNumCounter, cmd)); } bool TCmdBucket::CopyOut(size_t &sequence_num, TCmd &out_cmd) const { - assert(this); std::lock_guard lock(Mutex); if (CmdQueue.empty()) { @@ -51,7 +49,6 @@ bool TCmdBucket::CopyOut(size_t &sequence_num, TCmd &out_cmd) const { } bool TCmdBucket::Remove(size_t sequence_num) { - assert(this); bool ret = true; { diff --git a/src/dory/mock_kafka_server/cmd_handler.cc b/src/dory/mock_kafka_server/cmd_handler.cc index a2ce49a2..00a0965d 100644 --- a/src/dory/mock_kafka_server/cmd_handler.cc +++ b/src/dory/mock_kafka_server/cmd_handler.cc @@ -33,7 +33,6 @@ using namespace Dory::MockKafkaServer; using namespace Socket; void TCmdHandler::OnEvent(int fd, short /*flags*/) { - assert(this); TAddress client_address; TFd client_socket(IfLt0(Accept(fd, client_address))); RunThread(std::unique_ptr( diff --git a/src/dory/mock_kafka_server/cmd_worker.cc b/src/dory/mock_kafka_server/cmd_worker.cc index 3bc61729..200fe2a2 100644 --- a/src/dory/mock_kafka_server/cmd_worker.cc +++ b/src/dory/mock_kafka_server/cmd_worker.cc @@ -39,7 +39,6 @@ TCmdWorker::~TCmdWorker() { } void TCmdWorker::Run() { - assert(this); LOG(TPri::DEBUG) << "got connection on command port"; const TFd &shutdown_request_fd = GetShutdownRequestFd(); @@ -53,8 +52,6 @@ void TCmdWorker::Run() { } bool TCmdWorker::GetCmd() { - assert(this); - /* Start by reading just enough data to determine the size of the entire command, and then read the rest of the command. It would be more efficient to avoid reading in little pieces, but efficiency is not a big @@ -105,7 +102,6 @@ bool TCmdWorker::GetCmd() { } bool TCmdWorker::SendReply(bool success) { - assert(this); uint8_t reply = success ? 0 : 1; switch (TryWriteExactlyOrShutdown(ClientSocket, &reply, sizeof(reply))) { diff --git a/src/dory/mock_kafka_server/connect_handler.cc b/src/dory/mock_kafka_server/connect_handler.cc index aa2c2eea..1b3a85a8 100644 --- a/src/dory/mock_kafka_server/connect_handler.cc +++ b/src/dory/mock_kafka_server/connect_handler.cc @@ -33,7 +33,6 @@ using namespace Dory::MockKafkaServer; using namespace Socket; void TConnectHandler::OnEvent(int fd, short /*flags*/) { - assert(this); TAddress client_address; TFd client_socket(IfLt0(Accept(fd, client_address))); RunThread(ClientHandlerFactory.CreateClientHandler( diff --git a/src/dory/mock_kafka_server/connect_handler_base.cc b/src/dory/mock_kafka_server/connect_handler_base.cc index b590f189..f75e1525 100644 --- a/src/dory/mock_kafka_server/connect_handler_base.cc +++ b/src/dory/mock_kafka_server/connect_handler_base.cc @@ -37,13 +37,10 @@ using namespace Log; using namespace Thread; void TConnectHandlerBase::OnShutdown() { - assert(this); Unregister(); } void TConnectHandlerBase::RunThread(std::unique_ptr &&w) { - assert(this); - class t_cleanup final { NO_COPY_SEMANTICS(t_cleanup); @@ -103,8 +100,6 @@ void TConnectHandlerBase::RunThread(std::unique_ptr &&w) { } void TConnectHandlerBase::DeleteThreadState(int shutdown_wait_fd) { - assert(this); - auto iter = Ss.PerConnectionMap.find(shutdown_wait_fd); assert(iter != Ss.PerConnectionMap.end()); diff --git a/src/dory/mock_kafka_server/error_injector.cc b/src/dory/mock_kafka_server/error_injector.cc index accca005..9cbfcf81 100644 --- a/src/dory/mock_kafka_server/error_injector.cc +++ b/src/dory/mock_kafka_server/error_injector.cc @@ -127,7 +127,6 @@ TErrorInjector::MakeCmdDisconnectBeforeAllTopicsMetadataResponse( } bool TErrorInjector::Connect(const char *host, in_port_t port) { - assert(this); assert(host); Disconnect(); ConnectToHost(host, port, Sock); @@ -135,7 +134,6 @@ bool TErrorInjector::Connect(const char *host, in_port_t port) { } bool TErrorInjector::SendCmd(const TCmd &cmd) { - assert(this); assert(Sock.IsOpen()); std::vector buf; SerializeCmd(cmd, buf); @@ -158,7 +156,6 @@ bool TErrorInjector::SendCmd(const TCmd &cmd) { } bool TErrorInjector::ReceiveAck() { - assert(this); assert(Sock.IsOpen()); uint8_t response = 0; bool success = true; diff --git a/src/dory/mock_kafka_server/error_injector.h b/src/dory/mock_kafka_server/error_injector.h index b0edbe09..5b26737a 100644 --- a/src/dory/mock_kafka_server/error_injector.h +++ b/src/dory/mock_kafka_server/error_injector.h @@ -63,7 +63,6 @@ namespace Dory { bool Connect(const char *host, in_port_t port); void Disconnect() { - assert(this); Sock.Reset(); } @@ -71,7 +70,6 @@ namespace Dory { null then match any message body. */ bool InjectAckError(int16_t error_code, const char *msg_body_to_match, const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdAckError(error_code, msg_body_to_match, client_addr_to_match)); } @@ -80,7 +78,6 @@ namespace Dory { null then match any message body. */ bool InjectDisconnectBeforeAck(const char *msg_body_to_match, const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdDisconnectBeforeAck(msg_body_to_match, client_addr_to_match)); } @@ -88,7 +85,6 @@ namespace Dory { /* Return true on success or false on error. */ bool InjectMetadataResponseError(int16_t error_code, const char *topic, const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdMetadataResponseError(error_code, topic, client_addr_to_match)); } @@ -98,7 +94,6 @@ namespace Dory { gets the error. */ bool InjectAllTopicsMetadataResponseError(int16_t error_code, const char *topic, const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdAllTopicsMetadataResponseError( error_code, topic, client_addr_to_match)); } @@ -106,7 +101,6 @@ namespace Dory { /* Return true on success or false on error. */ bool InjectDisconnectBeforeMetadataResponse(const char *topic, const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdDisconnectBeforeMetadataResponse(topic, client_addr_to_match)); } @@ -114,14 +108,12 @@ namespace Dory { /* Return true on success or false on error. */ bool InjectDisconnectBeforeAllTopicsMetadataResponse( const char *client_addr_to_match) { - assert(this); return InjectCmd(MakeCmdDisconnectBeforeAllTopicsMetadataResponse( client_addr_to_match)); } /* Return true on success or false on error. */ bool InjectCmd(const TCmd &cmd) { - assert(this); assert(Sock.IsOpen()); return SendCmd(cmd) && ReceiveAck(); } diff --git a/src/dory/mock_kafka_server/main_thread.cc b/src/dory/mock_kafka_server/main_thread.cc index 7c6978e2..135ef40a 100644 --- a/src/dory/mock_kafka_server/main_thread.cc +++ b/src/dory/mock_kafka_server/main_thread.cc @@ -39,8 +39,6 @@ TMainThread::~TMainThread() { } void TMainThread::RequestShutdown() { - assert(this); - /* The standalone executable version of the mock Kafka server expects to get a shutdown signal, so here we mimic that behavior. @@ -52,7 +50,6 @@ void TMainThread::RequestShutdown() { } void TMainThread::Run() { - assert(this); OkShutdown = false; try { diff --git a/src/dory/mock_kafka_server/main_thread.h b/src/dory/mock_kafka_server/main_thread.h index e388e2ac..bd8b9fe0 100644 --- a/src/dory/mock_kafka_server/main_thread.h +++ b/src/dory/mock_kafka_server/main_thread.h @@ -59,17 +59,14 @@ namespace Dory { /* Return a file descriptor that becomes readable when the server has finished its initialization and is open for business. */ const Base::TFd &GetInitWaitFd() const { - assert(this); return InitFinishedSem.GetFd(); } bool ShutdownWasOk() const { - assert(this); return OkShutdown; } in_port_t GetCmdPort() const { - assert(this); return Server.GetCmdPort(); } @@ -78,7 +75,6 @@ namespace Dory { for an explanation of what is going on here. */ in_port_t VirtualPortToPhys(in_port_t v_port) const { - assert(this); return Server.VirtualPortToPhys(v_port); } @@ -87,19 +83,16 @@ namespace Dory { for an explanation of what is going on here. */ in_port_t PhysicalPortToVirt(in_port_t p_port) const { - assert(this); return Server.PhysicalPortToVirt(p_port); } void GetHandledRequests( std::list &result) { - assert(this); Server.GetHandledRequests(result); } void NonblockingGetHandledRequests( std::list &result) { - assert(this); Server.NonblockingGetHandledRequests(result); } diff --git a/src/dory/mock_kafka_server/mock_kafka_worker.cc b/src/dory/mock_kafka_server/mock_kafka_worker.cc index a85483c9..742bd72b 100644 --- a/src/dory/mock_kafka_server/mock_kafka_worker.cc +++ b/src/dory/mock_kafka_server/mock_kafka_worker.cc @@ -40,7 +40,6 @@ using namespace Dory::MockKafkaServer; TMockKafkaWorker::TIoResult TMockKafkaWorker::TryReadExactlyOrShutdown(int fd, void *buf, size_t size) { - assert(this); std::array events; struct pollfd &fd_event = events[0]; struct pollfd &shutdown_request_event = events[1]; @@ -103,7 +102,6 @@ TMockKafkaWorker::TryReadExactlyOrShutdown(int fd, void *buf, TMockKafkaWorker::TIoResult TMockKafkaWorker::TryWriteExactlyOrShutdown(int fd, const void *buf, size_t size) { - assert(this); struct stat stat_buf; IfLt0(Wr::fstat(fd, &stat_buf)); bool is_socket = S_ISSOCK(stat_buf.st_mode); diff --git a/src/dory/mock_kafka_server/port_map.cc b/src/dory/mock_kafka_server/port_map.cc index 59dc6c30..e81a256f 100644 --- a/src/dory/mock_kafka_server/port_map.cc +++ b/src/dory/mock_kafka_server/port_map.cc @@ -30,7 +30,6 @@ using namespace Dory; using namespace Dory::MockKafkaServer; void TPortMap::AddMapping(in_port_t virtual_port, in_port_t physical_port) { - assert(this); auto result1 = VToPMap.insert(std::make_pair(virtual_port, physical_port)); if (!result1.second) { @@ -45,13 +44,11 @@ void TPortMap::AddMapping(in_port_t virtual_port, in_port_t physical_port) { } in_port_t TPortMap::VirtualPortToPhys(in_port_t v_port) const { - assert(this); auto iter = VToPMap.find(v_port); return (iter == VToPMap.end()) ? 0 : iter->second; } in_port_t TPortMap::PhysicalPortToVirt(in_port_t p_port) const { - assert(this); auto iter = PToVMap.find(p_port); return (iter == PToVMap.end()) ? 0 : iter->second; } diff --git a/src/dory/mock_kafka_server/prod_req/msg.h b/src/dory/mock_kafka_server/prod_req/msg.h index e0ed976a..272d93d7 100644 --- a/src/dory/mock_kafka_server/prod_req/msg.h +++ b/src/dory/mock_kafka_server/prod_req/msg.h @@ -52,17 +52,14 @@ namespace Dory { TMsg &operator=(TMsg &&) = default; bool GetCrcOk() const { - assert(this); return CrcOk; } const std::string &GetKey() const { - assert(this); return Key; } const std::string &GetValue() const { - assert(this); return Value; } diff --git a/src/dory/mock_kafka_server/prod_req/msg_set.h b/src/dory/mock_kafka_server/prod_req/msg_set.h index 6a0829f7..338715cb 100644 --- a/src/dory/mock_kafka_server/prod_req/msg_set.h +++ b/src/dory/mock_kafka_server/prod_req/msg_set.h @@ -50,40 +50,33 @@ namespace Dory { TMsgSet &operator=(TMsgSet &&) = default; void AddMsg(const TMsg &msg) { - assert(this); MsgVec.push_back(msg); MsgCrcsOk = MsgCrcsOk && msg.GetCrcOk(); } void AddMsg(TMsg &&msg) { - assert(this); bool crc_ok = msg.GetCrcOk(); MsgVec.push_back(std::move(msg)); MsgCrcsOk = MsgCrcsOk && crc_ok; } int32_t GetPartition() const { - assert(this); return Partition; } void SetCompressionType(Compress::TCompressionType compression_type) { - assert(this); CompressionType = compression_type; } Compress::TCompressionType GetCompressionType() const { - assert(this); return CompressionType; } bool GetMsgCrcsOk() const { - assert(this); return MsgCrcsOk; } const std::vector &GetMsgVec() const { - assert(this); return MsgVec; } diff --git a/src/dory/mock_kafka_server/prod_req/prod_req.h b/src/dory/mock_kafka_server/prod_req/prod_req.h index d5c517a7..b11cd8dc 100644 --- a/src/dory/mock_kafka_server/prod_req/prod_req.h +++ b/src/dory/mock_kafka_server/prod_req/prod_req.h @@ -62,37 +62,30 @@ namespace Dory { TProdReq &operator=(TProdReq &&) = default; void AddTopicGroup(const TTopicGroup &topic_group) { - assert(this); TopicGroupVec.push_back(topic_group); } void AddTopicGroup(TTopicGroup &&topic_group) { - assert(this); TopicGroupVec.push_back(std::move(topic_group)); } int32_t GetCorrelationId() const { - assert(this); return CorrelationId; } const std::string &GetClientId() const { - assert(this); return ClientId; } int16_t GetRequiredAcks() const { - assert(this); return RequiredAcks; } int32_t GetReplicationTimeout() const { - assert(this); return ReplicationTimeout; } const std::vector &GetTopicGroupVec() const { - assert(this); return TopicGroupVec; } diff --git a/src/dory/mock_kafka_server/prod_req/prod_req_builder.cc b/src/dory/mock_kafka_server/prod_req/prod_req_builder.cc index 751eb833..1ad27f5b 100644 --- a/src/dory/mock_kafka_server/prod_req/prod_req_builder.cc +++ b/src/dory/mock_kafka_server/prod_req/prod_req_builder.cc @@ -40,7 +40,6 @@ using namespace Dory::MockKafkaServer::ProdReq; TProdReq TProdReqBuilder::BuildProdReq(const void *request, size_t request_size) { - assert(this); RequestReader.SetRequest(request, request_size); std::string client_id(RequestReader.GetClientIdBegin(), RequestReader.GetClientIdEnd()); @@ -57,7 +56,6 @@ TProdReq TProdReqBuilder::BuildProdReq(const void *request, } TTopicGroup TProdReqBuilder::BuildTopicGroup() { - assert(this); std::string topic(RequestReader.GetCurrentTopicNameBegin(), RequestReader.GetCurrentTopicNameEnd()); TTopicGroup topic_group(std::move(topic)); @@ -71,8 +69,6 @@ TTopicGroup TProdReqBuilder::BuildTopicGroup() { void TProdReqBuilder::GetCompressedData(const std::vector &msg_vec, std::vector &result) { - assert(this); - if (!msg_vec.empty()) { throw TCompressedMsgSetNotAlone(); } @@ -93,7 +89,6 @@ void TProdReqBuilder::GetCompressedData(const std::vector &msg_vec, void TProdReqBuilder::GzipUncompressMsgSet( const std::vector &compressed_data, std::vector &uncompressed_data) { - assert(this); const TGzipCodec &codec = TGzipCodec::The(); try { @@ -110,7 +105,6 @@ void TProdReqBuilder::GzipUncompressMsgSet( void TProdReqBuilder::SnappyUncompressMsgSet( const std::vector &compressed_data, std::vector &uncompressed_data) { - assert(this); const TSnappyCodec &codec = TSnappyCodec::The(); try { @@ -127,7 +121,6 @@ void TProdReqBuilder::SnappyUncompressMsgSet( void TProdReqBuilder::Lz4UncompressMsgSet( const std::vector &compressed_data, std::vector &uncompressed_data) { - assert(this); const TLz4Codec &codec = TLz4Codec::The(); try { @@ -144,7 +137,6 @@ void TProdReqBuilder::Lz4UncompressMsgSet( TMsgSet TProdReqBuilder::BuildUncompressedMsgSet(int32_t partition, const std::vector &msg_set_data, TCompressionType compression_type) { - assert(this); TMsgSet msg_set(partition); MsgSetReader.SetMsgSet(&msg_set_data[0], msg_set_data.size()); @@ -170,7 +162,6 @@ TMsgSet TProdReqBuilder::BuildUncompressedMsgSet(int32_t partition, } TMsgSet TProdReqBuilder::BuildMsgSet() { - assert(this); int32_t partition = RequestReader.GetPartitionOfCurrentMsgSet(); TMsgSet msg_set(partition); const std::vector &msg_vec = msg_set.GetMsgVec(); diff --git a/src/dory/mock_kafka_server/prod_req/topic_group.h b/src/dory/mock_kafka_server/prod_req/topic_group.h index 8b7ce868..57554d1c 100644 --- a/src/dory/mock_kafka_server/prod_req/topic_group.h +++ b/src/dory/mock_kafka_server/prod_req/topic_group.h @@ -54,22 +54,18 @@ namespace Dory { TTopicGroup &operator=(TTopicGroup &&) = default; void AddMsgSet(const TMsgSet &msg_set) { - assert(this); MsgSetVec.push_back(msg_set); } void AddMsgSet(TMsgSet &&msg_set) { - assert(this); MsgSetVec.push_back(std::move(msg_set)); } const std::string &GetTopic() const { - assert(this); return Topic; } const std::vector &GetMsgSetVec() const { - assert(this); return MsgSetVec; } diff --git a/src/dory/mock_kafka_server/received_request_tracker.h b/src/dory/mock_kafka_server/received_request_tracker.h index b154ce8d..64198585 100644 --- a/src/dory/mock_kafka_server/received_request_tracker.h +++ b/src/dory/mock_kafka_server/received_request_tracker.h @@ -116,19 +116,16 @@ namespace Dory { TReceivedRequestTracker() = default; void PutRequestInfo(TRequestInfo &&info) { - assert(this); Queue.Put(std::move(info)); } /* Append items to 'result'. */ void GetRequestInfo(std::list &result) { - assert(this); result.splice(result.end(), Queue.Get()); } /* Append items to 'result', but don't block if nothing is available. */ void NonblockingGetRequestInfo(std::list &result) { - assert(this); result.splice(result.end(), Queue.NonblockingGet()); } diff --git a/src/dory/mock_kafka_server/server.cc b/src/dory/mock_kafka_server/server.cc index 2d68700b..037f7f65 100644 --- a/src/dory/mock_kafka_server/server.cc +++ b/src/dory/mock_kafka_server/server.cc @@ -43,8 +43,6 @@ using namespace Socket; using namespace Thread; int TServer::Init() { - assert(this); - if (InitSucceeded) { Die("Init() method already called"); } @@ -75,8 +73,6 @@ int TServer::Init() { } int TServer::Run() { - assert(this); - class t_shutdown final { NO_COPY_SEMANTICS(t_shutdown); @@ -135,7 +131,6 @@ bool TServer::InitOutputDir() { } void TServer::ShutDownWorkers() { - assert(this); std::unordered_map &state_map = Ss.PerConnectionMap; @@ -161,7 +156,6 @@ void TServer::ShutDownWorkers() { } bool TServer::InitCmdPort() { - assert(this); in_port_t kafka_port_begin = Ss.Setup.BasePort; auto kafka_port_end = static_cast(kafka_port_begin + Ss.Setup.Ports.size()); @@ -189,8 +183,6 @@ bool TServer::InitCmdPort() { } void TServer::InitKafkaPorts() { - assert(this); - if (!ClientHandlerFactory) { ClientHandlerFactory = TClientHandlerFactoryBase::CreateFactory( Ss.CmdLineArgs, Ss.Setup); diff --git a/src/dory/mock_kafka_server/server.h b/src/dory/mock_kafka_server/server.h index a99e6c10..5434f855 100644 --- a/src/dory/mock_kafka_server/server.h +++ b/src/dory/mock_kafka_server/server.h @@ -58,7 +58,6 @@ namespace Dory { ); const TCmdLineArgs &GetCmdLineArgs() const { - assert(this); return Ss.CmdLineArgs; } @@ -81,17 +80,14 @@ namespace Dory { int Run(); in_port_t GetCmdPort() const { - assert(this); return CmdPort; } in_port_t VirtualPortToPhys(in_port_t v_port) const { - assert(this); return PortMap->VirtualPortToPhys(v_port); } in_port_t PhysicalPortToVirt(in_port_t p_port) const { - assert(this); return PortMap->PhysicalPortToVirt(p_port); } @@ -99,7 +95,6 @@ namespace Dory { server. */ void GetHandledRequests( std::list &result) { - assert(this); Ss.ReceivedRequests.GetRequestInfo(result); } @@ -107,7 +102,6 @@ namespace Dory { server. Nonblocking version of GetHandledRequests(). */ void NonblockingGetHandledRequests( std::list &result) { - assert(this); Ss.ReceivedRequests.NonblockingGetRequestInfo(result); } diff --git a/src/dory/mock_kafka_server/setup.cc b/src/dory/mock_kafka_server/setup.cc index 1bcfefdc..f1f2b276 100644 --- a/src/dory/mock_kafka_server/setup.cc +++ b/src/dory/mock_kafka_server/setup.cc @@ -51,7 +51,6 @@ TSetup::TFileFormatError::TFileFormatError(size_t line_num, const char *msg) } void TSetup::Get(const std::string &setup_file_path, TInfo &out) { - assert(this); Result.Clear(); std::ifstream infile(setup_file_path); @@ -73,7 +72,6 @@ void TSetup::Get(const std::string &setup_file_path, TInfo &out) { } void TSetup::NextInterestingLine(std::istream &in) { - assert(this); CurrentLineTokens.clear(); std::string line; std::vector split_result; @@ -104,15 +102,12 @@ void TSetup::NextInterestingLine(std::istream &in) { } std::string TSetup::ErrorBlurb() { - assert(this); std::ostringstream oss; oss << "Error on line " << LineNum << " of setup file: "; return oss.str(); } void TSetup::GetPortsLine(std::istream &in) { - assert(this); - if (CurrentLineTokens.empty()) { throw TFileFormatError(LineNum, "\"ports\" line not found"); } @@ -183,7 +178,6 @@ static bool ParseDelayAndInterval(const std::string &s, size_t &delay, } void TSetup::GetPortLines(std::istream &in) { - assert(this); assert(!Result.Ports.empty()); in_port_t min_port = Result.BasePort; in_port_t max_port = min_port + @@ -248,8 +242,6 @@ void TSetup::GetPortLines(std::istream &in) { } void TSetup::GetTopicLines(std::istream &in) { - assert(this); - for (; !CurrentLineTokens.empty() && (CurrentLineTokens[0] == "topic"); NextInterestingLine(in)) { if (CurrentLineTokens.size() != 4) { @@ -293,8 +285,6 @@ void TSetup::GetTopicLines(std::istream &in) { } void TSetup::GetPartitionErrorLines(std::istream &in) { - assert(this); - for (; !CurrentLineTokens.empty() && (CurrentLineTokens[0] == "partition_error"); NextInterestingLine(in)) { @@ -351,7 +341,6 @@ void TSetup::GetPartitionErrorLines(std::istream &in) { } void TSetup::FillResult(std::istream &in) { - assert(this); LineNum = 0; NextInterestingLine(in); GetPortsLine(in); diff --git a/src/dory/mock_kafka_server/single_client_handler_base.cc b/src/dory/mock_kafka_server/single_client_handler_base.cc index cb212921..96d1020f 100644 --- a/src/dory/mock_kafka_server/single_client_handler_base.cc +++ b/src/dory/mock_kafka_server/single_client_handler_base.cc @@ -43,7 +43,6 @@ using namespace Dory::MockKafkaServer::ProdReq; using namespace Log; void TSingleClientHandlerBase::Run() { - assert(this); GetSocketPeer(); LOG(TPri::DEBUG) << "got connection from " << PeerAddressString; @@ -62,7 +61,6 @@ void TSingleClientHandlerBase::Run() { void TSingleClientHandlerBase::PrintMdReq(size_t req_count, const TMetadataRequest &req, TAction action, const std::string &error_topic, int16_t topic_error_value, size_t wait) { - assert(this); Out << "md_n=" << req_count << " corr=" << req.CorrelationId << " act=" << ActionToString(action) << " ack=" << topic_error_value << " wait=" << wait << " inj_err=" << error_topic.size() << "[" << error_topic @@ -105,7 +103,6 @@ const char *TSingleClientHandlerBase::ActionToString(TAction action) { } void TSingleClientHandlerBase::GetSocketPeer() { - assert(this); Socket::TAddress address = Socket::GetPeerName(ClientSocket); char name_buf[128]; address.GetName(name_buf, sizeof(name_buf), nullptr, 0, NI_NUMERICHOST); @@ -113,7 +110,6 @@ void TSingleClientHandlerBase::GetSocketPeer() { } bool TSingleClientHandlerBase::OpenOutputFile() { - assert(this); std::string path(CmdLineArgs.OutputDir); std::ios_base::openmode flags = std::ios_base::out; @@ -144,8 +140,6 @@ bool TSingleClientHandlerBase::OpenOutputFile() { TSingleClientHandlerBase::TGetRequestResult TSingleClientHandlerBase::GetRequest() { - assert(this); - /* The first 6 bytes of a request contain the size and API key fields. */ InputBuf.resize(6); @@ -219,7 +213,6 @@ TSingleClientHandlerBase::GetRequest() { TSingleClientHandlerBase::TRequestType TSingleClientHandlerBase::GetRequestType() { - assert(this); assert(InputBuf.size() >= 6); int16_t api_key = ReadInt16FromHeader(&InputBuf[4]); @@ -243,7 +236,6 @@ TSingleClientHandlerBase::GetRequestType() { bool TSingleClientHandlerBase::CheckProduceRequestErrorInjectionCmd( size_t &cmd_seq, std::string &msg_body_match, bool &match_any_msg_body, int16_t &ack_error, bool &disconnect, size_t &delay) { - assert(this); cmd_seq = 0; msg_body_match.clear(); match_any_msg_body = false; @@ -322,7 +314,6 @@ bool TSingleClientHandlerBase::CheckProduceRequestErrorInjectionCmd( bool TSingleClientHandlerBase::CheckMetadataRequestErrorInjectionCmd( size_t &cmd_seq, bool &all_topics, std::string &topic, int16_t &error, bool &disconnect, size_t &delay) { - assert(this); cmd_seq = 0; all_topics = false; topic.clear(); @@ -387,7 +378,6 @@ TSingleClientHandlerBase::TAction TSingleClientHandlerBase::ChooseMsgSetAction(const TMsgSet &msg_set, const std::string &topic, int32_t partition, size_t &delay, int16_t &ack_error) { - assert(this); delay = 0; ack_error = 0; std::string msg_body_match; @@ -445,7 +435,6 @@ TSingleClientHandlerBase::ChooseMsgSetAction(const TMsgSet &msg_set, void TSingleClientHandlerBase::PrintCurrentMsgSet(const TMsgSet &msg_set, int32_t partition, TAction action, int16_t ack_error) { - assert(this); const char *s = (msg_set.GetCompressionType() == TCompressionType::None) ? "" : "C "; Out << " " << s << "partition: " << partition << " action: " @@ -471,7 +460,6 @@ void TSingleClientHandlerBase::PrintCurrentMsgSet(const TMsgSet &msg_set, bool TSingleClientHandlerBase::PrepareProduceResponse(const TProdReq &prod_req, std::vector &done_requests) { - assert(this); done_requests.clear(); TProduceResponseWriterApi &writer = GetProduceResponseWriter(); int32_t corr_id = prod_req.GetCorrelationId(); @@ -562,8 +550,6 @@ bool TSingleClientHandlerBase::PrepareProduceResponse(const TProdReq &prod_req, } bool TSingleClientHandlerBase::HandleProduceRequest() { - assert(this); - struct reader_t final { explicit reader_t(TProduceRequestReaderApi &reader) : Reader(reader) { } @@ -624,7 +610,6 @@ bool TSingleClientHandlerBase::HandleProduceRequest() { } bool TSingleClientHandlerBase::HandleMetadataRequest() { - assert(this); size_t cmd_seq = 0; bool all_topics = false; std::string error_topic; @@ -710,7 +695,6 @@ bool TSingleClientHandlerBase::HandleMetadataRequest() { const TSetup::TPartition *TSingleClientHandlerBase::FindPartition( const std::string &topic, int32_t partition) const { - assert(this); auto iter = Setup.Topics.find(topic); if (iter == Setup.Topics.end()) { @@ -734,7 +718,6 @@ const TSetup::TPartition *TSingleClientHandlerBase::FindPartition( } void TSingleClientHandlerBase::DoRun() { - assert(this); const TSetup::TPort &port = Setup.Ports[PortOffset]; ProduceRequestCount = 0; MetadataRequestCount = 0; diff --git a/src/dory/mock_kafka_server/single_client_handler_base.h b/src/dory/mock_kafka_server/single_client_handler_base.h index 0d41d80a..720b20a7 100644 --- a/src/dory/mock_kafka_server/single_client_handler_base.h +++ b/src/dory/mock_kafka_server/single_client_handler_base.h @@ -116,7 +116,6 @@ namespace Dory { const std::string &error_topic, size_t delay) = 0; size_t GetMetadataRequestCount() const { - assert(this); return MetadataRequestCount; } diff --git a/src/dory/mock_kafka_server/thread_terminate_handler.cc b/src/dory/mock_kafka_server/thread_terminate_handler.cc index 18ef8a86..2a650797 100644 --- a/src/dory/mock_kafka_server/thread_terminate_handler.cc +++ b/src/dory/mock_kafka_server/thread_terminate_handler.cc @@ -30,8 +30,6 @@ using namespace Dory; using namespace Dory::MockKafkaServer; void TThreadTerminateHandler::OnEvent(int /*fd*/, short /*flags*/) { - assert(this); - /* The terminate handler deletes the object whose method we are now executing. To be safe, make sure are not trying to access any of our own object state while it is being deleted. */ @@ -40,6 +38,5 @@ void TThreadTerminateHandler::OnEvent(int /*fd*/, short /*flags*/) { } void TThreadTerminateHandler::OnShutdown() { - assert(this); Unregister(); } diff --git a/src/dory/mock_kafka_server/v0_client_handler.cc b/src/dory/mock_kafka_server/v0_client_handler.cc index 1d749624..5d14a45e 100644 --- a/src/dory/mock_kafka_server/v0_client_handler.cc +++ b/src/dory/mock_kafka_server/v0_client_handler.cc @@ -52,23 +52,18 @@ TV0ClientHandler::~TV0ClientHandler() { } TProduceRequestReaderApi &TV0ClientHandler::GetProduceRequestReader() { - assert(this); return ProduceRequestReader; } TMsgSetReaderApi &TV0ClientHandler::GetMsgSetReader() { - assert(this); return MsgSetReader; } TProduceResponseWriterApi &TV0ClientHandler::GetProduceResponseWriter() { - assert(this); return ProduceResponseWriter; } bool TV0ClientHandler::ValidateMetadataRequestHeader() { - assert(this); - try { OptMetadataRequestReader.MakeKnown(&InputBuf[0], InputBuf.size()); } catch (const std::runtime_error &x) { diff --git a/src/dory/mock_kafka_server/v0_client_handler_factory.cc b/src/dory/mock_kafka_server/v0_client_handler_factory.cc index 0e362472..f514cc36 100644 --- a/src/dory/mock_kafka_server/v0_client_handler_factory.cc +++ b/src/dory/mock_kafka_server/v0_client_handler_factory.cc @@ -33,7 +33,6 @@ std::unique_ptr TV0ClientHandlerFactory::CreateClientHandler( const std::shared_ptr &port_map, size_t port_offset, TSharedState &ss, Base::TFd &&client_socket) { - assert(this); return std::unique_ptr( new TV0ClientHandler(CmdLineArgs, Setup, port_map, port_offset, ss, std::move(client_socket))); diff --git a/src/dory/msg.cc b/src/dory/msg.cc index e0471357..a3fffc41 100644 --- a/src/dory/msg.cc +++ b/src/dory/msg.cc @@ -63,7 +63,6 @@ TMsg::TPtr TMsg::CreatePartitionKeyMsg(int32_t partition_key, } TMsg::~TMsg() { - assert(this); MsgDestroy.Increment(); if (State != TState::Processed) { diff --git a/src/dory/msg.h b/src/dory/msg.h index 88814058..5d255888 100644 --- a/src/dory/msg.h +++ b/src/dory/msg.h @@ -78,60 +78,50 @@ namespace Dory { using TTimestamp = int64_t; TRoutingType GetRoutingType() const noexcept { - assert(this); return RoutingType; } int32_t GetPartitionKey() const noexcept { - assert(this); return PartitionKey; } /* Return the client's timestamp from the input datagram. */ TTimestamp GetTimestamp() const noexcept { - assert(this); return Timestamp; } /* Return our own monotonic raw timestamp that we use for per-topic message rate limiting. */ uint64_t GetCreationTimestamp() const noexcept { - assert(this); return CreationTimestamp; } /* Accessor for the Kafka topic string. */ const std::string &GetTopic() const noexcept { - assert(this); return Topic; } /* Accessor for the Kafka partition. */ int32_t GetPartition() const noexcept { - assert(this); return Partition; } /* Sets the Kafka partition to the given value. */ void SetPartition(int32_t partition) noexcept { - assert(this); Partition = partition; } /* Accessor method for the message body. */ const Capped::TBlob &GetKeyAndValue() const noexcept { - assert(this); return KeyAndValue; } size_t GetKeySize() const noexcept { - assert(this); assert(KeySize <= KeyAndValue.Size()); return KeySize; } size_t GetValueSize() const noexcept { - assert(this); assert(KeySize <= KeyAndValue.Size()); return KeyAndValue.Size() - KeySize; } @@ -141,27 +131,22 @@ namespace Dory { TODO: remove this method once legacy input format goes away */ bool BodyIsTruncated() const noexcept { - assert(this); return BodyTruncated; } size_t CountFailedDeliveryAttempt() noexcept { - assert(this); return ++FailedDeliveryAttemptCount; } size_t GetFailedDeliveryAttemptCount() const noexcept { - assert(this); return FailedDeliveryAttemptCount; } TState GetState() const noexcept { - assert(this); return State; } void SetState(TState state) noexcept { - assert(this); State = state; } diff --git a/src/dory/msg_dispatch/any_partition_chooser.cc b/src/dory/msg_dispatch/any_partition_chooser.cc index f0dd70fa..561498c9 100644 --- a/src/dory/msg_dispatch/any_partition_chooser.cc +++ b/src/dory/msg_dispatch/any_partition_chooser.cc @@ -26,7 +26,6 @@ using namespace Dory::MsgDispatch; void TAnyPartitionChooser::Choose(size_t broker_index, const TMetadata &md, const std::string &topic) { - assert(this); size_t num_choices = 0; const int32_t *choice_vec = md.FindPartitionChoices(topic, broker_index, num_choices); diff --git a/src/dory/msg_dispatch/any_partition_chooser.h b/src/dory/msg_dispatch/any_partition_chooser.h index f72be81f..2ee7ba51 100644 --- a/src/dory/msg_dispatch/any_partition_chooser.h +++ b/src/dory/msg_dispatch/any_partition_chooser.h @@ -39,8 +39,6 @@ namespace Dory { int32_t GetChoice(size_t broker_index, const TMetadata &md, const std::string &topic) { - assert(this); - if (Choice.IsUnknown()) { Choose(broker_index, md, topic); } @@ -49,12 +47,10 @@ namespace Dory { } void SetChoiceUsed() { - assert(this); ChoiceUsed = true; } void ClearChoice() { - assert(this); Choice.Reset(); if (ChoiceUsed) { diff --git a/src/dory/msg_dispatch/broker_msg_queue.cc b/src/dory/msg_dispatch/broker_msg_queue.cc index b5e4fa69..5e492d04 100644 --- a/src/dory/msg_dispatch/broker_msg_queue.cc +++ b/src/dory/msg_dispatch/broker_msg_queue.cc @@ -63,7 +63,6 @@ TBrokerMsgQueue::TBrokerMsgQueue(const TGlobalBatchConfig &batch_config, } void TBrokerMsgQueue::Put(TMsg::TTimestamp now, TMsg::TPtr &&msg) { - assert(this); assert(msg); TExpiryStatus per_topic_status, combined_topics_status; bool ready_list_empty_initial = false; @@ -135,7 +134,6 @@ void TBrokerMsgQueue::Put(TMsg::TTimestamp now, TMsg::TPtr &&msg) { } void TBrokerMsgQueue::PutNow(TMsg::TTimestamp now, TMsg::TPtr &&msg) { - assert(this); assert(msg); MsgStateTracker.MsgEnterSendWait(*msg); std::list single_item_list; @@ -163,8 +161,6 @@ void TBrokerMsgQueue::PutNow(TMsg::TTimestamp now, TMsg::TPtr &&msg) { void TBrokerMsgQueue::PutNow(TMsg::TTimestamp now, std::list> &&batch) { - assert(this); - if (batch.empty()) { return; } @@ -195,7 +191,6 @@ void TBrokerMsgQueue::PutNow(TMsg::TTimestamp now, bool TBrokerMsgQueue::NonblockingGet(TMsg::TTimestamp now, TMsg::TTimestamp &next_batch_complete_time, std::list> &ready_msgs) { - assert(this); TExpiryStatus per_topic_status, combined_topics_status; { @@ -220,21 +215,17 @@ bool TBrokerMsgQueue::NonblockingGet(TMsg::TTimestamp now, } std::list> TBrokerMsgQueue::GetAllOnShutdown() { - assert(this); - std::lock_guard lock(Mutex); return GetAllMsgs(); } std::list> TBrokerMsgQueue::Reset() { - assert(this); SenderNotify.Reset(); return GetAllMsgs(); } void TBrokerMsgQueue::TryBatchPerTopic(TMsg::TTimestamp now, TMsg::TPtr &&msg_ptr, TExpiryStatus &expiry_status) { - assert(this); expiry_status.Clear(); if (!PerTopicBatcher.IsEnabled()) { @@ -266,7 +257,6 @@ void TBrokerMsgQueue::TryBatchPerTopic(TMsg::TTimestamp now, void TBrokerMsgQueue::TryBatchCombinedTopics(TMsg::TTimestamp now, TMsg::TPtr &&msg_ptr, TExpiryStatus &expiry_status) { - assert(this); expiry_status.OptInitialExpiry = CombinedTopicsBatcher.GetNextCompleteTime(); TMsg &msg = *msg_ptr; std::list> batch_list = @@ -288,7 +278,6 @@ void TBrokerMsgQueue::TryBatchCombinedTopics(TMsg::TTimestamp now, std::list> TBrokerMsgQueue::CheckPerTopicBatcher(TMsg::TTimestamp now, TExpiryStatus &expiry_status) { - assert(this); expiry_status.Clear(); std::list> ready_batches; expiry_status.OptInitialExpiry = PerTopicBatcher.GetNextCompleteTime(); @@ -310,7 +299,6 @@ TBrokerMsgQueue::CheckPerTopicBatcher(TMsg::TTimestamp now, std::list> TBrokerMsgQueue::CheckCombinedTopicsBatcher(TMsg::TTimestamp now, TExpiryStatus &expiry_status) { - assert(this); expiry_status.Clear(); std::list> ready_batches; expiry_status.OptInitialExpiry = CombinedTopicsBatcher.GetNextCompleteTime(); @@ -332,7 +320,6 @@ TBrokerMsgQueue::CheckCombinedTopicsBatcher(TMsg::TTimestamp now, void TBrokerMsgQueue::CheckBothBatchers(TMsg::TTimestamp now, TExpiryStatus &per_topic_status, TExpiryStatus &combined_topics_status) { - assert(this); std::list> per_topic_batches = CheckPerTopicBatcher(now, per_topic_status); std::list> combined_topics_batches = @@ -360,7 +347,6 @@ void TBrokerMsgQueue::CheckBothBatchers(TMsg::TTimestamp now, std::list> TBrokerMsgQueue::GetAllMsgs() { - assert(this); TOpt per_topic_expiry = PerTopicBatcher.GetNextCompleteTime(); TOpt combined_topics_expiry = diff --git a/src/dory/msg_dispatch/broker_msg_queue.h b/src/dory/msg_dispatch/broker_msg_queue.h index 10e8fcac..6b526321 100644 --- a/src/dory/msg_dispatch/broker_msg_queue.h +++ b/src/dory/msg_dispatch/broker_msg_queue.h @@ -61,7 +61,6 @@ namespace Dory { previously set, or the time limit changes to an earlier value. */ const Base::TFd &GetSenderNotifyFd() { - assert(this); return SenderNotify.GetFd(); } @@ -99,7 +98,6 @@ namespace Dory { bool Get(TMsg::TTimestamp now, TMsg::TTimestamp &next_batch_complete_time, std::list> &ready_msgs) { - assert(this); SenderNotify.Pop(); return NonblockingGet(now, next_batch_complete_time, ready_msgs); } @@ -128,7 +126,6 @@ namespace Dory { Base::TOpt OptFinalExpiry; void Clear() { - assert(this); OptInitialExpiry.Reset(); OptFinalExpiry.Reset(); } diff --git a/src/dory/msg_dispatch/connector.cc b/src/dory/msg_dispatch/connector.cc index 6c8b692b..51451bfc 100644 --- a/src/dory/msg_dispatch/connector.cc +++ b/src/dory/msg_dispatch/connector.cc @@ -109,14 +109,12 @@ TConnector::~TConnector() { } void TConnector::SetMetadata(const std::shared_ptr &md) { - assert(this); assert(md); Metadata = md; RequestFactory.Init(Ds.Conf.CompressionConf, md); } void TConnector::StartSlowShutdown(uint64_t start_time) { - assert(this); assert(IsStarted()); assert(!OptShutdownCmd.IsKnown()); ConnectorStartSlowShutdown.Increment(); @@ -128,7 +126,6 @@ void TConnector::StartSlowShutdown(uint64_t start_time) { } void TConnector::StartFastShutdown() { - assert(this); assert(IsStarted()); assert(!OptShutdownCmd.IsKnown()); ConnectorStartFastShutdown.Increment(); @@ -140,7 +137,6 @@ void TConnector::StartFastShutdown() { } void TConnector::WaitForShutdownAck() { - assert(this); ConnectorStartWaitShutdownAck.Increment(); long broker_id = MyBrokerId(); LOG(TPri::NOTICE) @@ -173,7 +169,6 @@ void TConnector::WaitForShutdownAck() { } void TConnector::CleanupAfterJoin() { - assert(this); assert(SendWaitAfterShutdown.empty()); assert(NoAckAfterShutdown.empty()); assert(!Destroying); @@ -206,7 +201,6 @@ void TConnector::CleanupAfterJoin() { } void TConnector::Run() { - assert(this); assert(Metadata); ConnectorStartRun.Increment(); long broker_id = ~0; @@ -278,7 +272,6 @@ bool TConnector::DoConnect() { } bool TConnector::ConnectToBroker() { - assert(this); ConnectorStartConnect.Increment(); bool success = DoConnect(); @@ -310,7 +303,6 @@ static int AdjustTimeoutByDeadline(int initial_timeout, uint64_t now, } void TConnector::SetFastShutdownState() { - assert(this); uint64_t deadline = GetEpochMilliseconds() + Ds.Conf.MsgDeliveryConf.DispatcherRestartMaxDelay; @@ -324,8 +316,6 @@ void TConnector::SetFastShutdownState() { } void TConnector::HandleShutdownRequest() { - assert(this); - if (Destroying) { throw TShutdownOnDestroy(); } @@ -361,13 +351,11 @@ void TConnector::HandleShutdownRequest() { } void TConnector::SetPauseInProgress() { - assert(this); PauseInProgress = true; SetFastShutdownState(); } void TConnector::HandlePauseDetected() { - assert(this); LOG(TPri::NOTICE) << "Connector thread " << Gettid() << " (index " << MyBrokerIndex << " broker " << MyBrokerId() << ") detected pause: starting fast shutdown"; @@ -375,7 +363,6 @@ void TConnector::HandlePauseDetected() { } void TConnector::CheckInputQueue(uint64_t now, bool pop_sem) { - assert(this); ConnectorCheckInputQueue.Increment(); std::list> ready_msgs; TMsg::TTimestamp expiry = 0; @@ -392,7 +379,6 @@ void TConnector::CheckInputQueue(uint64_t now, bool pop_sem) { } bool TConnector::TrySendProduceRequest() { - assert(this); ssize_t ret = Wr::send(Wr::TDisp::Nonfatal, LostTcpConnectionErrorCodes, Sock, SendBuf.Data(), SendBuf.DataSize(), MSG_NOSIGNAL); @@ -415,7 +401,6 @@ bool TConnector::TrySendProduceRequest() { } bool TConnector::HandleSockWriteReady() { - assert(this); assert(CurrentRequest.IsKnown() == SendInProgress()); /* See whether we are starting a new produce request, or continuing a @@ -481,7 +466,6 @@ bool TConnector::HandleSockWriteReady() { } bool TConnector::ProcessSingleProduceResponse() { - assert(this); assert(!AckWaitQueue.empty()); assert(StreamReader.GetState() == TStreamMsgReader::TState::MsgReady); bool keep_running = true; @@ -570,7 +554,6 @@ bool TConnector::ProcessSingleProduceResponse() { produce response. Then return true to indicate no error. The main loop will call us again when appropriate. */ bool TConnector::HandleSockReadReady() { - assert(this); assert(!AckWaitQueue.empty()); TStreamMsgReader::TState reader_state = TStreamMsgReader::TState::AtEnd; @@ -642,7 +625,6 @@ bool TConnector::HandleSockReadReady() { } bool TConnector::PrepareForPoll(uint64_t now, int &poll_timeout) { - assert(this); poll_timeout = -1; bool need_sock_write = false; bool need_sock_read = !AckWaitQueue.empty(); @@ -742,7 +724,6 @@ bool TConnector::PrepareForPoll(uint64_t now, int &poll_timeout) { } void TConnector::DoRun() { - assert(this); OkShutdown = false; long broker_id = MyBrokerId(); diff --git a/src/dory/msg_dispatch/connector.h b/src/dory/msg_dispatch/connector.h index 9a8feaa4..33578a1f 100644 --- a/src/dory/msg_dispatch/connector.h +++ b/src/dory/msg_dispatch/connector.h @@ -68,19 +68,16 @@ namespace Dory { void SetMetadata(const std::shared_ptr &md); void Dispatch(TMsg::TPtr &&msg) { - assert(this); InputQueue.Put(Base::GetEpochMilliseconds(), std::move(msg)); assert(!msg); } void DispatchNow(TMsg::TPtr &&msg) { - assert(this); InputQueue.PutNow(Base::GetEpochMilliseconds(), std::move(msg)); assert(!msg); } void DispatchNow(std::list> &&batch) { - assert(this); InputQueue.PutNow(Base::GetEpochMilliseconds(), std::move(batch)); assert(batch.empty()); } @@ -94,17 +91,14 @@ namespace Dory { void CleanupAfterJoin(); bool ShutdownWasOk() const { - assert(this); return OkShutdown; } std::list> GetNoAckQueueAfterShutdown() { - assert(this); return std::move(NoAckAfterShutdown); } std::list> GetSendWaitQueueAfterShutdown() { - assert(this); return std::move(SendWaitAfterShutdown); } @@ -113,17 +107,14 @@ namespace Dory { private: const TMetadata::TBroker &MyBroker() const { - assert(this); return Metadata->GetBrokers()[MyBrokerIndex]; } long MyBrokerId() const { - assert(this); return MyBroker().GetId(); } bool SendInProgress() const { - assert(this); return !SendBuf.DataIsEmpty(); } diff --git a/src/dory/msg_dispatch/dispatcher_shared_state.cc b/src/dory/msg_dispatch/dispatcher_shared_state.cc index 3f4679a2..379cf21d 100644 --- a/src/dory/msg_dispatch/dispatcher_shared_state.cc +++ b/src/dory/msg_dispatch/dispatcher_shared_state.cc @@ -50,7 +50,6 @@ TDispatcherSharedState::TDispatcherSharedState(const TCmdLineArgs &args, void TDispatcherSharedState::Discard(TMsg::TPtr &&msg, TAnomalyTracker::TDiscardReason reason) { - assert(this); assert(msg); TMsg::TPtr to_discard(std::move(msg)); AnomalyTracker.TrackDiscard(to_discard, reason); @@ -59,7 +58,6 @@ void TDispatcherSharedState::Discard(TMsg::TPtr &&msg, void TDispatcherSharedState::Discard(std::list &&msg_list, TAnomalyTracker::TDiscardReason reason) { - assert(this); std::list to_discard(std::move(msg_list)); for (TMsg::TPtr &msg : to_discard) { @@ -72,7 +70,6 @@ void TDispatcherSharedState::Discard(std::list &&msg_list, void TDispatcherSharedState::Discard(std::list> &&batch, TAnomalyTracker::TDiscardReason reason) { - assert(this); std::list> to_discard(std::move(batch)); for (auto &msg_list : to_discard) { @@ -87,15 +84,12 @@ void TDispatcherSharedState::Discard(std::list> &&batch, void TDispatcherSharedState::MarkAllThreadsRunning( size_t in_service_broker_count) { - assert(this); assert(RunningThreadCount.load() == 0); assert(!ShutdownFinished.GetFd().IsReadable()); std::atomic_store(&RunningThreadCount, in_service_broker_count); } void TDispatcherSharedState::MarkThreadFinished() { - assert(this); - if (--RunningThreadCount == 0) { HandleAllThreadsFinished(); } @@ -108,7 +102,6 @@ void TDispatcherSharedState::HandleAllThreadsFinished() { } void TDispatcherSharedState::ResetThreadFinishedState() { - assert(this); assert(RunningThreadCount.load() == 0); assert(ShutdownFinished.GetFd().IsReadable()); ShutdownFinished.Reset(); diff --git a/src/dory/msg_dispatch/dispatcher_shared_state.h b/src/dory/msg_dispatch/dispatcher_shared_state.h index 243a9c81..adead5f6 100644 --- a/src/dory/msg_dispatch/dispatcher_shared_state.h +++ b/src/dory/msg_dispatch/dispatcher_shared_state.h @@ -70,12 +70,10 @@ namespace Dory { const Debug::TDebugSetup &debug_setup); size_t GetAckCount() const noexcept { - assert(this); return AckCount.load(); } void IncrementAckCount() noexcept { - assert(this); ++AckCount; } @@ -88,12 +86,10 @@ namespace Dory { TAnomalyTracker::TDiscardReason reason); const Base::TFd &GetShutdownWaitFd() const noexcept { - assert(this); return ShutdownFinished.GetFd(); } size_t GetRunningThreadCount() const noexcept { - assert(this); return RunningThreadCount.load(); } diff --git a/src/dory/msg_dispatch/kafka_dispatcher.cc b/src/dory/msg_dispatch/kafka_dispatcher.cc index 5af22e38..734a67f2 100644 --- a/src/dory/msg_dispatch/kafka_dispatcher.cc +++ b/src/dory/msg_dispatch/kafka_dispatcher.cc @@ -48,22 +48,18 @@ DEFINE_COUNTER(StartKafkaDispatcher); void TKafkaDispatcher::SetProduceProtocol( TProduceProtocol *protocol) noexcept { - assert(this); Ds.ProduceProtocol.reset(protocol); } TKafkaDispatcherApi::TState TKafkaDispatcher::GetState() const noexcept { - assert(this); return State; } size_t TKafkaDispatcher::GetBrokerCount() const noexcept { - assert(this); return Connectors.size(); } void TKafkaDispatcher::Start(const std::shared_ptr &md) { - assert(this); assert(md); assert(Ds.ProduceProtocol); assert(State == TState::Stopped); @@ -113,7 +109,6 @@ void TKafkaDispatcher::Start(const std::shared_ptr &md) { } void TKafkaDispatcher::Dispatch(TMsg::TPtr &&msg, size_t broker_index) { - assert(this); assert(msg); assert(State != TState::Stopped); DispatchOneMsg.Increment(); @@ -135,7 +130,6 @@ void TKafkaDispatcher::Dispatch(TMsg::TPtr &&msg, size_t broker_index) { } void TKafkaDispatcher::DispatchNow(TMsg::TPtr &&msg, size_t broker_index) { - assert(this); assert(msg); assert(State != TState::Stopped); DispatchOneMsg.Increment(); @@ -158,7 +152,6 @@ void TKafkaDispatcher::DispatchNow(TMsg::TPtr &&msg, size_t broker_index) { void TKafkaDispatcher::DispatchNow(std::list> &&batch, size_t broker_index) { - assert(this); assert(State != TState::Stopped); if (batch.empty()) { @@ -184,7 +177,6 @@ void TKafkaDispatcher::DispatchNow(std::list> &&batch, } void TKafkaDispatcher::StartSlowShutdown(uint64_t start_time) { - assert(this); assert(State != TState::Stopped); StartDispatcherSlowShutdown.Increment(); @@ -206,7 +198,6 @@ void TKafkaDispatcher::StartSlowShutdown(uint64_t start_time) { } void TKafkaDispatcher::StartFastShutdown() { - assert(this); assert(State != TState::Stopped); StartDispatcherFastShutdown.Increment(); @@ -228,17 +219,14 @@ void TKafkaDispatcher::StartFastShutdown() { } const TFd &TKafkaDispatcher::GetPauseFd() const noexcept { - assert(this); return Ds.PauseButton.GetFd(); } const TFd &TKafkaDispatcher::GetShutdownWaitFd() const noexcept { - assert(this); return Ds.GetShutdownWaitFd(); } void TKafkaDispatcher::JoinAll() { - assert(this); assert(State != TState::Stopped); StartDispatcherJoinAll.Increment(); LOG(TPri::NOTICE) << "Start waiting for dispatcher shutdown status"; @@ -264,13 +252,11 @@ void TKafkaDispatcher::JoinAll() { } bool TKafkaDispatcher::ShutdownWasOk() const noexcept { - assert(this); return OkShutdown; } std::list> TKafkaDispatcher::GetNoAckQueueAfterShutdown(size_t broker_index) { - assert(this); assert(State == TState::Stopped); if (broker_index >= Connectors.size()) { @@ -288,7 +274,6 @@ TKafkaDispatcher::GetNoAckQueueAfterShutdown(size_t broker_index) { std::list> TKafkaDispatcher::GetSendWaitQueueAfterShutdown(size_t broker_index) { - assert(this); assert(State == TState::Stopped); if (broker_index >= Connectors.size()) { @@ -304,6 +289,5 @@ TKafkaDispatcher::GetSendWaitQueueAfterShutdown(size_t broker_index) { } size_t TKafkaDispatcher::GetAckCount() const noexcept { - assert(this); return Ds.GetAckCount(); } diff --git a/src/dory/msg_dispatch/produce_request_factory.cc b/src/dory/msg_dispatch/produce_request_factory.cc index 43ffb1f6..b496bc32 100644 --- a/src/dory/msg_dispatch/produce_request_factory.cc +++ b/src/dory/msg_dispatch/produce_request_factory.cc @@ -72,7 +72,6 @@ TProduceRequestFactory::TProduceRequestFactory(const TConf &conf, void TProduceRequestFactory::Init( const TCompressionConf &compression_conf, const std::shared_ptr &md) { - assert(this); DefaultTopicCompressionInfo = TCompressionInfo(compression_conf.DefaultTopicConfig); Metadata = md; @@ -81,7 +80,6 @@ void TProduceRequestFactory::Init( } void TProduceRequestFactory::Reset() { - assert(this); Metadata.reset(); CorrIdCounter = 0; TopicDataMap.clear(); @@ -89,8 +87,6 @@ void TProduceRequestFactory::Reset() { TOpt TProduceRequestFactory::BuildRequest( std::vector &dst) { - assert(this); - if (IsEmpty()) { return TOpt(); } @@ -176,7 +172,6 @@ TProduceRequestFactory::TTopicData::TTopicData( void TProduceRequestFactory::InitTopicDataMap( const TCompressionConf &compression_conf) { - assert(this); TopicDataMap.clear(); const TCompressionConf::TTopicMap &topic_map = compression_conf.TopicConfigs; @@ -187,7 +182,6 @@ void TProduceRequestFactory::InitTopicDataMap( TProduceRequestFactory::TTopicData & TProduceRequestFactory::GetTopicData(const std::string &topic) { - assert(this); auto iter = TopicDataMap.find(topic); if (iter == TopicDataMap.end()) { @@ -259,7 +253,6 @@ static void SanityCheckRequestContents(TAllTopics &contents) { } size_t TProduceRequestFactory::AddFirstMsg(TAllTopics &result) { - assert(this); assert(!InputQueue.empty()); TMsg::TPtr msg_ptr; @@ -298,7 +291,6 @@ size_t TProduceRequestFactory::AddFirstMsg(TAllTopics &result) { bool TProduceRequestFactory::TryConsumeFrontMsg( std::list &next_batch, const std::string &topic, TTopicData &topic_data, size_t &result_data_size, TAllTopics &result) { - assert(this); assert(!next_batch.empty()); TMsg::TPtr &msg_ptr = next_batch.front(); bool any_partition = @@ -345,7 +337,6 @@ bool TProduceRequestFactory::TryConsumeFrontMsg( } TAllTopics TProduceRequestFactory::BuildRequestContents() { - assert(this); assert(!InputQueue.empty()); TAllTopics result; size_t result_data_size = AddFirstMsg(result); @@ -406,7 +397,6 @@ TAllTopics TProduceRequestFactory::BuildRequestContents() { void TProduceRequestFactory::SerializeUncompressedMsgSet( const std::list &msg_set, std::vector &dst) { - assert(this); assert(!msg_set.empty()); for (const TMsg::TPtr &msg_ptr : msg_set) { @@ -429,7 +419,6 @@ void TProduceRequestFactory::SerializeUncompressedMsgSet( void TProduceRequestFactory::SerializeToCompressionBuf( const std::list &msg_set) { - assert(this); assert(!msg_set.empty()); MsgSetWriter->OpenMsgSet(CompressionBuf, false); @@ -455,8 +444,6 @@ void TProduceRequestFactory::SerializeToCompressionBuf( void TProduceRequestFactory::WriteOneMsgSet(const TMsgSet &msg_set, const TCompressionInfo &info, std::vector &dst) { - assert(this); - if (info.CompressionCodec && (msg_set.DataSize >= info.MinCompressionSize)) { SerializeToCompressionBuf(msg_set.Contents); assert(info.CompressionCodec); diff --git a/src/dory/msg_dispatch/produce_request_factory.h b/src/dory/msg_dispatch/produce_request_factory.h index 96132eeb..f6db7b30 100644 --- a/src/dory/msg_dispatch/produce_request_factory.h +++ b/src/dory/msg_dispatch/produce_request_factory.h @@ -71,7 +71,6 @@ namespace Dory { void Reset(); bool IsEmpty() const { - assert(this); return InputQueue.empty(); } @@ -80,30 +79,25 @@ namespace Dory { /* Queue a single batch. */ void Put(std::list &&batch) { - assert(this); InputQueue.push_back(std::move(batch)); } /* Queue multiple batches. */ void Put(std::list> &&batch_list) { - assert(this); InputQueue.splice(InputQueue.end(), std::move(batch_list)); } /* Used for resending messages. */ void PutFront(std::list &&batch) { - assert(this); InputQueue.push_front(std::move(batch)); } /* Used for resending messages. */ void PutFront(std::list> &&batch_list) { - assert(this); InputQueue.splice(InputQueue.begin(), std::move(batch_list)); } std::list> GetAll() { - assert(this); return std::move(InputQueue); } diff --git a/src/dory/msg_dispatch/produce_response_processor.cc b/src/dory/msg_dispatch/produce_response_processor.cc index 5ded071b..1b0ed607 100644 --- a/src/dory/msg_dispatch/produce_response_processor.cc +++ b/src/dory/msg_dispatch/produce_response_processor.cc @@ -53,7 +53,6 @@ DEFINE_COUNTER(ProduceResponseUnexpectedTopic); TProduceResponseProcessor::TAction TProduceResponseProcessor::ProcessResponse(TProduceRequest &request, const uint8_t *response_buf, size_t response_buf_size) { - assert(this); ResponseReader.SetResponse(response_buf, response_buf_size); TCorrId corr_id = ResponseReader.GetCorrelationId(); @@ -77,7 +76,6 @@ TProduceResponseProcessor::ProcessResponse(TProduceRequest &request, void TProduceResponseProcessor::ReportBadResponseTopic( const std::string &topic) const { - assert(this); LOG_R(TPri::ERR, std::chrono::seconds(30)) << "Connector thread " << Gettid() << " (index " << MyBrokerIndex << " broker " << MyBrokerId << ") starting pause due to produce response with unexpected topic [" @@ -87,7 +85,6 @@ void TProduceResponseProcessor::ReportBadResponseTopic( void TProduceResponseProcessor::ReportBadResponsePartition( int32_t partition) const { - assert(this); LOG_R(TPri::ERR, std::chrono::seconds(30)) << "Connector thread " << Gettid() << " (index " << MyBrokerIndex << " broker " << MyBrokerId << ") starting pause due to produce response with unexpected partition: " @@ -97,7 +94,6 @@ void TProduceResponseProcessor::ReportBadResponsePartition( void TProduceResponseProcessor::ReportShortResponsePartitionList( const std::string &topic) const { - assert(this); LOG_R(TPri::ERR, std::chrono::seconds(30)) << "Connector thread " << Gettid() << " (index " << MyBrokerIndex << " broker " << MyBrokerId << ") starting pause due to produce response with short partition list " @@ -106,7 +102,6 @@ void TProduceResponseProcessor::ReportShortResponsePartitionList( } void TProduceResponseProcessor::ReportShortResponseTopicList() const { - assert(this); LOG_R(TPri::ERR, std::chrono::seconds(30)) << "Connector thread " << Gettid() << " (index " << MyBrokerIndex << " broker " << MyBrokerId << ") starting pause due to produce response with short topic list"; @@ -115,8 +110,6 @@ void TProduceResponseProcessor::ReportShortResponseTopicList() const { void TProduceResponseProcessor::CountFailedDeliveryAttempt( std::list &msg_set, const std::string &topic) { - assert(this); - for (auto iter = msg_set.begin(), next = iter; iter != msg_set.end(); iter = next) { @@ -143,7 +136,6 @@ void TProduceResponseProcessor::CountFailedDeliveryAttempt( void TProduceResponseProcessor::ProcessImmediateResendMsgSet( std::list &&msg_set, const std::string &topic) { - assert(this); assert(!msg_set.empty()); CountFailedDeliveryAttempt(msg_set, topic); @@ -160,7 +152,6 @@ void TProduceResponseProcessor::ProcessImmediateResendMsgSet( void TProduceResponseProcessor::ProcessPauseAndResendMsgSet( std::list &&msg_set, const std::string &topic) { - assert(this); assert(!msg_set.empty()); CountFailedDeliveryAttempt(msg_set, topic); @@ -176,7 +167,6 @@ void TProduceResponseProcessor::ProcessPauseAndResendMsgSet( } void TProduceResponseProcessor::ProcessNoAckMsgs(TAllTopics &all_topics) { - assert(this); std::list> tmp; EmptyAllTopics(all_topics, tmp); @@ -192,7 +182,6 @@ void TProduceResponseProcessor::ProcessNoAckMsgs(TAllTopics &all_topics) { bool TProduceResponseProcessor::ProcessOneAck(std::list &&msg_set, int16_t ack, const std::string &topic) { - assert(this); assert(!msg_set.empty()); Ds.IncrementAckCount(); @@ -265,7 +254,6 @@ bool TProduceResponseProcessor::ProcessOneAck(std::list &&msg_set, TProduceResponseProcessor::TAction TProduceResponseProcessor::ProcessResponseAcks(TProduceRequest &request) { - assert(this); std::string topic; bool got_pause_ack = false; bool bad_response = false; diff --git a/src/dory/msg_dispatch/produce_response_processor.h b/src/dory/msg_dispatch/produce_response_processor.h index 94de4173..bba6a806 100644 --- a/src/dory/msg_dispatch/produce_response_processor.h +++ b/src/dory/msg_dispatch/produce_response_processor.h @@ -92,7 +92,6 @@ namespace Dory { be called unless ProcessResponse() returned TAction::PauseAndFinishNow. */ std::list> TakeMsgsWithoutAcks() { - assert(this); return std::move(MsgsWithoutAcks); } @@ -102,7 +101,6 @@ namespace Dory { be called unless ProcessResponse() returned TAction::PauseAndFinishNow or TAction::PauseAndDeferFinish. */ std::list> TakePauseAndResendAckMsgs() { - assert(this); return std::move(PauseAndResendAckMsgs); } @@ -111,7 +109,6 @@ namespace Dory { without rerouting based on new metadata. This method must be called regardless of what value ProcessResponse() returned. */ std::list> TakeImmediateResendAckMsgs() { - assert(this); return std::move(ImmediateResendAckMsgs); } diff --git a/src/dory/msg_rate_limiter.cc b/src/dory/msg_rate_limiter.cc index 7f195c1a..db370210 100644 --- a/src/dory/msg_rate_limiter.cc +++ b/src/dory/msg_rate_limiter.cc @@ -28,8 +28,6 @@ using namespace Dory::Conf; bool TMsgRateLimiter::WouldExceedLimit(const std::string &topic, uint64_t timestamp) { - assert(this); - if (!IsEnabled) { /* Fast path for case where rate limiting is completely disabled. */ return false; @@ -59,7 +57,6 @@ bool TMsgRateLimiter::RateLimitingIsEnabled( TMsgRateLimiter::TTopicState & TMsgRateLimiter::GetTopicState(const std::string &topic, uint64_t timestamp) { - assert(this); auto iter = TopicStateMap.find(topic); if (iter != TopicStateMap.end()) { diff --git a/src/dory/msg_state_tracker.cc b/src/dory/msg_state_tracker.cc index 71931c44..3215366f 100644 --- a/src/dory/msg_state_tracker.cc +++ b/src/dory/msg_state_tracker.cc @@ -29,15 +29,12 @@ using namespace Dory; using namespace Log; void TMsgStateTracker::MsgEnterNew() noexcept { - assert(this); - std::lock_guard lock(Mutex); ++NewCount; assert(NewCount > 0); } void TMsgStateTracker::MsgEnterBatching(TMsg &msg) { - assert(this); TDeltaComputer comp; comp.CountBatchingEntered(msg.GetState()); msg.SetState(TMsg::TState::Batching); @@ -45,7 +42,6 @@ void TMsgStateTracker::MsgEnterBatching(TMsg &msg) { } void TMsgStateTracker::MsgEnterSendWait(TMsg &msg) { - assert(this); TDeltaComputer comp; comp.CountSendWaitEntered(msg.GetState()); msg.SetState(TMsg::TState::SendWait); @@ -54,8 +50,6 @@ void TMsgStateTracker::MsgEnterSendWait(TMsg &msg) { void TMsgStateTracker::MsgEnterSendWait( const std::list &msg_list) { - assert(this); - if (msg_list.empty()) { return; } @@ -76,15 +70,12 @@ void TMsgStateTracker::MsgEnterSendWait( void TMsgStateTracker::MsgEnterSendWait( const std::list> &msg_list_list) { - assert(this); - for (const auto &msg_list : msg_list_list) { MsgEnterSendWait(msg_list); } } void TMsgStateTracker::MsgEnterAckWait(TMsg &msg) { - assert(this); TDeltaComputer comp; comp.CountAckWaitEntered(msg.GetState()); msg.SetState(TMsg::TState::AckWait); @@ -92,8 +83,6 @@ void TMsgStateTracker::MsgEnterAckWait(TMsg &msg) { } void TMsgStateTracker::MsgEnterAckWait(const std::list &msg_list) { - assert(this); - if (msg_list.empty()) { return; } @@ -114,15 +103,12 @@ void TMsgStateTracker::MsgEnterAckWait(const std::list &msg_list) { void TMsgStateTracker::MsgEnterAckWait( const std::list> &msg_list_list) { - assert(this); - for (const auto &msg_list : msg_list_list) { MsgEnterAckWait(msg_list); } } void TMsgStateTracker::MsgEnterProcessed(TMsg &msg) { - assert(this); TDeltaComputer comp; comp.CountProcessedEntered(msg.GetState()); msg.SetState(TMsg::TState::Processed); @@ -131,8 +117,6 @@ void TMsgStateTracker::MsgEnterProcessed(TMsg &msg) { void TMsgStateTracker::MsgEnterProcessed( const std::list &msg_list) { - assert(this); - if (msg_list.empty()) { return; } @@ -153,8 +137,6 @@ void TMsgStateTracker::MsgEnterProcessed( void TMsgStateTracker::MsgEnterProcessed( const std::list> &msg_list_list) { - assert(this); - for (const auto &msg_list : msg_list_list) { MsgEnterProcessed(msg_list); } @@ -162,7 +144,6 @@ void TMsgStateTracker::MsgEnterProcessed( void TMsgStateTracker::GetStats(std::vector &result, long &new_count) const { - assert(this); result.clear(); std::lock_guard lock(Mutex); @@ -179,7 +160,6 @@ void TMsgStateTracker::GetStats(std::vector &result, } void TMsgStateTracker::PruneTopics(const TTopicExistsFn &topic_exists_fn) { - assert(this); std::lock_guard lock(Mutex); for (auto iter = TopicStats.begin(); iter != TopicStats.end(); ) { @@ -198,8 +178,6 @@ void TMsgStateTracker::PruneTopics(const TTopicExistsFn &topic_exists_fn) { void TMsgStateTracker::TDeltaComputer::CountBatchingEntered( TMsg::TState prev_state) noexcept { - assert(this); - switch (prev_state) { case TMsg::TState::New: { --NewDelta; @@ -236,8 +214,6 @@ void TMsgStateTracker::TDeltaComputer::CountBatchingEntered( void TMsgStateTracker::TDeltaComputer::CountSendWaitEntered( TMsg::TState prev_state) noexcept { - assert(this); - switch (prev_state) { case TMsg::TState::New: { --NewDelta; @@ -269,8 +245,6 @@ void TMsgStateTracker::TDeltaComputer::CountSendWaitEntered( void TMsgStateTracker::TDeltaComputer::CountAckWaitEntered( TMsg::TState prev_state) noexcept { - assert(this); - switch (prev_state) { case TMsg::TState::New: { LOG_R(TPri::ERR, std::chrono::seconds(30)) @@ -307,8 +281,6 @@ void TMsgStateTracker::TDeltaComputer::CountAckWaitEntered( void TMsgStateTracker::TDeltaComputer::CountProcessedEntered( TMsg::TState prev_state) noexcept { - assert(this); - switch (prev_state) { case TMsg::TState::New: { --NewDelta; @@ -340,7 +312,6 @@ void TMsgStateTracker::TDeltaComputer::CountProcessedEntered( void TMsgStateTracker::UpdateStats(const std::string &topic, const TDeltaComputer &comp) { - assert(this); long new_delta = comp.GetNewDelta(); long batching_delta = comp.GetBatchingDelta(); long send_wait_delta = comp.GetSendWaitDelta(); diff --git a/src/dory/msg_state_tracker.h b/src/dory/msg_state_tracker.h index b38783f2..8a750d95 100644 --- a/src/dory/msg_state_tracker.h +++ b/src/dory/msg_state_tracker.h @@ -137,22 +137,18 @@ namespace Dory { TDeltaComputer() noexcept = default; long GetNewDelta() const noexcept { - assert(this); return NewDelta; } long GetBatchingDelta() const noexcept { - assert(this); return BatchingDelta; } long GetSendWaitDelta() const noexcept { - assert(this); return SendWaitDelta; } long GetAckWaitDelta() const noexcept { - assert(this); return AckWaitDelta; } diff --git a/src/dory/router_thread.cc b/src/dory/router_thread.cc index f1e7dee6..0f9e8a5d 100644 --- a/src/dory/router_thread.cc +++ b/src/dory/router_thread.cc @@ -99,7 +99,6 @@ TRouterThread::~TRouterThread() { } void TRouterThread::Run() { - assert(this); int tid = static_cast(Gettid()); LOG(TPri::NOTICE) << "Router thread " << tid << " started"; @@ -147,8 +146,6 @@ size_t TRouterThread::ComputeRetryDelay(size_t mean_delay, size_t div) { } void TRouterThread::StartShutdown() { - assert(this); - if (Destroying) { throw TShutdownOnDestroy(); } @@ -166,7 +163,6 @@ void TRouterThread::StartShutdown() { void TRouterThread::Discard(TMsg::TPtr &&msg, TAnomalyTracker::TDiscardReason reason) { - assert(this); assert(msg); TMsg::TPtr to_discard(std::move(msg)); AnomalyTracker.TrackDiscard(to_discard, reason); @@ -175,7 +171,6 @@ void TRouterThread::Discard(TMsg::TPtr &&msg, void TRouterThread::Discard(std::list &&msg_list, TAnomalyTracker::TDiscardReason reason) { - assert(this); std::list to_discard(std::move(msg_list)); for (TMsg::TPtr &msg : to_discard) { @@ -188,7 +183,6 @@ void TRouterThread::Discard(std::list &&msg_list, void TRouterThread::Discard(std::list> &&batch_list, TAnomalyTracker::TDiscardReason reason) { - assert(this); std::list> to_discard(std::move(batch_list)); for (std::list &msg_list : to_discard) { @@ -203,7 +197,6 @@ void TRouterThread::Discard(std::list> &&batch_list, bool TRouterThread::UpdateMetadataAfterTopicAutocreate( const std::string &topic) { - assert(this); size_t sleep_ms = 3000; static const size_t NUM_ATTEMPTS = 3; @@ -239,7 +232,6 @@ bool TRouterThread::UpdateMetadataAfterTopicAutocreate( } bool TRouterThread::AutocreateTopic(TMsg::TPtr &msg) { - assert(this); assert(!KnownBrokers.empty()); assert(msg); const std::string &topic = msg->GetTopic(); @@ -312,7 +304,6 @@ bool TRouterThread::AutocreateTopic(TMsg::TPtr &msg) { } bool TRouterThread::ValidateNewMsg(TMsg::TPtr &msg) { - assert(this); assert(Metadata); const std::string &topic = msg->GetTopic(); int topic_index = Metadata->FindTopicIndex(topic); @@ -398,7 +389,6 @@ bool TRouterThread::ValidateNewMsg(TMsg::TPtr &msg) { } void TRouterThread::ValidateBeforeReroute(std::list &msg_list) { - assert(this); assert(!msg_list.empty()); const std::string &topic = msg_list.front()->GetTopic(); int topic_index = Metadata->FindTopicIndex(topic); @@ -441,7 +431,6 @@ void TRouterThread::ValidateBeforeReroute(std::list &msg_list) { size_t TRouterThread::LookupValidTopicIndex( const std::string &topic) const noexcept { - assert(this); assert(Metadata); int topic_index = Metadata->FindTopicIndex(topic); @@ -460,7 +449,6 @@ size_t TRouterThread::LookupValidTopicIndex( size_t TRouterThread::ChooseAnyPartitionBrokerIndex( const std::string &topic) noexcept { - assert(this); assert(Metadata); /* When we update our metadata, we delete from the batcher any topics that @@ -494,7 +482,6 @@ size_t TRouterThread::ChooseAnyPartitionBrokerIndex( const TMetadata::TPartition &TRouterThread::ChoosePartitionByKey( const TMetadata::TTopic &topic_meta, int32_t partition_key) noexcept { - assert(this); assert(Metadata); const std::vector &broker_vec = Metadata->GetBrokers(); assert(!broker_vec.empty()); @@ -523,7 +510,6 @@ const TMetadata::TPartition &TRouterThread::ChoosePartitionByKey( } size_t TRouterThread::AssignBroker(TMsg::TPtr &msg) noexcept { - assert(this); RouteSingleMsg.Increment(); const std::string &topic = msg->GetTopic(); @@ -544,21 +530,17 @@ size_t TRouterThread::AssignBroker(TMsg::TPtr &msg) noexcept { } void TRouterThread::Route(TMsg::TPtr &&msg) { - assert(this); size_t broker_index = AssignBroker(msg); Dispatcher.Dispatch(std::move(msg), broker_index); } void TRouterThread::RouteNow(TMsg::TPtr &&msg) { - assert(this); size_t broker_index = AssignBroker(msg); Dispatcher.DispatchNow(std::move(msg), broker_index); } void TRouterThread::RouteAnyPartitionNow( std::list> &&batch_list) { - assert(this); - if (batch_list.empty()) { return; } @@ -587,7 +569,6 @@ void TRouterThread::RouteAnyPartitionNow( void TRouterThread::RoutePartitionKeyNow( std::list> &&batch_list) { - assert(this); assert(Metadata); if (batch_list.empty()) { @@ -633,8 +614,6 @@ void TRouterThread::RoutePartitionKeyNow( } void TRouterThread::Reroute(std::list> &&batch_list) { - assert(this); - if (batch_list.empty()) { return; } @@ -684,7 +663,6 @@ void TRouterThread::Reroute(std::list> &&batch_list) { } void TRouterThread::RouteFinalMsgs() { - assert(this); assert(Metadata); if (PerTopicBatcher.IsEnabled()) { @@ -724,7 +702,6 @@ void TRouterThread::RouteFinalMsgs() { } void TRouterThread::DiscardFinalMsgs() { - assert(this); std::list msg_list; /* Get any remaining queued messages from the input thread. */ @@ -749,8 +726,6 @@ void TRouterThread::DiscardFinalMsgs() { } void TRouterThread::InitWireProtocol() { - assert(this); - /* This code is just a placeholder, since Dory currently supports only version 0 of the metadata and produce wire protocols. Eventually code will go here that handles cases where a specific metadata or produce @@ -772,7 +747,6 @@ void TRouterThread::InitWireProtocol() { } bool TRouterThread::Init() { - assert(this); InitWireProtocol(); std::shared_ptr meta; @@ -809,7 +783,6 @@ bool TRouterThread::Init() { } void TRouterThread::CheckDispatcherShutdown() { - assert(this); Dispatcher.JoinAll(); if (Dispatcher.ShutdownWasOk()) { @@ -821,7 +794,6 @@ void TRouterThread::CheckDispatcherShutdown() { bool TRouterThread::ReplaceMetadataOnRefresh( std::shared_ptr &&meta) { - assert(this); std::shared_ptr md = std::move(meta); LOG(TPri::NOTICE) << "Router thread starting fast dispatcher shutdown for metadata " @@ -868,7 +840,6 @@ bool TRouterThread::ReplaceMetadataOnRefresh( /* Return true on success, or false if we got a shutdown signal and the shutdown delay expired while trying to refresh metadata. */ bool TRouterThread::RefreshMetadata() { - assert(this); assert(ShutdownStartTime.IsUnknown()); std::shared_ptr meta; @@ -900,7 +871,6 @@ bool TRouterThread::RefreshMetadata() { } std::list> TRouterThread::EmptyDispatcher() { - assert(this); std::vector>> broker_lists; size_t broker_count = Dispatcher.GetBrokerCount(); broker_lists.reserve(broker_count); @@ -963,7 +933,6 @@ std::list> TRouterThread::EmptyDispatcher() { } bool TRouterThread::RespondToPause() { - assert(this); RouterThreadStartPause.Increment(); if (!HandlePause()) { @@ -997,8 +966,6 @@ bool TRouterThread::RespondToPause() { } void TRouterThread::DiscardOnShutdownDuringMetadataUpdate(TMsg::TPtr &&msg) { - assert(this); - if (Conf.LoggingConf.LogDiscards) { LOG_R(TPri::ERR, std::chrono::seconds(30)) << "Router thread discarding message with topic [" << msg->GetTopic() @@ -1010,7 +977,6 @@ void TRouterThread::DiscardOnShutdownDuringMetadataUpdate(TMsg::TPtr &&msg) { void TRouterThread::DiscardOnShutdownDuringMetadataUpdate( std::list &&msg_list) { - assert(this); std::list to_discard(std::move(msg_list)); for (TMsg::TPtr &msg : to_discard) { @@ -1020,7 +986,6 @@ void TRouterThread::DiscardOnShutdownDuringMetadataUpdate( void TRouterThread::DiscardOnShutdownDuringMetadataUpdate( std::list> &&batch_list) { - assert(this); std::list> to_discard(std::move(batch_list)); for (std::list &batch : to_discard) { @@ -1029,8 +994,6 @@ void TRouterThread::DiscardOnShutdownDuringMetadataUpdate( } bool TRouterThread::HandleMetadataUpdate() { - assert(this); - if (MetadataUpdateRequestSem.GetFd().IsReadable()) { MetadataUpdateRequestSem.Pop(); LOG(TPri::NOTICE) @@ -1053,7 +1016,6 @@ bool TRouterThread::HandleMetadataUpdate() { } void TRouterThread::ContinueShutdown() { - assert(this); NeedToContinueShutdown = false; /* Start watching for slow shutdown finish notification. Stop watching for @@ -1076,8 +1038,6 @@ void TRouterThread::ContinueShutdown() { } int TRouterThread::ComputeMainLoopPollTimeout() { - assert(this); - if (OptNextBatchExpiry.IsUnknown()) { return -1; // infinite timeout } @@ -1104,7 +1064,6 @@ int TRouterThread::ComputeMainLoopPollTimeout() { } void TRouterThread::InitMainLoopPollArray() { - assert(this); struct pollfd &pause_item = MainLoopPollArray[TMainLoopPollItem::Pause]; struct pollfd &shutdown_request_item = MainLoopPollArray[TMainLoopPollItem::ShutdownRequest]; @@ -1141,7 +1100,6 @@ void TRouterThread::InitMainLoopPollArray() { } void TRouterThread::DoRun() { - assert(this); OkShutdown = false; if (!Init()) { @@ -1204,8 +1162,6 @@ void TRouterThread::DoRun() { } void TRouterThread::HandleShutdownFinished() { - assert(this); - if (ShutdownStartTime.IsKnown()) { LOG(TPri::NOTICE) << "Router thread got shutdown finished notification from dispatcher"; @@ -1233,7 +1189,6 @@ void TRouterThread::HandleShutdownFinished() { } void TRouterThread::HandleBatchExpiry(uint64_t now) { - assert(this); assert(PerTopicBatcher.IsEnabled()); BatchExpiryDetected.Increment(); RouteAnyPartitionNow(PerTopicBatcher.GetCompleteBatches(now)); @@ -1245,7 +1200,6 @@ void TRouterThread::HandleBatchExpiry(uint64_t now) { } void TRouterThread::HandleMsgAvailable(uint64_t now) { - assert(this); RouterThreadGetMsgList.Increment(); std::list> ready_batches; std::list msg_list = MsgChannel.Get(); @@ -1322,8 +1276,6 @@ void TRouterThread::HandleMsgAvailable(uint64_t now) { } bool TRouterThread::HandlePause() { - assert(this); - /* Impose a delay before handling a pause that occurs shortly after a previous pause. If something goes seriously wrong, this prevents us from going into a tight pause loop. */ @@ -1380,7 +1332,6 @@ bool TRouterThread::HandlePause() { } void TRouterThread::UpdateKnownBrokers(const TMetadata &md) { - assert(this); std::vector broker_vec; const std::vector &new_brokers = md.GetBrokers(); @@ -1392,7 +1343,6 @@ void TRouterThread::UpdateKnownBrokers(const TMetadata &md) { } std::shared_ptr TRouterThread::TryGetMetadata() { - assert(this); assert(!KnownBrokers.empty()); TMetadataFetcher::TDisconnecter disconnecter(*MetadataFetcher); size_t chosen = std::rand() % KnownBrokers.size(); @@ -1452,13 +1402,11 @@ std::shared_ptr TRouterThread::TryGetMetadata() { } void TRouterThread::InitMetadataRefreshTimer() { - assert(this); MetadataRefreshTimer.reset(new TTimerFd(ComputeRetryDelay( Conf.MsgDeliveryConf.MetadataRefreshInterval * 60 * 1000, 5))); } std::shared_ptr TRouterThread::GetInitialMetadata() { - assert(this); std::shared_ptr result; TDoryRateLimiter retry_rate_limiter( Conf.MsgDeliveryConf.PauseRateLimitInitial, @@ -1490,7 +1438,6 @@ std::shared_ptr TRouterThread::GetInitialMetadata() { } std::shared_ptr TRouterThread::GetMetadataBeforeSlowShutdown() { - assert(this); std::shared_ptr result; TDoryRateLimiter retry_rate_limiter( Conf.MsgDeliveryConf.PauseRateLimitInitial, @@ -1527,7 +1474,6 @@ std::shared_ptr TRouterThread::GetMetadataBeforeSlowShutdown() { } std::shared_ptr TRouterThread::GetMetadataDuringSlowShutdown() { - assert(this); std::shared_ptr result; const size_t shutdown_delay = Conf.MsgDeliveryConf.ShutdownMaxDelay; const uint64_t finish_time = *ShutdownStartTime + shutdown_delay; @@ -1573,7 +1519,6 @@ std::shared_ptr TRouterThread::GetMetadataDuringSlowShutdown() { } std::shared_ptr TRouterThread::GetMetadata() { - assert(this); std::shared_ptr result; if (ShutdownStartTime.IsUnknown()) { @@ -1595,7 +1540,6 @@ std::shared_ptr TRouterThread::GetMetadata() { void TRouterThread::UpdateBatchStateForNewMetadata(const TMetadata &old_md, const TMetadata &new_md) { - assert(this); std::list deleted_topic_msgs, unavailable_topic_msgs; const std::vector &old_topic_vec = old_md.GetTopics(); const std::vector &new_topic_vec = new_md.GetTopics(); @@ -1656,7 +1600,6 @@ void TRouterThread::UpdateBatchStateForNewMetadata(const TMetadata &old_md, void TRouterThread::SetMetadata(std::shared_ptr &&meta, bool record_update) { - assert(this); assert(meta); /* TODO: make this a lambda */ diff --git a/src/dory/router_thread.h b/src/dory/router_thread.h index 7f0d50cf..9e5d11e7 100644 --- a/src/dory/router_thread.h +++ b/src/dory/router_thread.h @@ -89,33 +89,27 @@ namespace Dory { the case where the Kafka cluster is temporarily unavailable, router thread initialization can take arbitrarily long. */ const Base::TFd &GetInitWaitFd() const noexcept { - assert(this); return InitFinishedSem.GetFd(); } bool ShutdownWasOk() const noexcept { - assert(this); return OkShutdown; } Thread::TGatePutApi &GetMsgChannel() noexcept { - assert(this); return MsgChannel; } Base::TEventSemaphore &GetMetadataUpdateRequestSem() noexcept { - assert(this); return MetadataUpdateRequestSem; } const TMetadataTimestamp &GetMetadataTimestamp() const noexcept { - assert(this); return MetadataTimestamp; } /* Used by main thread during shutdown. */ std::list GetRemainingMsgs() { - assert(this); return MsgChannel.NonblockingGet(); } @@ -182,7 +176,6 @@ namespace Dory { metadata and return its metadata. */ const TMetadata::TTopic &GetValidTopicMetadata( const std::string &topic) const noexcept { - assert(this); assert(Metadata); return Metadata->GetTopics()[LookupValidTopicIndex(topic)]; } @@ -194,7 +187,6 @@ namespace Dory { const TMetadata::TPartition &ChoosePartitionByKey(const std::string &topic, int32_t partition_key) { - assert(this); assert(Metadata); /* All topics are validated before routing, so parameter 'topic' should diff --git a/src/dory/stream_client_handler.cc b/src/dory/stream_client_handler.cc index 1db83583..fb62e020 100644 --- a/src/dory/stream_client_handler.cc +++ b/src/dory/stream_client_handler.cc @@ -48,7 +48,6 @@ TStreamClientHandler::TStreamClientHandler(bool is_tcp, void TStreamClientHandler::HandleConnection(Base::TFd &&sock, const struct sockaddr *, socklen_t) { - assert(this); TWorkerPool::TReadyWorker worker = WorkerPool.GetReadyWorker(); worker.GetWorkFn().SetState(IsTcp, Conf, Pool, MsgStateTracker, AnomalyTracker, OutputQueue, WorkerPool.GetShutdownRequestFd(), @@ -57,7 +56,6 @@ void TStreamClientHandler::HandleConnection(Base::TFd &&sock, } void TStreamClientHandler::HandleNonfatalAcceptError(int errno_value) { - assert(this); /* TODO: Consider implementing rate limiting on a per-errno-value basis. */ LOG_ERRNO_R(TPri::ERR, errno_value, std::chrono::seconds(30)) << "Error accepting " << (IsTcp ? "TCP" : "UNIX stream") diff --git a/src/dory/stream_client_handler.test.cc b/src/dory/stream_client_handler.test.cc index 5dcfc3e1..356fd078 100644 --- a/src/dory/stream_client_handler.test.cc +++ b/src/dory/stream_client_handler.test.cc @@ -113,7 +113,6 @@ namespace { std::unique_ptr CreateStreamClientHandler() { - assert(this); return std::unique_ptr( new TStreamClientHandler(false, Conf, Pool, MsgStateTracker, AnomalyTracker, *OutputQueue, *StreamClientWorkerPool)); diff --git a/src/dory/stream_client_work_fn.cc b/src/dory/stream_client_work_fn.cc index 823eeba1..3abf72c3 100644 --- a/src/dory/stream_client_work_fn.cc +++ b/src/dory/stream_client_work_fn.cc @@ -67,7 +67,6 @@ DEFINE_COUNTER(UnixStreamInputUncleanDisconnect); TStreamClientWorkFn &TStreamClientWorkFn::TStreamClientWorkFn::operator=( nullptr_t) noexcept { - assert(this); IsTcp = false; Conf = nullptr; Pool = nullptr; @@ -81,7 +80,6 @@ TStreamClientWorkFn &TStreamClientWorkFn::TStreamClientWorkFn::operator=( } void TStreamClientWorkFn::operator()() { - assert(this); assert(Conf); assert(Pool); assert(MsgStateTracker); @@ -125,7 +123,6 @@ void TStreamClientWorkFn::SetState(bool is_tcp, const TConf &conf, TPool &pool, TMsgStateTracker &msg_state_tracker, TAnomalyTracker &anomaly_tracker, TGatePutApi &output_queue, const TFd &shutdown_request_fd, TFd &&client_socket) noexcept { - assert(this); IsTcp = is_tcp; Conf = &conf; Pool = &pool; @@ -165,7 +162,6 @@ void TStreamClientWorkFn::HandleClientClosed() const { } void TStreamClientWorkFn::HandleDataInvalid() { - assert(this); assert(StreamReader.GetDataInvalidReason().IsKnown()); switch (*StreamReader.GetDataInvalidReason()) { @@ -204,8 +200,6 @@ void TStreamClientWorkFn::HandleDataInvalid() { } bool TStreamClientWorkFn::HandleSockReadReady() { - assert(this); - if (IsTcp) { TcpInputSocketRead.Increment(); } else { diff --git a/src/dory/test_util/misc_util.cc b/src/dory/test_util/misc_util.cc index 36eeff02..88ba9b5c 100644 --- a/src/dory/test_util/misc_util.cc +++ b/src/dory/test_util/misc_util.cc @@ -33,7 +33,6 @@ using namespace Dory::TestUtil; TMsg::TPtr TTestMsgCreator::NewMsg(const std::string &topic, const std::string &value, TMsg::TTimestamp timestamp, bool set_processed) { - assert(this); TMsg::TPtr msg = TMsgCreator::CreateAnyPartitionMsg(timestamp, topic.data(), topic.data() + topic.size(), nullptr, 0, value.data(), value.size(), false, *Pool, MsgStateTracker); diff --git a/src/dory/test_util/mock_kafka_dispatcher.cc b/src/dory/test_util/mock_kafka_dispatcher.cc index 62e4a21a..210c410a 100644 --- a/src/dory/test_util/mock_kafka_dispatcher.cc +++ b/src/dory/test_util/mock_kafka_dispatcher.cc @@ -40,7 +40,6 @@ TMockKafkaDispatcher::TMockKafkaDispatcher(const TCmdLineArgs &/*args*/, void TMockKafkaDispatcher::SetProduceProtocol( KafkaProto::Produce::TProduceProtocol * /*protocol*/) noexcept { - assert(this); @@ -48,7 +47,6 @@ void TMockKafkaDispatcher::SetProduceProtocol( } TKafkaDispatcherApi::TState TMockKafkaDispatcher::GetState() const noexcept { - assert(this); @@ -57,7 +55,6 @@ TKafkaDispatcherApi::TState TMockKafkaDispatcher::GetState() const noexcept { } size_t TMockKafkaDispatcher::GetBrokerCount() const noexcept { - assert(this); @@ -68,7 +65,6 @@ size_t TMockKafkaDispatcher::GetBrokerCount() const noexcept { void TMockKafkaDispatcher::Start( const std::shared_ptr &/*md*/) { - assert(this); @@ -78,7 +74,6 @@ void TMockKafkaDispatcher::Start( void TMockKafkaDispatcher::Dispatch(TMsg::TPtr &&/*msg*/, size_t /*broker_index*/) { - assert(this); @@ -89,7 +84,6 @@ void TMockKafkaDispatcher::Dispatch(TMsg::TPtr &&/*msg*/, void TMockKafkaDispatcher::DispatchNow(TMsg::TPtr &&/*msg*/, size_t /*broker_index*/) { - assert(this); @@ -99,7 +93,6 @@ void TMockKafkaDispatcher::DispatchNow(TMsg::TPtr &&/*msg*/, void TMockKafkaDispatcher::DispatchNow( std::list> &&/*batch*/, size_t /*broker_index*/) { - assert(this); @@ -108,7 +101,6 @@ void TMockKafkaDispatcher::DispatchNow( } void TMockKafkaDispatcher::StartSlowShutdown(uint64_t /*start_time*/) { - assert(this); @@ -117,7 +109,6 @@ void TMockKafkaDispatcher::StartSlowShutdown(uint64_t /*start_time*/) { } void TMockKafkaDispatcher::StartFastShutdown() { - assert(this); @@ -126,7 +117,6 @@ void TMockKafkaDispatcher::StartFastShutdown() { } const TFd &TMockKafkaDispatcher::GetPauseFd() const noexcept { - assert(this); @@ -137,7 +127,6 @@ const TFd &TMockKafkaDispatcher::GetPauseFd() const noexcept { } const TFd &TMockKafkaDispatcher::GetShutdownWaitFd() const noexcept { - assert(this); @@ -148,7 +137,6 @@ const TFd &TMockKafkaDispatcher::GetShutdownWaitFd() const noexcept { } void TMockKafkaDispatcher::JoinAll() { - assert(this); @@ -157,7 +145,6 @@ void TMockKafkaDispatcher::JoinAll() { } bool TMockKafkaDispatcher::ShutdownWasOk() const noexcept { - assert(this); @@ -168,7 +155,6 @@ bool TMockKafkaDispatcher::ShutdownWasOk() const noexcept { std::list> TMockKafkaDispatcher::GetNoAckQueueAfterShutdown(size_t /*broker_index*/) { - assert(this); @@ -179,7 +165,6 @@ TMockKafkaDispatcher::GetNoAckQueueAfterShutdown(size_t /*broker_index*/) { std::list> TMockKafkaDispatcher::GetSendWaitQueueAfterShutdown(size_t /*broker_index*/) { - assert(this); @@ -189,7 +174,6 @@ TMockKafkaDispatcher::GetSendWaitQueueAfterShutdown(size_t /*broker_index*/) { } size_t TMockKafkaDispatcher::GetAckCount() const noexcept { - assert(this); diff --git a/src/dory/unix_dg_input_agent.cc b/src/dory/unix_dg_input_agent.cc index 78936306..e936ac98 100644 --- a/src/dory/unix_dg_input_agent.cc +++ b/src/dory/unix_dg_input_agent.cc @@ -68,8 +68,6 @@ TUnixDgInputAgent::~TUnixDgInputAgent() { } bool TUnixDgInputAgent::SyncStart() { - assert(this); - if (IsStarted()) { Die("Cannot call SyncStart() when UNIX datagram input agent is already " "started"); @@ -85,7 +83,6 @@ bool TUnixDgInputAgent::SyncStart() { } void TUnixDgInputAgent::Run() { - assert(this); int tid = static_cast(Gettid()); LOG(TPri::NOTICE) << "UNIX datagram input thread " << tid << " started"; @@ -117,7 +114,6 @@ void TUnixDgInputAgent::Run() { } void TUnixDgInputAgent::OpenUnixSocket() { - assert(this); LOG(TPri::NOTICE) << "UNIX datagram input thread opening socket"; TAddress input_socket_address; input_socket_address.SetFamily(AF_LOCAL); @@ -145,7 +141,6 @@ void TUnixDgInputAgent::OpenUnixSocket() { } TMsg::TPtr TUnixDgInputAgent::ReadOneMsg() { - assert(this); char * const msg_begin = reinterpret_cast(&InputBuf[0]); const ssize_t result = Wr::recv(Wr::TDisp::Nonfatal, {}, InputSocket, msg_begin, InputBuf.size(), 0); @@ -156,7 +151,6 @@ TMsg::TPtr TUnixDgInputAgent::ReadOneMsg() { } void TUnixDgInputAgent::ForwardMessages() { - assert(this); std::array events; struct pollfd &shutdown_request_event = events[0]; struct pollfd &input_socket_event = events[1]; diff --git a/src/dory/util/dory_rate_limiter.h b/src/dory/util/dory_rate_limiter.h index 466e5191..ff9c8849 100644 --- a/src/dory/util/dory_rate_limiter.h +++ b/src/dory/util/dory_rate_limiter.h @@ -41,12 +41,10 @@ namespace Dory { } size_t ComputeDelay() { - assert(this); return std::max(MinDelay, Limiter.ComputeDelay()); } void OnAction() { - assert(this); return Limiter.OnAction(); } diff --git a/src/dory/util/invalid_arg_error.h b/src/dory/util/invalid_arg_error.h index 7bab838b..a24f01ac 100644 --- a/src/dory/util/invalid_arg_error.h +++ b/src/dory/util/invalid_arg_error.h @@ -44,12 +44,10 @@ namespace Dory { } const std::string &GetMsg() const { - assert(this); return Msg; } const std::string &GetArgId() const { - assert(this); return ArgId; } diff --git a/src/dory/util/pause_button.cc b/src/dory/util/pause_button.cc index 0a55a2c1..b9c88756 100644 --- a/src/dory/util/pause_button.cc +++ b/src/dory/util/pause_button.cc @@ -29,7 +29,6 @@ using namespace Dory::Util; DEFINE_COUNTER(PauseStarted); void TPauseButton::Push() { - assert(this); std::lock_guard lock(Mutex); if (!PauseActivated) { @@ -40,7 +39,6 @@ void TPauseButton::Push() { } void TPauseButton::Reset() { - assert(this); Button.Reset(); PauseActivated = false; } diff --git a/src/dory/util/pause_button.h b/src/dory/util/pause_button.h index 7751e9c8..6cbedcf1 100644 --- a/src/dory/util/pause_button.h +++ b/src/dory/util/pause_button.h @@ -39,7 +39,6 @@ namespace Dory { TPauseButton() = default; const Base::TFd &GetFd() const noexcept { - assert(this); return Button.GetFd(); } diff --git a/src/dory/util/poll_array.h b/src/dory/util/poll_array.h index 1a756833..b0cab670 100644 --- a/src/dory/util/poll_array.h +++ b/src/dory/util/poll_array.h @@ -42,69 +42,56 @@ namespace Dory { } size_t Size() const { - assert(this); return SIZE; } const struct pollfd &operator[](TEnum index) const { - assert(this); size_t n = static_cast(index); assert(n < SIZE); return Items[n]; } struct pollfd &operator[](TEnum index) { - assert(this); size_t n = static_cast(index); assert(n < SIZE); return Items[n]; } operator const struct pollfd *() const { - assert(this); return Items; } operator struct pollfd *() { - assert(this); return Items; } void ClearRevents() { - assert(this); - for (size_t i = 0; i < SIZE; ++i) { DoClearRevents(i); } } void ClearRevents(TEnum index) { - assert(this); DoClearRevents(static_cast(index)); } void Clear() { - assert(this); - for (size_t i = 0; i < SIZE; ++i) { DoClear(i); } } void Clear(TEnum index) { - assert(this); DoClear(static_cast(index)); } private: void DoClearRevents(size_t index) { - assert(this); assert(index < SIZE); Items[index].revents = 0; } void DoClear(size_t index) { - assert(this); assert(index < SIZE); struct pollfd &item = Items[index]; item.fd = -1; diff --git a/src/dory/util/topic_map.cc b/src/dory/util/topic_map.cc index e75f7653..e17ca7dd 100644 --- a/src/dory/util/topic_map.cc +++ b/src/dory/util/topic_map.cc @@ -28,22 +28,18 @@ using namespace Dory; using namespace Dory::Util; void TTopicMap::Put(TMsg::TPtr &&msg) { - assert(this); assert(msg); std::list &msg_list = PutCommon(msg->GetTopic()); msg_list.push_back(std::move(msg)); } void TTopicMap::Put(std::list &&batch) { - assert(this); assert(!batch.empty()); std::list &msg_list = PutCommon(batch.front()->GetTopic()); msg_list.splice(msg_list.end(), std::move(batch)); } void TTopicMap::Put(std::list> &&batch_list) { - assert(this); - for (std::list &batch : batch_list) { Put(std::move(batch)); } @@ -52,7 +48,6 @@ void TTopicMap::Put(std::list> &&batch_list) { } std::list TTopicMap::Get(const std::string &topic) { - assert(this); std::list result; auto iter = TopicHash.find(topic); @@ -65,7 +60,6 @@ std::list TTopicMap::Get(const std::string &topic) { } std::list> TTopicMap::Get() { - assert(this); std::list> result; for (auto &item : TopicHash) { @@ -79,8 +73,6 @@ std::list> TTopicMap::Get() { } std::list &TTopicMap::PutCommon(const std::string &topic) { - assert(this); - /* We can eliminate this call to find() without affecting observed behavior. However, the common case should be a successful lookup, and then we avoid creating a temporary topic string while doing the insert. */ diff --git a/src/dory/util/topic_map.h b/src/dory/util/topic_map.h index f2c0b892..e60d887a 100644 --- a/src/dory/util/topic_map.h +++ b/src/dory/util/topic_map.h @@ -45,12 +45,10 @@ namespace Dory { /* A true value indicates that map contains no messages. */ bool IsEmpty() const noexcept { - assert(this); return TopicHash.empty(); } void Clear() noexcept { - assert(this); TopicHash.clear(); } diff --git a/src/dory/web_interface.cc b/src/dory/web_interface.cc index b1d46371..a51dcfe0 100644 --- a/src/dory/web_interface.cc +++ b/src/dory/web_interface.cc @@ -106,7 +106,6 @@ const char *TWebInterface::ToErrorBlurb(TRequestType request_type) { void *TWebInterface::OnEvent(mg_event event, mg_connection *conn, const mg_request_info *request_info) { - assert(this); bool is_handled = false; TRequestType request_type = TRequestType::UNIMPLEMENTED_REQUEST_METHOD; const char *error_blurb = ""; @@ -163,7 +162,6 @@ void *TWebInterface::OnEvent(mg_event event, mg_connection *conn, } void TWebInterface::WriteFrontPage(std::ostream &os) { - assert(this); os << "" << std::endl << " topic_stats; long new_count = 0; tracker.GetStats(topic_stats, new_count); @@ -345,7 +336,6 @@ void TWebRequestHandler::HandleQueueStatsRequestPlain(std::ostream &os, void TWebRequestHandler::HandleQueueStatsRequestJson(std::ostream &os, const TMsgStateTracker &tracker) { - assert(this); std::vector topic_stats; long new_count = 0; tracker.GetStats(topic_stats, new_count); @@ -401,7 +391,6 @@ void TWebRequestHandler::HandleQueueStatsRequestJson(std::ostream &os, void TWebRequestHandler::HandleGetDebugTopicsRequest(std::ostream &os, const Debug::TDebugSetup &debug_setup) { - assert(this); std::shared_ptr settings = debug_setup.GetSettings(); assert(settings); const std::unordered_set *topics = settings->GetDebugTopics(); @@ -419,29 +408,24 @@ void TWebRequestHandler::HandleGetDebugTopicsRequest(std::ostream &os, void TWebRequestHandler::HandleDebugAddAllTopicsRequest(std::ostream &os, Debug::TDebugSetup &debug_setup) { - assert(this); debug_setup.SetDebugTopics(nullptr); os << "All message debug topics enabled" << std::endl; } void TWebRequestHandler::HandleDebugDelAllTopicsRequest(std::ostream &os, Debug::TDebugSetup &debug_setup) { - assert(this); debug_setup.ClearDebugTopics(); os << "All message debug topics disabled" << std::endl; } void TWebRequestHandler::HandleDebugTruncateFilesRequest(std::ostream &os, Debug::TDebugSetup &debug_setup) { - assert(this); debug_setup.TruncateDebugFiles(); os << "Message debug files truncated" << std::endl; } void TWebRequestHandler::HandleDebugAddTopicRequest(std::ostream &os, Debug::TDebugSetup &debug_setup, const char *topic) { - assert(this); - if (debug_setup.AddDebugTopic(topic)) { os << "Enabled debug topic [" << topic << "]" << std::endl; } else { @@ -451,8 +435,6 @@ void TWebRequestHandler::HandleDebugAddTopicRequest(std::ostream &os, void TWebRequestHandler::HandleDebugDelTopicRequest(std::ostream &os, Debug::TDebugSetup &debug_setup, const char *topic) { - assert(this); - if (debug_setup.DelDebugTopic(topic)) { os << "Disabled debug topic [" << topic << "]" << std::endl; } else { @@ -462,7 +444,6 @@ void TWebRequestHandler::HandleDebugDelTopicRequest(std::ostream &os, void TWebRequestHandler::HandleMetadataUpdateRequest(std::ostream &os, Base::TEventSemaphore &update_request_sem) { - assert(this); update_request_sem.Push(); uint64_t now = GetEpochSeconds(); char time_buf[TIME_BUF_SIZE]; @@ -473,7 +454,6 @@ void TWebRequestHandler::HandleMetadataUpdateRequest(std::ostream &os, void TWebRequestHandler::WriteDiscardReportPlain(std::ostream &os, const TAnomalyTracker::TInfo &info) { - assert(this); char time_buf[TIME_BUF_SIZE]; uint64_t start_time = info.GetStartTime(); FillTimeBuf(start_time, time_buf); @@ -627,7 +607,6 @@ void TWebRequestHandler::WriteDiscardReportPlain(std::ostream &os, void TWebRequestHandler::WriteDiscardReportJson(std::ostream &os, const TAnomalyTracker::TInfo &info, Base::TIndent &ind0) { - assert(this); uint64_t start_time = info.GetStartTime(); os << ind0 << "\"id\": " << info.GetReportId() << "," << std::endl << ind0 << "\"start_time\": " << start_time << "," << std::endl diff --git a/src/fiber/dispatcher.cc b/src/fiber/dispatcher.cc index ca0e53c0..fe9bb8e8 100644 --- a/src/fiber/dispatcher.cc +++ b/src/fiber/dispatcher.cc @@ -34,8 +34,6 @@ using namespace Base; using namespace Fiber; TDispatcher::THandler::~THandler() { - assert(this); - /* If this fails, you probably forgot to call Unregister() in your destructor. */ assert(!Dispatcher); @@ -55,7 +53,6 @@ TDispatcher::THandler::THandler() noexcept { } void TDispatcher::THandler::ChangeEvent(int fd, short flags) { - assert(this); assert(fd >= 0); assert(flags); assert(Dispatcher); @@ -66,13 +63,11 @@ void TDispatcher::THandler::ChangeEvent(int fd, short flags) { } void TDispatcher::THandler::ClearDeadline() { - assert(this); Deadline.Reset(); } void TDispatcher::THandler::Register(TDispatcher *dispatcher, int fd, short flags) { - assert(this); assert(dispatcher); /* If we're only changing fd and/or flags, we can skip the linked-list stuff. */ @@ -99,13 +94,11 @@ void TDispatcher::THandler::Register(TDispatcher *dispatcher, int fd, } void TDispatcher::THandler::SetDeadline(const TTimeout &timeout) { - assert(this); Deadline.Reset(); Deadline.MakeKnown(Now() + timeout); } void TDispatcher::THandler::Unregister() noexcept { - assert(this); /* If we're not registered with a dispatcher, then there's nothing to do; otherwise, perform the list-unlinking dance and reinitialize our pointers and related member variables to their default-constructed state. */ @@ -126,13 +119,11 @@ void TDispatcher::THandler::Init() noexcept { } TDispatcher::THandler *&TDispatcher::THandler::GetNextConj() const noexcept { - assert(this); assert(Dispatcher); return NextHandler ? NextHandler->PrevHandler : Dispatcher->LastHandler; } TDispatcher::THandler *&TDispatcher::THandler::GetPrevConj() const noexcept { - assert(this); assert(Dispatcher); return PrevHandler ? PrevHandler->NextHandler : Dispatcher->FirstHandler; } @@ -152,14 +143,12 @@ TDispatcher::TDispatcher(size_t max_handler_count) } TDispatcher::~TDispatcher() { - assert(this); assert(!FirstHandler); delete [] Pollers; delete [] HandlerPtrs; } bool TDispatcher::ForEachHandler(const TCb &cb) { - assert(this); assert(cb); /* We cache each next-pointer as we go, just in case the handler is deleted. */ @@ -180,8 +169,6 @@ bool TDispatcher::ForEachHandler(const TCb &cb) { void TDispatcher::Run(const TTimeout &grace_period, const std::vector &allow_signals, int shutdown_signal_number) { - assert(this); - /* Install a do-nothing handler for the shutdown signal, so the shutdown won't abort the whole process. We'll mask out all signals while we're running, then unmask the shutdown signal only while we're blocked in @@ -235,7 +222,6 @@ void TDispatcher::Run(const TTimeout &grace_period, } void TDispatcher::Shutdown(std::thread &t, int signal_number) { - assert(this); ShuttingDown = true; pthread_kill(t.native_handle(), signal_number); t.join(); @@ -256,8 +242,6 @@ void TDispatcher::ShutdownSigHandler(int /*signum*/) noexcept { bool TDispatcher::Dispatch(const TOptTimeout &max_timeout, const sigset_t *mask_set) { - assert(this); - /* Walk the list of regsitered handlers and initialze the poller and handler pointer arrays. Also look for the nearest deadline, if any, among the handlers. */ diff --git a/src/fiber/dispatcher.h b/src/fiber/dispatcher.h index 1c152240..d628a9c8 100644 --- a/src/fiber/dispatcher.h +++ b/src/fiber/dispatcher.h @@ -36,7 +36,7 @@ #include #include -namespace Fiber{ +namespace Fiber { /* Handles overlapped I/O in a single thread, dispatching I/O events to their registered handlers. */ @@ -76,21 +76,18 @@ namespace Fiber{ /* The dispatcher with which we are registered, or null if we're not registered with a dispatcher. */ TDispatcher *GetDispatcher() const noexcept { - assert(this); return Dispatcher; } /* The fd for which we wait, or -1 if we're not registered with a dispatcher. */ int GetFd() const noexcept { - assert(this); return Fd; } /* The I/O flags for which we wait, or 0 if we're not registred with a dispatcher. */ short GetFlags() const noexcept { - assert(this); return Flags; } @@ -98,7 +95,6 @@ namespace Fiber{ handler in our dispatcher or if we're not registered with a dispatcher. */ THandler *GetNextHandler() const noexcept { - assert(this); return NextHandler; } @@ -106,13 +102,11 @@ namespace Fiber{ first handler in our dispatcher or if we're not registered with a dispatcher. */ THandler *GetPrevHandler() const noexcept { - assert(this); return PrevHandler; } /* The current deadline for this handler, if any. */ const TOptDeadline &GetDeadline() const noexcept { - assert(this); return Deadline; } @@ -226,7 +220,6 @@ namespace Fiber{ /* The number of handlers currently registered with this dispatcher. */ size_t GetHandlerCount() const noexcept { - assert(this); return HandlerCount; } diff --git a/src/fiber/dispatcher.test.broken.cc b/src/fiber/dispatcher.test.broken.cc index 9fd3a915..a0ab031d 100644 --- a/src/fiber/dispatcher.test.broken.cc +++ b/src/fiber/dispatcher.test.broken.cc @@ -20,7 +20,7 @@ */ #include - + #include #include #include @@ -28,14 +28,14 @@ #include #include #include - + #include #include #include #include - + #include - + using namespace Base; using namespace Fiber; using namespace Socket; @@ -52,7 +52,7 @@ namespace { public: /* We shutdown on this signal. */ static constexpr int SignalNumber = SIGUSR1; - + /* Construct a server which will accept connections on a system-assigned port. Return the port number via out-param. */ TServer(in_port_t &port) @@ -62,32 +62,28 @@ namespace { keep track of it. */ port = (new TAcceptor(this))->GetPort(); } - + /* See TDispatcher::GetHandlerCount(). */ size_t GetHandlerCount() const { - assert(this); return Dispatcher.GetHandlerCount(); } - + /* The number of times we have hung up on a client that was quiet for too long. */ size_t GetTimeouts() const { - assert(this); return Timeouts; } - + /* See TDispatcher::Run(). */ void Run() { - assert(this); Dispatcher.Run(std::chrono::seconds(2), {}, SignalNumber); } - + /* See TDispatcher::Shutdown(). */ void Shutdown(std::thread &t) { - assert(this); Dispatcher.Shutdown(t, SignalNumber); } - + private: /* A handler for I/O with a connected client. */ class TWorker final @@ -103,24 +99,21 @@ namespace { Register(&(server->Dispatcher), Fd, POLLIN); SetDeadline(Timeout); } - + /* Unregister from the dispatcher before we go. This is mandatory. */ virtual ~TWorker() { - assert(this); Unregister(); } - + /* Called by the dispatcher when our client has been quiet for too long. */ virtual void OnDeadline() override { - assert(this); ++(Server->Timeouts); delete this; } - + /* Called by the dispatcher when our socket has a connection waiting. */ virtual void OnEvent(int, short) override { - assert(this); if (Limit == Buffer) { /* Read data from the client. If we get some, register to write it back. */ @@ -159,10 +152,9 @@ namespace { } } } - + /* Called by the dispatcher when a shutdown begins. */ virtual void OnShutdown() override { - assert(this); if (Limit > Buffer) { /* We are waiting to echo to the client, so don't die yet. */ Shutdown = true; @@ -171,35 +163,34 @@ namespace { delete this; } } - + private: /* The server of which we are a part. */ TServer *Server; - + /* The socket that's connected to the client. */ TFd Fd; - + /* A workspace for reading and writing. */ char Buffer[1000]; - + /* Points into Buffer, above, to indicate where the last read message ends. */ char *Limit; - + /* If true, then we should self-destruct after we reply to the client. */ bool Shutdown; - + /* The amount of time we'll wait for I/O with the client. */ static const TTimeout Timeout; - }; // TServer::TWorker - + /* We are constructed by the server when it itself constructs. We handle accept requests. */ class TAcceptor final : public TDispatcher::THandler { public: - + /* Construct and register. */ TAcceptor(TServer *server) : Server(server) { @@ -218,54 +209,50 @@ namespace { /* Register as a handler of connection events on our socket. */ Register(&(server->Dispatcher), Fd, POLLIN); } - + /* Unregister from the dispatcher before we go. This is mandatory. */ virtual ~TAcceptor() { - assert(this); Unregister(); } - + /* The port number on which we're listening. */ in_port_t GetPort() const noexcept { - assert(this); return Port; } - + private: - + /* Called by the dispatcher when our socket has a connection waiting. */ virtual void OnEvent(int, short) { - assert(this); new TWorker(Server, TFd(Wr::accept(Fd, nullptr, nullptr))); } - + /* Called by the dispatcher when a shutdown begins. */ virtual void OnShutdown() { delete this; } - + /* The server of which we are a part. */ TServer *Server; - + /* The socket on which we're listening. */ TFd Fd; - + /* See accessor. */ in_port_t Port; - }; // TServer::TAcceptor - + /* See accessor. */ size_t Timeouts; - + /* The dispatcher managing all the server's I/O. */ TDispatcher Dispatcher; }; // TServer - + /* See declaration. */ const TServer::TWorker::TTimeout TServer::TWorker::Timeout = std::chrono::milliseconds(500); - + /* Client threads enter here. */ void ClientMain( size_t idx, // the unique id number of this client @@ -356,7 +343,7 @@ namespace { ASSERT_EQ(rude_count, 0u); } } - + TEST_F(TDispatcherTest, ShutdownBeforeClients) { const size_t repeat_count = 10, // number of times to repeat the whole test @@ -392,7 +379,7 @@ namespace { ASSERT_EQ(rude_count, client_count); } } - + TEST_F(TDispatcherTest, UpAndDown) { /* Construct a server and launch it in a background thread. */ in_port_t port; diff --git a/src/log/array_ostream_base.h b/src/log/array_ostream_base.h index c30b70fa..bafec791 100644 --- a/src/log/array_ostream_base.h +++ b/src/log/array_ostream_base.h @@ -54,14 +54,12 @@ namespace Log { Buf[PrefixSpace], and when (BufSize - PrefixSpace - SuffixSpace) bytes have been written, additional written bytes are discarded. */ size_t Size() const noexcept { - assert(this); assert(GetPos() >= GetBuf()); return GetPos() - GetBuf(); } /* Return true if no bytes have been written to stream. */ bool IsEmpty() const noexcept { - assert(this); return (Size() == 0); } @@ -74,28 +72,24 @@ namespace Log { /* Return pointer to start of internal array. Stream output begins at Buf[PrefixSpace]. */ const char *GetBuf() const noexcept { - assert(this); return this->Buf; } /* Return pointer to start of internal array. Stream output begins at Buf[PrefixSpace]. */ char *GetBuf() noexcept { - assert(this); return this->Buf; } /* Return pointer to array position one byte past last byte of stream output. */ const char *GetPos() const noexcept { - assert(this); return this->pptr(); } /* Return pointer to array position one byte past last byte of stream output. */ char *GetPos() noexcept { - assert(this); return this->pptr(); } }; diff --git a/src/log/array_ostream_base.test.cc b/src/log/array_ostream_base.test.cc index 069cf4c2..4f390ee0 100644 --- a/src/log/array_ostream_base.test.cc +++ b/src/log/array_ostream_base.test.cc @@ -43,12 +43,10 @@ namespace { } char *GetBuffer() noexcept { - assert(this); return TArrayOstreamBase::GetBuf(); } char *GetEnd() noexcept { - assert(this); return TArrayOstreamBase::GetPos(); } }; // TTestStream diff --git a/src/log/combined_log_writer.cc b/src/log/combined_log_writer.cc index 073f7a99..0e3b8ae9 100644 --- a/src/log/combined_log_writer.cc +++ b/src/log/combined_log_writer.cc @@ -46,7 +46,6 @@ TCombinedLogWriter::TCombinedLogWriter(const TCombinedLogWriter &old_writer, void TCombinedLogWriter::WriteEntry( Log::TLogEntryAccessApi &entry, bool no_stdout_stderr) const noexcept { - assert(this); StdoutStderrLogWriter.WriteEntry(entry, no_stdout_stderr); FileLogWriter.WriteEntry(entry, no_stdout_stderr); SyslogLogWriter.WriteEntry(entry, no_stdout_stderr); @@ -54,7 +53,6 @@ void TCombinedLogWriter::WriteEntry( void TCombinedLogWriter::WriteStackTrace(Log::TPri pri, void *const *buffer, size_t size, bool no_stdout_stderr) const noexcept { - assert(this); StdoutStderrLogWriter.WriteStackTrace(pri, buffer, size, no_stdout_stderr); FileLogWriter.WriteStackTrace(pri, buffer, size, no_stdout_stderr); SyslogLogWriter.WriteStackTrace(pri, buffer, size, no_stdout_stderr); diff --git a/src/log/combined_log_writer.h b/src/log/combined_log_writer.h index a784dd7b..b0eae8c1 100644 --- a/src/log/combined_log_writer.h +++ b/src/log/combined_log_writer.h @@ -55,28 +55,23 @@ namespace Log { const std::string &file_path, const Base::TOpt &file_mode); bool StdoutStderrLoggingIsEnabled() const noexcept { - assert(this); return StdoutStderrLogWriter.IsEnabled(); } bool SyslogLoggingIsEnabled() const noexcept { - assert(this); return SyslogLogWriter.IsEnabled(); } bool FileLoggingIsEnabled() const noexcept { - assert(this); return FileLogWriter.IsEnabled(); } /* Returns empty string if no logfile is open. */ const std::string &GetFilePath() const noexcept { - assert(this); return FileLogWriter.GetPath(); } Base::TOpt GetFileOpenMode() const noexcept { - assert(this); return FileLogWriter.GetOpenMode(); } diff --git a/src/log/file_log_writer.cc b/src/log/file_log_writer.cc index a9c4304c..8709417f 100644 --- a/src/log/file_log_writer.cc +++ b/src/log/file_log_writer.cc @@ -100,8 +100,6 @@ TFileLogWriter::TFileLogWriter(const std::string &path, void TFileLogWriter::WriteEntry(TLogEntryAccessApi &entry, bool /* no_stdout_stderr */) const noexcept { - assert(this); - if (IsEnabled()) { switch (WriteToFd(*FdRef, entry)) { case TFdWriteResult::Ok: { @@ -122,8 +120,6 @@ void TFileLogWriter::WriteEntry(TLogEntryAccessApi &entry, void TFileLogWriter::WriteStackTrace(TPri /* pri */, void *const *buffer, size_t size, bool /* no_stdout_stderr */) const noexcept { - assert(this); - if (IsEnabled()) { backtrace_symbols_fd(buffer, static_cast(size), *FdRef); } diff --git a/src/log/file_log_writer.h b/src/log/file_log_writer.h index 171dead5..11a6ca5a 100644 --- a/src/log/file_log_writer.h +++ b/src/log/file_log_writer.h @@ -44,7 +44,6 @@ namespace Log { class TError : public std::runtime_error { public: const std::string &GetPath() const noexcept { - assert(this); return Path; } @@ -68,7 +67,6 @@ namespace Log { TInvalidMode(const std::string &path, mode_t mode); mode_t GetMode() const noexcept { - assert(this); return Mode; } @@ -89,7 +87,6 @@ namespace Log { TFileLogWriter(const TFileLogWriter &) = default; bool IsEnabled() const noexcept { - assert(this); const bool is_open = FdRef->IsOpen(); assert(Path.empty() == !is_open); return is_open; @@ -97,13 +94,11 @@ namespace Log { /* Returns empty string if no logfile is open. */ const std::string &GetPath() const noexcept { - assert(this); assert(Path.empty() == !IsEnabled()); return Path; } Base::TOpt GetOpenMode() const noexcept { - assert(this); return OpenMode; } diff --git a/src/log/log_entry.h b/src/log/log_entry.h index 0e12f62d..a943d7aa 100644 --- a/src/log/log_entry.h +++ b/src/log/log_entry.h @@ -122,12 +122,10 @@ namespace Log { LOG(TPri::INFO) << "The answer is " << ComputeAnswer(); */ explicit operator bool() const noexcept { - assert(this); return true; } void AssignPrefix(const char *start, size_t len) noexcept override { - assert(this); assert(start || (len == 0)); PrefixLen = std::min(len, PrefixSpace); std::memcpy(&this->GetBuf()[PrefixSpace - PrefixLen], start, PrefixLen); @@ -136,15 +134,12 @@ namespace Log { /* This will be 0 until Get() has been called with a true value for with_prefix. In other words, the prefix is assigned on-demand. */ size_t PrefixSize() const noexcept override { - assert(this); assert(PrefixLen <= PrefixSpace); return PrefixLen; } std::pair Get(bool with_prefix, bool with_trailing_newline) noexcept override { - assert(this); - if (with_prefix && !HasPrefix()) { WritePrefix(*this); } @@ -164,22 +159,18 @@ namespace Log { } TPri GetLevel() const noexcept override { - assert(this); return Level; } /* True indicates that entry was written (either successfully or unsuccessfully). */ bool IsWritten() const noexcept { - assert(this); return Written; } /* If log entry has not already been written, write it by invoking TLogWriterApi passed to constructor. */ void Write() noexcept { - assert(this); - if (!Written) { Written = true; diff --git a/src/log/log_entry.test.cc b/src/log/log_entry.test.cc index c41ff032..6642fd4d 100644 --- a/src/log/log_entry.test.cc +++ b/src/log/log_entry.test.cc @@ -49,33 +49,27 @@ namespace { TTestLogWriter() = default; size_t GetWrittenCount() const noexcept { - assert(this); return WrittenCount; } const std::string &GetEntry() const noexcept { - assert(this); return Entry; } const std::string &GetEntryWithNewline() const noexcept { - assert(this); return EntryWithNewline; } const std::string &GetEntryWithPrefix() const noexcept { - assert(this); return EntryWithPrefix; }; const std::string &GetEntryWithPrefixAndNewline() const noexcept { - assert(this); return EntryWithPrefixAndNewline; } void WriteEntry(TLogEntryAccessApi &entry, bool /* no_stdout_stderr */) const noexcept override { - assert(this); Entry = entry.Get(false /* with_prefix */, false /* with_trailing_newline */).first; EntryWithNewline = entry.Get(false /* with_prefix */, @@ -90,7 +84,6 @@ namespace { void WriteStackTrace(TPri /* pri */, void *const * /* buffer */, size_t /* size */, bool /* no_stdout_stderr */) const noexcept override { - assert(this); ASSERT_TRUE(false); } diff --git a/src/log/log_entry_access_api.h b/src/log/log_entry_access_api.h index 17b9b151..164a46d2 100644 --- a/src/log/log_entry_access_api.h +++ b/src/log/log_entry_access_api.h @@ -36,7 +36,6 @@ namespace Log { virtual size_t PrefixSize() const noexcept = 0; bool HasPrefix() const noexcept { - assert(this); return (PrefixSize() > 0); } diff --git a/src/log/stdout_stderr_log_writer.cc b/src/log/stdout_stderr_log_writer.cc index e76186ce..acb8c6bf 100644 --- a/src/log/stdout_stderr_log_writer.cc +++ b/src/log/stdout_stderr_log_writer.cc @@ -37,8 +37,6 @@ void TStdoutStderrLogWriter::SetErrorHandler( void TStdoutStderrLogWriter::WriteEntry( TLogEntryAccessApi &entry, bool no_stdout_stderr) const noexcept { - assert(this); - if (IsEnabled() && !no_stdout_stderr) { /* Anything at least as severe as LOG_WARNING goes to stderr, so it doesn't get lost in the noise. */ @@ -61,8 +59,6 @@ void TStdoutStderrLogWriter::WriteEntry( void TStdoutStderrLogWriter::WriteStackTrace(TPri /* pri */, void *const *buffer, size_t size, bool no_stdout_stderr) const noexcept { - assert(this); - if (Enabled && !no_stdout_stderr) { backtrace_symbols_fd(buffer, static_cast(size), 2 /* stderr */); } diff --git a/src/log/stdout_stderr_log_writer.h b/src/log/stdout_stderr_log_writer.h index cf95cd54..66438fea 100644 --- a/src/log/stdout_stderr_log_writer.h +++ b/src/log/stdout_stderr_log_writer.h @@ -42,7 +42,6 @@ namespace Log { } bool IsEnabled() const noexcept { - assert(this); return Enabled; } diff --git a/src/log/syslog_log_writer.cc b/src/log/syslog_log_writer.cc index 5df4c0f8..9fcf4f83 100644 --- a/src/log/syslog_log_writer.cc +++ b/src/log/syslog_log_writer.cc @@ -66,8 +66,6 @@ TSyslogLogWriter::TSyslogLogWriter(bool enabled) noexcept void TSyslogLogWriter::WriteEntry(TLogEntryAccessApi &entry, bool /* no_stdout_stderr */) const noexcept { - assert(this); - if (Enabled) { /* Pass log entry via "%s" rather than directly, since it may contain formatting characters. This avoids injection vulnerabilities. */ @@ -80,8 +78,6 @@ void TSyslogLogWriter::WriteEntry(TLogEntryAccessApi &entry, void TSyslogLogWriter::WriteStackTrace(TPri pri, void *const *buffer, size_t size, bool /* no_stdout_stderr */) const noexcept { - assert(this); - if (Enabled) { TBacktraceSymbols symbols(buffer, size); diff --git a/src/log/syslog_log_writer.h b/src/log/syslog_log_writer.h index abc28208..8ff37997 100644 --- a/src/log/syslog_log_writer.h +++ b/src/log/syslog_log_writer.h @@ -45,7 +45,6 @@ namespace Log { explicit TSyslogLogWriter(bool enabled) noexcept; bool IsEnabled() const noexcept { - assert(this); return Enabled; } diff --git a/src/rpc/transceiver.cc b/src/rpc/transceiver.cc index 5b29190a..cd57a7a3 100644 --- a/src/rpc/transceiver.cc +++ b/src/rpc/transceiver.cc @@ -44,12 +44,10 @@ TTransceiver::TTransceiver() } TTransceiver::~TTransceiver() { - assert(this); free(AvailStart); } TTransceiver::operator bool() const noexcept { - assert(this); for (auto *desc = DataStart; desc < DataLimit; ++desc) { if (desc->iov_len) { return true; @@ -59,8 +57,6 @@ TTransceiver::operator bool() const noexcept { } TTransceiver &TTransceiver::operator+=(size_t size) { - assert(this); - /* Advance past all descriptors which have been entirely accounted for. */ while (DataStart < DataLimit && size >= DataStart->iov_len) { size -= DataStart->iov_len; @@ -81,7 +77,6 @@ TTransceiver &TTransceiver::operator+=(size_t size) { } iovec *TTransceiver::GetIoVecs(size_t size) { - assert(this); size_t avail_size = AvailLimit - AvailStart; if (size > avail_size) { @@ -104,7 +99,6 @@ iovec *TTransceiver::GetIoVecs(size_t size) { } size_t TTransceiver::Recv(int sock_fd, int flags) { - assert(this); assert(sock_fd >= 0); msghdr hdr; InitHdr(hdr); @@ -112,7 +106,6 @@ size_t TTransceiver::Recv(int sock_fd, int flags) { } size_t TTransceiver::Send(int sock_fd, int flags) { - assert(this); assert(sock_fd >= 0); msghdr hdr; InitHdr(hdr); @@ -120,7 +113,6 @@ size_t TTransceiver::Send(int sock_fd, int flags) { } void TTransceiver::InitHdr(msghdr &hdr) const noexcept { - assert(this); Zero(hdr); hdr.msg_iov = DataStart; hdr.msg_iovlen = DataLimit - DataStart; diff --git a/src/server/signal_handler_thread.cc b/src/server/signal_handler_thread.cc index 2a18ac9f..030d6272 100644 --- a/src/server/signal_handler_thread.cc +++ b/src/server/signal_handler_thread.cc @@ -41,8 +41,6 @@ TSignalHandlerThread &TSignalHandlerThread::The() { void TSignalHandlerThread::Init( Server::TSignalHandlerThread::THandler handler_callback, std::initializer_list signals) { - assert(this); - if (Initialized) { Die("TSignalHandlerThread already initialized"); } @@ -65,8 +63,6 @@ void TSignalHandlerThread::Init( } void TSignalHandlerThread::Start() { - assert(this); - if (!Initialized) { Die("TSignalHandlerThread must be initialized before starting"); } @@ -82,7 +78,6 @@ void TSignalHandlerThread::Start() { } void TSignalHandlerThread::Run() { - assert(this); assert(Initialized); assert(HandlerCallback); @@ -146,7 +141,6 @@ void TSignalHandlerThread::Handler(int signum, siginfo_t *info, } void TSignalHandlerThread::InstallHandler() const noexcept { - assert(this); TSigSet block_all(TSigSet::TListInit::Exclude, {}); /* Install our handler for each client-specified signal. */ diff --git a/src/server/signal_handler_thread.h b/src/server/signal_handler_thread.h index 46e0897d..0dba98d8 100644 --- a/src/server/signal_handler_thread.h +++ b/src/server/signal_handler_thread.h @@ -101,14 +101,12 @@ namespace Server { /* Signal handler calls this to record receipt of signal. */ void Set(const siginfo_t &sig_info) noexcept { - assert(this); std::memcpy(&Info, &sig_info, sizeof(sig_info)); Caught = true; } /* Thread calls this after calling client-provided callback. */ void Clear() noexcept { - assert(this); Caught = false; Base::Zero(Info); } diff --git a/src/server/stream_server_base.cc b/src/server/stream_server_base.cc index 7fa8d69e..79e8c91e 100644 --- a/src/server/stream_server_base.cc +++ b/src/server/stream_server_base.cc @@ -37,12 +37,10 @@ using namespace Server; void TStreamServerBase::TConnectionHandlerApi::HandleNonfatalAcceptError( int /*errno_value*/) { - assert(this); /* Base class version is no-op. Subclasses can override. */ } TStreamServerBase::~TStreamServerBase() { - assert(this); ShutdownOnDestroy(); if (IsBound()) { @@ -56,8 +54,6 @@ TStreamServerBase::~TStreamServerBase() { } void TStreamServerBase::Bind() { - assert(this); - if (IsBound()) { Die("TStreamServerBase::Bind() has already been called"); } @@ -72,8 +68,6 @@ void TStreamServerBase::Bind() { } bool TStreamServerBase::SyncStart() { - assert(this); - if (IsStarted()) { Die("Cannot call SyncStart() when server is already started"); } @@ -88,8 +82,6 @@ bool TStreamServerBase::SyncStart() { } void TStreamServerBase::Reset() { - assert(this); - if (IsStarted()) { RequestShutdown(); Join(); @@ -112,12 +104,10 @@ TStreamServerBase::TStreamServerBase(int backlog, struct sockaddr *addr, } void TStreamServerBase::CloseListeningSocket(TFd &sock) { - assert(this); sock.Reset(); } void TStreamServerBase::Run() { - assert(this); auto close_socket = OnDestroy( [this]() noexcept { CloseListeningSocket(ListeningSocket); @@ -146,7 +136,6 @@ void TStreamServerBase::Run() { } void TStreamServerBase::AcceptClients() { - assert(this); std::array events; struct pollfd &shutdown_request_event = events[0]; struct pollfd &new_client_event = events[1]; diff --git a/src/server/stream_server_base.h b/src/server/stream_server_base.h index 11ebd5f6..52a9f01d 100644 --- a/src/server/stream_server_base.h +++ b/src/server/stream_server_base.h @@ -87,7 +87,6 @@ namespace Server { void Bind(); bool IsBound() const noexcept { - assert(this); return ListeningSocket.IsOpen(); } @@ -135,7 +134,6 @@ namespace Server { void Run() override; const Base::TFd &GetListeningSocket() const noexcept { - assert(this); return ListeningSocket; } diff --git a/src/server/stream_servers.test.cc b/src/server/stream_servers.test.cc index 7beaa3fc..61b70e62 100644 --- a/src/server/stream_servers.test.cc +++ b/src/server/stream_servers.test.cc @@ -77,7 +77,6 @@ namespace { } void Join() { - assert(this); Worker.join(); } @@ -89,7 +88,6 @@ namespace { } const struct sockaddr *GetSockaddr() const noexcept { - assert(this); return reinterpret_cast(&Sockaddr[0]); } @@ -100,7 +98,6 @@ namespace { int32_t rather than int) because both communication endpoints are on the same host. */ void Run() { - assert(this); int values[2]; for (; ; ) { @@ -153,7 +150,6 @@ namespace { void HandleConnection(TFd &&sock, const struct sockaddr *addr, socklen_t addr_len) override { - assert(this); Workers.emplace_back(std::move(sock), addr, addr_len); } diff --git a/src/server/tcp_ipv4_server.cc b/src/server/tcp_ipv4_server.cc index 8171da48..e58c1ca6 100644 --- a/src/server/tcp_ipv4_server.cc +++ b/src/server/tcp_ipv4_server.cc @@ -44,8 +44,6 @@ TTcpIpv4Server::TTcpIpv4Server(int backlog, in_addr_t bind_addr, } in_port_t TTcpIpv4Server::GetBindPort() const noexcept { - assert(this); - if (!IsBound()) { Die("Cannot get bind port for unbound listening socket"); } @@ -58,7 +56,6 @@ in_port_t TTcpIpv4Server::GetBindPort() const noexcept { } void TTcpIpv4Server::InitListeningSocket(TFd &sock) { - assert(this); TFd sock_fd(Wr::socket(Wr::TDisp::Nonfatal, {}, AF_INET, SOCK_STREAM, 0)); int flag = true; Wr::setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); diff --git a/src/server/tcp_ipv4_server.h b/src/server/tcp_ipv4_server.h index bfc9f992..bd0f5125 100644 --- a/src/server/tcp_ipv4_server.h +++ b/src/server/tcp_ipv4_server.h @@ -47,17 +47,14 @@ namespace Server { ~TTcpIpv4Server() override = default; in_addr_t GetBindAddr() const noexcept { - assert(this); return BindAddr; } in_port_t GetPort() const noexcept { - assert(this); return Port; } const sockaddr_in &GetClientAddr() const noexcept { - assert(this); return ClientAddr; } diff --git a/src/server/tcp_ipv6_server.cc b/src/server/tcp_ipv6_server.cc index db75490a..7610f134 100644 --- a/src/server/tcp_ipv6_server.cc +++ b/src/server/tcp_ipv6_server.cc @@ -50,8 +50,6 @@ TTcpIpv6Server::TTcpIpv6Server(int backlog, const in6_addr &bind_addr, } in_port_t TTcpIpv6Server::GetBindPort() const noexcept { - assert(this); - if (!IsBound()) { Die("Cannot get bind port for unbound listening socket"); } @@ -64,7 +62,6 @@ in_port_t TTcpIpv6Server::GetBindPort() const noexcept { } void TTcpIpv6Server::InitListeningSocket(TFd &sock) { - assert(this); TFd sock_fd(Wr::socket(Wr::TDisp::Nonfatal, {}, AF_INET6, SOCK_STREAM, 0)); int flag = true; Wr::setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); diff --git a/src/server/tcp_ipv6_server.h b/src/server/tcp_ipv6_server.h index d4659909..98b5f623 100644 --- a/src/server/tcp_ipv6_server.h +++ b/src/server/tcp_ipv6_server.h @@ -51,22 +51,18 @@ namespace Server { ~TTcpIpv6Server() override = default; const in6_addr &GetBindAddr() const noexcept { - assert(this); return BindAddr; } in_port_t GetPort() const noexcept { - assert(this); return Port; } uint32_t GetScopeId() const noexcept { - assert(this); return ScopeId; } const sockaddr_in6 &GetClientAddr() const noexcept { - assert(this); return ClientAddr; } diff --git a/src/server/unix_stream_server.cc b/src/server/unix_stream_server.cc index 86ec48e8..cc40d69c 100644 --- a/src/server/unix_stream_server.cc +++ b/src/server/unix_stream_server.cc @@ -45,8 +45,6 @@ TUnixStreamServer::TUnixStreamServer(int backlog, const char *path, } void TUnixStreamServer::SetMode(mode_t mode) noexcept { - assert(this); - if (Mode.IsKnown()) { *Mode = mode; } else { @@ -55,7 +53,6 @@ void TUnixStreamServer::SetMode(mode_t mode) noexcept { } void TUnixStreamServer::InitListeningSocket(TFd &sock) { - assert(this); TFd sock_fd(IfLt0(Wr::socket(AF_LOCAL, SOCK_STREAM, 0))); struct sockaddr_un serv_addr; std::memset(&serv_addr, 0, sizeof(serv_addr)); @@ -83,7 +80,6 @@ void TUnixStreamServer::CloseListeningSocket(TFd &sock) { } void TUnixStreamServer::UnlinkPath() { - assert(this); int ret = Wr::unlink(Path.c_str()); if ((ret < 0) && (errno != ENOENT)) { diff --git a/src/server/unix_stream_server.h b/src/server/unix_stream_server.h index cd9d28fc..a60ca59b 100644 --- a/src/server/unix_stream_server.h +++ b/src/server/unix_stream_server.h @@ -49,12 +49,10 @@ namespace Server { ~TUnixStreamServer() override = default; const std::string &GetPath() const noexcept { - assert(this); return Path; } const struct sockaddr_un &GetClientAddr() const noexcept { - assert(this); return ClientAddr; } @@ -66,7 +64,6 @@ namespace Server { determined by the umask. This is the default behavior if SetMode() has not been called. */ void ClearMode() noexcept { - assert(this); Mode.Reset(); } diff --git a/src/server/url_decode.h b/src/server/url_decode.h index fde9d6fd..f9b854d3 100644 --- a/src/server/url_decode.h +++ b/src/server/url_decode.h @@ -35,7 +35,6 @@ namespace Server { } unsigned int GetOffset() const noexcept { - assert(this); return Offset; } diff --git a/src/socket/address.cc b/src/socket/address.cc index 67467e7a..b8e19de5 100644 --- a/src/socket/address.cc +++ b/src/socket/address.cc @@ -174,7 +174,6 @@ TAddress::TAddress(std::istream &&strm) { } bool TAddress::operator==(const TAddress &that) const noexcept { - assert(this); bool result = (Storage.ss_family == that.Storage.ss_family); if (result) { @@ -206,14 +205,12 @@ bool TAddress::operator==(const TAddress &that) const noexcept { } size_t TAddress::GetHash() const noexcept { - assert(this); return std::_Fnv_hash_bytes(&Storage, GetLen(), 0); } void TAddress::GetName( char *node_buf, size_t node_buf_size, char *serv_buf, size_t serv_buf_size, int flags) const { - assert(this); assert(node_buf || !node_buf_size); assert(serv_buf || !serv_buf_size); Db::IfNe0(Wr::getnameinfo(&Generic, GetLen(), node_buf, @@ -222,7 +219,6 @@ void TAddress::GetName( } in_port_t TAddress::GetPort() const noexcept { - assert(this); in_port_t result; switch (Storage.ss_family) { @@ -245,8 +241,6 @@ in_port_t TAddress::GetPort() const noexcept { } TAddress &TAddress::SetPort(in_port_t port) noexcept { - assert(this); - switch (Storage.ss_family) { case AF_UNSPEC: { break; @@ -266,7 +260,6 @@ TAddress &TAddress::SetPort(in_port_t port) noexcept { } const char *TAddress::GetPath() const noexcept { - assert(this); const char *result = nullptr; switch (Storage.ss_family) { @@ -281,8 +274,6 @@ const char *TAddress::GetPath() const noexcept { } TAddress &TAddress::SetPath(const char *path) { - assert(this); - switch (Storage.ss_family) { case AF_LOCAL: { std::strncpy(Local.sun_path, path, sizeof(Local.sun_path)); @@ -299,7 +290,6 @@ TAddress &TAddress::SetPath(const char *path) { } void TAddress::Write(std::ostream &strm) const { - assert(this); in_port_t port = 0; switch (Storage.ss_family) { diff --git a/src/socket/address.h b/src/socket/address.h index cb9da72f..67e05426 100644 --- a/src/socket/address.h +++ b/src/socket/address.h @@ -93,45 +93,38 @@ namespace Socket { /* Swaperator. */ TAddress &operator=(TAddress &&that) noexcept { - assert(this); std::swap(Storage, that.Storage); return *this; } /* Assignment operator. */ TAddress &operator=(const TAddress &that) noexcept { - assert(this); return *this = TAddress(that); } /* Assign from a naked sockaddr. */ TAddress &operator=(const sockaddr &sa) noexcept { - assert(this); return *this = TAddress(sa); } /* Extract from the given stream. */ TAddress &operator=(std::istream &&strm) { - assert(this); return *this = TAddress(std::move(strm)); } /* Assign the given special address, setting port to 0. */ TAddress &operator=(TSpecial special) noexcept { - assert(this); return *this = TAddress(special); } /* Cast to a naked sockaddr. */ operator const sockaddr *() const noexcept { - assert(this); return &Generic; } /* Cast to a modifiable naked sockaddr. If you modify the structure, call Verify() afterward to make sure it's still in good shape. */ operator sockaddr *() noexcept { - assert(this); return &Generic; } @@ -145,24 +138,20 @@ namespace Socket { /* Assign the given special address and port. */ TAddress &Assign(TSpecial special, in_port_t port = 0) noexcept { - assert(this); return *this = TAddress(special, port); } /* Copy the naked address to the given buffer. */ void CopyOut(sockaddr_storage &storage) const noexcept { - assert(this); memcpy(&storage, &Storage, GetLen()); } /* The family of the address. */ sa_family_t GetFamily() const noexcept { - assert(this); return Storage.ss_family; } TAddress &SetFamily(sa_family_t family) { - assert(this); Storage.ss_family = family; Verify(); return *this; @@ -174,7 +163,6 @@ namespace Socket { /* The number of bytes in use in the address. Use this, along with the naked cast, to make OS calls like bind(). */ socklen_t GetLen() const noexcept { - assert(this); return GetLen(Storage.ss_family); } @@ -203,8 +191,6 @@ namespace Socket { otherwise, it resets the address to the default-constructed state and throws an exception. */ void Verify() { - assert(this); - switch (Storage.ss_family) { case AF_UNSPEC: case AF_INET: @@ -225,7 +211,6 @@ namespace Socket { /* Return to the default-constructed state. */ TAddress &Reset() noexcept { - assert(this); return *this = TAddress(); } diff --git a/src/socket/db/cursor.cc b/src/socket/db/cursor.cc index a236383d..91a9b9f2 100644 --- a/src/socket/db/cursor.cc +++ b/src/socket/db/cursor.cc @@ -41,19 +41,15 @@ TCursor::TCursor(const char *node, const char *serv, int family, int socktype, } TCursor::~TCursor() { - assert(this); freeaddrinfo(First); } TFd TCursor::NewCompatSocket() const { - assert(this); Freshen(); return TFd(Wr::socket(Csr->ai_family, Csr->ai_socktype, Csr->ai_protocol)); } void TCursor::TryFreshen() const noexcept { - assert(this); - if (!Csr) { Csr = Next; diff --git a/src/socket/db/cursor.h b/src/socket/db/cursor.h index d8d7c512..fa614d1e 100644 --- a/src/socket/db/cursor.h +++ b/src/socket/db/cursor.h @@ -47,28 +47,24 @@ namespace Socket { /* True iff. we have a current address. */ operator bool() const noexcept { - assert(this); TryFreshen(); return Csr != nullptr; } /* The current address. */ const TAddress &operator*() const noexcept { - assert(this); Freshen(); return Address; } /* The current address. */ const TAddress *operator->() const noexcept { - assert(this); Freshen(); return &Address; } /* Move to the next address, if any. */ TCursor &operator++() noexcept { - assert(this); Freshen(); Csr = nullptr; return *this; @@ -79,7 +75,6 @@ namespace Socket { /* Go back to the first address, if any. */ TCursor &Rewind() noexcept { - assert(this); Csr = nullptr; Next = First; return *this; @@ -88,7 +83,6 @@ namespace Socket { private: /* Make sure we have a current address. */ void Freshen() const noexcept { - assert(this); TryFreshen(); assert(Csr); } diff --git a/src/socket/named_unix_socket.cc b/src/socket/named_unix_socket.cc index 888e370d..b62e75c1 100644 --- a/src/socket/named_unix_socket.cc +++ b/src/socket/named_unix_socket.cc @@ -36,7 +36,6 @@ TNamedUnixSocket::TNamedUnixSocket(int type, int protocol) } void TNamedUnixSocket::Reset() noexcept { - assert(this); Fd.Reset(); if (!Path.empty()) { diff --git a/src/socket/named_unix_socket.h b/src/socket/named_unix_socket.h index f7433d7a..6a347c5c 100644 --- a/src/socket/named_unix_socket.h +++ b/src/socket/named_unix_socket.h @@ -41,32 +41,26 @@ namespace Socket { TNamedUnixSocket(int type, int protocol); ~TNamedUnixSocket() { - assert(this); Reset(); } const Base::TFd &GetFd() const noexcept { - assert(this); return Fd; } const std::string &GetPath() const noexcept { - assert(this); return Path; } operator int() const noexcept { - assert(this); return Fd; } bool IsBound() const noexcept { - assert(this); return !Path.empty(); } bool IsOpen() const noexcept { - assert(this); return Fd.IsOpen(); } diff --git a/src/socket/option.h b/src/socket/option.h index 441f143f..c35b3206 100644 --- a/src/socket/option.h +++ b/src/socket/option.h @@ -382,13 +382,11 @@ namespace Socket { /* The code number used by getsockopt() and setsockopt() when referring to this option. */ int GetCode() const noexcept { - assert(this); return Code; } /* The human-readable name of this option. */ const std::string &GetName() const noexcept { - assert(this); return Name; } @@ -423,7 +421,6 @@ namespace Socket { /* The option's value for the given socket, returned by value. */ TVal Get(int sock) const noexcept { - assert(this); TVal val; Get(sock, val); return val; @@ -431,13 +428,11 @@ namespace Socket { /* The option's value for the given socket, returned via out-parameter. */ void Get(int sock, TVal &val) const noexcept { - assert(this); Conv::GetSockOpt(sock, TAnyOption::GetCode(), val); } /* See base class. */ void Dump(std::ostream &strm, int sock) const final { - assert(this); strm << TAnyOption::GetName() << ": "; TVal val; Get(sock, val); diff --git a/src/third_party/mongoose/mongoose.h b/src/third_party/mongoose/mongoose.h index ed58baca..7448d660 100644 --- a/src/third_party/mongoose/mongoose.h +++ b/src/third_party/mongoose/mongoose.h @@ -233,7 +233,6 @@ namespace Mongoose { /* TODO */ virtual ~TMongoose() { - assert(this); assert(!Handle); } @@ -245,7 +244,6 @@ namespace Mongoose { /* TODO */ void Start(const char **options) { - assert(this); Stop(); Handle = mg_start(Callback, this, options); if (!Handle) { @@ -255,7 +253,6 @@ namespace Mongoose { /* TODO */ void Stop() { - assert(this); if (Handle) { mg_stop(Handle); Handle = 0; diff --git a/src/thread/fd_managed_thread.cc b/src/thread/fd_managed_thread.cc index b2802b88..c3956108 100644 --- a/src/thread/fd_managed_thread.cc +++ b/src/thread/fd_managed_thread.cc @@ -27,8 +27,6 @@ using namespace Base; using namespace Thread; TFdManagedThread::~TFdManagedThread() { - assert(this); - /* This should have already been called by a subclass destructor. Calling it here a second time is harmless and acts as a safeguard, just in case some subclass omits calling it. */ @@ -40,13 +38,10 @@ void TFdManagedThread::Start() { } bool TFdManagedThread::IsStarted() const noexcept { - assert(this); return Thread.joinable(); } void TFdManagedThread::RequestShutdown() { - assert(this); - if (!Thread.joinable()) { Die("Cannot request shutdown on nonexistent worker thread"); } @@ -55,13 +50,10 @@ void TFdManagedThread::RequestShutdown() { } const TFd &TFdManagedThread::GetShutdownWaitFd() const noexcept { - assert(this); return ShutdownFinishedSem.GetFd(); } void TFdManagedThread::Join() { - assert(this); - if (!Thread.joinable()) { Die("Cannot join nonexistent worker thread"); } @@ -78,8 +70,6 @@ void TFdManagedThread::Join() { } void TFdManagedThread::DoStart() { - assert(this); - if (Thread.joinable()) { Die("Worker thread is already started"); } @@ -96,8 +86,6 @@ void TFdManagedThread::DoStart() { } void TFdManagedThread::ShutdownOnDestroy() noexcept { - assert(this); - if (Thread.joinable()) { ShutdownRequestedSem.Push(); @@ -113,8 +101,6 @@ void TFdManagedThread::ShutdownOnDestroy() noexcept { } void TFdManagedThread::RunAndTerminate() { - assert(this); - try { Run(); } catch (...) { diff --git a/src/thread/fd_managed_thread.h b/src/thread/fd_managed_thread.h index a51682b7..d54a3906 100644 --- a/src/thread/fd_managed_thread.h +++ b/src/thread/fd_managed_thread.h @@ -100,13 +100,11 @@ namespace Thread { void Join(); const std::thread &GetThread() const noexcept { - assert(this); assert(Thread.joinable()); return Thread; } std::thread &GetThread() noexcept { - assert(this); assert(Thread.joinable()); return Thread; } @@ -132,7 +130,6 @@ namespace Thread { shutdown request, which is indicated when the descriptor becomes readable. */ const Base::TFd &GetShutdownRequestFd() const noexcept { - assert(this); return ShutdownRequestedSem.GetFd(); } @@ -142,7 +139,6 @@ namespace Thread { monitor the FD in case it becomes readable due to some emergency scenario causing unexpected destructor invocation. */ void ClearShutdownRequest() noexcept { - assert(this); ShutdownRequestedSem.Pop(); } diff --git a/src/thread/gate.h b/src/thread/gate.h index 44f4b09c..606d5b87 100644 --- a/src/thread/gate.h +++ b/src/thread/gate.h @@ -43,8 +43,6 @@ namespace Thread { ~TGate() override = default; void Put(std::list &&put_list) override { - assert(this); - if (!put_list.empty()) { bool was_empty = false; @@ -61,7 +59,6 @@ namespace Thread { } void Put(TMsgType &&put_item) override { - assert(this); bool was_empty = false; { @@ -76,13 +73,11 @@ namespace Thread { } std::list Get() override { - assert(this); Sem.Pop(); return NonblockingGet(); } std::list NonblockingGet() override { - assert(this); std::list result; { @@ -94,12 +89,10 @@ namespace Thread { } const Base::TFd &GetMsgAvailableFd() const noexcept override { - assert(this); return Sem.GetFd(); } void Reset() noexcept { - assert(this); Sem.Reset(); MsgList.clear(); } diff --git a/src/thread/managed_thread_pool.h b/src/thread/managed_thread_pool.h index dfaf577c..63700020 100644 --- a/src/thread/managed_thread_pool.h +++ b/src/thread/managed_thread_pool.h @@ -90,7 +90,6 @@ namespace Thread { /* Swap internal state with 'that'. */ void Swap(TReadyWorker &that) noexcept { - assert(this); TManagedThreadPoolBase::TReadyWorkerBase::Swap(that); } @@ -98,7 +97,6 @@ namespace Thread { assign a value to it before calling Launch(). Must only be called when wrapper is nonempty (i.e. IsLaunchable() returns true). */ TWorkCallable &GetWorkFn() noexcept { - assert(this); assert(GetWorker()); return GetWorker()->GetWorkFn(); } @@ -106,7 +104,6 @@ namespace Thread { /* Get the pool that the contained worker belongs to. Must only be called when wrapper is nonempty (i.e. IsLaunchable() returns true). */ TManagedThreadPool &GetPool() const { - assert(this); assert(GetWorker()); return static_cast(GetWorker()->GetPool()); } @@ -145,7 +142,6 @@ namespace Thread { attempting to launch the thread it contains (not necessary if no max pool size is configured). */ TReadyWorker GetReadyWorker() { - assert(this); return TReadyWorker(static_cast(GetAvailableWorker())); } @@ -153,7 +149,6 @@ namespace Thread { /* Our base class calls this when it needs to create a new thread to add to the pool. */ TWorkerBase *CreateWorker(bool start) override { - assert(this); return new TWorker(*this, start); } @@ -178,20 +173,16 @@ namespace Thread { /* Return function pointer or object that worker calls to perform work. */ TWorkCallable &GetWorkFn() noexcept { - assert(this); return WorkFn; } protected: /* Perform work by calling the client-defined callable object. */ void DoWork() override { - assert(this); WorkFn(); } void DoClearClientState() override { - assert(this); - /* Depending on the type of TWorkCallable, this may invoke an overloaded operator function, which must not throw since any exception that escapes from here will cause invocation of the fatal diff --git a/src/thread/managed_thread_pool.test.cc b/src/thread/managed_thread_pool.test.cc index 0cc4f71c..5093a0df 100644 --- a/src/thread/managed_thread_pool.test.cc +++ b/src/thread/managed_thread_pool.test.cc @@ -77,12 +77,10 @@ class TSimpleWorkFn { } void SetThrowAction(TThrowAction action) { - assert(this); ThrowAction = action; } void operator()() { - assert(this); ++Counter; switch (ThrowAction) { @@ -132,7 +130,6 @@ class TStressTest1WorkFn { } void operator()() { - assert(this); size_t num_working = WorkingCount.load(); ++Counter; uint64_t now = GetMonotonicRawMilliseconds(); @@ -221,39 +218,32 @@ class TStressTest2WorkFn { } TStressTest2WorkFn &operator=(nullptr_t) { - assert(this); Clear(); return *this; } void SetPool(TManagedThreadFnObjPool &pool) { - assert(this); Pool = &pool; } void SetCounter(std::atomic &counter) { - assert(this); Counter = &counter; } void SetWorkingCount(std::atomic &working_count) { - assert(this); WorkingCount = &working_count; } void SetRemainingCount(size_t count) { - assert(this); RemainingCount = count; } bool IsClear() const { - assert(this); return (Pool == nullptr) && (Counter == nullptr) && (WorkingCount == nullptr) && (RemainingCount == 1); } void operator()() { - assert(this); ++*Counter; if (--RemainingCount == 0) { @@ -304,7 +294,6 @@ class TStressTest2WorkFn { TStressTest2WorkFn() = default; void Clear() { - assert(this); *this = TStressTest2WorkFn(); } diff --git a/src/thread/managed_thread_pool_base.cc b/src/thread/managed_thread_pool_base.cc index a8e638ba..6e3ab132 100644 --- a/src/thread/managed_thread_pool_base.cc +++ b/src/thread/managed_thread_pool_base.cc @@ -45,7 +45,6 @@ TManagedThreadPoolBase::~TManagedThreadPoolBase() { void TManagedThreadPoolBase::SetConfig( const TManagedThreadPoolConfig &cfg) noexcept { - assert(this); bool notify = false; { @@ -66,8 +65,6 @@ void TManagedThreadPoolBase::SetConfig( } void TManagedThreadPoolBase::Start(bool populate) { - assert(this); - if (Manager.IsStarted()) { Die("Thread pool is already started"); } @@ -108,7 +105,6 @@ void TManagedThreadPoolBase::Start(bool populate) { std::list TManagedThreadPoolBase::GetAllPendingErrors() { - assert(this); std::list result; { @@ -124,8 +120,6 @@ TManagedThreadPoolBase::GetAllPendingErrors() { } TManagedThreadPoolStats TManagedThreadPoolBase::GetStats() const noexcept { - assert(this); - std::lock_guard lock(PoolLock); Stats.LiveWorkerCount = LiveWorkerCount; Stats.IdleWorkerCount = IdleList.Size(); @@ -133,8 +127,6 @@ TManagedThreadPoolStats TManagedThreadPoolBase::GetStats() const noexcept { } void TManagedThreadPoolBase::RequestShutdown() { - assert(this); - if (!Manager.IsStarted()) { Die("Cannot call RequestShutdown() on thread pool that is not started"); } @@ -143,8 +135,6 @@ void TManagedThreadPoolBase::RequestShutdown() { } void TManagedThreadPoolBase::WaitForShutdown() { - assert(this); - if (!Manager.IsStarted()) { Die("Cannot call WaitForShutdown() on thread pool that is not started"); } @@ -207,8 +197,6 @@ TManagedThreadPoolBase::TWorkerBase::~TWorkerBase() { } void TManagedThreadPoolBase::TWorkerBase::Activate() { - assert(this); - if (WorkerThread.joinable()) { /* The thread was obtained from the idle list, and has been placed on the busy list but not yet awakened. When we release 'WakeupWait' below, it @@ -338,8 +326,6 @@ void TManagedThreadPoolBase::TWorkerBase::DoPutBack(TWorkerBase *worker) { } void TManagedThreadPoolBase::TWorkerBase::ClearClientState() noexcept { - assert(this); - try { /* This should not throw, but be prepared just in case it does. */ DoClearClientState(); @@ -354,7 +340,6 @@ void TManagedThreadPoolBase::TWorkerBase::ClearClientState() noexcept { } void TManagedThreadPoolBase::TWorkerBase::Terminate() { - assert(this); assert(WorkerThread.joinable()); TerminateRequested = true; WakeupWait.unlock(); @@ -362,7 +347,6 @@ void TManagedThreadPoolBase::TWorkerBase::Terminate() { void TManagedThreadPoolBase::TWorkerBase::XferFromBusyList( std::list &dst) noexcept { - assert(this); assert(BusyListPos != MyPool.BusyList.end()); dst.splice(dst.end(), MyPool.BusyList, BusyListPos); BusyListPos = MyPool.BusyList.end(); @@ -370,7 +354,6 @@ void TManagedThreadPoolBase::TWorkerBase::XferFromBusyList( TManagedThreadPoolBase::TWorkerBase::TAfterBusyAction TManagedThreadPoolBase::TWorkerBase::LeaveBusyList() noexcept { - assert(this); assert(BusyListPos != MyPool.BusyList.end()); TAfterBusyAction next_action = TAfterBusyAction::BecomeIdle; std::list my_ptr; @@ -399,7 +382,6 @@ TManagedThreadPoolBase::TWorkerBase::LeaveBusyList() noexcept { } void TManagedThreadPoolBase::TWorkerBase::DoBusyRun() { - assert(this); std::list error; TAfterBusyAction next_action = TAfterBusyAction::BecomeIdle; @@ -480,8 +462,6 @@ void TManagedThreadPoolBase::TWorkerBase::DoBusyRun() { } void TManagedThreadPoolBase::TWorkerBase::BusyRun() { - assert(this); - /* If an exception escapes from DoBusyRun(), the source is the thread pool implementation, not client code. Any exceptions thrown by client code are caught inside DoBusyRun(). */ @@ -497,8 +477,6 @@ void TManagedThreadPoolBase::TWorkerBase::BusyRun() { } void TManagedThreadPoolBase::TWorkerBase::IdleRun() { - assert(this); - /* If an exception escapes from DoBusyRun(), the source is the thread pool implementation, not client code. Any exceptions thrown by client code are caught inside DoBusyRun(). */ @@ -529,8 +507,6 @@ TManagedThreadPoolBase::TManagedThreadPoolBase() TManagedThreadPoolBase::TWorkerBase * TManagedThreadPoolBase::GetAvailableWorker() { - assert(this); - { std::lock_guard lock(PoolLock); size_t max_pool_size = Config.GetMaxPoolSize(); @@ -588,8 +564,6 @@ TManagedThreadPoolBase::TManager::~TManager() { } void TManagedThreadPoolBase::TManager::Run() { - assert(this); - try { DoRun(); } catch (const std::exception &x) { @@ -603,7 +577,6 @@ void TManagedThreadPoolBase::TManager::Run() { uint64_t TManagedThreadPoolBase::TManager::HandleReconfig( uint64_t old_prune_at, uint64_t now) noexcept { - assert(this); MyPool.ReconfigSem.Pop(); bool reset_segments = false; size_t old_prune_quantum_ms = Config.GetPruneQuantumMs(); @@ -635,7 +608,6 @@ uint64_t TManagedThreadPoolBase::TManager::HandleReconfig( size_t TManagedThreadPoolBase::TManager::GetMaxThreadsToPrune() const noexcept { - assert(this); assert(MyPool.IdleList.Size() <= MyPool.LiveWorkerCount); if (MyPool.LiveWorkerCount <= Config.GetMinPoolSize()) { @@ -718,7 +690,6 @@ TManagedThreadPoolBase::TManager::GetMaxThreadsToPrune() const noexcept { } void TManagedThreadPoolBase::TManager::PruneThreadPool() { - assert(this); std::list pruned; { @@ -766,7 +737,6 @@ void TManagedThreadPoolBase::TManager::PruneThreadPool() { } void TManagedThreadPoolBase::TManager::HandleShutdownRequest() { - assert(this); std::list idle_workers, dead_workers; bool wait_for_workers = false; @@ -821,8 +791,6 @@ void TManagedThreadPoolBase::TManager::HandleShutdownRequest() { } void TManagedThreadPoolBase::TManager::DoRun() { - assert(this); - { /* make private copy of pool config */ std::lock_guard lock(MyPool.PoolLock); @@ -876,7 +844,6 @@ void TManagedThreadPoolBase::TManager::DoRun() { TManagedThreadPoolBase::TWorkerBase * TManagedThreadPoolBase::AddToBusyList( std::list &ready_worker) noexcept { - assert(this); assert(ready_worker.size() == 1); BusyList.splice(BusyList.begin(), ready_worker); TWorkerBase &worker = *BusyList.front(); diff --git a/src/thread/managed_thread_pool_base.h b/src/thread/managed_thread_pool_base.h index e8106b51..eb25cdf5 100644 --- a/src/thread/managed_thread_pool_base.h +++ b/src/thread/managed_thread_pool_base.h @@ -138,7 +138,6 @@ namespace Thread { obtained from the pool. This may facilitate maintaining metrics on the pool's effectiveness. */ bool IsNew() const noexcept { - assert(this); assert(Worker); return !Worker->IsStarted(); } @@ -149,8 +148,6 @@ namespace Thread { configured with a maximum size, client must call IsLaunchable() to verify that thread allocation succeeded before calling this method. */ std::thread::id Launch() { - assert(this); - if (!IsLaunchable()) { Base::Die("Cannot call Launch() method on empty TReadyWorkerBase"); } @@ -166,8 +163,6 @@ namespace Thread { this is a no-op. Once this has been called, IsLaunchable() will return false and Launch() can no longer be called. */ void PutBack() noexcept { - assert(this); - if (Worker) { TWorkerBase::PutBack(Worker); Worker = nullptr; @@ -180,7 +175,6 @@ namespace Thread { to indicate that a thread could not be allocated due to the size limit. */ bool IsLaunchable() noexcept { - assert(this); return (Worker != nullptr); } @@ -216,14 +210,12 @@ namespace Thread { /* Swap our internal state with 'that'. */ void Swap(TReadyWorkerBase &that) noexcept { - assert(this); std::swap(Worker, that.Worker); } /* Return a pointer to the worker (if any) that we contain. Return nullptr if we are empty. We retain ownership of worker. */ TWorkerBase *GetWorkerBase() const noexcept { - assert(this); return Worker; } @@ -245,8 +237,6 @@ namespace Thread { /* Return the pool's current configuration. */ TManagedThreadPoolConfig GetConfig() const noexcept { - assert(this); - std::lock_guard lock(PoolLock); return Config; } @@ -265,7 +255,6 @@ namespace Thread { /* True when Start() has been called, but WaitForShutdown() has not yet been called. */ bool IsStarted() const noexcept { - assert(this); return Manager.IsStarted(); } @@ -274,7 +263,6 @@ namespace Thread { supplied worker code. The error details may be obtained by calling GetAllPendingErrors(). */ const Base::TFd &GetErrorPendingFd() const noexcept { - assert(this); return ErrorPendingSem.GetFd(); } @@ -298,7 +286,6 @@ namespace Thread { of time must monitor this file descriptor and finish their work if it becomes readable. */ const Base::TFd &GetShutdownRequestFd() const noexcept { - assert(this); return Manager.GetShutdownRequestFd(); } @@ -311,7 +298,6 @@ namespace Thread { descriptor should be monitored for readability so that fatal errors may be detected. */ const Base::TFd &GetShutdownWaitFd() const noexcept { - assert(this); return Manager.GetShutdownWaitFd(); } @@ -359,7 +345,6 @@ namespace Thread { /* Return true if this object contains an actual thread, or false otherwise. */ bool IsStarted() const noexcept { - assert(this); return WorkerThread.joinable(); } @@ -368,21 +353,18 @@ namespace Thread { before it returns to the idle list after finishing its work, thus preventing a race condition. */ void SetWaitAfterDoWork() { - assert(this); WaitAfterDoWork = true; } /* Returns the thread ID. It is assumed that the thread has been started (i.e. IsStarted() returns true). */ std::thread::id GetId() const noexcept { - assert(this); assert(IsStarted()); return WorkerThread.get_id(); } /* Return a reference to the pool that this thread belongs to. */ TManagedThreadPoolBase &GetPool() const noexcept { - assert(this); return MyPool; } @@ -427,7 +409,6 @@ namespace Thread { /* The manager calls this after calling Terminate(), or when processing worker on 'JoinList'. */ void Join() { - assert(this); WorkerThread.join(); } diff --git a/src/thread/managed_thread_pool_config.cc b/src/thread/managed_thread_pool_config.cc index 6aec013c..8c4c611a 100644 --- a/src/thread/managed_thread_pool_config.cc +++ b/src/thread/managed_thread_pool_config.cc @@ -54,7 +54,6 @@ TManagedThreadPoolConfig::TManagedThreadPoolConfig(size_t min_pool_size, bool TManagedThreadPoolConfig::operator==( const TManagedThreadPoolConfig &that) const noexcept { - assert(this); return (MinPoolSize == that.MinPoolSize) && (PruneQuantumMs == that.PruneQuantumMs) && (PruneQuantumCount == that.PruneQuantumCount) && @@ -64,8 +63,6 @@ bool TManagedThreadPoolConfig::operator==( void TManagedThreadPoolConfig::SetPruneQuantumMs( size_t prune_quantum_ms) noexcept { - assert(this); - if (prune_quantum_ms == 0) { Die("PruneQuantumMs must be > 0"); } @@ -75,8 +72,6 @@ void TManagedThreadPoolConfig::SetPruneQuantumMs( void TManagedThreadPoolConfig::SetPruneQuantumCount( size_t prune_quantum_count) noexcept { - assert(this); - if (prune_quantum_count == 0) { Die("PruneQuantumCount must be > 0"); } @@ -86,8 +81,6 @@ void TManagedThreadPoolConfig::SetPruneQuantumCount( void TManagedThreadPoolConfig::SetMaxPruneFraction( size_t max_prune_fraction) noexcept { - assert(this); - if (max_prune_fraction > 1000) { Die("MaxPruneFraction must be <= 1000"); } @@ -97,8 +90,6 @@ void TManagedThreadPoolConfig::SetMaxPruneFraction( void TManagedThreadPoolConfig::SetMinIdleFraction( size_t min_idle_fraction) noexcept { - assert(this); - if (min_idle_fraction > 1000) { Die("MinIdleFraction must be <= 1000"); } diff --git a/src/thread/managed_thread_pool_config.h b/src/thread/managed_thread_pool_config.h index 58f2f40c..1bbd0f87 100644 --- a/src/thread/managed_thread_pool_config.h +++ b/src/thread/managed_thread_pool_config.h @@ -85,53 +85,44 @@ namespace Thread { bool operator==(const TManagedThreadPoolConfig &that) const noexcept; bool operator!=(const TManagedThreadPoolConfig &that) const noexcept { - assert(this); return !(*this == that); } size_t GetMinPoolSize() const noexcept { - assert(this); return MinPoolSize; } void SetMinPoolSize(size_t min_pool_size) noexcept { - assert(this); MinPoolSize = min_pool_size; } size_t GetMaxPoolSize() const noexcept { - assert(this); return MaxPoolSize; } void SetMaxPoolSize(size_t max_pool_size) noexcept { - assert(this); MaxPoolSize = max_pool_size; } size_t GetPruneQuantumMs() const noexcept { - assert(this); return PruneQuantumMs; } void SetPruneQuantumMs(size_t prune_quantum_ms) noexcept; size_t GetPruneQuantumCount() const noexcept { - assert(this); return PruneQuantumCount; } void SetPruneQuantumCount(size_t prune_quantum_count) noexcept; size_t GetMaxPruneFraction() const noexcept { - assert(this); return MaxPruneFraction; } void SetMaxPruneFraction(size_t max_prune_fraction) noexcept; size_t GetMinIdleFraction() const noexcept { - assert(this); return MinIdleFraction; } diff --git a/src/thread/segmented_list.h b/src/thread/segmented_list.h index 7ebba53f..3bcaa951 100644 --- a/src/thread/segmented_list.h +++ b/src/thread/segmented_list.h @@ -72,7 +72,6 @@ namespace Thread { independent of the number of segments. For instance, true is returned even if there are many segments, as long as all segments are empty. */ bool Empty() const noexcept { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -83,7 +82,6 @@ namespace Thread { /* Return the total number of items in all segments (not the number of segments). */ size_t Size() const noexcept { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -94,7 +92,6 @@ namespace Thread { /* Return the number of segments. Note that some or all segments may be empty. The list always contains at least one segment. */ size_t SegmentCount() const noexcept { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -104,7 +101,6 @@ namespace Thread { /* Copy 'item' to front of first segment. */ void AddNew(const T &item) { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -120,7 +116,6 @@ namespace Thread { /* Move 'item' to front of first segment. */ void AddNew(T &&item) { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -136,7 +131,6 @@ namespace Thread { /* Move contents of 'item_list' to front of first segment. */ void AddNew(std::list &item_list) { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -155,7 +149,6 @@ namespace Thread { initially empty, returned list will be empty. Otherwise returned list will contain exactly one item. */ std::list RemoveOneNewest() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -180,7 +173,6 @@ namespace Thread { /* Remove and return all items from last segment. Returned list will be empty if last segment was empty. */ std::list EmptyOldest() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -200,7 +192,6 @@ namespace Thread { segment. Returned list will have fewer than 'max_count' items (possibly 0) if oldest segment has fewer items than requested. */ std::list RemoveOldest(size_t max_count) { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -222,7 +213,6 @@ namespace Thread { /* Remove and return all items from all segments, but don't change the number of segments. */ std::list EmptyAll() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -247,7 +237,6 @@ namespace Thread { /* Remove and return all items from all segments, and reset the segment count to 1. */ std::list EmptyAllAndResetSegments() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -265,7 +254,6 @@ namespace Thread { /* Add a new empty segment, which becomes the first segment. */ void AddNewSegment() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -278,7 +266,6 @@ namespace Thread { from the last segment to the end of the next to last segment. Then move the (now empty) last segment to the front. */ void RecycleOldestSegment() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -320,7 +307,6 @@ namespace Thread { /* Reorganize list so all items are in a single segment, maintaining their order. On return, the segment count will be 1. */ void ResetSegments() { - assert(this); assert(!AllSegments.empty()); assert(NumSegments > 0); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -357,7 +343,6 @@ namespace Thread { /* for testing */ std::list> CopyOutSegments() const { - assert(this); assert(!AllSegments.empty()); assert(AllSegments.size() == NumSegments); assert((FirstNonempty == nullptr) == (LastNonempty == nullptr)); @@ -378,8 +363,6 @@ namespace Thread { /* for testing */ bool SanityCheck() const noexcept { - assert(this); - if (NumSegments != AllSegments.size()) { return false; } @@ -446,21 +429,18 @@ namespace Thread { /* Return true if segment is empty or false otherwise. */ bool Empty() const noexcept { - assert(this); assert(Items.empty() == (NumItems == 0)); return (NumItems == 0); } /* Return number of items in segment. */ size_t Size() const noexcept { - assert(this); assert(Items.empty() == (NumItems == 0)); return NumItems; } /* Copy 'item' to front of segment. */ void AddToFront(const T &item) { - assert(this); assert(Items.empty() == (NumItems == 0)); Items.push_front(item); ++NumItems; @@ -468,7 +448,6 @@ namespace Thread { /* Move 'item' to front of segment. */ void AddToFront(T &&item) { - assert(this); assert(Items.empty() == (NumItems == 0)); Items.push_front(std::move(item)); ++NumItems; @@ -476,7 +455,6 @@ namespace Thread { /* Move 'item_list' to front of segment. */ void AddToFront(std::list &item_list) { - assert(this); assert(Items.empty() == (NumItems == 0)); size_t n = item_list.size(); Items.splice(Items.begin(), item_list); @@ -486,7 +464,6 @@ namespace Thread { /* Remove front item from segment and append it to 'dst'. Segment must be initially nonempty. */ void TakeFront(std::list &dst) { - assert(this); assert(NumItems); assert(!Items.empty()); dst.splice(dst.end(), Items, Items.begin()); @@ -497,7 +474,6 @@ namespace Thread { 'pos'. */ void TakeAll(std::list &dst, typename std::list::iterator pos) { - assert(this); assert(Items.empty() == (NumItems == 0)); dst.splice(pos, Items); NumItems = 0; @@ -505,7 +481,6 @@ namespace Thread { /* Remove and return all items from segment. */ std::list TakeAll() { - assert(this); assert(Items.empty() == (NumItems == 0)); NumItems = 0; return std::move(Items); @@ -514,7 +489,6 @@ namespace Thread { /* Remove and return last 'n' items from segment, or all items if segment initially has fewer than 'n' items. */ std::list TakeUpToLastN(size_t n) { - assert(this); assert(Items.empty() == (NumItems == 0)); if (n >= NumItems) { @@ -536,7 +510,6 @@ namespace Thread { /* Remove all items and append them to 'dst'. */ void AppendAllTo(TSegment &dst) { - assert(this); assert(Items.empty() == (NumItems == 0)); dst.Items.splice(dst.Items.end(), Items); dst.NumItems += NumItems; @@ -545,14 +518,12 @@ namespace Thread { /* for testing */ std::list CopyOutContents() const { - assert(this); assert(Items.size() == NumItems); return Items; } /* for testing */ bool SanityCheck() const noexcept { - assert(this); return (Items.size() == NumItems); } @@ -572,7 +543,6 @@ namespace Thread { /* The first segment just became nonempty. Add it to the front of the nonempty segment list. */ void AddFirstSegToNonemptySegList() noexcept { - assert(this); TSegment &first_seg = AllSegments.front(); assert(FirstNonempty != &first_seg); assert(LastNonempty != &first_seg); @@ -598,7 +568,6 @@ namespace Thread { /* Remove front item from nonempty segment list, since segment just became empty. */ void RemoveFrontItemFromNonemptySegList() noexcept { - assert(this); assert(NumSegments > 0); assert(FirstNonempty); assert(LastNonempty); @@ -621,7 +590,6 @@ namespace Thread { /* The last segment just became empty. Remove it from the back of the nonempty segment list. */ void RemoveLastSegFromNonemptySegList() noexcept { - assert(this); assert(NumSegments > 0); assert(FirstNonempty); assert(LastNonempty); @@ -645,7 +613,6 @@ namespace Thread { /* The last segment just became nonempty. Add it to the back of the nonempty segment list. */ void AddLastSegToNonemptySegList() noexcept { - assert(this); TSegment &last_seg = AllSegments.back(); assert(FirstNonempty != &last_seg); assert(LastNonempty != &last_seg); diff --git a/src/xml/config/config_errors.h b/src/xml/config/config_errors.h index 1826630a..49f678b4 100644 --- a/src/xml/config/config_errors.h +++ b/src/xml/config/config_errors.h @@ -70,7 +70,6 @@ namespace Xml { } const Base::TOpt &GetLocation() const noexcept { - assert(this); return Location; } @@ -139,13 +138,13 @@ namespace Xml { /* Return the document's actual encoding (not the expected one). */ const std::string &GetEncoding() const noexcept { - assert(this); + return Encoding; } /* Return the document's expected encoding. */ const std::string &GetExpectedEncoding() const noexcept { - assert(this); + return ExpectedEncoding; } @@ -179,7 +178,6 @@ namespace Xml { class TElementError : public TContentError { public: const std::string &GetElementName() const noexcept { - assert(this); return ElementName; } @@ -223,7 +221,6 @@ namespace Xml { } const std::string &GetExpectedElementName() const noexcept { - assert(this); return ExpectedElementName; } @@ -243,7 +240,6 @@ namespace Xml { } const std::string &GetChildElementName() const noexcept { - assert(this); return ChildElementName; } @@ -267,7 +263,6 @@ namespace Xml { class TAttrError : public TElementError { public: const std::string &GetAttrName() const noexcept { - assert(this); return AttrName; } @@ -308,7 +303,6 @@ namespace Xml { } const std::string &GetAttrValue() const noexcept { - assert(this); return AttrValue; } @@ -332,12 +326,10 @@ namespace Xml { } const std::string &GetTrueValue() const noexcept { - assert(this); return TrueValue; } const std::string &GetFalseValue() const noexcept { - assert(this); return FalseValue; } @@ -384,12 +376,10 @@ namespace Xml { } Base::TBase GetFoundBase() const noexcept { - assert(this); return Found; } unsigned int GetAllowedBases() const noexcept { - assert(this); return Allowed; } diff --git a/src/xml/dom_parser_with_line_info.cc b/src/xml/dom_parser_with_line_info.cc index dd8e0664..2cc9553a 100644 --- a/src/xml/dom_parser_with_line_info.cc +++ b/src/xml/dom_parser_with_line_info.cc @@ -56,7 +56,6 @@ TDomParserWithLineInfo::~TDomParserWithLineInfo() { } void TDomParserWithLineInfo::startDocument() { - assert(this); XercesDOMParser::startDocument(); SetUserData(); } @@ -65,7 +64,6 @@ void TDomParserWithLineInfo::startElement(const XMLElementDecl &elemDecl, const unsigned int urlId, const XMLCh *const elemPrefix, const RefVectorOf &attrList, const XMLSize_t attrCount, const bool isEmpty, const bool isRoot) { - assert(this); XercesDOMParser::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, isEmpty, isRoot); SetUserData(); @@ -73,20 +71,17 @@ void TDomParserWithLineInfo::startElement(const XMLElementDecl &elemDecl, void TDomParserWithLineInfo::docCharacters(const XMLCh *const chars, const XMLSize_t length, const bool cdataSection) { - assert(this); XercesDOMParser::docCharacters(chars, length, cdataSection); SetUserData(); } void TDomParserWithLineInfo::docComment(const XMLCh *const comment) { - assert(this); XercesDOMParser::docComment(comment); SetUserData(); } void TDomParserWithLineInfo::docPI(const XMLCh *const target, const XMLCh *const data) { - assert(this); XercesDOMParser::docPI(target, data); SetUserData(); } diff --git a/src/xml/dom_parser_with_line_info.h b/src/xml/dom_parser_with_line_info.h index 3f60aaaf..07963684 100644 --- a/src/xml/dom_parser_with_line_info.h +++ b/src/xml/dom_parser_with_line_info.h @@ -54,7 +54,6 @@ namespace Xml { TDomParserWithLineInfo(); const XMLCh *GetLineInfoKey() const { - assert(this); return LineInfoKey.get(); } diff --git a/src/xml/test/xml_test_initializer.cc b/src/xml/test/xml_test_initializer.cc index 918cf202..e25dda9f 100644 --- a/src/xml/test/xml_test_initializer.cc +++ b/src/xml/test/xml_test_initializer.cc @@ -33,7 +33,6 @@ using namespace Xml; using namespace Xml::Test; bool TXmlTestInitializer::HandleInitError(const XMLException &x) { - assert(this); std::cerr << "Xerces XML library initialization error: " << TranscodeToString(x.getMessage()) << std::endl; std::exit(1); @@ -41,8 +40,6 @@ bool TXmlTestInitializer::HandleInitError(const XMLException &x) { } void TXmlTestInitializer::HandleCleanupError(const XMLException &x) noexcept { - assert(this); - try { std::cerr << "Xerces XML library cleanup error: " << TranscodeToString(x.getMessage()) << std::endl; @@ -52,8 +49,6 @@ void TXmlTestInitializer::HandleCleanupError(const XMLException &x) noexcept { } void TXmlTestInitializer::HandleUnknownErrorOnCleanup() noexcept { - assert(this); - try { std::cerr << "Unknown error while doing Xerces XML library cleanup" << std::endl; diff --git a/src/xml/xml_initializer.h b/src/xml/xml_initializer.h index 79834461..6e318048 100644 --- a/src/xml/xml_initializer.h +++ b/src/xml/xml_initializer.h @@ -55,7 +55,6 @@ namespace Xml { /* Return true if we have successfully initialized Xerces, or false othewise. */ bool IsInitialized() const noexcept { - assert(this); return Initialized; } diff --git a/src/xml/xml_input_line_info.h b/src/xml/xml_input_line_info.h index ec75705d..bca089bd 100644 --- a/src/xml/xml_input_line_info.h +++ b/src/xml/xml_input_line_info.h @@ -62,19 +62,16 @@ namespace Xml { } XMLFileLoc GetLineNum() const noexcept { - assert(this); return LineNum; } XMLFileLoc GetColumnNum() const noexcept { - assert(this); return ColumnNum; } /* Increment reference count on object. Nodes in DOM tree hold references to these objects. */ void AddRef() noexcept { - assert(this); assert(RefCount); ++RefCount; } @@ -82,7 +79,6 @@ namespace Xml { /* Decrement reference count on object. When returned new reference count reaches 0, caller must delete object. */ size_t RemoveRef() noexcept { - assert(this); assert(RefCount); return --RefCount; }