@@ -867,7 +867,7 @@ local function process_tuple(self, state, tuple, opts)
867
867
if clock .monotonic64 () > qcontext .deadline_clock then
868
868
error (e .timeout_exceeded ((
869
869
' query execution timeout exceeded timeout_ms limit (%s ms)' ):format (
870
- tostring (self .settings .timeout_ms ))))
870
+ tostring (state . qcontext .settings .timeout_ms ))))
871
871
end
872
872
local collection_name = opts .collection_name
873
873
local pcre = opts .pcre
@@ -1038,11 +1038,12 @@ local function select_internal(self, collection_name, from, filter, args, extra)
1038
1038
collection_name ))
1039
1039
1040
1040
-- read-write variables for process_tuple
1041
+ local qcontext = extra .qcontext
1041
1042
local select_state = {
1042
1043
count = 0 ,
1043
1044
objs = {},
1044
1045
pivot_found = false ,
1045
- qcontext = extra . qcontext
1046
+ qcontext = qcontext
1046
1047
}
1047
1048
1048
1049
-- read only process_tuple options
@@ -1051,8 +1052,8 @@ local function select_internal(self, collection_name, from, filter, args, extra)
1051
1052
filter = filter ,
1052
1053
do_filter = not full_match ,
1053
1054
pivot_filter = nil , -- filled later if needed
1054
- resulting_object_cnt_max = self .settings .resulting_object_cnt_max ,
1055
- fetched_object_cnt_max = self .settings .fetched_object_cnt_max ,
1055
+ resulting_object_cnt_max = qcontext .settings .resulting_object_cnt_max ,
1056
+ fetched_object_cnt_max = qcontext .settings .fetched_object_cnt_max ,
1056
1057
collection_name = collection_name ,
1057
1058
unflatten_tuple = self .funcs .unflatten_tuple ,
1058
1059
use_tomap = self .collection_use_tomap [collection_name ] or false ,
@@ -1079,10 +1080,10 @@ local function select_internal(self, collection_name, from, filter, args, extra)
1079
1080
collection_name )
1080
1081
1081
1082
-- count full scan select request
1082
- extra . qcontext .statistics .select_requests_cnt =
1083
- extra . qcontext .statistics .select_requests_cnt + 1
1084
- extra . qcontext .statistics .full_scan_select_requests_cnt =
1085
- extra . qcontext .statistics .full_scan_select_requests_cnt + 1
1083
+ qcontext .statistics .select_requests_cnt =
1084
+ qcontext .statistics .select_requests_cnt + 1
1085
+ qcontext .statistics .full_scan_select_requests_cnt =
1086
+ qcontext .statistics .full_scan_select_requests_cnt + 1
1086
1087
1087
1088
for _ , tuple in primary_index :pairs () do
1088
1089
assert (pivot == nil ,
@@ -1127,10 +1128,10 @@ local function select_internal(self, collection_name, from, filter, args, extra)
1127
1128
local tuple_count = 0
1128
1129
1129
1130
-- count index select request
1130
- extra . qcontext .statistics .select_requests_cnt =
1131
- extra . qcontext .statistics .select_requests_cnt + 1
1132
- extra . qcontext .statistics .index_select_requests_cnt =
1133
- extra . qcontext .statistics .index_select_requests_cnt + 1
1131
+ qcontext .statistics .select_requests_cnt =
1132
+ qcontext .statistics .select_requests_cnt + 1
1133
+ qcontext .statistics .index_select_requests_cnt =
1134
+ qcontext .statistics .index_select_requests_cnt + 1
1134
1135
1135
1136
for _ , tuple in index :pairs (index_value , iterator_opts ) do
1136
1137
tuple_count = tuple_count + 1
@@ -1307,23 +1308,62 @@ local function validate_funcs(funcs)
1307
1308
type (funcs .delete_tuple ))
1308
1309
end
1309
1310
1311
+ local function validate_settings (settings , opts )
1312
+ local opts = opts or {}
1313
+ local allow_nil = opts .allow_nil or false
1314
+
1315
+ local resulting_object_cnt_max = settings .resulting_object_cnt_max
1316
+ local fetched_object_cnt_max = settings .fetched_object_cnt_max
1317
+ local timeout_ms = settings .timeout_ms
1318
+ local enable_mutations = settings .enable_mutations
1319
+
1320
+ if not allow_nil or type (resulting_object_cnt_max ) ~= ' nil' then
1321
+ assert (type (resulting_object_cnt_max ) == ' number' and
1322
+ resulting_object_cnt_max > 0 ,
1323
+ ' resulting_object_cnt_max must be natural number' )
1324
+ end
1325
+ if not allow_nil or type (fetched_object_cnt_max ) ~= ' nil' then
1326
+ assert (type (fetched_object_cnt_max ) == ' number' and
1327
+ fetched_object_cnt_max > 0 ,
1328
+ ' fetched_object_cnt_max must be natural number' )
1329
+ end
1330
+ if not allow_nil or type (timeout_ms ) ~= ' nil' then
1331
+ assert (type (timeout_ms ) == ' number' or (type (timeout_ms ) == ' cdata' and
1332
+ tostring (ffi .typeof (timeout_ms )) == ' ctype<uint64_t>' ),
1333
+ ' timeout_ms must a number, got ' .. type (timeout_ms ))
1334
+ assert (timeout_ms <= TIMEOUT_INFINITY ,
1335
+ (' timeouts more then graphql.TIMEOUT_INFINITY (%s) ' ..
1336
+ ' do not supported' ):format (tostring (TIMEOUT_INFINITY )))
1337
+ end
1338
+ if not allow_nil or type (enable_mutations ) ~= ' nil' then
1339
+ check (enable_mutations , ' enable_mutations' , ' boolean' )
1340
+ end
1341
+ end
1342
+
1310
1343
--- This function is called on first select related to a query. Its purpose is
1311
1344
--- to initialize qcontext table.
1312
1345
--- @tparam table accessor
1313
1346
--- @tparam table qcontext per-query table which stores query internal state;
1314
1347
--- all neccessary initialization of this parameter should be performed by this
1315
1348
-- function
1316
1349
local function init_qcontext (accessor , qcontext )
1317
- local settings = accessor .settings
1350
+ for k , v in pairs (accessor .settings ) do
1351
+ if qcontext .settings [k ] == nil then
1352
+ qcontext .settings [k ] = v
1353
+ end
1354
+ end
1355
+ validate_settings (qcontext .settings )
1356
+
1357
+ qcontext .deadline_clock = clock .monotonic64 () +
1358
+ qcontext .settings .timeout_ms * 1000 * 1000
1359
+
1318
1360
qcontext .statistics = {
1319
1361
resulting_object_cnt = 0 ,
1320
1362
fetched_object_cnt = 0 ,
1321
1363
select_requests_cnt = 0 ,
1322
1364
full_scan_select_requests_cnt = 0 ,
1323
1365
index_select_requests_cnt = 0 ,
1324
1366
}
1325
- qcontext .deadline_clock = clock .monotonic64 () +
1326
- settings .timeout_ms * 1000 * 1000
1327
1367
end
1328
1368
1329
1369
--- Create default unflatten/flatten/xflatten functions, that can be called
@@ -1474,11 +1514,16 @@ function accessor_general.new(opts, funcs)
1474
1514
local collections = opts .collections
1475
1515
local service_fields = opts .service_fields
1476
1516
local indexes = opts .indexes
1517
+
1518
+ check (schemas , ' schemas' , ' table' )
1519
+ check (collections , ' collections' , ' table' )
1520
+ check (service_fields , ' service_fields' , ' table' )
1521
+ check (indexes , ' indexes' , ' table' )
1522
+
1477
1523
local resulting_object_cnt_max = opts .resulting_object_cnt_max or
1478
- DEF_RESULTING_OBJECT_CNT_MAX
1524
+ DEF_RESULTING_OBJECT_CNT_MAX
1479
1525
local fetched_object_cnt_max = opts .fetched_object_cnt_max or
1480
- DEF_FETCHED_OBJECT_CNT_MAX
1481
- -- TODO: move this setting to `tgql.compile` after #59
1526
+ DEF_FETCHED_OBJECT_CNT_MAX
1482
1527
local timeout_ms = opts .timeout_ms or DEF_TIMEOUT_MS
1483
1528
-- Mutations are disabled for avro-schema-2*, because it can work
1484
1529
-- incorrectly for schemas with nullable types.
@@ -1488,28 +1533,13 @@ function accessor_general.new(opts, funcs)
1488
1533
else
1489
1534
enable_mutations = opts .enable_mutations
1490
1535
end
1491
-
1492
- assert (type (schemas ) == ' table' ,
1493
- ' schemas must be a table, got ' .. type (schemas ))
1494
- assert (type (collections ) == ' table' ,
1495
- ' collections must be a table, got ' .. type (collections ))
1496
- assert (type (service_fields ) == ' table' ,
1497
- ' service_fields must be a table, got ' .. type (service_fields ))
1498
- assert (type (indexes ) == ' table' ,
1499
- ' indexes must be a table, got ' .. type (indexes ))
1500
- assert (type (resulting_object_cnt_max ) == ' number' and
1501
- resulting_object_cnt_max > 0 ,
1502
- ' resulting_object_cnt_max must be natural number' )
1503
- assert (type (fetched_object_cnt_max ) == ' number' and
1504
- fetched_object_cnt_max > 0 ,
1505
- ' fetched_object_cnt_max must be natural number' )
1506
- assert (type (timeout_ms ) == ' number' or (type (timeout_ms ) == ' cdata' and
1507
- tostring (ffi .typeof (timeout_ms )) == ' ctype<uint64_t>' ),
1508
- ' timeout_ms must a number, got ' .. type (timeout_ms ))
1509
- assert (timeout_ms <= TIMEOUT_INFINITY ,
1510
- (' timeouts more then graphql.TIMEOUT_INFINITY (%s) ' ..
1511
- ' do not supported' ):format (tostring (TIMEOUT_INFINITY )))
1512
- check (enable_mutations , ' enable_mutations' , ' boolean' )
1536
+ local settings = {
1537
+ resulting_object_cnt_max = resulting_object_cnt_max ,
1538
+ fetched_object_cnt_max = fetched_object_cnt_max ,
1539
+ timeout_ms = timeout_ms ,
1540
+ enable_mutations = enable_mutations ,
1541
+ }
1542
+ validate_settings (settings )
1513
1543
1514
1544
local models , service_fields_defaults = compile_schemas (schemas ,
1515
1545
service_fields )
@@ -1536,12 +1566,7 @@ function accessor_general.new(opts, funcs)
1536
1566
collection_use_tomap = opts .collection_use_tomap or {},
1537
1567
index_cache = index_cache ,
1538
1568
funcs = funcs ,
1539
- settings = {
1540
- resulting_object_cnt_max = resulting_object_cnt_max ,
1541
- fetched_object_cnt_max = fetched_object_cnt_max ,
1542
- timeout_ms = timeout_ms ,
1543
- enable_mutations = enable_mutations ,
1544
- }
1569
+ settings = settings ,
1545
1570
}, {
1546
1571
__index = {
1547
1572
select = function (self , parent , collection_name , from ,
@@ -1576,4 +1601,7 @@ function accessor_general.new(opts, funcs)
1576
1601
})
1577
1602
end
1578
1603
1604
+ -- export the function
1605
+ accessor_general .validate_settings = validate_settings
1606
+
1579
1607
return accessor_general
0 commit comments