@@ -76,11 +76,20 @@ def list(cls):
76
76
)
77
77
78
78
79
- def get_table_description (table_name ):
80
- return """
79
+ def get_table_description (table_name , mode ):
80
+ if mode == "row" :
81
+ store_entry = "STORE = ROW,"
82
+ ttl_entry = """TTL = Interval("PT240S") ON `timestamp` AS SECONDS,"""
83
+ elif mode == "column" :
84
+ store_entry = "STORE = COLUMN,"
85
+ ttl_entry = ""
86
+ else :
87
+ raise RuntimeError ("Unkown mode: {}" .format (mode ))
88
+
89
+ return f"""
81
90
CREATE TABLE `{ table_name } ` (
82
91
key Uint64 NOT NULL,
83
- `timestamp` Timestamp, -- NOT NULL, -- not working for now
92
+ `timestamp` Uint64 NOT NULL,
84
93
value Utf8 FAMILY lz4_family NOT NULL,
85
94
PRIMARY KEY (key),
86
95
FAMILY lz4_family (
@@ -89,7 +98,8 @@ def get_table_description(table_name):
89
98
INDEX by_timestamp GLOBAL ON (`timestamp`)
90
99
)
91
100
WITH (
92
- TTL = Interval("PT240S") ON `timestamp`,
101
+ { store_entry }
102
+ { ttl_entry }
93
103
AUTO_PARTITIONING_BY_SIZE = ENABLED,
94
104
AUTO_PARTITIONING_BY_LOAD = ENABLED,
95
105
AUTO_PARTITIONING_PARTITION_SIZE_MB = 128,
@@ -100,7 +110,7 @@ def get_table_description(table_name):
100
110
101
111
102
112
def timestamp ():
103
- return int (1000 * time .time ())
113
+ return int (time .time ())
104
114
105
115
106
116
def extract_keys (response ):
@@ -180,7 +190,7 @@ def print_stats(self):
180
190
181
191
182
192
class YdbQueue (object ):
183
- def __init__ (self , idx , database , stats , driver , pool ):
193
+ def __init__ (self , idx , database , stats , driver , pool , mode ):
184
194
self .working_dir = os .path .join (database , socket .gethostname ().split ('.' )[0 ].replace ('-' , '_' ) + "_" + str (idx ))
185
195
self .copies_dir = os .path .join (self .working_dir , 'copies' )
186
196
self .table_name = self .table_name_with_timestamp ()
@@ -195,6 +205,7 @@ def __init__(self, idx, database, stats, driver, pool):
195
205
self .ops = ydb .BaseRequestSettings ().with_operation_timeout (19 ).with_timeout (20 )
196
206
self .driver .scheme_client .make_directory (self .working_dir )
197
207
self .driver .scheme_client .make_directory (self .copies_dir )
208
+ self .mode = mode
198
209
print ("Working dir %s" % self .working_dir )
199
210
f = self .prepare_new_queue (self .table_name )
200
211
f .result ()
@@ -212,7 +223,7 @@ def table_name_with_timestamp(self, working_dir=None):
212
223
def prepare_new_queue (self , table_name = None ):
213
224
session = self .pool .acquire ()
214
225
table_name = self .table_name_with_timestamp () if table_name is None else table_name
215
- f = session .async_execute_scheme (get_table_description (table_name ), settings = self .ops )
226
+ f = session .async_execute_scheme (get_table_description (table_name , self . mode ), settings = self .ops )
216
227
f .add_done_callback (lambda x : self .on_received_response (session , x , 'create' ))
217
228
return f
218
229
@@ -230,6 +241,12 @@ def on_received_response(self, session, response, event, callback=None):
230
241
response .result ()
231
242
self .stats .save_event (event )
232
243
except ydb .Error as e :
244
+ debug = False
245
+ if debug :
246
+ print (event )
247
+ print (e )
248
+ print ()
249
+
233
250
self .stats .save_event (event , e .status )
234
251
235
252
def send_query (self , query , parameters , event_kind , callback = None ):
@@ -335,7 +352,7 @@ def write(self):
335
352
DECLARE $key as Uint64;
336
353
DECLARE $value as Utf8;
337
354
DECLARE $timestamp as Uint64;
338
- UPSERT INTO `{}` (`key`, `timestamp`, `value`) VALUES ($key, CAST( $timestamp as Timestamp) , $value);
355
+ UPSERT INTO `{}` (`key`, `timestamp`, `value`) VALUES ($key, $timestamp, $value);
339
356
""" .format (self .table_name ),
340
357
{
341
358
'$key' : ydb .PrimitiveType .Uint64 .proto ,
@@ -429,16 +446,18 @@ def copy_table(self):
429
446
430
447
431
448
class Workload (object ):
432
- def __init__ (self , endpoint , database , duration ):
449
+ def __init__ (self , endpoint , database , duration , mode ):
433
450
self .database = database
434
451
self .driver = ydb .Driver (ydb .DriverConfig (endpoint , database ))
435
452
self .pool = ydb .SessionPool (self .driver , size = 200 )
436
453
self .round_size = 1000
437
454
self .duration = duration
438
455
self .delayed_events = queue .Queue ()
439
456
self .workload_stats = WorkloadStats (* EventKind .list ())
457
+ # TODO: run both modes in parallel?
458
+ self .mode = mode
440
459
self .ydb_queues = [
441
- YdbQueue (idx , database , self .workload_stats , self .driver , self .pool )
460
+ YdbQueue (idx , database , self .workload_stats , self .driver , self .pool , self . mode )
442
461
for idx in range (2 )
443
462
]
444
463
@@ -511,7 +530,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
511
530
parser .add_argument ('--endpoint' , default = 'localhost:2135' , help = "An endpoint to be used" )
512
531
parser .add_argument ('--database' , default = None , required = True , help = 'A database to connect' )
513
532
parser .add_argument ('--duration' , default = 10 ** 9 , type = lambda x : int (x ), help = 'A duration of workload in seconds.' )
533
+ parser .add_argument ('--mode' , default = "row" , choices = ["row" , "column" ], help = 'STORE mode for CREATE TABLE' )
514
534
args = parser .parse_args ()
515
- with Workload (args .endpoint , args .database , args .duration ) as workload :
535
+ with Workload (args .endpoint , args .database , args .duration , args . mode ) as workload :
516
536
for handle in workload .loop ():
517
537
handle ()
0 commit comments