8000 Merge branch 'devel' of https://github.com/arangodb/arangodb into fea… · arangodb/arangodb@8c94d3c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c94d3c

Browse files
committed
Merge branch 'devel' of https://github.com/arangodb/arangodb into feature/smart-join-views-2
* 'devel' of https://github.com/arangodb/arangodb: rawPayload shouldn't return the full reply buffer (#10319) micro optimizations (#10316) test attempt to increase max collection name length from 64 chars to 256 (#9890) Feature/force backup (#10265) upgrade vpack library (#10314) avoid string copies in several cases (#10317) Round index estimates when comparing plan, we do not really care for exact equallity, they should only not be off by much (#10312) make ccache optional (#10310)
2 parents f3f69e6 + ac10332 commit 8c94d3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+647
-275
lines changed

3rdParty/iresearch/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ endif()
5252
### setup ccache
5353
################################################################################
5454

55-
find_program(CCACHE_FOUND ccache)
55+
option(USE_CCACHE "Use CCACHE if present" ON)
5656

57-
if(CCACHE_FOUND)
58-
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
59-
endif(CCACHE_FOUND)
57+
if (USE_CCACHE)
58+
find_program(CCACHE_FOUND ccache)
59+
60+
if(CCACHE_FOUND)
61+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
62+
endif(CCACHE_FOUND)
63+
endif()
6064

6165
if (USE_OPTIMIZE_FOR_ARCHITECTURE)
6266
include(OptimizeForArchitecture)

