Back to home page

Enduro/X

 
 

    


0001 TPCACHE.INI(5)
0002 ==============
0003 :doctype: manpage
0004 
0005 
0006 NAME
0007 ----
0008 tpcache.ini - Enduro/X tpcall caching configuration
0009 
0010 
0011 SYNOPSIS
0012 --------
0013 ---------------------------------------------------------------------
0014 [@cachedb/DBNAME_SECTION]
0015 cachedb=DBNAME_DB
0016 resource=DATABASE_DIRECTORY
0017 flags=FLAGS
0018 limit=LIMIT
0019 expiry=EXPIRY
0020 max_readers=MAX_READERS
0021 max_dbs=MAX_NAMED_DBS
0022 map_size=MAP_SIZE
0023 perms=DB_PERMISSIONS
0024 
0025 
0026 [@cachedb/DBNAME_2]
0027 ...
0028 
0029 [@cachedb/DBNAME_N]
0030 ...
0031 
0032 
0033 [@cache]
0034 svc SERVICE_NAME=
0035     {
0036         "caches":[
0037                 {
0038                     "cachedb":"CACHE_DBNAME",
0039                     "flags":"CACHE_FLAGS",
0040                     "type":"TYPE",
0041                     "subtype":"SUBTYPE",
0042                     "rule":"RULE",
0043                     "keyfmt":"KEYFMT",
0044                     "save":"SAVE",
0045                     "delete":"DELETE",
0046                     "rsprule":"RSPRULE",
0047                     "refreshrule":"REFRESHRULE",
0048                     "inval_svc":"INVAL_SVC",
0049                     "inval_idx":"INVAL_IDX",
0050                     "keygrpdb":"KEYGRPDB",
0051                     "keygrpfmt":"KEYGRPFMT",
0052                     "keygrpmaxtperrno":"KEYGRPMAXTPERRNO",
0053                     "keygrpmaxtpurcode":"KEYGRPMAXTPURCODE",
0054                     "keygroupmrej":"KEYGROUPMREJ",
0055                     "keygroupmax":"KEYGROUPMAX"
0056                 },
0057                 {
0058                     "cachedb":"DBNAME_2",
0059                     ...
0060                 },
0061                 ...
0062             ]
0063     }
0064 svc SERVICE_NAME_N=
0065     {
0066         "caches":[
0067                 {
0068                     "cachedb":"DBNAME_N",
0069                     ...
0070                 },
0071                 ...
0072             ]
0073     }
0074 
0075 
0076 ---------------------------------------------------------------------
0077 
0078 
0079 DESCRIPTION
0080 -----------
0081 Enduro/X supports tpcall(3) caching, by writing results into LMDB. LMDB is
0082 integral par to of the Enduro/X. To avoid conflict with users choice of LMDB
0083 version, the embedded version is renamed to "EXDB", so that global C symbols
0084 does not conflict. To configure Enduro/x tpcall caching, firstly database must
0085 be configured. Enduro/X uses approach, that each database is stored into separate
0086 file system directory. On Linux systems (or others which support RAM drivers),
0087 the directory can be defined in RAM drive, and thus avoid the cache writing to
0088 disk (as the LMDB uses memory mapped files). On Linux for this purpose /dev/shm
0089 can be used.
0090 
0091 Caching is performed at service level. Thus when software is doing *tpcall(3)*,
0092 the client's call is intercepted, and tested against cache. If saved data is
0093 found, then data is directly returned from LMDB and no service invocation is done.
0094 
0095 Each cached item must have a key. The key is build from the call data. Key is zero
0096 (0x00 byte) terminated string. Key format is given in cache configuration. Before
0097 lookup to DB is made, rule expression is tested. This indicates either the call
0098 must be cached or not. If rule is true, key is built and with key DB is tested,
0099 if result is found, it is returned to caller. If result is not found, then service
0100 invocation is performed. When service responds, data is written to cache.
0101 
0102 Service can have multiple caches, with different rules. Once request is processed
0103 the first cache which matches the rule is used for lookup or data saving.
0104 
0105 Each cache references database definition, single database can be use by multiple
0106 caches or each cache can have it's own database. Keeping multiple databases
0107 could make better performance for caches were often writes are done. As concurrent
0108 writes are synchronized so that only one process writes to the same database.
0109 
0110 If writing to the same database, user shall ensure that keys are unique between
0111 different service cache definitions. This can be reached by adding different
0112 prefixes in key format.
0113 
0114 DEFINITIONS
0115 -----------
0116 
0117 *Simple cache* - this is cache were data is saved in one cache database. No
0118 linked databases are used.
0119 
0120 *Keygroup* is separate database where records can be grouped. For example 
0121 by user id. The group record holds the *UBF* buffer with string key occurrences
0122 which are linked in the group. Keygroup database name is encoded as 
0123 
0124 *Keyitem* is linked record to the group.
0125 
0126 
0127 DATABASE DEFINITION
0128 -------------------
0129 
0130 *DBNAME_SECTION*::
0131     In case of simple database. This is a name of the database. For example
0132     "cachedb1". Allowed symbols a-z, A-Z, 0-9. In case of keygroup or keyitems
0133     databases, format for section is "<dbname>/<logical_db_name>. For the caches
0134     the db names are encoded as "<logical_db_name>@<dbname>". Parameter is
0135     *mandatory*.
0136 *DBNAME_DB*::
0137     This is database name. For simple caches, name must be the same as 
0138     *DBNAME_SECTION*. For keygroup or keyitems databases name format is
0139     "<logical_db_name>@<dbname>". Parameter is *mandatory*.
0140 *DATABASE_DIRECTORY*::
0141     This is file system directory where cache database is located. The directory
0142     must exist when application domain is started. In case of keygroup 
0143     and keyitems databases, the directory must be the same.
0144     Parameter is *mandatory*.
0145 *FLAGS*::
0146     This is comma separated list of keywords - flags. See next section for list
0147     of flags supported for cache db.
0148 *LIMIT*::
0149     If number of cached items in database must be limited (for example 1000 recs
0150     max), then the number is defined by this parameter. If this parameter is set
0151     then one of the following flags must be present *fifo*, *lru* or *hits* - 
0152     delete strategy. So that *tpcached(8)* process would know how to sort and
0153     which records to remove. The limit is not guaranteed maximum. As records are
0154     removed by *tpcached* daemon, there could be times that limit is overreached,
0155     because *tpcached* works with periods. And during the sleep time, more records
0156     could be added to db and only after sleep period *tpcached* will zap them.
0157 *EXPIRY*::
0158     Time specification for record to live in cache. After time is passed, the
0159     *tpcached* process will zap the record. The configuration is specified as:
0160     N+s for seconds, (e.g. 20s), N+.D+m for minutes (e.g. 30.5m - 30 min, 30 sec)
0161     or N+.D+h for hours (e.g 3.5h, will store message for 3 hours and 30 minutes).
0162 *MAX_READERS*::
0163     See LMDB documentation for this. Basically this is number of threads used
0164     by process. See LMDB's mdb_env_set_maxreaders() function description. The
0165     default value set by Enduro/X is *1000*.
0166 *MAP_SIZE*::
0167     Maximum size of the database in bytes. The size must be multiple of OS page
0168     size. See LMDB's mdb_env_set_mapsize() function description. The default 
0169     value used by Enduro/X is *10485760*. Postifx multiplier can be used for
0170     value in configuration: kK(x1000) mM (x1000'000) gG (x1000'000'000) e.g. 10M.
0171 *MAX_NAMED_DBS*::
0172     Maximum number of "named" logical databases in given resource. Named DB is
0173     only uses with "@" syntax, and usually only for keygroups (to keep transactions
0174     atomic between two DBs). The default value is *2*.
0175 *DB_PERMISSIONS*::
0176     Octal permissions for map files on file system. The default value is *0664*.
0177 
0178 DATABASE FLAGS
0179 --------------
0180 *bootreset*::
0181     Clean up the cache database when Enduro/X application domain is booting. The
0182     reset is performed by *tpcachebtsv* binary. Thus this binary must be configured
0183     in *ndrxconfig.xml(5)*. And it should be one of the first XATMI servers booted.
0184     The *tpcachetbsv* simple removes database files at boot.
0185 *bcastput*::
0186     Should process perform broadcast (send event) of putting data in cache. If
0187     this is set and data is put into cache. This invokes calling *tpevsrv* with
0188     current tpcall response data buffer. Event is @CPNNN//<SVCNM>. Where NNN is
0189     cluster node id.
0190 *bcastdel*::
0191     When cache data is deleted either by invalidate cache or by *tpcached*
0192     operations, if flag is set, the event is broadcasted to *tpevsrv*. The event
0193     in case of invalidated is @CDNNN/F/<SVCNM> (which contains the data buffer 
0194     by which data is deleted. It is buffer which performs invalidate, not 
0195     the actually stored data. Data is processed by cache's *delete* parameter
0196     which might limit the data sent for deletion over the event server - in order
0197     to save some traffic). The NNN is cluster node id which initiates the
0198     invalidate. The F is flags, in case if is 'G', then whole group is deleted if
0199     record is part of the keygroup, otherwise 'F' flag (full) is sent.
0200 *timesync*::
0201     In case if of network update received (add to cache) message, the message
0202     will be added to cache without replacing the existing record. The caller
0203     will receive the latest record by time stamp.
0204 *scandup*::
0205     In case of *timesync* mode, the database may accumulate duplicate records,
0206     thus if this flag is set, the *tpcached* daemon will scan the cache records
0207     and erase the older records. Note that duplicates also are removed during
0208     real time data lookup.
0209 *clrnosvc*::
0210     Clear cache when service for which data is cached, is not advertised anymore
0211     by any XATMI server. The cleanup is performed by *tpcached*.
0212 *keyitems*::
0213     This is key-items database. Required flag for keygroup items database pair.
0214 *keygroup*::
0215     This database is for storing key-groups. Note that when using key-group, both
0216     keyitems and keygroup must be in the same physical resource. And syntax
0217     for boths databases must be "<logical_db_name>@<dbname>".
0218 *nosync*::
0219     Do not perform fsync (flush to disk) when committing transaction. This is
0220     suitable for caches which are reset at boot. Used for performance increase.
0221     In case of persisted databases (used after reboot), at case of crash, this
0222     data might be corrupt. See *MDB_NOSYNC* mode for mdb_env_open().
0223 *nometasync*::
0224     Flush metadata only when doing commit. The risks are the same as with *nosync*.
0225     Recommended for non persisted caches. See *MDB_NOMETASYNC* for mdb_env_open()
0226     function.
0227 
0228 CACHE DEFINITION
0229 ----------------
0230 *CACHE_DBNAME*::
0231     Reference to database name. This must match with chosen storage db *DBNAME_DB*.
0232 *CACHE_FLAGS*::
0233     Flags of the cache (comma separate of flags for cache). See section bellow for
0234     flags available.
0235 *TYPE*::
0236     This is buffer type name for which cache is designed. Currently supported type
0237     is *UBF*.
0238 *SUBTYPE*::
0239     This is buffer sub type. For example for *VIEW* buffers this is view name.
0240     Currently this parameter is reserved for future use.
0241 *RULE*::
0242     This is buffer type specific expression for defining the rule in which case
0243     the call shall be cached/cache-looked-up or not. If rule is not specified, then
0244     by default call is accepted for cache. In case if *TYPE* is UBF, then standard
0245     boolean expression applies here.
0246 *KEYFMT*::
0247     This is buffer type specific format. For *UBF* fields this is format string
0248     which might contain field free text with format of '$(UBF_FIELD)', where 
0249     given construction will be substituted with UBF field value of field 'UBF_FIELD'.
0250     For example having 'T_STRING_3_FLD' equal to *ABC* and 'T_STRING_2_FLD' occurrence 2
0251     equal to  XX' and format string 'SV1$(T_STRING_3_FLD)-$(T_STRING_2_FLD[1])', 
0252     then key will render as 'SV1ABC-XX'. Key is used to distinguish under which
0253     record to save the data and how to lookup data into database.
0254 *SAVE*::
0255     This field specifies how data is saved into cache. It is type specific and
0256     and flags specific. For *UBF* buffer with flag *putfull* full UBF buffer is
0257     saved. If flag is not specified and 'SAVE' is set to * then full buffer
0258     is saved too. If flags is not specified, but it is comma separated list of
0259     *UBF* fields, then only those fields are saved to cache. If flags is set to
0260     *putrex*, then 'SAVE' field shall contain regular expression which is executed
0261     on buffer fields (names). The names which matches expression are added to
0262     cache.
0263 *DELETE*::
0264     This field specifies field which shall be broadcast to other cluster node
0265     in case if invalidate their cache is performed. This makes a projection of
0266     incoming buffer in order to save the traffic. The projected buffer is then
0267     sent to event server for other cluster node processing. Rules for
0268     the field syntax is similar to the 'SAVE' parameter.
0269     For *UBF* buffer with flag *delfull* full UBF buffer is sent in event.
0270     If flag is not specified and 'SAVE' is set to  * then full buffer
0271     is sent too. If flags is not specified, but it is comma separated list of
0272     *UBF* fields, then only those fields are sent in event. If flags is set to
0273     *delrex*, then 'DELETE' field shall contain regular expression which is executed
0274     on buffer fields (names). The names which matches expression are added to
0275     to buffer which is sent to other cluster node.
0276 *RSPRULE*::
0277     This is boolean expression with following two fields in buffer *EX_TPERRNO*
0278     which corresponds to *tperrno* of tpcall() and *EX_TPURCODE* corresponds to
0279     tpcall() user return code. If *RSPRULE* setting is not present, then cached
0280     are only successful calls (i.e. EX_TPERRNO==0).
0281 *REFRESHRULE*::
0282     Optional type specific expression. When performing tpcall(), the saved data
0283     is returned from cache. In case if this expression is defined and executes
0284     true on tpcall buffer,the real service all will be performed, 
0285     even if data in cache are present. For *UBF* buffers this is boolean expression.
0286 *INVAL_SVC*::
0287     This is service name if "their" service to be invalidated. When service call
0288     is performed, this "allows" to intercept the call and when response is received
0289     the other service cache, specified in 'INVAL_SVC' will be reset (removed
0290     cached data). The key used for data access is build by this invalidate cache
0291     and not by target 'INVAL_SVC' cache definition. If target cache uses
0292     *invalkeygrp* flag, then then whole group is invalidated. The group access is
0293     made by 'KEYGRPDB' and 'KEYGRPFMT'.
0294 *INVAL_IDX*::
0295     This is cache index (zero based array index) of target invalidate service cache.
0296     This must be defined in case if 'INVAL_SVC' parameter is used, this parameter
0297     must be set too.
0298 *KEYGRPDB*::
0299     Optional key group database name. The database must be consists be in format
0300     of <logical database>@<physical database name>. If using 'KEYGRPDB' DB, then
0301     the 'CACHE_DBNAME' must be set in the same format. So that logical names for
0302     cache database is different but physical is the same. Physical resources must
0303     be the same for LMDB, for need to ensure transactional consistency between
0304     group and items.
0305 *KEYGRPFMT*::
0306     This format string to build a key for a group. It shall be lower level
0307     of object "resolution", to have something common between linked 'KEYFMT'.
0308     For example if paging (user iterates over her statement) needs to be cached
0309     and invalidated at any single transaction, then 'KEYGRPFMT' is the userid
0310     and 'KEYFMT' shall contain userid and page number. The syntax for 'KEYGRPFMT'
0311     is the same as for 'KEYFMT' is buffer type specific. Field is *conditional*,
0312     must be present when configuring key group.
0313 *KEYGROUPMAX*::
0314     Key group can be used to protect against DoS attacks - by limiting number
0315     of "new" records that can appear in key group. The time component is
0316     processed by *tpcached* binary, which could remove key group after it is
0317     expired. They 'KEYGROUPMAX' is number records allowed in key group.
0318     Parameter is *optional*.
0319 *KEYGROUPMREJ*::
0320     This is buffer definition which shall be filled in response (merged or
0321     replaced according to flags) in case if cache lookup is made, request is
0322     part of key group, record does not exists and number of records in key
0323     group already reached 'KEYGROUPMAX'. In this case service call is denied
0324     and response is filled with buffer definition found in this parameter. For
0325     *UBF* buffers, it is UBF buffer defined in JSON format (see tpjsontoubf(3)
0326     man page). Parameter is *conditional* and must be present in case if 'KEYGROUPMAX'
0327     is set.
0328 *KEYGRPMAXTPERRNO*::
0329     In case of doing reject for 'KEYGROUPMAX' max reached, this is TP error code
0330     that tpcall(3) will return. Normally it would be *11* (service routine error).
0331     Parameter is *optional*, if not present the error value will be *0* - no
0332     error, thus data should indicate that reject was performed.
0333 *KEYGRPMAXTPURCODE*::
0334     Value of user return code in case if doing key group max reject. See
0335     *tpurcode(3)*. Parameter is *optional* and if not set and reject will be
0336     performed, user return code value will be *0*.
0337 
0338 CACHE FLAGS
0339 -----------
0340 *putfull*::
0341     Flag indicates that when saving data to cache full XATMI buffer shall be
0342     saved. In case if *putfull* or *putrex* is not present then 'SAVE' parameter
0343     is analyzed.
0344 *putrex*::
0345     Indicates that 'SAVE' field is regular expression. *putfull* and *putrex*
0346     flags cannot be mixed.
0347 *getreplace*::
0348     Flag indicates that if data is returned from, then buffer passed to
0349     *tpcall(3)* must be replaced with data from cache.
0350 *getmerge*::
0351     Flag indicates that if data is returned from, then buffer passed to
0352     *tpcall(3)* must be merged with incoming data. If using *UBF* buffer type
0353     then for merge operation *Bupdate(3)* is used. Where destination buffer
0354     is buffer passed to *tpcall(3)* and source buffer is one save in cache.
0355 *nosvcok*::
0356     If flag is set and service call is made (*tpcall(3)*) to service which is
0357     not currently advertised, but cached data exists in cache, then return
0358     result from cache as if the the service was advertised and working ok.
0359     For such case if flag is not present, the system will respond with error
0360     TPENOENT.
0361 *next*::
0362     Flag indicates that next cache (if having multiple for single service) should
0363     be processed, after this one. Flag is suitable for cases when current cache
0364     is invalidate their. Thus invalidate is performed and for example at next
0365     cache would be actually save results. Or multiple invalidates can be configured.
0366 *delfull*::
0367     When using invalidate cache, then this flag indicates that full XATMI buffer
0368     sent to tpcall() shall be broadcasted (published in event) to other nodes.
0369     In case of UBF buffer if flag is not present, then * in 'DELETE' cache
0370     parameter indicates all fields must be Broadcast. If not * then it is
0371     comma separated list of fields.
0372 *delrex*::
0373     This indicates that 'DELETE' parameter is regular expression. In case of
0374     UBF buffer, the expression is executed on each field in incoming buffer,
0375     if field name matches expression, then it is added to broadcast list.
0376 *inval*::
0377     Flag indicates that this cache is invalidate. In this case cache parameters
0378     'INVAL_SVC' and 'INVAL_IDX' must be present.
0379 *invalkeygrp*::
0380     If performing invalidated of record and record is part of key group, then
0381     delete whole key group (all linked records and group by it self). If flag
0382     is not present, then single record is delete (keyitem) and group is updated
0383     (linkage removed from group). This flag applies to all mechanisms how
0384     record can be removed, either by invalidate their, or zapped by *tpcached*
0385     or deleted by xadmin tooling.
0386 
0387 PERFORMANCE
0388 -----------
0389 For performance reasons, if non persistent cache is required, it is recommended
0390 to store data file in RAM driver, for example on GNU/Linux systems it is
0391 */dev/shm*. It is considered that in such scenario LMDB will use twice the
0392 memory. As one is a copy in RAM drive and another is mapped pages in process
0393 to the file. It is up to kernel realization to make some optimizations here.
0394 
0395 EXAMPLE
0396 -------
0397 
0398 Simple caches
0399 ---------------------------------------------------------------------
0400 [@cachedb/db02_1]
0401 cachedb=db02_1
0402 resource=${TESTDIR_DB}/db02_1
0403 flags=bootreset
0404 
0405 [@cachedb/db02_2]
0406 cachedb=db02_2
0407 resource=${TESTDIR_DB}/db02_2
0408 flags=bootreset
0409 
0410 
0411 [@cache]
0412 svc TESTSV02=
0413     {
0414         "caches":[
0415                 {
0416                     "cachedb":"db02_1",
0417                     "type":"UBF",
0418                     "keyfmt":"SV2-$(T_STRING_FLD)",
0419                     "save":"*",
0420                     "rule":"T_STRING_2_FLD=='HELLO CACHE 1'"
0421                 },
0422                 {
0423                     "cachedb":"db02_2",
0424                     "type":"UBF",
0425                     "keyfmt":"SV2-$(T_STRING_FLD)",
0426                     "save":"T_STRING.*|T_FLOAT.*|T_LONG_2_FLD|T_SHORT.*",
0427                     "flags":"putrex"
0428                 }
0429             ]
0430     }
0431 
0432 svc SOMEOTHERSVC=
0433     {
0434         "caches":[
0435                 {
0436                     "cachedb":"db02_1",
0437                     "type":"UBF",
0438                     "keyfmt":"SVOTHER-$(T_STRING_FLD)",
0439                     "save":"*",
0440                 }
0441             ]
0442     }
0443 
0444 ---------------------------------------------------------------------
0445 
0446 
0447 Cache with keygroup and buffer reject:
0448 ---------------------------------------------------------------------
0449 [@cachedb/db15]
0450 max_dbs=2
0451 resource=${TESTDIR_DB}/db15
0452 subscr=@C.001/.*/.*|@C.002/.*/.*
0453 
0454 #
0455 # These two inherits settings from above.
0456 #
0457 [@cachedb/db15/g]
0458 cachedb=g@db15
0459 flags=bootreset,bcastput,bcastdel,keygroup
0460 expiry=30s
0461 
0462 [@cachedb/db15/k]
0463 cachedb=k@db15
0464 flags=bootreset,bcastput,bcastdel,keyitems
0465 expiry=10s
0466 
0467 
0468 [@cache]
0469 
0470 svc TESTSV15=
0471     {
0472         "caches":[
0473                 {
0474                     "cachedb":"k@db15",
0475                     "keygrpdb":"g@db15",
0476                     "type":"UBF",
0477                     "keyfmt":"SV15$(T_STRING_FLD)-SV15$(T_SHORT_FLD)",
0478                     "keygrpfmt":"SV15$(T_STRING_FLD)",
0479                     "save":"T_STRING_FLD,T_STRING_2_FLD,T_LONG_2_FLD,T_SHORT_FLD",
0480                     "flags":"getmerge",
0481                     "keygroupmax":"7",
0482                     "keygroupmrej":"{\"T_STRING_3_FLD\":\"REJECT\",\"T_LONG_2_FLD\":[\"1\", \"2\"]}",
0483                     "keygrpmaxtperrno":"11",
0484                     "keygrpmaxtpurcode":"4"
0485                 }
0486             ]
0487     }
0488 
0489 ---------------------------------------------------------------------
0490 
0491 For more unit tests please see 'atmitest/test048_cache' unit test folder ini
0492 files.
0493 
0494 
0495 BUGS
0496 ----
0497 Report bugs to support@mavimax.com
0498 
0499 SEE ALSO
0500 --------
0501 *xadmin(8)* *ndrxd(8)* *ndrxconfig.xml(5)* *tpcached(8)* *tpcachesv(8)* *tpcachebtsv(8)*
0502 
0503 COPYING
0504 -------
0505 (C) Mavimax, Ltd
0506