Skip to content

Commit 001865c

Browse files
author
Luke Bakken
committed
Improve unix timestamp -> datetime conversion, update to riak_pb 2.1.3.0
1 parent 2de89c4 commit 001865c

12 files changed

Lines changed: 149 additions & 213 deletions

File tree

riak/codecs/ttb.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from riak import RiakError
88
from riak.codecs import Codec, Msg
9+
from riak.pb.messages import MSG_CODE_TS_TTB_MSG
910
from riak.ts_object import TsColumns
1011
from riak.util import bytes_to_str, unix_time_millis, \
1112
datetime_from_unix_time_millis
@@ -23,9 +24,6 @@
2324
tsdelreq_a = Atom('tsdelreq')
2425
timestamp_a = Atom('timestamp')
2526

26-
# TODO RTS-842
27-
MSG_CODE_TS_TTB = 104
28-
2927

3028
class TtbCodec(Codec):
3129
'''
@@ -36,7 +34,7 @@ def __init__(self, **unused_args):
3634
super(TtbCodec, self).__init__(**unused_args)
3735

3836
def parse_msg(self, msg_code, data):
39-
if msg_code != MSG_CODE_TS_TTB:
37+
if msg_code != MSG_CODE_TS_TTB_MSG:
4038
raise RiakError("TTB can't parse code: {}".format(msg_code))
4139
if len(data) > 0:
4240
decoded = decode(data)
@@ -61,6 +59,7 @@ def encode_to_ts_cell(self, cell):
6159
else:
6260
if isinstance(cell, datetime.datetime):
6361
ts = unix_time_millis(cell)
62+
# logging.debug('encoded datetime %s as %s', cell, ts)
6463
return ts
6564
elif isinstance(cell, bool):
6665
return cell
@@ -84,19 +83,19 @@ def encode_timeseries_keyreq(self, table, key, is_delete=False):
8483
else:
8584
raise ValueError("key must be a list")
8685

87-
mc = MSG_CODE_TS_TTB
88-
rc = MSG_CODE_TS_TTB
86+
mc = MSG_CODE_TS_TTB_MSG
87+
rc = MSG_CODE_TS_TTB_MSG
8988
req_atom = tsgetreq_a
9089
if is_delete:
9190
req_atom = tsdelreq_a
9291

93-
# TODO RTS-842 timeout is last
92+
# TODO FUTURE add timeout as last param
9493
req = req_atom, table.name, \
9594
[self.encode_to_ts_cell(k) for k in key_vals], udef_a
9695
return Msg(mc, encode(req), rc)
9796

9897
def validate_timeseries_put_resp(self, resp_code, resp):
99-
if resp is None and resp_code == MSG_CODE_TS_TTB:
98+
if resp is None and resp_code == MSG_CODE_TS_TTB_MSG:
10099
return True
101100
if resp is not None:
102101
return True
@@ -123,8 +122,8 @@ def encode_timeseries_put(self, tsobj):
123122
req_r.append(self.encode_to_ts_cell(cell))
124123
req_rows.append(tuple(req_r))
125124
req = tsputreq_a, tsobj.table.name, [], req_rows
126-
mc = MSG_CODE_TS_TTB
127-
rc = MSG_CODE_TS_TTB
125+
mc = MSG_CODE_TS_TTB_MSG
126+
rc = MSG_CODE_TS_TTB_MSG
128127
return Msg(mc, encode(req), rc)
129128
else:
130129
raise RiakError("TsObject requires a list of rows")
@@ -135,8 +134,8 @@ def encode_timeseries_query(self, table, query, interpolations=None):
135134
q = q.format(table=table.name)
136135
tsi = tsinterpolation_a, q, []
137136
req = tsqueryreq_a, tsi, False, []
138-
mc = MSG_CODE_TS_TTB
139-
rc = MSG_CODE_TS_TTB
137+
mc = MSG_CODE_TS_TTB_MSG
138+
rc = MSG_CODE_TS_TTB_MSG
140139
return Msg(mc, encode(req), rc)
141140

142141
def decode_timeseries(self, resp_ttb, tsobj):

riak/pb/messages.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@
8181
MSG_CODE_TS_COVERAGE_RESP = 101
8282
MSG_CODE_TS_COVERAGE_ENTRY = 102
8383
MSG_CODE_TS_RANGE = 103
84-
MSG_CODE_TS_TTB_PUT_REQ = 104
85-
MSG_CODE_TOGGLE_ENCODING_REQ = 110
86-
MSG_CODE_TOGGLE_ENCODING_RESP = 111
84+
MSG_CODE_TS_TTB_MSG = 104
8785
MSG_CODE_AUTH_REQ = 253
8886
MSG_CODE_AUTH_RESP = 254
8987
MSG_CODE_START_TLS = 255
@@ -168,9 +166,7 @@
168166
MSG_CODE_TS_COVERAGE_RESP: riak.pb.riak_ts_pb2.TsCoverageResp,
169167
MSG_CODE_TS_COVERAGE_ENTRY: riak.pb.riak_ts_pb2.TsCoverageEntry,
170168
MSG_CODE_TS_RANGE: riak.pb.riak_ts_pb2.TsRange,
171-
MSG_CODE_TS_TTB_PUT_REQ: riak.pb.riak_ts_pb2.TsTtbPutReq,
172-
MSG_CODE_TOGGLE_ENCODING_REQ: riak.pb.riak_pb2.RpbToggleEncodingReq,
173-
MSG_CODE_TOGGLE_ENCODING_RESP: riak.pb.riak_pb2.RpbToggleEncodingResp,
169+
MSG_CODE_TS_TTB_MSG: None,
174170
MSG_CODE_AUTH_REQ: riak.pb.riak_pb2.RpbAuthReq,
175171
MSG_CODE_AUTH_RESP: None,
176172
MSG_CODE_START_TLS: None

riak/pb/riak_pb2.py

Lines changed: 1 addition & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)