8000 update codebase (#7125) · temon/arangodb@d30cf31 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit d30cf31

Browse files
author
Andrey Abramov
authored
update codebase (arangodb#7125)
1 parent c7c838e commit d30cf31

File tree

12 files changed

+311
-82
lines changed

12 files changed

+311
-82
lines changed

3rdParty/iresearch/core/error/error.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ struct IRESEARCH_API error_base: std::exception {
6060
// -----------------------------------------------------------------------------
6161
// detailed_error_base
6262
// -----------------------------------------------------------------------------
63-
class IRESEARCH_API detailed_error_base: public error_base {
63+
class IRESEARCH_API detailed_error_base : public error_base {
6464
public:
65-
explicit detailed_error_base(const char* error): error_(error) {}
65+
explicit detailed_error_base(const char* error)
66+
: error_(error) {
67+
}
68+
6669
explicit detailed_error_base(std::string&& error) NOEXCEPT
6770
: error_(std::move(error)) {
6871
}
69-
virtual const char* what() const NOEXCEPT final { return error_.c_str(); }
72+
73+
virtual const char* what() const NOEXCEPT override final {
74+
return error_.c_str();
75+
}
7076

7177
private:
7278
IRESEARCH_API_PRIVATE_VARIABLES_BEGIN
@@ -190,4 +196,4 @@ struct IRESEARCH_API illegal_state: error_base {
190196

191197
NS_END
192198

193-
#endif
199+
#endif

3rdParty/iresearch/core/formats/formats_10.cpp

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ using namespace iresearch;
158158
class features {
159159
public:
160160
enum Mask : uint32_t {
161-
POS = 3, POS_OFFS = 7, POS_PAY = 11, POS_OFFS_PAY = 15
161+
DOCS = 0,
162+
FREQ = 1,
163+
POS = 2,
164+
OFFS = 4,
165+
PAY = 8
162166
};
163167

164168
features() = default;
@@ -188,10 +192,20 @@ class features {
188192
bool payload() const NOEXCEPT { return irs::check_bit<3>(mask_); }
189193
operator Mask() const NOEXCEPT { return static_cast<Mask>(mask_); }
190194

195+
bool any(Mask mask) const NOEXCEPT {
196+
return Mask(0) != (mask_ & mask);
197+
}
198+
199+
bool all(Mask mask) const NOEXCEPT {
200+
return mask != (mask_ & mask);
201+
}
202+
191203
private:
192204
irs::byte_type mask_{};
193205
}; // features
194206

207+
ENABLE_BITMASK_ENUM(features::Mask);
208+
195209
// ----------------------------------------------------------------------------
196210
// --SECTION-- forward declarations
197211
// ----------------------------------------------------------------------------
@@ -492,7 +506,7 @@ void postings_writer::prepare(index_output& out, const iresearch::flush_state& s
492506
std::memset(doc.freqs.get(), 0, sizeof(uint32_t) * BLOCK_SIZE);
493507
}
494508

495-
if (features.check< position >()) {
509+
if (features.check<position>()) {
496510
// prepare proximity stream
497511
if (!pos_) {
498512
pos_ = memory::make_unique< pos_stream >();
@@ -501,7 +515,7 @@ void postings_writer::prepare(index_output& out, const iresearch::flush_state& s
501515
pos_->reset();
502516
prepare_output(name, pos_->out, state, POS_EXT, POS_FORMAT_NAME, FORMAT_MAX);
503517

504-
if (features.check< payload >() || features.check< offset >()) {
518+
if (features.check<payload>() || features.check<offset>()) {
505519
// prepare payload stream
506520
if (!pay_) {
507521
pay_ = memory::make_unique<pay_stream>();
@@ -629,11 +643,11 @@ void postings_writer::begin_term() {
629643
doc.start = doc.out->file_pointer();
630644
std::fill_n(doc.skip_ptr, MAX_SKIP_LEVELS, doc.start);
631645
if (features_.position()) {
632-
assert(pos_);
646+
assert(pos_ && pos_->out);
633647
pos_->start = pos_->out->file_pointer();
634648
std::fill_n(pos_->skip_ptr, MAX_SKIP_LEVELS, pos_->start);
635-
if (features_.payload() || features_.offset()) {
636-
assert(pay_);
649+
if (features_.any(features::OFFS | features::PAY)) {
650+
assert(pay_ && pay_->out);
637651
pay_->start = pay_->out->file_pointer();
638652
std::fill_n(pay_->skip_ptr, MAX_SKIP_LEVELS, pay_->start);
639653
}
@@ -674,7 +688,7 @@ void postings_writer::begin_doc(doc_id_t id, const frequency* freq) {
674688

675689
void postings_writer::add_position(uint32_t pos, const offset* offs, const payload* pay) {
676690
assert(!offs || offs->start <= offs->end);
677-
assert(pos_); /* at least positions stream should be created */
691+
assert(features_.position() && pos_ && pos_->out); /* at least positions stream should be created */
678692

679693
pos_->pos(pos - pos_->last);
680694
if (pay) pay_->payload(pos_->size, pay->value);
@@ -686,26 +700,29 @@ void postings_writer::add_position(uint32_t pos, const offset* offs, const paylo
686700
pos_->flush(buf);
687701

688702
if (pay) {
703+
assert(features_.payload() && pay_ && pay_->out);
689704
pay_->flush_payload(buf);
690705
}
691706

692707
if (offs) {
708+
assert(features_.payload() && pay_ && pay_->out);
693709
pay_->flush_offsets(buf);
694710
}
695711
}
696712
}
697713

698714
void postings_writer::end_doc() {
699-
if ( doc.full() ) {
715+
if (doc.full()) {
700716
doc.block_last = doc.last;
701717
doc.end = doc.out->file_pointer();
702-
if ( pos_ ) {
703-
assert( pos_ );
718+
if (features_.position()) {
719+
assert(pos_ && pos_->out);
704720
pos_->end = pos_->out->file_pointer();
705721
// documents stream is full, but positions stream is not
706722
// save number of positions to skip before the next block
707723
pos_->block_last = pos_->size;
708-
if ( pay_ ) {
724+
if (features_.any(features::OFFS | features::PAY)) {
725+
assert(pay_ && pay_->out);
709726
pay_->end = pay_->out->file_pointer();
710727
pay_->block_last = pay_->pay_buf_.size();
711728
}
@@ -751,6 +768,8 @@ void postings_writer::end_term(version10::term_meta& meta, const uint32_t* tfreq
751768
/* write remaining position using
752769
* variable length encoding */
753770
if (features_.position()) {
771+
assert(pos_ && pos_->out);
772+
754773
if (meta.freq > BLOCK_SIZE) {
755774
meta.pos_end = pos_->out->file_pointer() - pos_->start;
756775
}
@@ -763,6 +782,8 @@ void postings_writer::end_term(version10::term_meta& meta, const uint32_t* tfreq
763782
for (uint32_t i = 0; i < pos_->size; ++i) {
764783
const uint32_t pos_delta = pos_->buf[i];
765784
if (features_.payload()) {
785+
assert(pay_ && pay_->out);
786+
766787
const uint32_t size = pay_->pay_sizes[i];
767788
if (last_pay_size != size) {
768789
last_pay_size = size;
@@ -781,6 +802,8 @@ void postings_writer::end_term(version10::term_meta& meta, const uint32_t* tfreq
781802
}
782803

783804
if (features_.offset()) {
805+
assert(pay_ && pay_->out);
806+
784807
const uint32_t pay_offs_delta = pay_->offs_start_buf[i];
785808
const uint32_t len = pay_->offs_len_buf[i];
786809
if (len == last_offs_len) {
@@ -794,6 +817,7 @@ void postings_writer::end_term(version10::term_meta& meta, const uint32_t* tfreq
794817
}
795818

796819
if (features_.payload()) {
820+
assert(pay_ && pay_->out);
797821
pay_->pay_buf_.clear();
798822
}
799823
}
@@ -850,8 +874,8 @@ void postings_writer::write_skip(size_t level, index_output& out) {
850874

851875
pos_->skip_ptr[level] = pos_ptr;
852876

853-
if (features_.payload() || features_.offset()) {
854-
assert(pay_);
877+
if (features_.any(features::OFFS | features::PAY)) {
878+
assert(pay_ && pay_->out);
855879

856880
if (features_.payload()) {
857881
out.write_vint(static_cast<uint32_t>(pay_->block_last));
@@ -886,7 +910,7 @@ void postings_writer::encode(
886910
if (type_limits<type_t::address_t>::valid(meta.pos_end)) {
887911
out.write_vlong(meta.pos_end);
888912
}
889-
if (features_.payload() || features_.offset()) {
913+
if (features_.any(features::OFFS | features::PAY)) {
890914
out.write_vlong(meta.pay_start - last_state.pay_start);
891915
}
892916
}
@@ -5053,6 +5077,12 @@ void postings_reader::decode(
50535077
}
50545078
}
50555079

5080+
#if defined(_MSC_VER)
5081+
#elif defined (__GNUC__)
5082+
#pragma GCC diagnostic push
5083+
#pragma GCC diagnostic ignored "-Wswitch"
5084+
#endif
5085+
50565086
irs::doc_iterator::ptr postings_reader::iterator(
50575087
const flags& field,
50585088
const attribute_view& attrs,
@@ -5064,17 +5094,24 @@ irs::doc_iterator::ptr postings_reader::iterator(
50645094
const auto enabled = features & req;
50655095
doc_iterator::ptr it;
50665096

5067-
switch(enabled) {
5068-
case features::POS_OFFS_PAY:
5097+
// MSVC 2013 doesn't support constexpr, can't use
5098+
// 'operator|' in the following switch statement
5099+
CONSTEXPR const auto FREQ_POS_OFFS_PAY = features::FREQ | features::POS | features::OFFS | features::PAY;
5100+
CONSTEXPR const auto FREQ_POS_OFFS = features::FREQ | features::POS | features::OFFS;
5101+
CONSTEXPR const auto FREQ_POS_PAY = features::FREQ | features::POS | features::PAY;
5102+
CONSTEXPR const auto FREQ_POS = features::FREQ | features::POS;
5103+
5104+
switch (enabled) {
5105+
case FREQ_POS_OFFS_PAY:
50695106
it = doc_iterator::make<pos_doc_iterator<offs_pay_iterator>>();
50705107
break;
5071-
case features::POS_OFFS:
5108+
case FREQ_POS_OFFS:
50725109
it = doc_iterator::make<pos_doc_iterator<offs_iterator>>();
50735110
break;
5074-
case features::POS_PAY:
5111+
case FREQ_POS_PAY:
50755112
it = doc_iterator::make<pos_doc_iterator<pay_iterator>>();
50765113
break;
5077-
case features::POS:
5114+
case FREQ_POS:
50785115
it = doc_iterator::make<pos_doc_iterator<pos_iterator>>();
50795116
break;
50805117
default:
@@ -5089,6 +5126,11 @@ irs::doc_iterator::ptr postings_reader::iterator(
50895126
return IMPLICIT_MOVE_WORKAROUND(it);
50905127
}
50915128

5129+
#if defined(_MSC_VER)
5130+
#elif defined (__GNUC__)
5131+
#pragma GCC diagnostic pop
5132+
#endif
5133+
50925134
// actual implementation
50935135
class format : public irs::version10::format {
50945136
public:
@@ -5231,4 +5273,4 @@ NS_END // root
52315273

52325274
// -----------------------------------------------------------------------------
52335275
// --SECTION-- END-OF-FILE
5234-
// -----------------------------------------------------------------------------
5276+
// -----------------------------------------------------------------------------

3rdParty/iresearch/core/index/index_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,4 +2156,4 @@ NS_END
21562156

21572157
// -----------------------------------------------------------------------------
21582158
// --SECTION-- END-OF-FILE
2159-
// -----------------------------------------------------------------------------
2159+
// -----------------------------------------------------------------------------

3rdParty/iresearch/core/utils/string_utils.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
#include "shared.hpp"
2828

29+
#if defined(_MSC_VER) && _MSC_VER < 1900 // before MSVC2015
30+
#define snprintf _snprintf
31+
#endif
32+
2933
NS_ROOT
3034
NS_BEGIN(string_utils)
3135

@@ -49,8 +53,7 @@ inline std::basic_string<T>& oversize(
4953
////////////////////////////////////////////////////////////////////////////////
5054
template <typename... Args>
5155
inline int to_string(std::string& buf, const char* format, Args&&... args) {
52-
char ch;
53-
auto result = snprintf(&ch, 0, format, std::forward<Args>(args)...);
56+
auto result = snprintf(nullptr, 0, format, std::forward<Args>(args)...); // MSVC requires 'nullptr' buffer and '0' size to get expected size
5457

5558
if (result <= 0) {
5659
return result;
@@ -63,7 +66,7 @@ inline int to_string(std::string& buf, const char* format, Args&&... args) {
6366

6467
try {
6568
result = snprintf(&buf[start], result, format, std::forward<Args>(args)...);
66-
buf.resize(start + std::max(0, result));
69+
buf.resize(start + (std::max)(0, result));
6770
} catch (...) {
6871
buf.resize(start);
6972

@@ -84,7 +87,6 @@ inline std::string to_string(const char* format, Args&&... args) {
8487

8588
assert(result >= 0);
8689
assert(size_t(result) == buf.size());
87-
8890
UNUSED(result);
8991

9092
return buf;
@@ -93,4 +95,4 @@ inline std::string to_string(const char* format, Args&&... args) {
9395
NS_END // string_utils
9496
NS_END
9597

96-
#endif
98+
#endif

3rdParty/iresearch/core/utils/timer_utils.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
/// @author Vasiliy Nabatchikov
2222
////////////////////////////////////////////////////////////////////////////////
2323

24-
#include <mutex>
25-
#include <unordered_map>
2624
#include "singleton.hpp"
2725
#include "timer_utils.hpp"
2826

27+
#include <mutex>
28+
#include <unordered_map>
29+
#include <map>
30+
2931
NS_LOCAL
3032

3133
class timer_states: public iresearch::singleton<timer_states> {
@@ -138,9 +140,45 @@ bool visit(
138140
return timer_states::instance().visit(visitor);
139141
}
140142

143+
void flush_stats(std::ostream &out) {
144+
std::map<std::string, std::pair<size_t, size_t>> ordered_stats;
145+
146+
iresearch::timer_utils::visit([&ordered_stats](const std::string& key, size_t count, size_t time)->bool {
147+
std::string key_str = key;
148+
149+
#if defined(__GNUC__)
150+
if (key_str.compare(0, strlen("virtual "), "virtual ") == 0) {
151+
key_str = key_str.substr(strlen("virtual "));
152+
}
153+
154+
size_t i;
155+
156+
if (std::string::npos != (i = key_str.find(' ')) && key_str.find('(') > i) {
157+
key_str = key_str.substr(i + 1);
158+
}
159+
#elif defined(_MSC_VER)
160+
size_t i;
161+
162+
if (std::string::npos != (i = key_str.find("__cdecl "))) {
163+
key_str = key_str.substr(i + strlen("__cdecl "));
164+
}
165+
#endif
166+
167+
ordered_stats.emplace(key_str, std::make_pair(count, time));
168+
return true;
169+
});
170+
171+
for (auto& entry: ordered_stats) {
172+
auto& key = entry.first;
173+
auto& count = entry.second.first;
174+
auto& time = entry.second.second;
175+
out << key << "\tcalls:" << count << ",\ttime: " << time/1000 << " us,\tavg call: " << time/1000/(double)count << " us"<< std::endl;
176+
}
177+
}
178+
141179
NS_END // timer_utils
142180
NS_END // NS_ROOT
143181

144182
// -----------------------------------------------------------------------------
145183
// --SECTION-- END-OF-FILE
146-
// -----------------------------------------------------------------------------
184+
// -----------------------------------------------------------------------------

3rdParty/iresearch/core/utils/timer_utils.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ IRESEARCH_API bool visit(
103103
const std::function<bool(const std::string& key, size_t count, size_t time_us)>& visitor
104104
);
105105

106+
////////////////////////////////////////////////////////////////////////////////
107+
/// @brief flush formatted timer stats to a specified stream
108+
////////////////////////////////////////////////////////////////////////////////
109+
IRESEARCH_API void flush_stats(std::ostream &out);
110+
106111
NS_END // timer_utils
107112
NS_END // NS_ROOT
108113

109-
#endif
114+
#endif

0 commit comments

Comments
 (0)
0