Skip to content

Commit

Permalink
minor legacy code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dspeterson committed Jan 16, 2017
1 parent 4be27a6 commit 2ecc2d9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/dory/batch/per_topic_batcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ TPerTopicBatcher::AddMsg(TMsg::TPtr &&msg, TMsg::TTimestamp now) {
}

if (add_new_expiry) {
auto result = ExpiryTracker.insert(
entry.ExpiryRef = ExpiryTracker.insert(
TBatchExpiryRecord(*opt_nct_final, topic));
assert(result.second);
entry.ExpiryRef = result.first;
}

if (!complete_batch.empty()) {
Expand Down
30 changes: 11 additions & 19 deletions src/dory/batch/per_topic_batcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ namespace Dory {

private:
/* We store these in a multiset. Each record represents a topic batch
with a time limit. The records are ordered by ascending expiry time.
*/
with a time limit. The records are ordered by ascending expiry time,
regardless of topic. In other words, two records with the same
timestamp but different topics are considered equal from the
multiset's point of view. The multiset contains at most one record
for a given topic. No record for a given topic appears in the
multiset in the case where the batch for that topic is empty or has no
time limit. */
class TBatchExpiryRecord final {
public:
TBatchExpiryRecord(TMsg::TTimestamp expiry, const std::string &topic)
Expand Down Expand Up @@ -141,13 +146,7 @@ namespace Dory {

bool operator<(const TBatchExpiryRecord &that) const {
assert(this);
/* FIXME: temporary hack until we switch from Starsha to SCons */
#if 0
return (Expiry < that.Expiry);
#else
return (Expiry == that.Expiry) ?
(Topic < that.Topic) : (Expiry < that.Expiry);
#endif
}

TMsg::TTimestamp GetExpiry() const {
Expand All @@ -164,14 +163,11 @@ namespace Dory {
/* Batch expiry time. */
TMsg::TTimestamp Expiry;

/* Batch topic. The multiset contains at most one record for a given
topic. No record for a given topic appears in the multiset in the
case where the batch for that topic is empty or has no time limit.
*/
/* Batch topic. */
std::string Topic;
}; // TBatchExpiryRecord

using TExpiryRef = std::set<TBatchExpiryRecord>::const_iterator;
using TExpiryRef = std::multiset<TBatchExpiryRecord>::const_iterator;

struct TBatchMapEntry {
/* A batch for a single topic. */
Expand Down Expand Up @@ -200,12 +196,8 @@ namespace Dory {

/* This contains a record for each nonempty topic batch with a time
limit. It lets us efficiently determine the soonest time limit
expiration.
TODO: Make this a multiset and change TBatchExpiryRecord::operator<()
so it compares only the expiration times. Starsha seems to have
problems with multiset. */
std::set<TBatchExpiryRecord> ExpiryTracker;
expiration. */
std::multiset<TBatchExpiryRecord> ExpiryTracker;
}; // TPerTopicBatcher

} // Batch
Expand Down
3 changes: 0 additions & 3 deletions src/dory/input_dg/input_dg_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ enum { INPUT_DG_SZ_FIELD_SIZE = 4 };
enum { INPUT_DG_API_KEY_FIELD_SIZE = 2 };

enum { INPUT_DG_API_VERSION_FIELD_SIZE = 2 };

/* TODO: remove this */
enum { INPUT_DG_OLD_VER_FIELD_SIZE = 1 };
7 changes: 1 addition & 6 deletions src/dory/unix_dg_input_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ TUnixDgInputAgent::TUnixDgInputAgent(const TConfig &config, TPool &pool,
MsgStateTracker(msg_state_tracker),
AnomalyTracker(anomaly_tracker),
InputSocket(SOCK_DGRAM, 0),

/* Add 1 to our buffer size so we can detect messages that are too large
and log them as discards, rather then silently passing them along
truncated. */
InputBuf(config.MaxInputMsgSize + 1),

InputBuf(config.MaxInputMsgSize),
OutputQueue(output_queue),
SyncStartSuccess(false),
SyncStartNotify(nullptr) {
Expand Down
14 changes: 3 additions & 11 deletions src/dory/util/misc_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Dory::Util::InitSyslog(const char *prog_name, int max_level,
syslog(LOG_NOTICE, "Log started");
}

static bool RunTest(std::vector<uint8_t> &buf,
static bool RunUnixDgSocketTest(std::vector<uint8_t> &buf,
const TFd fd_pair[]) {
std::fill(buf.begin(), buf.end(), 0xff);

Expand Down Expand Up @@ -108,14 +108,6 @@ TUnixDgSizeTestResult Dory::Util::TestUnixDgSize(size_t size) {
return TUnixDgSizeTestResult::Fail;
}

/* We must be able to read datagrams 1 byte larger than the requested size.
This allows us to detect and reject attempts by clients to send messages
that are too large, rather than silently passing them along truncated.
TODO: remove this old stull once legacy message format goes away
*/
++size;

std::vector<uint8_t> buf(size);
TFd fd_pair[2];

Expand All @@ -127,7 +119,7 @@ TUnixDgSizeTestResult Dory::Util::TestUnixDgSize(size_t size) {
fd_pair[1] = tmp_fd_pair[1];
}

if (RunTest(buf, fd_pair)) {
if (RunUnixDgSocketTest(buf, fd_pair)) {
return TUnixDgSizeTestResult::Pass;
}

Expand All @@ -142,7 +134,7 @@ TUnixDgSizeTestResult Dory::Util::TestUnixDgSize(size_t size) {
IfLt0(ret); // this will throw
}

return RunTest(buf, fd_pair) ?
return RunUnixDgSocketTest(buf, fd_pair) ?
TUnixDgSizeTestResult::PassWithLargeSendbuf :
TUnixDgSizeTestResult::Fail;
}
Expand Down

0 comments on commit 2ecc2d9

Please sign in to comment.