1
0
Fork 0

Change encoding of HLC time stamps, tolerate old ticks in _rev.

This commit is contained in:
Max Neunhoeffer 2016-07-12 14:01:33 +02:00
parent 8f69fb74f5
commit 17e4c05de5
2 changed files with 36 additions and 8 deletions

View File

@ -2359,7 +2359,13 @@ void TRI_SanitizeObjectWithEdges(VPackSlice const slice, VPackBuilder& builder)
/// @brief Convert a revision ID to a string
////////////////////////////////////////////////////////////////////////////////
constexpr static TRI_voc_rid_t tickLimit
= static_cast<TRI_voc_rid_t>(2016-1970) * 1000 * 60 * 60 * 24 * 365;
std::string TRI_RidToString(TRI_voc_rid_t rid) {
if (rid <= tickLimit) {
return arangodb::basics::StringUtils::itoa(rid);
}
return HybridLogicalClock::encodeTimeStamp(rid);
}
@ -2368,7 +2374,7 @@ std::string TRI_RidToString(TRI_voc_rid_t rid) {
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t TRI_StringToRid(std::string const& ridStr) {
return HybridLogicalClock::decodeTimeStamp(ridStr);
return TRI_StringToRid(ridStr.c_str(), ridStr.size());
}
////////////////////////////////////////////////////////////////////////////////
@ -2376,6 +2382,17 @@ TRI_voc_rid_t TRI_StringToRid(std::string const& ridStr) {
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t TRI_StringToRid(char const* p, size_t len) {
if (len > 0 && *p >= '1' && *p <= '9') {
// Remove this case before the year 3887 AD because then it will
// start to clash with encoded timestamps:
TRI_voc_rid_t r = arangodb::basics::StringUtils::uint64(p, len);
if (r > tickLimit) {
// An old tick value that could be confused with a time stamp
LOG(WARN)
<< "Saw old _rev value that could be confused with a time stamp!";
}
return r;
}
return HybridLogicalClock::decodeTimeStamp(p, len);
}
@ -2384,7 +2401,7 @@ TRI_voc_rid_t TRI_StringToRid(char const* p, size_t len) {
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t TRI_StringToRidWithCheck(std::string const& ridStr) {
return HybridLogicalClock::decodeTimeStampWithCheck(ridStr);
return TRI_StringToRidWithCheck(ridStr.c_str(), ridStr.size());
}
////////////////////////////////////////////////////////////////////////////////
@ -2392,6 +2409,17 @@ TRI_voc_rid_t TRI_StringToRidWithCheck(std::string const& ridStr) {
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t TRI_StringToRidWithCheck(char const* p, size_t len) {
if (len > 0 && *p >= '1' && *p <= '9') {
// Remove this case before the year 3887 AD because then it will
// start to clash with encoded timestamps:
TRI_voc_rid_t r = arangodb::basics::StringUtils::uint64_check(p, len);
if (r > tickLimit) {
// An old tick value that could be confused with a time stamp
LOG(WARN)
<< "Saw old _rev value that could be confused with a time stamp!";
}
return r;
}
return HybridLogicalClock::decodeTimeStampWithCheck(p, len);
}

View File

@ -24,17 +24,17 @@
#include "Basics/HybridLogicalClock.h"
char arangodb::basics::HybridLogicalClock::encodeTable[65]
= "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
= "-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
char arangodb::basics::HybridLogicalClock::decodeTable[256]
= {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0 - 15
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 16 - 31
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,-1,-1, // 32 - 47
1, 2, 3, 4, 5, 6, 7, 8, 9,10,-1,-1,-1,-1,-1,-1, // 48 - 63
-1,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, // 64 - 79
26,27,28,29,30,31,32,33,34,35,36,-1,-1,-1,-1,37, // 80 - 95
-1,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52, // 96 - 111
53,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1, // 112 - 127
54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1, // 48 - 63
-1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, // 64 - 79
17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1, 1, // 80 - 95
-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42, // 96 - 111
43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1, // 112 - 127
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 128 - 143
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 144 - 159
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 160 - 175