diff --git a/di/compression/VERSION b/di/compression/VERSION new file mode 100644 index 00000000..6e8bf73a --- /dev/null +++ b/di/compression/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/di/permissions/VERSION b/di/permissions/VERSION index 6e8bf73a..0ea3a944 100644 --- a/di/permissions/VERSION +++ b/di/permissions/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/di/permissions/permissions.q b/di/permissions/permissions.q index adee9ad0..6157f700 100644 --- a/di/permissions/permissions.q +++ b/di/permissions/permissions.q @@ -14,8 +14,21 @@ / is permitted rather than refused. / config coercion - a .toml tier gives strings, a .q tier gives typed values -asbool:{[x] $[-1h=type x;x;10h=abs type x;first "B"$(),x;-7h=type x;0<>x;0b]}; -aslong:{[x] $[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]}; +asbool:{[x] + if[-1h=type x;:x]; + if[(type x) in -4 -5 -6 -7 -8 -9h;:0<>x]; + if[10h=abs type x; + s:`$lower (),x; + :$[s in `1`true;1b; + s in `0`false;0b; + '"di.permissions: cannot read \"",(string s),"\" as a boolean - use true or false"]]; + '"di.permissions: cannot read a value of type ",(string type x)," as a boolean - use true or false" + }; +aslong:{[x] + r:$[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]; + if[null r;'"di.permissions: cannot read \"",$[10h=abs type x;(),x;-3!x],"\" as a whole number"]; + r + }; / wildcard/superuser marker for functions and data ALL:`$"*"; diff --git a/di/permissions/test.csv b/di/permissions/test.csv index 920e8516..266efae1 100644 --- a/di/permissions/test.csv +++ b/di/permissions/test.csv @@ -81,6 +81,7 @@ true,0,0,q,`name`public`descrip`params`return~cols pm[`getapimeta][],1,,getapime true,0,0,q,all pm[`getapimeta][][`name] in key pm,1,,every documented name is an exported function comment,0,0,q,,1,,--- a dispatched payload q elides when stringified (di.asyncdispatch's shape) --- +fail,0,0,q,pm[`init][badmaxsizecfg[];mockdeps[]],1,,a maxsize that does not parse must error rather than refuse every result run,0,0,q,pm[`init][cfg[1b];mockdeps[]],1,,re-init with the defaults true,0,0,q,"runsok[`alice;elidedpayload[]]",1,,lamq's tokenizer must not signal on an elided function source true,0,0,q,"`.gw.addserverresult~first pm[`requ][`alice;elidedpayload[]]",1,,and the payload runs - it reports the result callback diff --git a/di/permissions/test.q b/di/permissions/test.q index 875f0274..1206e127 100644 --- a/di/permissions/test.q +++ b/di/permissions/test.q @@ -19,6 +19,9 @@ badlog:{[] enlist[`log]!enlist `info`warn!({[c;m]};{[c;m]})} cfg:{[e] (enlist`enabled)!enlist e} cfgwith:{[k;v] (`enabled`maxsize`runmode`permissivemode!(1b;200000000;1b;0b)),(enlist k)!enlist v} +/ a maxsize that does not parse +badmaxsizecfg:{[] cfgwith[`maxsize;"2e8x"]} + / which events got an exec owner execevents:{[] asc exec event from reg where phase=`exec} pcregistered:{[] 0x]; + if[10h=abs type x; + s:`$lower (),x; + :$[s in `1`true;1b; + s in `0`false;0b; + '"di.torq.proc.compression: cannot read \"",(string s),"\" as a boolean - use true or false"]]; + '"di.torq.proc.compression: cannot read a value of type ",(string type x)," as a boolean - use true or false" + } + +aslong:{[x] + r:$[-7h=type x;x;10h=abs type x;"J"$(),x;"j"$x]; + if[null r;'"di.torq.proc.compression: cannot read \"",$[10h=abs type x;(),x;-3!x],"\" as a whole number"]; + r + } + +/ code and config under TORQXAPPHOME, runtime data under TORQXDATAHOME +apphome:{getenv[`TORQXAPPHOME]} +datahome:{$[count h:getenv[`TORQXDATAHOME];h;getenv[`TORQXAPPHOME]]} + +/ resolve a possibly-relative path setting to an absolute path string under base +resolvedir:{[base;dir] + dir:$[10h=abs type dir;(),dir;string dir]; + dir:$[(00; + .z.m.log[`warn][`compression;"exiting 1 - ",(string .z.m.errors)," error(s) during compression"]; + exit 1]; + .z.m.log[`info][`compression;"exitonfinish set, exiting"]; + exit 0; + } + +/ di.compression's post-compression summary table +getstatstab:{[] requireinit[`getstatstab]; (.z.m.cmp`getstatstab)[]} + +/ how many errors the last pass logged +errorcount:{[] requireinit[`errorcount]; .z.m.errors} + +init:{[config;deps] + / resolve and validate before setting any module state + if[not `log in key deps;'"di.torq.proc.compression: log dependency is required - see di.util.log"]; + lg:deps`log; + hp:hsym `$resolvedir[datahome[];$[`hdbpath in key config;config`hdbpath;"hdb"]]; + cp:resolvecsv config; + / defaults - must match the shipped settings file + ma:$[`maxage in key config;aslong config`maxage;30]; + eof:$[`exitonfinish in key config;asbool config`exitonfinish;1b]; + / refuse a missing hdb path + if[not count key hp;lg[`error][`compression;e:"invalid hdb path ",string hp];'e]; + .z.m.errors:0; + .z.m.log:counterrors lg; + .z.m.hdbpath:hp; + .z.m.csvpath:cp; + .z.m.maxage:ma; + .z.m.exitonfinish:eof; + .z.m.cmp:use`di.compression; + (.z.m.cmp`init)[enlist[`log]!enlist .z.m.log]; + / publish at root names for the runhook and IPC callers + set[`.compression.run;run]; + set[`.compression.compressnow;compressnow]; + .z.m.log[`info][`init;"initialised, hdbpath=",(string hp),", csvpath=",(string cp), + ", maxage=",(string ma),", exitonfinish=",string eof]; + } diff --git a/di/torq/proc/compression/deps.toml b/di/torq/proc/compression/deps.toml new file mode 100644 index 00000000..d094894f --- /dev/null +++ b/di/torq/proc/compression/deps.toml @@ -0,0 +1,3 @@ +# Peer modules di.torq.proc.compression `use`s (see di/torq/depcheck/depcheck.md). +[dependencies] +"di.compression" = "0.1.0" diff --git a/di/torq/proc/compression/init.q b/di/torq/proc/compression/init.q new file mode 100644 index 00000000..0632bbb3 --- /dev/null +++ b/di/torq/proc/compression/init.q @@ -0,0 +1,5 @@ +\l ::compression.q + +version:first read0`:::VERSION + +export:([init;compressnow;getstatstab;errorcount;version]) diff --git a/di/torq/proc/compression/test.csv b/di/torq/proc/compression/test.csv new file mode 100644 index 00000000..951c804c --- /dev/null +++ b/di/torq/proc/compression/test.csv @@ -0,0 +1,49 @@ +action,ms,bytes,lang,code,repeat,minver,comment +before,0,0,q,cmp:use`di.torq.proc.compression,1,,load module +before,0,0,q,system "l di/torq/proc/compression/test.q",1,,load mock deps and fixture helpers +before,0,0,q,setupfixture[],1,,build the fixture hdb and its compression csv + +fail,0,0,q,cmp[`init][basecfg[];()!()],1,,init without a log dependency must error +fail,0,0,q,cmp[`compressnow][],1,,compressnow before init must error +fail,0,0,q,cmp[`init][badhdbcfg[];mockdeps[]],1,,init on a missing hdb path must error + +true,0,0,q,`csvpath`hdbpath`maxage`exitonfinish~key shippeddefaults[],1,,the settings file declares every tunable +true,0,0,q,1b~(shippeddefaults[])`exitonfinish,1,,shipped exitonfinish default +true,0,0,q,30~(shippeddefaults[])`maxage,1,,shipped maxage default matches TorQ's config/settings/compression.q + +run,0,0,q,resetcalls[],1,,clear the captured log +run,0,0,q,cmp[`init][nodefaultscfg[];mockdeps[]],1,,init with only the required paths so the code defaults apply +true,0,0,q,initlog[] like "*maxage=30*",1,,code maxage default agrees with the settings file +true,0,0,q,initlog[] like "*exitonfinish=1",1,,code exitonfinish default agrees with the settings file + +run,0,0,q,cmp[`init][basecfg[];mockdeps[]],1,,init with the full fixture config +true,0,0,q,not compressed[PARTS 0;`price],1,,the fixture starts uncompressed +run,0,0,q,cmp[`compressnow][],1,,run one compression pass +true,0,0,q,compressed[PARTS 0;`price],1,,the configured column is compressed in the first partition +true,0,0,q,compressed[PARTS 1;`price],1,,and in the second +true,0,0,q,not compressed[PARTS 0;`size],1,,a column the csv does not name is left alone +true,0,0,q,not compressed[OLD;`price],1,,a partition older than maxage is left alone + +true,0,0,q,100h=type get `.compression.run,1,,run is published at a root name for di.torq's runhook +true,0,0,q,100h=type get `.compression.compressnow,1,,compressnow is published at a root name for IPC callers + +run,0,0,q,teardownfixture[],1,,rebuild the fixture so the toml run has uncompressed files to work on +run,0,0,q,setupfixture[],1,, +run,0,0,q,cmp[`init][tomlcfg[];mockdeps[]],1,,init accepts the string values a .toml settings file delivers +run,0,0,q,cmp[`compressnow][],1,,and compresses with them +true,0,0,q,compressed[PARTS 0;`price],1,,the string-valued maxage was coerced and the pass ran +fail,0,0,q,cmp[`init][badboolcfg[];mockdeps[]],1,,a boolean setting that is neither true/false nor 1/0 must error rather than silently read as false +fail,0,0,q,cmp[`init][symboolcfg[];mockdeps[]],1,,a symbol must error too - it used to fall through the type guard and read as false +fail,0,0,q,cmp[`init][badlongcfg[];mockdeps[]],1,,a maxage that does not parse must error - a 0N maxage compressed nothing and exited 0 + +run,0,0,q,cmp[`init][nocsvcfg[];mockdeps[]],1,,an app with no compression csv falls back to the one the framework ships +true,0,0,q,initlog[] like "*di/torq/compressionconfig.csv*",1,,and the init log names it + +run,0,0,q,writebadalgocsv[],1,,swap in a csv naming an unsupported algorithm +run,0,0,q,cmp[`init][basecfg[];mockdeps[]],1,,point back at the fixture csv - the previous row inited against the framework one +run,0,0,q,resetcalls[],1,,clear the captured log +run,0,0,q,cmp[`compressnow][],1,,an invalid algorithm is logged and skipped rather than thrown - see compression.md +true,0,0,q,0 algo, block, level) +hdbpath:`:hdb / hdb root to compress, under TORQXDATAHOME +maxage:30 / only scan partitions this many days old or newer +exitonfinish:1b / exit when the pass completes diff --git a/di/torq/torq.md b/di/torq/torq.md index 76527af3..44f6d918 100644 --- a/di/torq/torq.md +++ b/di/torq/torq.md @@ -86,13 +86,13 @@ expects. ### Process-type dispatch A built-in registry maps proctype → module name, `` `x → `di.torq.proc.x `` for each of `hdb`, -`tickerplant`, `rdb`, `wdb`, `gateway`, `idb`, `segmentedtp`, `chainedtp`, `housekeeping`, `discovery` -and `tickerlogreplay`; `segmentedchainedtp` also maps to `di.torq.proc.segmentedtp` and resolves the +`tickerplant`, `rdb`, `wdb`, `gateway`, `idb`, `segmentedtp`, `chainedtp`, `housekeeping`, `discovery`, +`tickerlogreplay` and `compression`; `segmentedchainedtp` also maps to `di.torq.proc.segmentedtp` and resolves the `segmentedtp` settings tier (builtin and app root alike); its chained behaviour comes from the instance's own settings, e.g. `sctp1.toml`, as any other per-instance distinction does: ```q -builtin:`hdb`tickerplant`rdb`wdb`gateway`idb`segmentedtp`chainedtp`housekeeping`discovery`tickerlogreplay`segmentedchainedtp!`di.torq.proc.hdb`di.torq.proc.tickerplant ... +builtin:`hdb`tickerplant`rdb`wdb`gateway`idb`segmentedtp`chainedtp`housekeeping`discovery`tickerlogreplay`segmentedchainedtp`compression!`di.torq.proc.hdb`di.torq.proc.tickerplant ... ``` If `proctype` is in `builtin`, `startbuiltin` `use`-loads that module and calls its diff --git a/di/torq/torq.q b/di/torq/torq.q index 44e93d88..a7fb74c2 100644 --- a/di/torq/torq.q +++ b/di/torq/torq.q @@ -4,7 +4,7 @@ / same init[config;deps] calling convention. / built-in process type registry: proctype -> di.* module name -builtin:`hdb`tickerplant`rdb`wdb`sort`gateway`idb`segmentedtp`chainedtp`housekeeping`sortworker`discovery`tickerlogreplay`segmentedchainedtp!`di.torq.proc.hdb`di.torq.proc.tickerplant`di.torq.proc.rdb`di.torq.proc.wdb`di.torq.proc.wdb`di.torq.proc.gateway`di.torq.proc.idb`di.torq.proc.segmentedtp`di.torq.proc.chainedtp`di.torq.proc.housekeeping`di.torq.proc.wdb`di.torq.proc.discovery`di.torq.proc.tickerlogreplay`di.torq.proc.segmentedtp +builtin:`hdb`tickerplant`rdb`wdb`sort`gateway`idb`segmentedtp`chainedtp`housekeeping`sortworker`discovery`tickerlogreplay`segmentedchainedtp`compression!`di.torq.proc.hdb`di.torq.proc.tickerplant`di.torq.proc.rdb`di.torq.proc.wdb`di.torq.proc.wdb`di.torq.proc.gateway`di.torq.proc.idb`di.torq.proc.segmentedtp`di.torq.proc.chainedtp`di.torq.proc.housekeeping`di.torq.proc.wdb`di.torq.proc.discovery`di.torq.proc.tickerlogreplay`di.torq.proc.segmentedtp`di.torq.proc.compression reqenv:{[e] v:getenv e;