db: Use microsecond precision for server-side timestamps
Currently server-side timestamps use a clock with millisecond precision. Timestamps have microsecond resolution, with lower bits used to serialize mutations originating from given client. Timestamps for column drops always use just the millisecond base. A column drop which is executed after an insert may thus be given lower timestamp than the insert, even when the two are serialized on the client side over same connection. Use microsecond precision to reduce chances of that event. This is supposed to fix sporadic failures of schema_test.py:TestSchema.drop_column_queries_test dtest. Message-Id: <1482343119-27698-1-git-send-email-tgrabiec@scylladb.com>
This commit is contained in:
committed by
Paweł Dziepak
parent
875635554d
commit
d87d50dc64
22
timestamp.hh
22
timestamp.hh
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <chrono>
|
||||
#include "db_clock.hh"
|
||||
|
||||
namespace api {
|
||||
@@ -32,9 +33,28 @@ timestamp_type constexpr missing_timestamp = std::numeric_limits<timestamp_type>
|
||||
timestamp_type constexpr min_timestamp = std::numeric_limits<timestamp_type>::min() + 1;
|
||||
timestamp_type constexpr max_timestamp = std::numeric_limits<timestamp_type>::max();
|
||||
|
||||
// Used for generating server-side mutation timestamps.
|
||||
// Same epoch as Java's System.currentTimeMillis() for compatibility.
|
||||
// Satisfies requirements of TrivialClock.
|
||||
class timestamp_clock {
|
||||
using base = std::chrono::system_clock;
|
||||
public:
|
||||
using rep = timestamp_type;
|
||||
using duration = std::chrono::microseconds;
|
||||
using period = typename duration::period;
|
||||
using time_point = std::chrono::time_point<timestamp_clock, duration>;
|
||||
|
||||
static constexpr bool is_steady = base::is_steady;
|
||||
|
||||
static time_point now() noexcept {
|
||||
auto now_since_epoch = base::now() - base::from_time_t(0);
|
||||
return time_point(std::chrono::duration_cast<duration>(now_since_epoch)) + get_clocks_offset();
|
||||
}
|
||||
};
|
||||
|
||||
static inline
|
||||
timestamp_type new_timestamp() {
|
||||
return db_clock::now_in_usecs();
|
||||
return timestamp_clock::now().time_since_epoch().count();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user