Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief UBF field database
0003  *
0004  * @file ubfdb.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #ifndef __UBFDB_H
0035 #define __UBFDB_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <ndrx_config.h>
0043 #include <ndrstandard.h>
0044 #include <exdb.h>
0045 
0046 #include "ferror.h"
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049     
0050 #define NDRX_UBFDB_BERROR(atmierr, fmt, ...)\
0051         UBF_LOG(log_error, fmt, ##__VA_ARGS__);\
0052         userlog(fmt, ##__VA_ARGS__);\
0053         ndrx_Bset_error_fmt(atmierr, fmt, ##__VA_ARGS__);
0054 
0055 #define NDRX_UBFDB_ERROR(fmt, ...)\
0056         UBF_LOG(log_error, fmt, ##__VA_ARGS__);\
0057         userlog(fmt, ##__VA_ARGS__);
0058     
0059     
0060 #define NDRX_UBFDB_BERRORNOU(errlev, atmierr, fmt, ...)\
0061         UBF_LOG(log_error, fmt, ##__VA_ARGS__);\
0062         ndrx_Bset_error_fmt(atmierr, fmt, ##__VA_ARGS__);
0063     
0064 #define NDRX_UBFDB_MAGIC        0xf19c5da3
0065 
0066 #define NDRX_UBFDB_MAX_READERS_DFLT 1000
0067 #define NDRX_UBFDB_MAP_SIZE_DFLT    512000 /* 500K */
0068 #define NDRX_UBFDB_PERMS_DFLT       0664
0069 
0070 /* KWD -> keywords for database */
0071 #define NDRX_UBFDB_KWD_MAX_READERS            "max_readers"
0072 #define NDRX_UBFDB_KWD_MAP_SIZE               "map_size"
0073 #define NDRX_UBFDB_KWD_RESOURCE               "resource"
0074 #define NDRX_UBFDB_KWD_PERMS                  "perms"
0075     
0076     
0077 /**
0078  * Dump the UBF database configuration
0079  */
0080 #define NDRX_UBFDB_DUMPCFG(LEV, UBFDB)\
0081     UBF_LOG(LEV, "-------------- UBF FIELD TABLE DB ---------------");\
0082     UBF_LOG(LEV, "%s=[%s]", NDRX_UBFDB_KWD_RESOURCE, UBFDB->resource);\
0083     UBF_LOG(LEV, "%s=[%ld]", NDRX_UBFDB_KWD_MAX_READERS, UBFDB->max_readers);\
0084     UBF_LOG(LEV, "%s=[%ld]", NDRX_UBFDB_KWD_MAP_SIZE, UBFDB->map_size);\
0085     UBF_LOG(LEV, "%s=[%o]", NDRX_UBFDB_KWD_PERMS, UBFDB->perms);\
0086     UBF_LOG(LEV, "-------------------------------------------------");
0087     
0088 /*---------------------------Enums--------------------------------------*/
0089 /*---------------------------Typedefs-----------------------------------*/
0090     
0091 /**
0092  * UBF dynamic field table database
0093  */
0094 typedef struct ndrx_ubf_db ndrx_ubf_db_t;
0095 struct ndrx_ubf_db
0096 {
0097     char resource[PATH_MAX+1];  /* physical path of the cache folder        */
0098     long max_readers;           /* db settings                              */
0099     long map_size;              /* db settings                              */
0100     int perms;                  /* permissions of the database resource     */
0101     
0102     /* LMDB Related */
0103     EDB_env *env;               /* env handler                              */
0104     EDB_dbi dbi_id;             /* named id mapping db                      */
0105     EDB_dbi dbi_nm;             /* named field name database                */
0106 };
0107 
0108 /**
0109  * field definition found in .fd files
0110  */
0111 typedef struct ndrx_ubfdb_entry ndrx_ubfdb_entry_t;
0112 struct  ndrx_ubfdb_entry
0113 {
0114     BFLDID bfldid;
0115     char fldname[UBFFLDMAX+1];
0116 };
0117 
0118 /*---------------------------Globals------------------------------------*/
0119 /*---------------------------Statics------------------------------------*/
0120 
0121 extern NDRX_API ndrx_ubf_db_t *ndrx_G_ubf_db;
0122 extern NDRX_API int ndrx_G_ubf_db_triedload; /* did we try to load? */
0123         
0124 /*---------------------------Prototypes---------------------------------*/
0125 extern int ndrx_ubfdb_Bflddbload(void);
0126 extern int ndrx_ubfdb_Bflddbadd(EDB_txn *txn, short fldtype, BFLDID bfldno, 
0127         char *fldname);
0128 extern int ndrx_ubfdb_Bflddbdel(EDB_txn *txn, BFLDID bfldid);
0129 extern int ndrx_ubfdb_Bflddbdrop(EDB_txn *txn);
0130 extern void ndrx_ubfdb_Bflddbunload(void);
0131 extern int ndrx_ubfdb_Bflddbunlink(void);
0132 extern int ndrx_ubfdb_Bflddbget(EDB_val *data,
0133         short *p_fldtype, BFLDID *p_bfldno, BFLDID *p_bfldid, 
0134         char *fldname, int fldname_bufsz);
0135 extern char * ndrx_ubfdb_Bflddbname (BFLDID bfldid);
0136 extern BFLDID ndrx_ubfdb_Bflddbid (char *fldname);
0137 extern EDB_env * ndrx_ubfdb_Bfldddbgetenv (EDB_dbi **dbi_id, EDB_dbi **dbi_nm);
0138 
0139 #ifdef  __cplusplus
0140 }
0141 #endif
0142 
0143 #endif  /* __UBFDB_H */
0144 /* vim: set ts=4 sw=4 et smartindent: */