sstables: continuous_data_consumer: Make position() meaningful inside state_processor::process_state()

Will allow state_processor to know its position in the
stream.

Currently position() is meaningless inside process_state() because in
some cases it points to the position after the buffer and in some
cases before it. This patch standardizes on the former. This is more
useful than the latter because process_state() trims from the front of
the buffer as it consumes, so the position inside the stream can be
obtained by subtracting the remaining buffer size from position(),
without introducing any new variables.
This commit is contained in:
Tomasz Grabiec
2018-12-15 20:21:19 +01:00
parent e950c8b00a
commit 36dd660507

View File

@@ -404,11 +404,12 @@ public:
// We received more data than we actually care about, so process
// the beginning of the buffer, and return the rest to the stream
auto segment = data.share(0, _remain);
_stream_position.position += _remain;
auto ret = process(segment);
_stream_position.position -= segment.size();
data.trim_front(_remain - segment.size());
auto len = _remain - segment.size();
_remain -= len;
_stream_position.position += len;
if (_remain == 0 && ret == proceed::yes) {
verify_end_state();
}
@@ -464,6 +465,9 @@ public:
return fast_forward_to(begin, _stream_position.position + _remain);
}
// Returns the offset of the first byte which has not been consumed yet.
// When called from state_processor::process_state() invoked by this consumer,
// returns the offset of the first byte after the buffer passed to process_state().
uint64_t position() const {
return _stream_position.position;
}