8000 Merge branch 'devel' of https://github.com/arangodb/arangodb into devel · rowhit/arangodb@62c3240 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62c3240

Browse files
committed
Merge branch 'devel' of https://github.com/arangodb/arangodb into devel
2 parents c6ef45b + 76c0789 commit 62c3240

File tree

15 files changed

+205
-9
lines changed

15 files changed

+205
-9
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// @brief Library to build up VPack documents.
3+
///
4+
/// DISCLAIMER
5+
///
6+
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
7+
///
8+
/// Licensed under the Apache License, Version 2.0 (the "License");
9+
/// you may not use this file except in compliance with the License.
10+
/// You may obtain a copy of the License at
11+
///
12+
/// http://www.apache.org/licenses/LICENSE-2.0
13+
///
14+
/// Unless required by applicable law or agreed to in writing, software
15+
/// distributed under the License is distributed on an "AS IS" BASIS,
16+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
/// See the License for the specific language governing permissions and
18+
/// limitations under the License.
19+
///
20+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
21+
///
22+
/// @author Max Neunhoeffer
23+
/// @author Jan Steemann
24+
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
25+
////////////////////////////////////////////////////////////////////////////////
26+
27+
#ifndef VELOCYPACK_UTF8HELPER_H
28+
#define VELOCYPACK_UTF8HELPER_H 1
29+
30+
#include "velocypack/velocypack-common.h"
31+
32+
namespace arangodb {
33+
namespace velocypack {
34+
35+
struct Utf8Helper {
36+
static bool isValidUtf8(uint8_t const* p, ValueLength len);
37+
};
38+
39+
}
40+
}
41+
42+
#endif

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ using VPackSlimBuffer = arangodb::velocypack::SliceContainer;
151151
#endif
152152
#endif
153153

154+
#ifdef VELOCYPACK_UTF8HELPER_H
155+
#ifndef VELOCYPACK_ALIAS_UTF8HELPER
156+
#define VELOCYPACK_ALIAS_UTF8HELPER
157+
using VPackUtf8Helper = arangodb::velocypack::Utf8Helper;
158+
#endif
159+
#endif
160+
154161
#ifdef VELOCYPACK_VALIDATOR_H
155162
#ifndef VELOCYPACK_ALIAS_VALIDATOR
156163
#define VELOCYPACK_ALIAS_VALIDATOR
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// @brief Library to build up VPack documents.
3+
///
4+
/// DISCLAIMER
5+
///
6+
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
7+
///
8+
/// Licensed under the Apache License, Version 2.0 (the "License");
9+
/// you may not use this file except in compliance with the License.
10+
/// You may obtain a copy of the License at
11+
///
12+
/// http://www.apache.org/licenses/LICENSE-2.0
13+
///
14+
/// Unless required by applicable law or agreed to in writing, software
15+
/// distributed under the License is distributed on an "AS IS" BASIS,
16+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
/// See the License for the specific language governing permissions and
18+
/// limitations under the License.
19+
///
20+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
21+
///
22+
/// @author Max Neunhoeffer
23+
/// @author Jan Steemann
24+
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
25+
////////////////////////////////////////////////////////////////////////////////
26+
27+
#include "velocypack/velocypack-common.h"
28+
#include "velocypack/Utf8Helper.h"
29+
30+
using namespace arangodb::velocypack;
31+
32+
namespace {
33+
34+
static constexpr uint8_t ValidChar = 0;
35+
static constexpr uint8_t InvalidChar = 1;
36+
37+
static const uint8_t states[] = {
38+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
39+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
40+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
41+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
42+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
43+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
44+
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
45+
0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
46+
0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
47+
0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
48+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
49+
1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
50+
1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
51+
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
52+
};
53+
54+
}
55+
56+
bool Utf8Helper::isValidUtf8(uint8_t const* p, ValueLength len) {
57+
uint8_t const* end = p + len;
58+
59+
uint8_t state = ValidChar;
60+
while (p < end) {
61+
state = states[256 + state * 16 + states[*p]];
62+
if (state == InvalidChar) {
63+
return false;
64+
}
65+
++p;
66+
}
67+
68+
return (state == ValidChar);
69+
}

3rdParty/velocypack/src/Validator.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "velocypack/Validator.h"
2929
#include "velocypack/Exception.h"
3030
#include "velocypack/Slice.h"
31+
#include "velocypack/Utf8Helper.h"
3132
#include "velocypack/ValueType.h"
3233

3334
using namespace arangodb::velocypack;
@@ -88,11 +89,23 @@ bool Validator::validate(uint8_t const* ptr, size_t length, bool isSubPart) cons
8889
}
8990

9091
case ValueType::String: {
92+
uint8_t const* p;
93+
ValueLength len;
9194
if (head == 0xbfU) {
9295
// long UTF-8 string. must be at least 9 bytes long so we
9396
// can read the entire string length safely
9497
validateBufferLength(1 + 8, length, true);
95-
}
98+
p = ptr + 1 + 8;
99+
len = readInteger<ValueLength>(p, 8);
100+
} else {
101+
p = ptr + 1;
102+
len = head - 0x40U;
103+
}
104+
validateBufferLength(length - (p - ptr), len, true);
105+
106+
if (options->validateUtf8Strings && !Utf8Helper::isValidUtf8(p, len)) {
107+
throw Exception(Exception::InvalidUtf8Sequence);
108+
}
96109
break;
97110
}
98111