3rdParty/velocypack/include/velocypack/Buffer.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ class Buffer {
5555

5656
Buffer(Buffer const& that) : Buffer() {
5757
if (that._size > 0) {
58-
if (that._size > sizeof(_local)) {
59-
_buffer = static_cast<T*>(malloc(checkOverflow(sizeof(T) * that._size)));
58+
if (that._size > sizeof(that._local)) {
59+
_buffer = static_cast<T*>(malloc(checkOverflow(that._size)));
6060
ensureValidPointer(_buffer);
6161
_capacity = that._size;
6262
} else {
63+
VELOCYPACK_ASSERT(_buffer == &_local[0]);
6364
_capacity = sizeof(_local);
6465
}
6566
memcpy(_buffer, that._buffer, checkOverflow(that._size));
@@ -73,10 +74,9 @@ class Buffer {
7374
// our own buffer is big enough to hold the data
7475
initWithNone();
7576
memcpy(_buffer, that._buffer, checkOverflow(that._size));
76-
}
77-
else {
77+
} else {
7878
// our own buffer is not big enough to hold the data
79-
T* buffer = static_cast<T*>(malloc(checkOverflow(sizeof(T) * that._size)));
79+
T* buffer = static_cast<T*>(malloc(checkOverflow(that._size)));
8080
ensureValidPointer(buffer);
8181
buffer[0] = '\x00';
8282
memcpy(buffer, that._buffer, checkOverflow(that._size));
@@ -94,8 +94,11 @@ class Buffer {
9494
}
9595

9696
Buffer(Buffer&& that) noexcept : _buffer(_local), _capacity(sizeof(_local)) {
97+
poison(_buffer, _capacity);
98+
initWithNone();
9799
if (that._buffer == that._local) {
98-
memcpy(_buffer, that._buffer, static_cast<std::size_t>(that._size));
100+
VELOCYPACK_ASSERT(that._capacity == sizeof(that._local));
101+
memcpy(_buffer, that._buffer, checkOverflow(that._size));
99102
} else {
100103
_buffer = that._buffer;
101104
_capacity = that._capacity;
@@ -104,23 +107,28 @@ class Buffer {
104107
}
105108
_size = that._size;
106109
that._size = 0;
110+
that.initWithNone();
107111
}
108112

109113
Buffer& operator=(Buffer&& that) noexcept {
110114
if (this != &that) {
115+
if (_buffer != _local) {
116+
free(_buffer);
117+
}
111118
if (that._buffer == that._local) {
112-
memcpy(_buffer, that._buffer, static_cast<std::size_t>(that._size));
119+
_buffer = _local;
120+
_capacity = sizeof(_local);
121+
initWithNone();
122+
memcpy(_buffer, that._buffer, checkOverflow(that._size));
113123
} else {
114-
if (_buffer != _local) {
115-
free(_buffer);
116-
}
117124
_buffer = that._buffer;
118125
_capacity = that._capacity;
119126
that._buffer = that._local;
120127
that._capacity = sizeof(that._local);
121128
}
122129
_size = that._size;
123130
that._size = 0;
131+
that.initWithNone();
124132
}
125133
return *this;
126134
}
@@ -281,11 +289,11 @@ class Buffer {
281289
VELOCYPACK_ASSERT(newLen > 0);
282290
T* p;
283291
if (_buffer != _local) {
284-
p = static_cast<T*>(realloc(_buffer, checkOverflow(sizeof(T) * newLen)));
292+
p = static_cast<T*>(realloc(_buffer, checkOverflow(newLen)));
285293
ensureValidPointer(p);
286294
// realloc will have copied the old data
287295
} else {
288-
p = static_cast<T*>(malloc(checkOverflow(sizeof(T) * newLen)));
296+
p = static_cast<T*>(malloc(checkOverflow(newLen)));
289297
ensureValidPointer(p);
290298
// copy existing data into buffer
291299
memcpy(p, _buffer, checkOverflow(_size));

3rdParty/velocypack/include/velocypack/Builder.h

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,58 @@ class Builder {
9191
public:
9292
Options const* options;
9393

94-
// create an empty Builder, using default Options
95-
Builder();
96-
97-
explicit Builder(Options const* options);
94+
// create an empty Builder, using Options
95+
explicit Builder(Options const* options = &Options::Defaults);
96+
97+
// create an empty Builder, using an existing buffer
9898
explicit Builder(std::shared_ptr<Buffer<uint8_t>> const& buffer,
9999
Options const* options = &Options::Defaults);
100+
101+
// create a Builder that uses an existing Buffer. the Builder will not
102+
// claim ownership for this Buffer
100103
explicit Builder(Buffer<uint8_t>& buffer,
101104
Options const* options = &Options::Defaults);
105+
106+
// populate a Builder from a Slice
102107
explicit Builder(Slice slice, Options const* options = &Options::Defaults);
108+
103109
~Builder() = default;
104110

105111
Builder(Builder const& that);
106112
Builder& operator=(Builder const& that);
107-
Builder(Builder&& that);
108-
Builder& operator=(Builder&& that);
113+
Builder(Builder&& that) noexcept;
114+
Builder& operator=(Builder&& that) noexcept;
109115

110-
// get a const reference to the Builder's Buffer object
111-
std::shared_ptr<Buffer<uint8_t>> const& buffer() const { return _buffer; }
116+
// get a reference to the Builder's Buffer object
117+
// note: this object may be a nullptr if the buffer was already stolen
118+
// from the Builder, or if the Builder has no ownership for the Buffer
119+
std::shared_ptr<Buffer<uint8_t>> const& buffer() const {
120+
return _buffer;
121+
}
122+
123+
Buffer<uint8_t>& bufferRef() const {
124+
if (_bufferPtr == nullptr) {
125+
throw Exception(Exception::InternalError, "Builder has no Buffer");
126+
}
127+
return *_bufferPtr;
128+
}
112129

113130
// steal the Builder's Buffer object. afterwards the Builder
114-
// is unusable
131+
// is unusable - note: this may return a nullptr if the Builder does not
132+
// own the Buffer!
115133
std::shared_ptr<Buffer<uint8_t>> steal() {
116134
// After a steal the Builder is broken!
117-
std::shared_ptr<Buffer<uint8_t>> res = _buffer;
118-
_buffer.reset();
135+
std::shared_ptr<Buffer<uint8_t>> res(std::move(_buffer));
119136
_bufferPtr = nullptr;
120-
_pos = 0;
137+
_start = nullptr;
138+
clear();
121139
return res;
122140
}
123141

124-
uint8_t const* data() const noexcept { return _bufferPtr->data(); }
< 10000 /code>142+
uint8_t const* data() const noexcept {
143+
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
144+
return _bufferPtr->data();
145+
}
125146

126147
std::string toString() const;
127148

@@ -153,6 +174,7 @@ class Builder {
153174
(void) checkOverflow(_pos + len);
154175
#endif
155176

177+
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
156178
_bufferPtr->reserve(len);
157179
_start = _bufferPtr->data();
158180
}
@@ -161,8 +183,11 @@ class Builder {
161183
void clear() noexcept {
162184
_pos = 0;
163185
_stack.clear();
164-
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
165-
_bufferPtr->reset();
186+
_index.clear();
187+
if (_bufferPtr != nullptr) {
188+
_bufferPtr->reset();
189+
_start = _bufferPtr->data();
190+
}
166191
_keyWritten = false;
167192
}
168193

@@ -564,8 +589,8 @@ class Builder {
564589
uint8_t* addInternal(char const* attrName, std::size_t attrLength, T const& sub) {
565590
bool haveReported = false;
566591
if (!_stack.empty()) {
567-
ValueLength& tos = _stack.back();
568-
if (VELOCYPACK_UNLIKELY(_start[tos] != 0x0b && _start[tos] != 0x14)) {
592+
ValueLength const to = _stack.back();
593+
if (VELOCYPACK_UNLIKELY(_start[to] != 0x0b && _start[to] != 0x14)) {
569594
throw Exception(Exception::BuilderNeedOpenObject);
570595
}
571596
if (VELOCYPACK_UNLIKELY(_keyWritten)) {
@@ -621,9 +646,9 @@ class Builder {
621646
void openCompoundValue(uint8_t type) {
622647
bool haveReported = false;
623648
if (!_stack.empty()) {
624-
ValueLength& tos = _stack.back();
649+
ValueLength const to = _stack.back();
625650
if (!_keyWritten) {
626-
if (VELOCYPACK_UNLIKELY(_start[tos] != 0x06 && _start[tos] != 0x13)) {
651+
if (VELOCYPACK_UNLIKELY(_start[to] != 0x06 && _start[to] != 0x13)) {
627652
throw Exception(Exception::BuilderNeedOpenArray);
628653
}
629654
reportAdd();
@@ -797,11 +822,13 @@ struct ObjectBuilder final : public BuilderContainer,
797822
}
798823
~ObjectBuilder() {
799824
try {
800-
builder->close();
825+
if (!builder->isClosed()) {
826+
builder->close();
827+
}
801828
} catch (...) {
802829
// destructors must not throw. however, we can at least
803830
// signal something is very wrong in debug mode
804-
VELOCYPACK_ASSERT(false);
831+
VELOCYPACK_ASSERT(builder->isClosed());
805832
}
806833
}
807834
};
@@ -826,11 +853,13 @@ struct ArrayBuilder final : public BuilderContainer,
826853
}
827854
~ArrayBuilder() {
828855
try {
829-
builder->close();
856+
if (!builder->isClosed()) {
857+
builder->close();
858+
}
830859
} catch (...) {
831860
// destructors must not throw. however, we can at least
832861
// signal something is very wrong in debug mode
833-
VELOCYPACK_ASSERT(false);
862+
VELOCYPACK_ASSERT(builder->isClosed());
834863
}
835864
}
836865
};

3rdParty/velocypack/include/velocypack/HexDump.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ struct HexDump {
4141
HexDump() = delete;
4242

4343
HexDump(Slice const& slice, int valuesPerLine = 16,
44-
std::string const& separator = " ")
45-
: slice(slice), valuesPerLine(valuesPerLine), separator(separator) {}
44+
std::string const& separator = " ", std::string const& header = "0x")
45+
: slice(slice), valuesPerLine(valuesPerLine), separator(separator), header(header) {}
4646

4747
HexDump(Slice const* slice, int valuesPerLine = 16,
48-
std::string const& separator = " ")
49-
: HexDump(*slice, valuesPerLine, separator) {}
48+
std::string const& separator = " ", std::string const& header = "0x")
49+
: HexDump(*slice, valuesPerLine, separator, header) {}
5050

51-
static std::string toHex(uint8_t value);
51+
static std::string toHex(uint8_t value, std::string const& header = "0x");
52+
static void appendHex(std::string& result, uint8_t value);
5253
std::string toString() const;
5354

5455
friend std::ostream& operator<<(std::ostream&, HexDump const&);
5556

5657
Slice const slice;
5758
int valuesPerLine;
5859
std::string separator;
60+
std::string header;
5961
};
6062

6163
} // namespace arangodb::velocypack

3rdParty/velocypack/include/velocypack/Options.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,48 @@ struct Options;
3939
class Slice;
4040

4141
struct CustomTypeHandler {
42-
virtual ~CustomTypeHandler() {}
42+
virtual ~CustomTypeHandler() = default;
4343
virtual void dump(Slice const&, Dumper*, Slice const&);
4444
virtual std::string toString(Slice const&, Options const*, Slice const&);
4545
};
4646

4747
struct Options {
48+
// Behavior to be applied when dumping VelocyPack values that cannot be
49+
// expressed in JSON without data loss
4850
enum UnsupportedTypeBehavior {
51+
// convert any non-JSON-representable value to null
4952
NullifyUnsupportedType,
53+
// emit a JSON string "(non-representable type ...)"
5054
ConvertUnsupportedType,
55+
// throw an exception for any non-JSON-representable value
5156
FailOnUnsupportedType
5257
};
5358

59+
// Behavior to be applied when building VelocyPack Array/Object values
60+
// with a Builder
61+
enum PaddingBehavior {
62+
// use padding - fill unused head bytes with zero-bytes (ASCII NUL) in
63+
// order to avoid a later memmove
64+
UsePadding,
65+
// don't pad and do not fill any gaps with zero-bytes (ASCII NUL).
66+
// instead, memmove data down so there is no gap between the head bytes
67+
// and the payload
68+
NoPadding,
69+
// pad in cases the Builder considers it useful, and don't pad in other
70+
// cases when the Builder doesn't consider it useful
71+
Flexible
72+
};
73+
5474
Options() {}
5575

5676
// Dumper behavior when a VPack value is serialized to JSON that
5777
// has no JSON equivalent
5878
UnsupportedTypeBehavior unsupportedTypeBehavior = FailOnUnsupportedType;
79+
80+
// Builder behavior w.r.t. padding or memmoving data
81+
PaddingBehavior paddingBehavior = PaddingBehavior::Flexible;
5982

83+
// custom attribute translator for integer keys
6084
AttributeTranslator* attributeTranslator = nullptr;
6185

6286
// custom type handler used for processing custom types by Dumper and Slicer

3rdParty/velocypack/include/velocypack/Sink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct Sink {
4242
Sink(Sink const&) = delete;
4343
Sink& operator=(Sink const&) = delete;
4444

45-
virtual ~Sink() {}
45+
virtual ~Sink() = default;
4646
virtual void push_back(char c) = 0;
4747
virtual void append(std::string const& p) = 0;
4848
virtual void append(char const* p) = 0;

3rdParty/velocypack/include/velocypack/Slice.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@
4747
namespace arangodb {
4848
namespace velocypack {
4949

50-
class Slice {
51-
// This class provides read only access to a VPack value, it is
52-
// intentionally light-weight (only one pointer value), such that
53-
// it can easily be used to traverse larger VPack values.
54-
55-
// A Slice does not own the VPack data it points to!
50+
// This class provides read only access to a VPack value, it is
51+
// intentionally light-weight (only one pointer value), such that
52+
// it can easily be used to traverse larger VPack values.
5653

54+
// A Slice does not own the VPack data it points to!
55+
class Slice {
5756
friend class Builder;
5857
friend class ArrayIterator;
5958
friend class ObjectIterator;
@@ -1105,6 +1104,9 @@ class Slice {
11051104
}
11061105
};
11071106

1107+
static_assert(!std::is_polymorphic<Slice>::value, "Slice must not be polymorphic");
1108+
static_assert(!std::has_virtual_destructor<Slice>::value, "Slice must not have virtual dtor");
1109+
11081110
} // namespace arangodb::velocypack
11091111
} // namespace arangodb
11101112

3rdParty/velocypack/include/velocypack/velocypack-aliases.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ using VPackNormalizedCompare = arangodb::velocypack::NormalizedCompare;
7070
#ifdef VELOCYPACK_BUFFER_H
7171
#ifndef VELOCYPACK_ALIAS_BUFFER
7272
#define VELOCYPACK_ALIAS_BUFFER
73+
using VPackCharBuffer = arangodb::velocypack::CharBuffer;
7374
using VPackBufferUInt8 = arangodb::velocypack::UInt8Buffer;
7475
template<typename T> using VPackBuffer = arangodb::velocypack::Buffer<T>;
7576
#endif

0 commit comments

Comments
 (0)
0