query: Optionally send cell ttl

This patch adds support to send a cell's ttl as part of a query's
result. This is needed for thrift support.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2016-06-19 21:25:27 +02:00
parent eb8f5fafb2
commit 21d0a2c764
4 changed files with 24 additions and 8 deletions

View File

@@ -6,6 +6,8 @@ class qr_cell stub [[writable]] {
// Specified by CQL binary protocol, according to cql_serialization_format in read_command.
bytes value;
std::experimental::optional<gc_clock::duration> ttl [[version 1.3]] = { }; // present when send_ttl option set in partition_slice
};
class qr_row stub [[writable]] {

View File

@@ -564,14 +564,20 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, ::atomic_cell
return std::move(wr).skip_timestamp();
}
}();
[&, wr = std::move(after_timestamp)] () mutable {
auto after_value = [&, wr = std::move(after_timestamp)] () mutable {
if (slice.options.contains<query::partition_slice::option::send_expiry>() && c.is_live_and_has_ttl()) {
return std::move(wr).write_expiry(c.expiry());
} else {
return std::move(wr).skip_expiry();
}
}().write_value(c.value())
.end_qr_cell();
}().write_value(c.value());
[&, wr = std::move(after_value)] () mutable {
if (slice.options.contains<query::partition_slice::option::send_ttl>() && c.is_live_and_has_ttl()) {
return std::move(wr).write_ttl(c.ttl());
} else {
return std::move(wr).skip_ttl();
}
}().end_qr_cell();
}
template<typename RowWriter>
@@ -583,6 +589,7 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, const data_ty
w.add().write().skip_timestamp()
.skip_expiry()
.write_value(ctype->to_value(v, slice.cql_format()))
.skip_ttl()
.end_qr_cell();
}

View File

@@ -103,7 +103,7 @@ constexpr auto max_rows = std::numeric_limits<uint32_t>::max();
// Schema-dependent.
class partition_slice {
public:
enum class option { send_clustering_key, send_partition_key, send_timestamp, send_expiry, reversed, distinct, collections_as_maps };
enum class option { send_clustering_key, send_partition_key, send_timestamp, send_expiry, reversed, distinct, collections_as_maps, send_ttl };
using option_set = enum_set<super_enum<option,
option::send_clustering_key,
option::send_partition_key,
@@ -111,7 +111,8 @@ public:
option::send_expiry,
option::reversed,
option::distinct,
option::collections_as_maps>>;
option::collections_as_maps,
option::send_ttl>>;
clustering_row_ranges _row_ranges;
public:
std::vector<column_id> static_columns; // TODO: consider using bitmap

View File

@@ -39,10 +39,11 @@ namespace query {
class result_atomic_cell_view {
api::timestamp_type _timestamp;
expiry_opt _expiry;
ttl_opt _ttl;
bytes_view _value;
public:
result_atomic_cell_view(api::timestamp_type timestamp, expiry_opt expiry, bytes_view value)
: _timestamp(timestamp), _expiry(expiry), _value(value) { }
result_atomic_cell_view(api::timestamp_type timestamp, expiry_opt expiry, ttl_opt ttl, bytes_view value)
: _timestamp(timestamp), _expiry(expiry), _ttl(ttl), _value(value) { }
api::timestamp_type timestamp() const {
return _timestamp;
@@ -52,6 +53,10 @@ public:
return _expiry;
}
ttl_opt ttl() const {
return _ttl;
}
bytes_view value() const {
return _value;
}
@@ -82,8 +87,9 @@ public:
ser::qr_cell_view v = *cell_opt;
api::timestamp_type timestamp = v.timestamp().value_or(api::missing_timestamp);
expiry_opt expiry = v.expiry();
ttl_opt ttl = v.ttl();
_tmp_value = v.value();
return {result_atomic_cell_view(timestamp, expiry, _tmp_value)};
return {result_atomic_cell_view(timestamp, expiry, ttl, _tmp_value)};
}
std::experimental::optional<bytes_view> next_collection_cell() {
auto cell_opt = *_i++;