UnitTests/Basics/hashes-test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,38 @@ BOOST_FIXTURE_TEST_SUITE(CHashesTest, CHashesSetup)
8686
/// @brief test fasthash64
8787
////////////////////////////////////////////////////////////////////////////////
8888

89+
BOOST_AUTO_TEST_CASE (tst_fasthash64_uint64) {
90+
uint64_t value;
91+
92+
value = 0;
93+
BOOST_CHECK_EQUAL((uint64_t) 606939172421154273ULL, fasthash64(&value, sizeof(value), 0x12345678));
94+
BOOST_CHECK_EQUAL((uint64_t) 606939172421154273ULL, fasthash64_uint64(value, 0x12345678));
95+
96+
value = 1;
97+
BOOST_CHECK_EQUAL((uint64_t) 2986466439906256014ULL, fasthash64(&value, sizeof(value), 0x12345678));
98+
BOOST_CHECK_EQUAL((uint64_t) 2986466439906256014ULL, fasthash64_uint64(value, 0x12345678));
99+
100+
value = 123456;
101+
BOOST_CHECK_EQUAL((uint64_t) 10846706210321519612ULL, fasthash64(&value, sizeof(value), 0x12345678));
102+
BOOST_CHECK_EQUAL((uint64_t) 10846706210321519612ULL, fasthash64_uint64(value, 0x12345678));
103+
104+
value = 123456789012345ULL;
105+
BOOST_CHECK_EQUAL((uint64_t) 11872028338155052138ULL, fasthash64(&value, sizeof(value), 0x12345678));
106+
BOOST_CHECK_EQUAL((uint64_t) 11872028338155052138ULL, fasthash64_uint64(value, 0x12345678));
107+
108+
value = 0xffffff000000ULL;
109+
BOOST_CHECK_EQUAL((uint64_t) 5064027312035038651ULL, fasthash64(&value, sizeof(value), 0x12345678));
110+
BOOST_CHECK_EQUAL((uint64_t) 5064027312035038651ULL, fasthash64_uint64(value, 0x12345678));
111+
112+
value = 0xffffffffffffULL;
113+
BOOST_CHECK_EQUAL((uint64_t) 12472603196990564371ULL, fasthash64(&value, sizeof(value), 0x12345678));
114+
BOOST_CHECK_EQUAL((uint64_t) 12472603196990564371ULL, fasthash64_uint64(value, 0x12345678));
115+
}
116+
117+
////////////////////////////////////////////////////////////////////////////////
118+
/// @brief test fasthash64
119+
////////////////////////////////////////////////////////////////////////////////
120+
89121
BOOST_AUTO_TEST_CASE (tst_fasthash64) {
90122
std::string buffer;
91123

arangod/Agency/Supervision.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,12 @@ void Supervision::enforceReplication() {
621621
auto const& db = *(db_.second);
622622
for (const auto& col_ : db.children()) { // Planned collections
623623
auto const& col = *(col_.second);
624-
auto const& replicationFactor = col("replicationFactor").slice().getUInt();
624+
auto replicationFactor = col("replicationFactor").slice().getUInt();
625+
626+
// mop: satellites => distribute to every server
627+
if (replicationFactor == 0) {
628+
replicationFactor = available.size();
629+
}
625630

626631
bool clone = false;
627632
try {

arangod/Indexes/EdgeIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static uint64_t HashElementEdge(void*, SimpleIndexElement const& element, bool b
6464
}
6565

6666
TRI_voc_rid_t revisionId = element.revisionId();
67-
return fasthash64(&revisionId, sizeof(revisionId), 0x56781234);
67+
return fasthash64_uint64(revisionId, 0x56781234);
6868
}
6969

7070
/// @brief checks if key and element match

arangod/Indexes/HashIndex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class HashIndex final : public PathBasedIndex {
237237
}
238238

239239
TRI_voc_rid_t revisionId = element->revisionId();
240-
return fasthash64(&revisionId, sizeof(revisionId), hash);
240+
return fasthash64_uint64(revisionId, hash);
241241
}
242242
};
243243

arangod/Utils/AqlTransaction.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ int AqlTransaction::processCollectionCoordinator(aql::Collection* collection) {
5656
/// @brief add a regular collection to the transaction
5757

5858
int AqlTransaction::processCollectionNormal(aql::Collection* collection) {
59-
arangodb::LogicalCollection const* col =
60-
this->resolver()->getCollectionStruct(collection->getName());
6159
TRI_voc_cid_t cid = 0;
6260

61+
arangodb::LogicalCollection const* col =
62+
this->resolver()->getCollectionStruct(collection->getName());
63+
if (col == nullptr) {
64+
auto startTime = TRI_microtime();
65+
auto endTime = startTime + 60.0;
66+
do {
67+
usleep(10000);
68+
if (TRI_microtime() > endTime) {
69+
break;
70+
}
71+
col = this->resolver()->getCollectionStruct(collection->getName());
72+
} while (col == nullptr);
73+
}
6374
if (col != nullptr) {
6475
cid = col->cid();
6576
}

arangod/V8Server/v8-query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static void JS_ChecksumCollection(
394394
if (withData) {
395395
// with data
396396
uint64_t const n = slice.length() ^ 0xf00ba44ba5;
397-
uint64_t seed = fasthash64(&n, sizeof(n), 0xdeadf054);
397+
uint64_t seed = fasthash64_uint64(n, 0xdeadf054);
398398

399399
for (auto const& it : VPackObjectIterator(slice, false)) {
400400
// loop over all attributes, but exclude _rev, _id and _key

0 commit comments

Comments
 (0)
0