
b709e29 Fix URL typo in release notes 01f203c Update release notes c49810a Update COPYRIGHT e327526 Add BSL version number to LICENSE.TXT 07e3a4e Remove superfluous COPURIGHT.md and LICENSE.md 54c3310 Replace Dynamic Data Routing Platform with Database Proxy 305d02f Remove *.cmake wildcard from .gitignore b0b5208 Cleanup of spaces aeca6d0 Extend maxscaled error messages 817d74c Document where the CDC users are stored 9a569db Update license ff8697a MXS-716: Fix table level privilege detection 2071a8c Only check replies of slaves that are in use f8dfa42 Fix possible hangs in CDC python scripts fa1d99e Removed "filestem option" from example 009b549 Removed "filestem option" from example 8d515c2 Add example Kafka producer script for Python 64e976b Fix sporadic SSL authentication failures 5a655dc MXS-814: Check service/monitor permissions on all servers 2a7f596 Add note about galeramon priority to Galera tutorials b90b5a6 Fixed SHOW SLAVE STATUS in binlog router e22fe39 Changed couln size for SHOW SLAVE STATUS ae97b18 Fix avrorouter build failure with older sqlite libraries 56ef8b7 Replace GPL license with BSL license in scripts and tests 552836f Initialize all fields when MySQL users are loaded from cache bf42947 Update all licensing related files b29db9d Remove optimize_wildcard parameter from use 5170844 Make readwritesplit diagnosting output more clear 262ffb1 Fix crash when a config parameter has no section 33ac9e6 Add note about LEAST_BEHIND_MASTER and server weights e13e860 Fix a memory leak when backend authentication fails 75d00c2 MXS-801: Set the default value of strip_db_esc to true bd5f2db MXS-800: Add a log message about the working directory 4b1dd8c Update MySQL Monitor documentation on detect_replication_lag 559bc99 Fix installation of license file b057587 Change LICENSE to LICENSE.TXT 223fa43 Remove null characters from log messages 36fd05b Fix fatal signal handler log message 053dc8a Fix typos in documentation 371dc87 Fix Galera text in Master-Slave tutorial 30b6265 Disable adding of new objects at runtime db92311 Update the documentation on configuration reloading 0923d40 Update Connector-C version c4738b5 Add define for avro-conversion.ini 196e6ac Update license from GPL to BSL. e612366 Correctly calculate the number of bytes read in dcb_read 93a2a03 Update rotate documentation in admin tutorial c5eb854 MXS-585: Fix authentication handling regression 6330070 Fix schemarouter memory leak aa5827e Fix CDC authentication memory leak a5af4ad Fix avro memory leaks 627d73f Fix Avro scripts 0ff7556 Add build instructions to avrorouter documentation 734a1c8 Fix doxygen mainpage e51ce09 Add licence text to avro scripts 4d27c14 Update Avro documentation and fix installation directories a58a330 Fix readconnroute error message about router_options 22b138c MXS-772: Fix postinstall script a9960b7 Fix function declaration in mysql_backend.c cbe1704 Add missing newline 09d76ee Fix avro documentation default values 1d3f8f3 Added refresh users on START SLAVE 880db34 Make router configuration errors fatal 3bad5ca Update documentation and add logging to avrorouter 10f3384 Disable SSLv3 ca8d902 Fix rwsplit error reporting when master is lost e816d65 Fix MaxScale Tutorial deca3e1 Update MaxScale man page f1735b7 Update release notes 9238714 qc: Change type of DEALLOCATE PREPARE 0b77c3b dbfwfilter: Do not require a trailing new line 1152ca9 Remove copyright message a038a85 Remove debug assertion on ERANGE error in galeramon 12ab235 Fix comparison error for connections limit. 5de1a8f qc_sqlite: Correct string recognition b63d754 Fix links in documentation contents 05d457e CDC protocol link fix 50676ef Fix monitor code formatting 218ba09 Remove MaxScale-and-SSL.md 0d6845b Add images to Avro documentation and tutorial 8dd2c9b Update MaxScale-2.0.0-Release-Notes.md 6d4b593 Change avrorouter default transaction grouping 4c629de Add notes about monitor changes to upgrading and release notes 267d0dc Update Binlogrouter.md c624781 Update Replication-Proxy-Binlog-Router-Tutorial.md f3261bc CDC users 1368797 Format authenticator and module headers ab01749 Format filters 8b05d32 Format core and include files f3974e5 Add GPL LICENSE to qc_mysqlembedded bfec36a astyle rabbitmq_consumer/consumer.c 54b960a Check that the Avro directory is writable 3d4cd2e Fix cdc_users using the wrong path for service users cache 1e738dd Add CDC client program documentation f6809fd Remove superfluous rabbitmw_consumer/LICENSE 6b5e667 Update license text in files 9bfcb46 Change CDC protocol documentation formatting 607f25c REQUEST-DATA formatting 8175ab4 CDC protocol update d5ca272 CDC protocol update 6c91764 Only check wsrep_local_index if node is joined f12e2c2 Do not use SSL for monitors and services 6d2cd99 Fix TestAdminUsers f4ae50d Apply astyle to server/core/test/*.c 7cc2824 Update build instructions cf8e2b5 Update release notes 03c7a6c Remove wrong function prototypes 5a11eed Revert "Remove duplicate functions" 80ed488 Remove duplicate functions bb0de8d Add info on SSL and throttling to release notes for 2.0. 0934aee Update MaxAdmin reference guide 2a3fe9b Update source URL in release notes e575cf0 Merge branch 'MXS-177-develop' into develop cc8c88d Change header for BSL ecde266 Change header for BSL 890b208 Log a message when a script is executed 9c365df Added information on server side SSL to config guide. aa3e002 Remove obsolete heading 79dd73a Make dprintAllSessions use dprintSession 1fc0db9 Align output of "show services" 1b9d301 Make monitorShowAll use monitorShow 983615e Adjust output of 'show modules' 436badd qc_sqlite: The module is now beta a7cbbe5 Update Upgrade document 71ac13f Remove obsolete user/password from example eb20ff8 Fix and clean up Avrorouter diagnostics code 31d4052 Change MaxScale to MariaDB MaxScale e6e4858 Fix `source` parameter not working with `router_options` d8de99a Update module version numbers eb81add Merge remote-tracking branch 'origin/develop' into MXS-177-develop daba563 Merge remote-tracking branch 'origin/MXS-651-develop-merge' into develop 678f417 Changes in response to reviews. 410fb81 Changes in response to reviews. 60135e5 Add initial release notes about Avrorouter 7400ecc qc_sqlite: Remove uninitialized read 536962c Update version number 018f044 Fix debug assertion in client command processing 51f0804 Prevent 'show monitor' from crashing with failed monitor 559347e Fix "Too many connections" message; add comments. 01d3929 Add printf format checking to dcb_printf fbd49a6 dbfwfilter: Require complete parsing only when needed 1885863 Add information to release notes about readwritesplit changes 73b56a2 Update MaxScale section in release notes. 0a2f56f MaxAdmin: Remove debug information from 'show users' 3cf3279 MaxAdmin: Report SSL information as well 29c2b66 Always use SSL if server configured with SSL 7d6b335 dprintAllServers should use dprintServer 02a5246 qc_sqlite: Correctly detect parsing context 469419b compare: Add strict mode 8c5b3d3 compare: Allow the comparison of a single statement 4691514 Add Updgrade to 2.0 document 38b3ecb Expand the checks done before a monitor is stopped 8e2cfb9 Add backend name to authentication error message 9600a07 Fix MaxInfo crash 91c58b0 Removed log message for duplicate entry while adding an user 40392fe Fixed log message priority 0ec35b8 maxadmin: Allow the last user to be removed 5a0ebed maxadmin: Change name of user file 87aa8f1 maxadmin: Always allow root to connect bf37751 Fix COM_QUIT packet detection 7c93ee4 Update avrorouter documentation and tutorial 95ce463 Fix wrong directory in avrorouter log message cfe54c7 Update ChangeLog d69562c Fix LOAD DATA LOCAL INFILE data size tracking 24e7cd6 MXS-584: added support for SET @@session.autocommit d6f6f76 Fixes, correct too many connections message efeb924 Update release notes for 2.0.0 8f71a87 qc_sqlite: Adjust error messages b967d60 Remove copy of enum enum_server_command 822b7e3 Update package license b58301a Update MaxScale License for overlooked files c09ee47 Update MaxScale License 49f46fa Tidy up. Comment out config items not yet supported. f5c3470 Updated and simplified the Building from Source document 98b98e2 Add note about master failure modes to documentation e036f2c Update Limitations document 62219a5 Merge remote-tracking branch 'origin/drain-writeq' into develop 5caf667 Invoke DCB_REASON_DRAINED more frequently. 77b107b qc_sqlite: Add support for LOAD DATA INFILE 8e70f26 compare: Optionally print out the parse result ad750e6 Merge remote-tracking branch 'origin/MXS-651-develop-merge' into develop ef85779 Merge remote-tracking branch 'origin/develop' into MXS-651-develop-merge ea9fdda MXS-477: Add LONGBLOB support for readconnroute eae6d42 qc_sqlite: Remove superfluous columnname definition 8fe2b21 Add binlog source to avrorouter b25cc37 qc_sqlite: Add missing destructors 8a749e7 qc_sqlite: Reduce number of keywords 5f4bb8b compare: Output query immediately 2456e52 dbfwfilter: Reject queries that cannot be parsed 5f1fbbd qc_sqlite: Extend SET grammar b8d8418 dbfwfilter: Remove 'allow' from firewall filter rule 0bd2a44 MXS-741 When no events are read from binlog file, ... a07c491 Remove duplicated function (merge error, probably) b237008 Save conflict resolution, missed last time. a0c0b40 Merge remote-tracking branch 'origin/develop' into MXS-651-develop 385d47d Change SSL logic, fix large read problem. b93b5e0 Remove false debug assertion b953b1f Turn off SSL read ahead. e0d46a5 Fix error messages and remove commented code 49b4655 MXS-739: Fix invalid JSON in Maxinfo 0c30692 qc_sqlite: Handle GROUP_CONCAT arguments 54e48a1 qc_sqlite: Consider \ as an escape character in strings 713a5d6 qc_sqlite: Add test cases 20d1b51 qc_sqlite: Handle qualified names in CREATE VIEW 1019313 qc_sqlite: Make QUERY_TYPE_WRITE default for SHOW 059c14e qc_sqlite: Accept qualified function names in SELECT db34989 qc_sqlite: Accept qualified function names b93e2f1 qc_sqlite: Add limited support for GRAND and REVOKE 678672d qc_sqlite: Cleanup copying of database and table names 9b744b9 qc_sqlite: Update table and database names at the same time db75e61 qc: Support getting the qualified table names 1f867f4 qc: Add join.test 9c7e02a qc_sqlite: Accept "...from NATURAL straight_join..." 93d1c31 qc_sqlite: Both " and ' can enclose a string literal 8055b21 qc_sqlite: Set more information based upon tokens 37e3663 qc_sqlite: Do not blindly add affected fields 50f1360 qc: Correctly collect affected fields 71c234e qc_sqlite: Recognize CREATE TABLE ... UNION 01803f1 qc_sqlite: Recognize {DEALLOCATE|DROP} PREPARE ... 6ecd4b3 qc_sqlite: Parse index hints 0bdab01 qc: Compare sets of tables b908c8f Fix double freeing of internal DCBs 8903556 qc_sqlite: Recognize LEFT, INSERT and REPLACE 266e6c0 qc: Log all problems by default (compare program) 7b54cac qc_sqlite: Fix logging bug 9566e9f qc_sqlite: Plug a leak b0a860d qc: Run compare a specified number of times 050d698 qc_sqlite: Simplified argument handling 97c56b8 qc: Allow arguments to be passed to the query classifier 09a46e0 qc_sqlite: Add argument log_unrecognized_statements fd98153 qc: Allow arguments to be provided to the query classifier 313aa7e Fix Problems SSL assertion; non SSL connect to SSL 1d721e6 Fix DEB packaging errors 96bdc39 Fix RPM packaging failures on CentOS 7 6ba900d qc_sqlite: Recognize more SHOW commands 2869d0b qc_sqlite: Exclude support for sqlite's PRAGMA 0be68a3 qc_sqlite: Enhance SELECT syntax 28f3e1a Merge branch 'develop' into MXS-729 e18bd41 qc: Expose the result of the parsing 5896085 Add BUILD_AVRO to the CMake cache daeb896 Remove changes to blr_master.c memory handling d523821 Add comments 4eb9a66 Empty admin users file is now handled 52b46c6 qc: Update create.test db09711 qc_sqlite: Ignore case when looking for test language keywords f042a1d qc_sqlite: Extend CREATE TABLE syntax 177d2de qc_sqlite: Extend CREATE TABLE syntax d3ca8e6 qc_sqlite: Add some support for HANDLER 86c6a96 qc_sqlite: Recognize RENAME TABLE 471594f qc_sqlite: Accept more table options at CREATE TABLE 3da6cde qc_sqlite: Remove unused keywords bd89662 Fix crash on corrupted passwd file b5d1764 MXS-733: Always print session states 043e2db Remove unused CMake variables 5604fe2 Restore missing line, fixes logic error. 66d15a5 Added log message warning for old users found 5be9fca Changes in response to review by Johan 899e0e2 Removed password parameter from admin_user_add and admin_remove_user a2d9302 Merge branch 'develop' into MXS-729 bcaf82f Code review update e61c716 Nagios plugin update with Maxadmin using UNIX socket only d7150a2 qc_sqlite: Extend column syntax 3b78df0 qc_sqlite: Accept VALUE in addition to VALUES 85a705b qc_sqlite: Accept CHARSET in addition to CHARACTER SET db9cec8 qc_sqlite: Accept qualified column names in CREATE TABLE a9cabb0 qc_sqlite: Extend SELECT syntax f5e9878 qc_sqlite: Add set type 675cb93 qc_sqlite: Allow BINARY to turn into an identifier b04a760 qc_sqlite: Accept DROP TABLES 1075d9c qc_sqlite: Allow qualified name with LIKE in CREATE 420ac56 qc_sqlite: Extend EXPLAIN grammar 727d626 Add missing error message to readwritesplit f4fd09e Change templates and testing configurations to use sockets 1ef2e06 Add configurable default admin user a723731 Remove wrong file 7c3b02b Maxadmin/maxscaled UNIX socket update eed78d4 qc_sqlite: Pick out more information from select when CREATEing 267f091 qc_sqlite: Recognise DROP TEMPORARY TABLE 54fc29f qc_sqlite: Accept $ as a valid character in identifiers afa2ec9 qc_sqlite: Allow keywords to be used in qualified name db0427d MXS-729 code review update a3b3000 Merge branch 'develop' into MXS-729 e73d66c qc_sqlite: Identify qualified identifiers 5bacade Trailing space fix 3bc9be3 MXS-729 socket=default support in maxscale.cnf 1a5c23c Code review update for MXS-729 d6665c7 qc_sqlite: Extend CREATE TABLE grammar 91725ce qc_sqlite: Dequote table and database names cd7a022 qc: Add create test 1aa4e6b qc: Update test files 762b0c2 qc_mysqlembedded: Do not return "*" as table name cd9968f qc_sqlite: Update delete.test f16703d qc_sqlite: Add support for CALL e3ca9b4 qc_mysqlembedded: Do not return an array of empty strings 5878a22 qc_sqlite: Support selects in DELETE 1cf0444 qc_sqlite: Fix bug in DELETE grammar 0bf39a1 qc_sqlite: Add support for CHECK TABLE 4a8feca qc_sqlite: Add helper for catenating SrcLists ab299b3 qc_sqlite: Extend DELETE syntax 5778856 qc_sqlite: Extract database name as well 99901f1 qc_sqlite: Extend DELETE syntax 63396f8 qc_sqlite: Match "autocommit" caseinsensitively e804dd3 qc_sqlite: Add support for LOCK/UNLOCK c23e442 qc_sqlite: Extend DELETE syntax 5460e31 qc: Add delete test ab392ad qc_sqlite: Free unused data 598c6f0 qc: Measure time of parsing 2fa3844 qc_sqlite: Put all changes being {%|#}ifdefs 1b43992 qc_sqlite: Modified update.test 1676ea4 qc_sqlite: LEFT|RIGHT are not required with JOIN 224ebd3 qc_sqlite: Extend UPDATE grammar dbecca9 qc_sqlite: Extend UPDATE grammar b6ca3b3 MaxAdmin security modification MXS-729 8fb47dd Remove copying of MariaDB embedded library files 22e1257 Normalize whitespace when canonicalizing queries 269cff2 MXS-697: Fix dbfwfilter logging for matched queries 6344f6f Ignore Apple .DS_Store files. d606977 Improve comments in response to code review. 619aa13 Add configuration check flag to MaxScale 27c860b Drain write queue improvements. 33d4154 Read only one configuration file d104c19 Format more core files 83fdead Format part of core source code 311d5de Format gateway.c and config.c with Astyle 8cbb48e Don't build maxavro library if BUILD_AVRO is not defined 32bb77a Merge branch 'MXS-483' into develop db72c5d Format CDC/Avro related files 3c26e27 qc_sqlite: Use SrcList instead of Expr f96ad6a Merge branch 'develop' into MXS-729 0728734 Fix query canonical form tests e68262d Merge remote-tracking branch 'gpl-maxscale/master' into develop 65460dc Fix missing symbols from MySQLAuth 791c821 MaxAdmin listens on UNIX socket only and maxadmin can connect 89afed6 MXS-66: All configuration errors are fatal errors d613053 Add more details to galeramon documentation 22f4f57 qc: Add support for multi UPDATE 0dba25a Added default port to blr_make_registration 9d8248c qc_sqlit: Plug leaks and access errors 057551a qc_sqlite: Fix to small an allocation 1f73820 qc_sqlite: Free memory allocated during parsing 93fefb9 qc: Enable compare to run the same test repeatedly e52c578 qc_sqlite: Handle last_insert_id() 929e02a qc_sqlite: Extend UPDATE grammar de3b9f7 qc_sqlite: Defines provided when running cmake and make 4d5c3b2 qc_sqlite: Add support for multiple-table DELETE FROM 36a4296 qc_mysqlembedded: Handle SQLCOM_DELETE_MULTI 41f613a Fix DCB and SESSION removal from free object pools 00f2ddd Move some common code used in only one protocol into protocol. 6fbd0b0 Format Go source with gofmt abfbbcb Fix build failures and internal test suite 31de74a Merge branch 'develop' into MXS-483 20d461d Remove uniqueness constrain on oneshot tasks 6c09288 Add missing error message to converter task 0c2c389 Merge branch 'develop' into MXS-483 fa0accc Set freed memory to NULL after authentication failure 63f24e4 Install cdc_schema.go 5123c21 Fix ALTER TABLE parsing 004acc2 Merge branch 'develop' into MXS-483 f69a671 Remove array foreach macro use a159cd9 qc_sqlite: Add support for SHOW DATABASES 31a2118 Make qc_mysqlembedded optional 27ef30e Changed the default query classifier 359010d Add -h flag as the alias for --host bebc086 Fix minor bugs c7ca253 qc_sqlite: Recognize START [TRANSACTION] 240f8bf qc_sqlite: Collect info from nested SELECTs 93ea393 qc_sqlite: Pass along the relative position of a token cc960af qc_sqlite: Fix incorrect assigment 22a6fef Fix `gtid` avro index table 4c38bef qc_sqlite: STATUS is not a registered word cace998 qc_sqlite: Include all fields of UPDATE 997b19c qc: Add update tests 7601b3f qc_sqlite: Parse "INSERT INTO t VALUES (), ();" correctly ca426f1 qc_sqlite: Handle CREATE TRIGGER f54f963 qc_sqlite: Allow INSERT without INTO e4a1b6d Remove foreign keys from Avro index e4501a2 Merge branch 'develop' into MXS-483 82b9585 Fix MMMon never assigning master status a45a709 qc_mysqlembedded: Find the leaf name 2f3ca8f qc_mysqlembedded: Recognize SQLCOM_REPLACE cc7ad83 qc_mysqlembedded: Pick up fields for INSERT SELECT as well 0e6b39e qc: Cleanup of select.test 9113f4f qc_sqlite: Pickup more fields from INSERT 4d58f98 Dummy query classifier dfe824f Document `query_classifier` option 4aa329b MXS-718: Collect fields of INSERT 53818f2 Modify packet number for SSL backend connection 346f973 qc_sqlite: Accept qualified column names 8a83616 Fix in-memory SQLite table structure 6f2c884 Further backend SSL development 4444e92 qc_sqlite: Extend INSERT grammar 2aebcab qc_sqlite: Add support for TRUNCATE 1a6742e qc_sqlite: Accept DEFAULT as value in INSERT 07dec05 qc_sqlite: Crude classification made based on seen keywords a90a579 Add missing function documentation 72bd0cf qc_sqlite: Change CREATE TABLE grammar 6e04bc8 qc: Add INSERT tests 3666bda qc_sqlite: Add SELECT test d27e173 Add server/mysql-test/t/select.test to query_classifier 562d004 qc_sqlite: Cleanup error logging. 819cacb Merge branch 'develop' into MXS-483 0d3a789 Add warnings and comments to Avro row event processing 2fab570 Added support for SET autocommit=1 1aa83cf Code review fix c999f0a Addition of SELECT USER() 8c723da Clean up avro_client.c and avro_file.c eb21ee8 Clean up avro.c 946a284 Added Avro schema to table metadata processing 72f90be qc_sqlite: Add support for CREATE {FUNCTION|PROCEDURE} ... 4a4ab49 qc: Update line number also when skipping a block ffddb2a qc_sqlite: Allow queries using INTERVAL b8b03bd qc_sqlite: Add support for SELECT * FROM tbl2 = tbl1; 77a261a qc_sqlite: Add support for GROUP BY ... WITH ROLLUP 0ead41e cdc_schema now generates lowercase JSON 66e327a Classifier has to be specified explicitly 9074b91 Updated Avrorouter documentation cf06c7a qc_sqlite: Some comments added. f579eff Added simple Go based Avro schema generator f448e90 MXS-419: Added ulimit calls to init scripts b4ad257 Added FindAvro.cmake 56cc9b9 Added the last transaction script to installations 2d52da2 Added temporary avro-alpha package name 6ada071 Fixed cdc_users script 61f0206 Renaming and minor fixes to CDC Python scripts 9d77c32 Moved GTID table tracking to an in-memory database 8ae7cb0 MXS-704: Fixed `which` usage in post-install scripts 195e118 Readwritesplit sessions aren't created if master is down 2be91da Added affected tables to avro diagnostics b185320 QUERY-LAST-TRANSACTION now returns proper table names 90860b5 Log stale master message only once 4859c60 Table name to GTID mapping f77bd23 First steps to backend SSL, not yet working. 68b5bf0 qc_sqlite: Don't treat TRUE and FALSE as identifiers fca8e59 qc_sqlite: Collect database names as well 6b0e04d qc_sqlite: Add support for SHOW CREATE VIEW 77f4b34 qc_mysqlembedded: Report more, rather than less a73e033 qc_sqlite: Extend builtin functions 9d9650e qc_sqlite: SQL_BUFFER_RESULT must decay to an id 83fe99d qc_sqlite: Support INSERT IGNORE 9d1c9ca Added avrorouter limitations and tutorial 8dd094d qc_sqlite: Recognize builtin functions 2edc3d6 Moved write operations of the maxavro library to a different file 1364e54 Added more comments to the Avro RBR handling code f711588 Added warnign about unsupported field types df0d250 Added SQLite3 based indexing to avrorouter 0c55706 Added GTID event flag check in AVRO processing bfe28dd qc_sqlite: Accept SET GLOBAL|SESSION ... a8d2068 qc_mysqlembedded: Exlude code that won't compile on 5.5.42 16ea0b3 qc_sqlite: Add support for DROP FUNCTION 1c0f1fc qc: Report stats after comparison 02345b2 qc_sqlite: Recognize builtin readonly functions c7a5e75 qc_sqlite: Recognize := 0aa849d qc: Make compare undestand the delimiter command fb0a877 qc_mysqlembedded: Examine Item::SUBSELECT_ITEMs 045cf8d qc: Add missing mtl commands e5c6f45 qc_sqlite: Relax qc_get_type comparison ac3b2df qc_sqlite: Add support for SHOW STATUS 73a34fb qc_sqlite: Add initial support for FLUSH 4ffbe79 qc_sqlite: Extend CREATE TABLE syntax 009af81 qc_sqlite: Add support for SHOW WARNINGS 001de97 qc: Ignore mysqltest constructs 128307d Merge branch 'release-1.4.3' into gpl-master 5e8a06a SET NAMES XXX added 3ca12ba MXS-685: MMMon clears server state before setting it dc4d2b0 Further steps to connection limit, non-working. ef70257 MXS-636: Master failures are no longer fatal errors 99f4c64 Updated QUERY-LAST-TRANSACTION format d1ff157 Changed QUERY-LAST-TRANSACTION format to JSON 8b2f1ac Fixed formatting of the avrorouter 61543df Added QUERY-LAST-TRANSACTION command c10d10b qc_sqlite: Add support for SHOW CREATE TABLE 106a38f qc_sqlite: Add support for DROP INDEX 2a85421 qc_sqlite: Extend what can be stated about a table 794cd1c qc_sqlite: Add support for MATCH ... AGAINST dd7b747 qc_sqlite: Accept FULLTEXT and SPATIAL in CREATE TABLE a13d6ce qc_sqlite: Add support for PREPARE and EXECUTE 0c5d29f qc_sqlite: Add support for ANALYZE a6cd32b qc_sqlite: Extend SET syntax 5d47704 qc_sqlite: Pick out fields from UPDATE t SET i = ... 0e05735 qc: Understand --error in server test files 8535975 qc_sqlite: Extend CREATE VIEW syntax b35e638 qc: Igore read type bit if write bit is on 818a814 qc_sqlite: Add support for SHOW VARIABLES 1aa877b qc_sqlite: Add initial support for DO e92913a qc_sqlite: Add support for CREATE VIEW d53a46d qc_sqlite: Recognize bit field literals b'1010' 1fb7977 Added GTID event timestmap into struct gtid_pos 8f95b10 Added new fields in AVRO diagnostics cb4db54 Added tests with large SQL packets to modutil tests e4dbd6b MXS-621: More fixes to log messages at startup 4f1e9ee qc: compare tester can now read server MySQL tests cd8154b qc_sqlite: Allow CHARACTER SET to be specified for column 6f8d053 Added MariaDB 10.1 check for new flags in GTID event 71c471b qc_mysqlembedded: Fix type bits setting 26b00a7 qc_sqlite: Extend ALTER grammar ea6057c qc_sqlite: Handle also pInto when dupping a struct select 2271559 qc_sqlite: Add support for SHOW TABLE STATUS 9caaf27 qc_sqlite: Add support for CREATE ... LIKE oldtable cd19932 Merge tag '1.4.2' into master 9e9e4d8 Merge branch 'develop' of https://github.com/mariadb-corporation/maxscale-bsl into develop 267cb60 qc_mysqlembedded: Look into parenthesized comma expressions 77c6ca9 qc_sqlite: Recognize token "<=>" 5ca9a9f qc_sqlite: Allow comma expressions in where clause b08e910 qc_sqlite: Add SELECT options d11e581 qc_sqlite: Some recursion cleanup d53d063 Add but don't invoke connection queue functionality. 6818104 Fix logic error in connections limiter 3c61605 qc_sqlite: Find more affected fields 9af8dfd Allow the classifiers to be specified on the command line 5d4a134 Activate call to protocol for max connections error message. 16638e7 Fix another mistake 234f9e6 Fix mistake 843a6fc Fix mistake. 2c6e9ad Fix errors in config.c; enable call to protocol on connection limit. fd27849 Introduce configuration items for Maximum and Queued Service connections 60d198d Implement very simple connection limit. 84d8f0f Merge remote-tracking branch 'origin/develop' into MXS-177 8a58e63 Merge remote-tracking branch 'origin/develop' into develop 08487cd Add assertion to enforce number of free DCBs not being negative. f73af2f Added MariaDB 10.1 check for new flags in GTID event 23898ec Fix wrong sprintf specifier, trailing white space. ea6cfa3 readwritesplit: Cleaned up routeQuery 3858df0 Cleaned up select_connect_backend_servers c38ee13 Added more buffer tests 48816df Added more modutils tests 537eac2 Added tests for modutil_get_complete_packets 22a6095 MXS-669: modutil_get_complete_packets no longer makes the buffer contiguous 51af97e qc_sqlite: Add support for CREATE INDEX e50c573 qc_sqlite: Dig out fields for IN f58c6df qc_sqlite: Dequote table name 319422b qc_sqlite: Accept ENUM as type for a column 5d6a45c qc_sqlite: Allow UNSIGNED to fallback to an id 16a5f20 qc_sqlite: Extend CREATE TABLE syntax d6268da qc_sqlite: Accept RIGHT and FULL OUTER joins 2207415 qc_sqlite: Allow STRAIGHT_JOIN in SELECT 6fee546 qc_sqlite: Pick upp more table names 9de5f84 Remove trailing white space. 758f84d Improve comments and messages in dcb.c and session.c re recycle memory. 1c2de21 Merge remote-tracking branch 'origin/develop' into dcb-optimise 6614944 DCB code tidying. Fix missing spinlock release; remove redundant variables ecd5e5c Remove extra code introduced by merge. 877127a Merge commit '3c0d3e5ab6ddde59da764ec904b517759074a31e' into develop 4275bbe Updated the Connector-C version to 2.2.3 c71042b Some tentative list management code; provide for counting service clients. ad0c8a6 qc_sqlite: Allow empty insert statement 72e75e5 qc_sqlite: Add support for SELECT ... INTO cc553fa qc_sqlite: MAXSCALE define can now be used everywhere 3305c6e qc_sqlite: Handle CASE in SELECT 702f62e qc_sqlite: Extend CREATE TABLE grammar 941c212 qc_sqlite: Add support for SHOW [INDEX|INDEXES|KEYS] 6a79136 qc_sqlite: Extend grammar for SHOW TABLES and SHOW COLUMNS f175d2d qc_sqlite: Add SHOW COLUMNS support 6e47951 qc_sqlite: Add support for SHOW TABLES bcfa0e7 qc_mysqlembedded: Return the actual name and not as-name 3e19f2e Fixed qlafilter build failure 810b24e MXS-675: Standardized qlafilter output be92173 qc_sqlite: Exclude alias names from affected fields 9479280 qc_sqlite: Add support for explain EXTENDED 13b0e10 qc_sqlite: Add support for DELETE a6ccfea qc_mysqlembedded: Look at all conditional items b428041 qc_sqlite: Extend SELECT options 83f829f query_classifier: Correctly calculate the length of a GWBUF 2ddb24c query_classifier: Ensure that -- comments are handled fa7a746 qc_sqlite: Allow STRAIGHT_JOIN in SELECTS 6f47819 FindLibUUID update 5ed897b Added FindLibUUID cmake file 16e02bb Added FindLibUUID cmake file aff63e0 MXS-680: qc_mysqlembedded does not look into functions 8a0eeb4 query_classifier: Improve output of compare 6f08185 Query classifier can now convert enums to strings 124e2b9 MXS-679: Correctly collect fields of WHERE 353c97c transaction_safety default is off 896e37b qc_sqlite: Invert stop logic and be more verbose 7a44d4d qc_sqlite: Extend what is accepted in CREATE TABLE 4dbf499 qc_sqlite: Accept FIRST in ALTER TABLE 3f655c0 qc_sqlite: Update table and affected fields for INSERT 8e1e275 qc_sqlite: Make AS optional in CREATE statement 5f2084b qc_sqlite: Add support for ENGINE when creating a table 242f183 qc_sqlite: CREATE paramters handled in the correct place 8ed2e25 qc_sqlite: Trace only when needed 63d4531 qc_sqlite: Update affected fields also from functions 118cdc3 qc_sqlite: Allow multiple index names in USE|IGNORE INDEX 912da76 qc_sqlite: Add initial support for ...IGNORE INDEX... 0aa7de6 qc_sqlite: Log detailed message on error 3e3bf1a qc_sqlite: Extend create syntax. c4a4572 qc_sqlite: Exclude quoted values 1621f49 Removed MYSQL_EMBEDDED_LIBRARIES d3e324c UUID generation now comes from libuuid e8fe678 qc_sqlite: Enable confitional compilation a9522ba qc_sqlite: Handle X.Y selects 9bc9770 qc_sqlite: Use same stream when outputting padding 366257a qc_sqlite: Add support for UNSIGNED and ZEROFILL d4d90ff qc_sqlite: Add support for DROP VIEW d0519bd qc_sqlite: Extend DROP TABLE syntax c1e4894 qc_sqlite: Add flag to compare for stopping at first error 9fd6344 MXS-674: Maxinfo generates invalid JSON 3c0d3e5 Fix stupid errors. 9d32b2d Include read queue in buffer provided by dcb_read; changes to match. b690797 Fix double spinlock release in random_jkiss. 6a4328f Fix problems of memory not being freed in some error cases. 2112e56 Change DCB and Session handling to recycle memory; fix bug in random_jkiss. 3912f72 MXS-631, MXS-632: Cleaned up default value CMake files 383ccb8 Fixed build failure on MariaDB 5.5 a60bca5 Merge branch '1.2.1-binlog_router_trx' into develop 3c2a062 Fix to crashes in embedded library with MariaDB 10.0 d3fe938 MXS-662: Service protocol check no longer ignores bind address c3da49b qc_sqlite: Update affected fields from everywhere 7a0fab8 qc_sqlite: Allow verbosity of compare test to be controlled 81d6822 qc_sqlite: Cleanup handling of select columns 13e5c59 qc_sqlite: Introduce custom allocation functions 026f27d qc_sqlite: Add support for "USE database" 99079df qc_sqlite: Ignore duplicates when comparing affected fields ca45cd6 qc_sqlite: Add initial support for qc_get_database_names 75970b6 qc_sqlite: Add support for DROP TABLE. b97e45d qc_sqlite: Move get_affected_fields() to other helpers cb0fa96 qc_sqlite: Collect table names of INSERT 3a7c513 qc_mysqlembedded: Only look for created name if CREATE 308b0a4 qc_sqlite: Add support for gc_get_created_table_name. 0dc4af2 qc_sqlite: Add qc_has_clause() handling to update e9f2d1d qc_sqlite: Update now also provides table names c3192e4 qc_sqlite: Add initial support for get_table_names c51eafd qc_sqlite: Add support for qc_has_clause f318fb2 qc_mysqlembedded: Work around embedded lib bug 4ba2e11 qc_sqlite: Add initial support for qc_get_affected_fields 080dea5 qc_sqlite: Support is_read_query 3f94df1 Fixed compare.cc build failure 868a712 Updated freeing of buffer chains in readwritesplit 9bf7fca Formatted readwritesplit source code de4da2b Add assertion to spinlock release to detect release of already released spinlock. d30955a qc_sqlite: Handle the default case of affected fields. 5d02b3f qc_sqlite: Set operation when creating table 94a334d Add test for comparing qc-output aa6f5d6 Allow a specific query classifier to be loaded explicitly c799d37 Test both qc_mysqlembedded and qc_sqlite f8d9aa1 qc_sqlite: Enable "set @user_var=@@system_var" f190bdc qc_sqlite: Recognize /*!-comments b694b55 Fixed binary Avro format streaming c95fa86 qc_sqlite: Report correctly the type of set autocommit 9cb236c qc_sqlite: Add test case 77b4e62 Ensure classify test checks all types 962039e Change return type of qc_get_type ae00df8 qc_sqlite: Add initial support for the SET statement. 88253c5 qc_sqlite: Rename functions fa48043 Rework of MySQL backend protocol clean up to fix fault. 3851064 qc_sqlite: Correct recognition of system variables (@@xyz). 9d86f7f qc_sqlite: Detect user and system variables. a683297 qc_sqlite: Recognize and accept system variables (@@xyz). a4f64dd qc_sqlite: Add initial support for CREATE [TEMPORARY] TABLE f834b4f MXS-661: Only COM_QUERY packets are parsed 30077c1 CMake policies set only for correct versions a166f34 Suppress warning about unknown CMake target 1412730 Added more variables to launchable monitor scripts 358c194 MXS-656: Galera nodes with index 0 can be master again 842aec5 qc_sqlite: Add support for BEGIN, COMMIT, ROLLBACK b9cad6d Add initial support for UPDATE. 95741cb Add initial support for insert. 3796158 Re-install sqlite whenever parse.y has changed 5bcd8cf Ensure that the query is the one passed cf05533 Add support for obtaining the type of a query 400d8b4 Always log the outcome 45cf632 Fixed resource leaks and minor bugs fa9e970 Printout the query when there is a mismatch. 263cb07 All classify to be used with any query classifier ea381b9 Further cleanup of classify.c 23f6f30 Merge pull request #107 from godmodelabs/typo-dpkg 8c2a64e Fixed classify build failure 0c3070b Fixed binlog to Avro conversion bugs b827ba9 MXS-653: Silence maxpasswd 30d981c MXS-654: Add test for checking maxpasswd 984039b Rearrange classify.c 837e46d Add log initialization 1cc7a6e Reformat query_classifier/test/classify.c 065a4e5 Merge branch 'develop' into develop-MXS-544-b-merge ca27f13 Fixed binlog build failure fb81be2 fixed typo dpgk <-> dpkg 1e88d5d Added python based CDC user creation script 040bbdd MXS-633: Monitor permission checks moved to modules cde7595 Master-Slave clusters are now robust by default 158c776 Cleaned up core test suite 94c6e66 Fixed bugs resulting from merge a491e11 Merge remote-tracking branch 'origin/MXS-544-b' into develop-MXS-544-b-merge 30f9f25 Cleaned up avro.c 6286f64 Merge branch 'release-1.4.1' into develop 00206ac MXS-194: Added support for more query types to dbfwfilter 267832b Fixed diagnostic output a64b694 Fixed bugs in avrorouter 8faaba1 Fixed a bug in GTID seeking a5fafb7 Fixed typos in avrorouter documentation 8080379 Added avrorouter documentation fa07d8a Fixed dbfwfilter rule parser build failure 744ce0d Constraints are ignored in DDL statement processing 50808c6 Cleaned up avrorouter 47f6032 Merge branch '1.2.1-binlog_router_trx_lint' into develop caa0956 Added missing dependencies to maxscale-core 92df61a Remove parallel make from travis coverity builds fa2b2b4 Added more error logging to Avro record reading 9a98e8b Support for GTID requests and data bursts c2a787b Small diagnostic fix c4cee7e Added format output requested by client 50483c7 Cleaning up of Avro code d485379 Added support for binary Avro protocol c22cdbb Converted Avro GTID from string to integer representation 5795ca9 Added coverity notification email to .travis.yml a06e44d Added coverity_scan to Travis 6b94384 Fixed memory leak in avro_schema.c a11096c Support for db.table request for Avrorouter 4e5cbbf Fixed bugs in Avro record reading a99e427 Fixed minor bugs in avrorouter 01db8ae Fixed errors with CREATE TABLE statements f5f3d7a Diagnostic routine update 209324f Added missing include for log_manager.h e62f764 Added sending of schemas and file rotation 8c8fcbb Added missing log_manager.h include b13942d Changed printf calls in maxavro library to MXS_ERROR 1168962 More lint inspired changes, mainly in blr_master.c and blr_slave.c ced8f2f Fixed directory checks in avrorouter a8ae6be Minor fix to string processing fbd2d95 Fixed typo in dbfwfilter's CMakeLists.txt 29c3cf4 Merge pull request #106 from mariadb-corporation/willfong-patch-1 854d4e9 Add password column name to example 2f956df Moved server state change logging to a common function 007121f Fixed truncated string values 782892b Fix lint errors and warnings for blr_file.c 4f99fc5 Added Avro testing script 2820980 Small fix to help clear lint problems in blr.c 3afeda4 Fixed errors and warnings located by lint ecfff82 Fix most lint problems in blr.c 223689c Added ALTER TABLE support 80bc935 Fix final lint problems with mysql_common protocol functions. e068310 Added preliminary alter table parsing 8c723f1 Lint monitor modules fdb5620 Fix lint issues in authenticators. 84f0e04 Added function documentation and renamed files 365d9f5 Tidy up, mainly for lint 2ff3005 Added update rows event processing and event types to avro records 2ae0371 Fixed failing regex and improved data streaming f19206a Renamed avrorouter header aa7174b Moved relpacement and storage of ddl statements to a separate function 0c10be8 Improved client notification and added Avro block size managemet 91405a7 Cleaned up instance creation dd97485 Removed useless vars af64e9e Added CDC authentication with a db file b73a118 Streamline and lint MySQL backend protocol. 65034ce Merge branch 'release-1.4.0' into develop 28f7e4e Added callback for AVRO client async data transmission 628c27a Added MAXAVRO_FILE struct to AVRO_CLIENT 32b3645 Fixed slavelag build failure 7b15542 Added default authentication method for CDC protocol 5f8e20f Renamed maxavro types and formatted files that use them 882cf84 Added more function documentation to maxavro library 9532f0b Fixed CDC protocol build failure 35a1d3a Added support for offsets in client requests 94577ac Fixed, formatted and refactored CDC protocol da9bcad Use the maxavro library to read data from Avro files 3ececee Added low level error checking to maxavro library 01b0b8b Tidy and lint mysql_client.c 943f0a7 Added handling of Avro boolean data types to maxavro library 4c781f7 Cleaned up maxavro library and avrorouter 6b2e85d Renamed functions more consistently and cleaned up code e07158a Moved query event handling to its own function df7d4c0 Added avro_ prefix to rbr.c fcbfceb Added seeking to a position in an Avro file 068243a CDC auth decoding 3584d54 Add checks to simplify downstream logic. 9b2c323 Removed useless fprintf bd5cd52 Added missing authfunc setup e4aff59 Added record value processing 5cc8615 Added value length functions 7921ecc Merge branch 'MXS-615' into MXS-483 4b09cca Added Travis status to readme.md cca3a48 Simplify interface to max admin authentication. 4739838 Authenticator API update 233505f Maxavrocheck now accepts multiple files 3fdd137 Improved the Avro file handling a6ba913 Merge from MXS-615 417d742 Added maxavrocheck 014f9cf Remove obsolete second parameter from authenticate function in authenticators. ece7ece MaxAdmin authentication converted to a module. Fix quirk in SSL setup. 7c8b37e Moved contents of avro_schema.h into mxs_avro.h d6660cf Improvements to type handling 71ed0cf Protocol API to have entry point for obtaining default authenticator name. 9d35de2 Fixed transaction tracking 5be02a2 Avrorouter internal state is now stored in the Avro file directory 9293464 Added new info to avro diagnostics 06e0e93 Protocol modules can still handle the authentication outside authenticator modules 6d7108b Added JSON output when Requesting an avro file 6188211 Added new CDC protocol state c8af27f CDC authentication uses its own authenticator 6590f94 Factor out qc_get_qtype_str b7880f1 Fix qc_sqlite CMakeLists.txt bd4ff43 Fixed connector-c being updated and built after every make invokation 0d9e57b Fixed non-MariaDB connectors being used in builds 3d3b779 FIX BUG IN CLIENT DCB SHUTDOWN THAT CAN CAUSE CRASHES e45ba33 Fixed Connector-C .cmake files c130189 Fixed connector-c being updated and built after every make invokation 7f3cdf3 Fixed errors on binlog rotation 9d3c83a Remove qc_sqlite 15e8ba5 CDC protocol is now compliant with new protocol structure 4460869 Merge branch 'release-1.4.0' into MXS-483 ea40812 Cleaned up the binlog processing loop cb646ca Add minimal select recognition to qc_sqlite ac1a9c5 Fixed binlogrouter test 85dd227 Re-route sqlite's sqlite3Select. 7a2e6f3 Update CMakeLists.txt for qc_sqlite 7a751c3 Added timestamps to records and fixed minor bugs f73bdde Avrorouter state storage to disk fcf0488 Fixed Connector-C .cmake files 48b8e4e Merge branch 'MXS-615' into MXS-615-binlog-merge 7c8e19f Add missing dependencies for qc_sqlite bb9b667 Improvements to type handling and binlog position tracking dc66b74 Client UUID added f12fce4 AVRO registration is now handled by avro router 575b809 Add skeleton sqlite-based query classifier. d09d5fc Build sqlite 146d1f9 Fixed BLOB type handling and refined error messages 6e9e521 Added client user to diagnostics 4538bb8 Merge pull request #104 from rasmushoj/develop 7e18d95 Avro router diagnostics routine update 01e3f75 reverted changes in CMakeLists.txt 52f7c78 reverted changes in postinst.in eaed577 Added sqlite 3110100 a58cdda Travis configuration for MaxScale. ... 38b452d MIGRATE FREE CLIENT DATA TO AUTH MODULE; BUG FIXES; TIDY UP 6e64506 Fixed minor bugs aff2411 Enabled CDC protocol f669100 Fixed NULL Avro value being assigned to a field which cannot be NULL 8f6b16a Added row event processing to avrorouter 2939fe0 Updated Avro schema management to use actual column names 9e3b0cb Removed use of RBR related functions in binlogrouter d674903 Formatted avro files fe028d1 DEVELOPMENT OF AUTHENTICATION AS MODULE - WILL NOT WORK YET 977aded Added authenticator modules to the build a2b384f MOVE MYSQL AUTH CODE INTO AUTHENTICATOR MODULES DIRECTORY a5d7484 PRELIMINARY CHANGES TO CREATE AUTHENTICATORS AS MODULES 66cf802 Merge remote-tracking branch 'origin/develop' into MXS-615 bca0a7d MINOR CHANGES TO SATISFY LINT 5a9e397 Added Avrorouter binlog file walking fbc737f Fixed binlogrouter test 3c7c9d7 Added avrorouter main event handling loop 07ad81b Moved common binlogrouter code to a separate file 8c605ed Fixed avrorouter build failures aa1ba05 Moved binlog definitions to a separate header and fixed build failures eee7c55 Added create table statement detection e52b27e Added AVRO_INSTANCE and AVRO_CLIENT 0830caa Change test for client DCB to use role being DCB_ROLE_CLIENT_HANDLER. ... 997bbca Change protocols to continue looping if an accept fails; ... 522e42d Make use of dcb_accept and dcb_listen in httpd and telnetd protocols. 4e692b0 Generalise dcb_listen to tailor log messages to different protocols. ... 52c431d Remove support for passing default port number when handling ... afe5abc Fix bug in creation of SSL listener structure; fix bugs in ... 0bd6c77 Merge remote-tracking branch 'origin/MXS-544' into MXS-544-a ... 7598597 Add dcb_listen function to make a given DCB into a listener, ... a275d89 Maxbinlogcheck avro version can detect proper end of file 9bb55a5 Moved row event and table map event handling to a separate file b7d9e09 Add/improve comments, fix mistake with premature return. c598770 First attempt at extracting general code into dcb_accept, ... f20f28f Testing with maxbinlogcheck b3c60b7 Added mysql_binlog files 0ff9971 Added MariaDB/MySQL binary data processing functions 124560c Merge branch '1.2.1-binlog_router_trx' into MXS-483 4deccff New router fro cdc client 2c11434 Fixed test compiler errors c1f7d24 Obliged to merge remote-tracking branch 'origin/develop' ... 1775599 Merge remote-tracking branch 'origin/MXS-544' into Test-dev-544-merge c5317da Small modifications in comments 11c0666 Code cleanup 64a5e9a Merge branch 'release-1.3.0' into MXS-483 2c11e89 First Implementation of CDC
2843 lines
74 KiB
C++
2843 lines
74 KiB
C++
/*
|
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
|
*
|
|
* Change Date: 2019-01-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
#include <log_manager.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include <errno.h>
|
|
#include <syslog.h>
|
|
#include <atomic.h>
|
|
|
|
#include <mlist.h>
|
|
#include <skygw_debug.h>
|
|
#include <skygw_types.h>
|
|
#include <skygw_utils.h>
|
|
|
|
#define MAX_PREFIXLEN 250
|
|
#define MAX_SUFFIXLEN 250
|
|
#define MAX_PATHLEN 512
|
|
#define MAXNBLOCKBUFS 10
|
|
|
|
/** for procname */
|
|
#if !defined(_GNU_SOURCE)
|
|
# define _GNU_SOURCE
|
|
#endif
|
|
|
|
static const char LOGFILE_NAME_PREFIX[] = "maxscale";
|
|
static const char LOGFILE_NAME_SUFFIX[] = ".log";
|
|
|
|
extern char *program_invocation_name;
|
|
extern char *program_invocation_short_name;
|
|
|
|
typedef enum
|
|
{
|
|
BB_READY = 0x00,
|
|
BB_FULL,
|
|
BB_CLEARED
|
|
} blockbuf_state_t;
|
|
|
|
typedef enum
|
|
{
|
|
FILEWRITER_INIT,
|
|
FILEWRITER_RUN,
|
|
FILEWRITER_DONE
|
|
} filewriter_state_t;
|
|
|
|
/**
|
|
* UNINIT means zeroed memory buffer allocated for the struct.
|
|
* INIT means that struct members may have values, and memory may
|
|
* have been allocated. Done function must check and free it.
|
|
* RUN Struct is valid for run-time checking.
|
|
* DONE means that possible memory allocations have been released.
|
|
*/
|
|
typedef enum
|
|
{
|
|
UNINIT = 0,
|
|
INIT,
|
|
RUN,
|
|
DONE
|
|
} flat_obj_state_t;
|
|
|
|
/**
|
|
* LOG_FLUSH_NO Do not flush after writing.
|
|
* LOG_FLUSH_YES Flush after writing.
|
|
*/
|
|
enum log_flush
|
|
{
|
|
LOG_FLUSH_NO = 0,
|
|
LOG_FLUSH_YES = 1
|
|
};
|
|
|
|
#if defined(SS_DEBUG)
|
|
static int write_index;
|
|
static int block_start_index;
|
|
static int prevval;
|
|
static simple_mutex_t msg_mutex;
|
|
#endif
|
|
|
|
/**
|
|
* Default augmentation.
|
|
*/
|
|
static int DEFAULT_LOG_AUGMENTATION = 0;
|
|
|
|
static struct
|
|
{
|
|
int augmentation; // Can change during the lifetime of log_manager.
|
|
bool do_highprecision; // Can change during the lifetime of log_manager.
|
|
bool do_syslog; // Can change during the lifetime of log_manager.
|
|
bool do_maxlog; // Can change during the lifetime of log_manager.
|
|
bool use_stdout; // Can NOT changed during the lifetime of log_manager.
|
|
} log_config =
|
|
{
|
|
DEFAULT_LOG_AUGMENTATION, // augmentation
|
|
false, // do_highprecision
|
|
true, // do_syslog
|
|
true, // do_maxlog
|
|
false // use_stdout
|
|
};
|
|
|
|
/**
|
|
* Variable holding the enabled priorities information.
|
|
* Used from logging macros.
|
|
*/
|
|
int mxs_log_enabled_priorities = 0;
|
|
|
|
/**
|
|
* Thread-specific struct variable for storing current session id and currently
|
|
* enabled log files for the session.
|
|
*/
|
|
__thread mxs_log_info_t mxs_log_tls = {0, 0};
|
|
|
|
/**
|
|
* Global counter for each log file type. It indicates for how many sessions
|
|
* each log type is currently enabled.
|
|
*/
|
|
ssize_t mxs_log_session_count[LOG_DEBUG + 1] = {0};
|
|
|
|
/**
|
|
* BUFSIZ comes from the system. It equals with block size or
|
|
* its multiplication.
|
|
*/
|
|
#define MAX_LOGSTRLEN BUFSIZ
|
|
|
|
/**
|
|
* Path to directory in which all files are stored to shared memory
|
|
* by the OS.
|
|
*/
|
|
const char* shm_pathname_prefix = "/dev/shm/";
|
|
|
|
/** Forward declarations
|
|
*/
|
|
typedef struct filewriter filewriter_t;
|
|
typedef struct logfile logfile_t;
|
|
typedef struct fnames_conf fnames_conf_t;
|
|
typedef struct logmanager logmanager_t;
|
|
|
|
/**
|
|
* Global log manager pointer and lock variable.
|
|
* lmlock protects logmanager access.
|
|
*/
|
|
static int lmlock;
|
|
static logmanager_t* lm;
|
|
static bool flushall_flag;
|
|
static bool flushall_started_flag;
|
|
static bool flushall_done_flag;
|
|
|
|
/** This is used to detect if the initialization of the log manager has failed
|
|
* and that it isn't initialized again after a failure has occurred. */
|
|
static bool fatal_error = false;
|
|
|
|
/** Writer thread structure */
|
|
struct filewriter
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t fwr_chk_top;
|
|
#endif
|
|
flat_obj_state_t fwr_state;
|
|
logmanager_t* fwr_logmgr;
|
|
/** Physical files */
|
|
skygw_file_t* fwr_file;
|
|
/** fwr_logmes is for messages from log clients */
|
|
skygw_message_t* fwr_logmes;
|
|
/** fwr_clientmes is for messages to log clients */
|
|
skygw_message_t* fwr_clientmes;
|
|
skygw_thread_t* fwr_thread;
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t fwr_chk_tail;
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* Log client's string is copied to block-sized log buffer, which is passed
|
|
* to file writer thread.
|
|
*/
|
|
typedef struct blockbuf
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t bb_chk_top;
|
|
#endif
|
|
blockbuf_state_t bb_state; /**State of the block buffer*/
|
|
simple_mutex_t bb_mutex; /**< bb_buf_used, bb_isfull */
|
|
int bb_refcount; /**< protected by list mutex. #of clients */
|
|
// int bb_blankcount; /**< # of blanks used btw strings */
|
|
size_t bb_buf_size;
|
|
size_t bb_buf_left;
|
|
size_t bb_buf_used;
|
|
char bb_buf[MAX_LOGSTRLEN];
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t bb_chk_tail;
|
|
#endif
|
|
} blockbuf_t;
|
|
|
|
/**
|
|
* logfile object corresponds to physical file(s) where
|
|
* certain log is written.
|
|
*/
|
|
struct logfile
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t lf_chk_top;
|
|
#endif
|
|
flat_obj_state_t lf_state;
|
|
bool lf_init_started;
|
|
bool lf_store_shmem;
|
|
logmanager_t* lf_lmgr;
|
|
/** fwr_logmes is for messages from log clients */
|
|
skygw_message_t* lf_logmes;
|
|
char* lf_filepath; /**< path to file used for logging */
|
|
char* lf_linkpath; /**< path to symlink file. */
|
|
const char* lf_name_prefix;
|
|
const char* lf_name_suffix;
|
|
int lf_name_seqno;
|
|
char* lf_full_file_name; /**< complete log file name */
|
|
char* lf_full_link_name; /**< complete symlink name */
|
|
int lf_nfiles_max;
|
|
size_t lf_file_size;
|
|
/** list of block-sized log buffers */
|
|
mlist_t lf_blockbuf_list;
|
|
size_t lf_buf_size;
|
|
bool lf_flushflag;
|
|
bool lf_rotateflag;
|
|
int lf_spinlock; /**< lf_flushflag & lf_rotateflag */
|
|
int lf_npending_writes;
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t lf_chk_tail;
|
|
#endif
|
|
};
|
|
|
|
|
|
struct fnames_conf
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t fn_chk_top;
|
|
#endif
|
|
flat_obj_state_t fn_state;
|
|
char* fn_logpath;
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t fn_chk_tail;
|
|
#endif
|
|
};
|
|
|
|
struct logmanager
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t lm_chk_top;
|
|
#endif
|
|
bool lm_enabled;
|
|
simple_mutex_t lm_mutex;
|
|
size_t lm_nlinks;
|
|
/** fwr_logmes is for messages from log clients */
|
|
skygw_message_t* lm_logmes;
|
|
/** fwr_clientmes is for messages to log clients */
|
|
skygw_message_t* lm_clientmes;
|
|
fnames_conf_t lm_fnames_conf;
|
|
logfile_t lm_logfile;
|
|
filewriter_t lm_filewriter;
|
|
mxs_log_target_t lm_target;
|
|
#if defined(SS_DEBUG)
|
|
skygw_chk_t lm_chk_tail;
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* Type definition for string part. It is used in forming the log file name
|
|
* from string parts provided by the client of log manager, as arguments.
|
|
*/
|
|
|
|
typedef struct strpart
|
|
{
|
|
const char* sp_string;
|
|
struct strpart* sp_next;
|
|
} strpart_t;
|
|
|
|
|
|
/** Static function declarations */
|
|
static bool logfiles_init(logmanager_t* lmgr);
|
|
static bool logfile_init(logfile_t* logfile,
|
|
logmanager_t* logmanager,
|
|
bool store_shmem);
|
|
static void logfile_done(logfile_t* logfile);
|
|
static void logfile_free_memory(logfile_t* lf);
|
|
static void logfile_flush(logfile_t* lf);
|
|
static void logfile_rotate(logfile_t* lf);
|
|
static bool logfile_build_name(logfile_t* lf);
|
|
static bool logfile_open_file(filewriter_t* fw, logfile_t* lf);
|
|
static char* form_full_file_name(strpart_t* parts, logfile_t* lf, int seqnoidx);
|
|
|
|
static bool filewriter_init(logmanager_t* logmanager,
|
|
filewriter_t* fw);
|
|
static void filewriter_done(filewriter_t* filewriter);
|
|
static bool fnames_conf_init(fnames_conf_t* fn, const char* logdir);
|
|
static void fnames_conf_done(fnames_conf_t* fn);
|
|
static void fnames_conf_free_memory(fnames_conf_t* fn);
|
|
static void* thr_filewriter_fun(void* data);
|
|
static logfile_t* logmanager_get_logfile(logmanager_t* lm);
|
|
static bool logmanager_register(bool writep);
|
|
static void logmanager_unregister(void);
|
|
static bool logmanager_init_nomutex(const char* ident,
|
|
const char* logdir,
|
|
mxs_log_target_t target);
|
|
static void logmanager_done_nomutex(void);
|
|
|
|
static int logmanager_write_log(int priority,
|
|
enum log_flush flush,
|
|
size_t prefix_len,
|
|
size_t len,
|
|
const char* str);
|
|
|
|
static blockbuf_t* blockbuf_init();
|
|
static void blockbuf_node_done(void* bb_data);
|
|
static char* blockbuf_get_writepos(blockbuf_t** p_bb,
|
|
size_t str_len,
|
|
bool flush);
|
|
|
|
static void blockbuf_register(blockbuf_t* bb);
|
|
static void blockbuf_unregister(blockbuf_t* bb);
|
|
static char* add_slash(char* str);
|
|
|
|
static bool check_file_and_path(char* filename,
|
|
bool* writable,
|
|
bool do_log);
|
|
|
|
static bool file_is_symlink(char* filename);
|
|
static int find_last_seqno(strpart_t* parts, int seqno, int seqnoidx);
|
|
void flushall_logfiles(bool flush);
|
|
bool thr_flushall_check();
|
|
|
|
static bool logmanager_init_nomutex(const char* ident,
|
|
const char* logdir,
|
|
mxs_log_target_t target)
|
|
{
|
|
fnames_conf_t* fn;
|
|
filewriter_t* fw;
|
|
int err;
|
|
bool succ = false;
|
|
|
|
lm = (logmanager_t *)calloc(1, sizeof(logmanager_t));
|
|
|
|
if (lm == NULL)
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
lm->lm_target = (target == MXS_LOG_TARGET_DEFAULT ? MXS_LOG_TARGET_FS : target);
|
|
#if defined(SS_DEBUG)
|
|
lm->lm_chk_top = CHK_NUM_LOGMANAGER;
|
|
lm->lm_chk_tail = CHK_NUM_LOGMANAGER;
|
|
write_index = 0;
|
|
block_start_index = 0;
|
|
prevval = -1;
|
|
simple_mutex_init(&msg_mutex, "Message mutex");
|
|
#endif
|
|
lm->lm_clientmes = skygw_message_init();
|
|
lm->lm_logmes = skygw_message_init();
|
|
|
|
if (lm->lm_clientmes == NULL || lm->lm_logmes == NULL)
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
fn = &lm->lm_fnames_conf;
|
|
fw = &lm->lm_filewriter;
|
|
fn->fn_state = UNINIT;
|
|
fw->fwr_state = UNINIT;
|
|
|
|
// The openlog call is always made, but a connection to the system logger will
|
|
// not be made until a call to syslog is made.
|
|
openlog(ident, LOG_PID | LOG_ODELAY, LOG_USER);
|
|
|
|
// This will disable logging to actual files but they are still created
|
|
if (target == MXS_LOG_TARGET_STDOUT)
|
|
{
|
|
logdir = NULL;
|
|
}
|
|
|
|
/** Initialize configuration including log file naming info */
|
|
if (!fnames_conf_init(fn, logdir))
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
/** Initialize logfiles */
|
|
if (!logfiles_init(lm))
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
/**
|
|
* Set global variable
|
|
*/
|
|
mxs_log_enabled_priorities = MXS_LOG_ERR | MXS_LOG_NOTICE | MXS_LOG_WARNING;
|
|
|
|
/**
|
|
* Initialize filewriter data and open the log file
|
|
* for each log file type.
|
|
*/
|
|
if (!filewriter_init(lm, fw))
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
/** Initialize and start filewriter thread */
|
|
fw->fwr_thread = skygw_thread_init("filewriter thr", thr_filewriter_fun, (void *)fw);
|
|
|
|
if (fw->fwr_thread == NULL)
|
|
{
|
|
err = 1;
|
|
goto return_succ;
|
|
}
|
|
|
|
if ((err = skygw_thread_start(fw->fwr_thread)) != 0)
|
|
{
|
|
goto return_succ;
|
|
}
|
|
/** Wait message from filewriter_thr */
|
|
skygw_message_wait(fw->fwr_clientmes);
|
|
|
|
succ = true;
|
|
lm->lm_enabled = true;
|
|
|
|
return_succ:
|
|
if (err != 0)
|
|
{
|
|
/** This releases memory of all created objects */
|
|
logmanager_done_nomutex();
|
|
fprintf(stderr, "*\n* Error : Initializing log manager failed.\n*\n");
|
|
}
|
|
return succ;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Initializes log managing routines in MariaDB Corporation MaxScale.
|
|
*
|
|
* @param ident The syslog ident. If NULL, then the program name is used.
|
|
* @param logdir The directory for the log file. If NULL logging will be made to stdout.
|
|
* @param target Whether the log should be written to filesystem or shared memory.
|
|
* Meaningless if logdir is NULL.
|
|
*
|
|
* @return true if succeed, otherwise false
|
|
*
|
|
*/
|
|
bool mxs_log_init(const char* ident, const char* logdir, mxs_log_target_t target)
|
|
{
|
|
bool succ = false;
|
|
|
|
acquire_lock(&lmlock);
|
|
|
|
if (!lm)
|
|
{
|
|
succ = logmanager_init_nomutex(ident, logdir, target);
|
|
}
|
|
else
|
|
{
|
|
// TODO: This is not ok. If the parameters are different then
|
|
// TODO: we pretend something is what it is not.
|
|
succ = true;
|
|
}
|
|
|
|
release_lock(&lmlock);
|
|
|
|
return succ;
|
|
}
|
|
|
|
/**
|
|
* Release resources of log manager.
|
|
*
|
|
* Lock must have been acquired before calling
|
|
* this function.
|
|
*/
|
|
static void logmanager_done_nomutex(void)
|
|
{
|
|
int i;
|
|
logfile_t* lf;
|
|
filewriter_t* fwr;
|
|
|
|
fwr = &lm->lm_filewriter;
|
|
|
|
if (fwr->fwr_state == RUN)
|
|
{
|
|
CHK_FILEWRITER(fwr);
|
|
/** Inform filewriter thread and wait until it has stopped. */
|
|
skygw_thread_set_exitflag(fwr->fwr_thread, fwr->fwr_logmes, fwr->fwr_clientmes);
|
|
|
|
/** Free thread memory */
|
|
skygw_thread_done(fwr->fwr_thread);
|
|
}
|
|
|
|
/** Free filewriter memory. */
|
|
filewriter_done(fwr);
|
|
|
|
lf = logmanager_get_logfile(lm);
|
|
/** Release logfile memory */
|
|
logfile_done(lf);
|
|
|
|
closelog();
|
|
|
|
/** Release messages and finally logmanager memory */
|
|
fnames_conf_done(&lm->lm_fnames_conf);
|
|
skygw_message_done(lm->lm_clientmes);
|
|
skygw_message_done(lm->lm_logmes);
|
|
|
|
/** Set global pointer NULL to prevent access to freed data. */
|
|
free(lm);
|
|
lm = NULL;
|
|
}
|
|
|
|
/**
|
|
* End execution of log manager
|
|
*
|
|
* Stops file writing thread, releases filewriter, and logfiles.
|
|
*
|
|
*/
|
|
void mxs_log_finish(void)
|
|
{
|
|
acquire_lock(&lmlock);
|
|
|
|
if (lm)
|
|
{
|
|
CHK_LOGMANAGER(lm);
|
|
/** Mark logmanager unavailable */
|
|
lm->lm_enabled = false;
|
|
|
|
/** Wait until all users have left or someone shuts down
|
|
* logmanager between lock release and acquire.
|
|
*/
|
|
while (lm != NULL && lm->lm_nlinks != 0)
|
|
{
|
|
release_lock(&lmlock);
|
|
pthread_yield();
|
|
acquire_lock(&lmlock);
|
|
}
|
|
|
|
/** Shut down if not already shutted down. */
|
|
if (lm)
|
|
{
|
|
ss_dassert(lm->lm_nlinks == 0);
|
|
logmanager_done_nomutex();
|
|
}
|
|
}
|
|
|
|
release_lock(&lmlock);
|
|
}
|
|
|
|
static logfile_t* logmanager_get_logfile(logmanager_t* lmgr)
|
|
{
|
|
logfile_t* lf;
|
|
CHK_LOGMANAGER(lmgr);
|
|
lf = &lmgr->lm_logfile;
|
|
|
|
if (lf->lf_state == RUN)
|
|
{
|
|
CHK_LOGFILE(lf);
|
|
}
|
|
return lf;
|
|
}
|
|
|
|
/**
|
|
* Finds write position from block buffer for log string and writes there.
|
|
*
|
|
* Parameters:
|
|
*
|
|
* @param priority Syslog priority
|
|
* @param flush indicates whether log string must be written to disk
|
|
* immediately
|
|
* @param rotate if set, closes currently open log file and opens a
|
|
* new one
|
|
* @param prefix_len length of prefix to be stripped away when syslogging
|
|
* @param str_len length of formatted string (including terminating NULL).
|
|
* @param str string to be written to log
|
|
*
|
|
* @return 0 if succeed, -1 otherwise
|
|
*
|
|
*/
|
|
static int logmanager_write_log(int priority,
|
|
enum log_flush flush,
|
|
size_t prefix_len,
|
|
size_t str_len,
|
|
const char* str)
|
|
{
|
|
logfile_t* lf;
|
|
char* wp;
|
|
int err = 0;
|
|
blockbuf_t* bb;
|
|
blockbuf_t* bb_c;
|
|
size_t timestamp_len;
|
|
int i;
|
|
|
|
// The config parameters are copied to local variables, because the values in
|
|
// log_config may change during the course of the function, with would have
|
|
// unpleasant side-effects.
|
|
int do_highprecision = log_config.do_highprecision;
|
|
int do_maxlog = log_config.do_maxlog;
|
|
int do_syslog = log_config.do_syslog;
|
|
|
|
assert(str);
|
|
assert((priority & ~LOG_PRIMASK) == 0);
|
|
CHK_LOGMANAGER(lm);
|
|
|
|
// All messages are now logged to the error log file.
|
|
lf = &lm->lm_logfile;
|
|
CHK_LOGFILE(lf);
|
|
|
|
/** Length of string that will be written, limited by bufsize */
|
|
size_t safe_str_len;
|
|
/** Length of session id */
|
|
size_t sesid_str_len;
|
|
size_t cmplen = 0;
|
|
/**
|
|
* 2 braces, 2 spaces and terminating char
|
|
* If session id is stored to mxs_log_tls structure, allocate
|
|
* room for session id too.
|
|
*/
|
|
if ((priority == LOG_INFO) && (mxs_log_tls.li_sesid != 0))
|
|
{
|
|
sesid_str_len = 5 * sizeof(char) + get_decimal_len(mxs_log_tls.li_sesid);
|
|
}
|
|
else
|
|
{
|
|
sesid_str_len = 0;
|
|
}
|
|
if (do_highprecision)
|
|
{
|
|
timestamp_len = get_timestamp_len_hp();
|
|
}
|
|
else
|
|
{
|
|
timestamp_len = get_timestamp_len();
|
|
}
|
|
cmplen = sesid_str_len > 0 ? sesid_str_len - sizeof(char) : 0;
|
|
|
|
bool overflow = false;
|
|
/** Find out how much can be safely written with current block size */
|
|
if (timestamp_len - sizeof(char) + cmplen + str_len > lf->lf_buf_size)
|
|
{
|
|
safe_str_len = lf->lf_buf_size;
|
|
overflow = true;
|
|
}
|
|
else
|
|
{
|
|
safe_str_len = timestamp_len - sizeof(char) + cmplen + str_len;
|
|
}
|
|
/**
|
|
* Seek write position and register to block buffer.
|
|
* Then print formatted string to write position.
|
|
*/
|
|
|
|
#if defined (SS_LOG_DEBUG)
|
|
{
|
|
char *copy, *tok;
|
|
int tokval;
|
|
|
|
simple_mutex_lock(&msg_mutex, true);
|
|
copy = strdup(str);
|
|
tok = strtok(copy, "|");
|
|
tok = strtok(NULL, "|");
|
|
|
|
if (strstr(str, "message|") && tok)
|
|
{
|
|
tokval = atoi(tok);
|
|
|
|
if (prevval > 0)
|
|
{
|
|
ss_dassert(tokval == (prevval + 1));
|
|
}
|
|
prevval = tokval;
|
|
}
|
|
free(copy);
|
|
simple_mutex_unlock(&msg_mutex);
|
|
}
|
|
#endif
|
|
/** Book space for log string from buffer */
|
|
if (do_maxlog)
|
|
{
|
|
// All messages are now logged to the error log file.
|
|
wp = blockbuf_get_writepos(&bb, safe_str_len, flush);
|
|
}
|
|
else
|
|
{
|
|
wp = (char*)malloc(sizeof(char) * (timestamp_len - sizeof(char) + cmplen + str_len + 1));
|
|
}
|
|
|
|
if (wp == NULL)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
#if defined (SS_LOG_DEBUG)
|
|
{
|
|
sprintf(wp, "[msg:%d]", atomic_add(&write_index, 1));
|
|
safe_str_len -= strlen(wp);
|
|
wp += strlen(wp);
|
|
}
|
|
#endif
|
|
/**
|
|
* Write timestamp with at most <timestamp_len> characters
|
|
* to wp.
|
|
* Returned timestamp_len doesn't include terminating null.
|
|
*/
|
|
if (do_highprecision)
|
|
{
|
|
timestamp_len = snprint_timestamp_hp(wp, timestamp_len);
|
|
}
|
|
else
|
|
{
|
|
timestamp_len = snprint_timestamp(wp, timestamp_len);
|
|
}
|
|
if (sesid_str_len != 0)
|
|
{
|
|
/**
|
|
* Write session id
|
|
*/
|
|
snprintf(wp + timestamp_len, sesid_str_len, "[%lu] ", mxs_log_tls.li_sesid);
|
|
sesid_str_len -= 1; /*< don't calculate terminating char anymore */
|
|
}
|
|
/**
|
|
* Write next string to overwrite terminating null character
|
|
* of the timestamp string.
|
|
*/
|
|
snprintf(wp + timestamp_len + sesid_str_len,
|
|
safe_str_len - timestamp_len - sesid_str_len,
|
|
"%s",
|
|
str);
|
|
|
|
/** Add an ellipsis to an overflowing message to signal truncation. */
|
|
if (overflow && safe_str_len > 4)
|
|
{
|
|
memset(wp + safe_str_len - 4, '.', 3);
|
|
}
|
|
/** write to syslog */
|
|
if (do_syslog)
|
|
{
|
|
// Strip away the timestamp and the prefix (e.g. "error : ").
|
|
const char *message = wp + timestamp_len + prefix_len;
|
|
|
|
switch (priority)
|
|
{
|
|
case LOG_EMERG:
|
|
case LOG_ALERT:
|
|
case LOG_CRIT:
|
|
case LOG_ERR:
|
|
case LOG_WARNING:
|
|
case LOG_NOTICE:
|
|
syslog(priority, "%s", message);
|
|
break;
|
|
|
|
default:
|
|
// LOG_INFO and LOG_DEBUG messages are never written to syslog.
|
|
break;
|
|
}
|
|
}
|
|
/** remove double line feed */
|
|
if (wp[safe_str_len - 2] == '\n')
|
|
{
|
|
wp[safe_str_len - 2] = ' ';
|
|
}
|
|
wp[safe_str_len - 1] = '\n';
|
|
|
|
if (do_maxlog)
|
|
{
|
|
blockbuf_unregister(bb);
|
|
}
|
|
else
|
|
{
|
|
free(wp);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* Register writer to a block buffer. When reference counter is non-zero the
|
|
* flusher thread doesn't write the block to disk.
|
|
*
|
|
* @param bb block buffer
|
|
*/
|
|
static void blockbuf_register(blockbuf_t* bb)
|
|
{
|
|
CHK_BLOCKBUF(bb);
|
|
ss_dassert(bb->bb_refcount >= 0);
|
|
atomic_add(&bb->bb_refcount, 1);
|
|
}
|
|
|
|
/**
|
|
* Unregister writer from block buffer. If the buffer got filled up and there
|
|
* are no other registered writers anymore, notify the flusher thread.
|
|
*
|
|
* @param bb block buffer
|
|
*/
|
|
static void blockbuf_unregister(blockbuf_t* bb)
|
|
{
|
|
logfile_t* lf;
|
|
|
|
CHK_BLOCKBUF(bb);
|
|
ss_dassert(bb->bb_refcount >= 1);
|
|
lf = &lm->lm_logfile;
|
|
CHK_LOGFILE(lf);
|
|
/**
|
|
* if this is the last client in a full buffer, send write request.
|
|
*/
|
|
if (atomic_add(&bb->bb_refcount, -1) == 1 && bb->bb_state == BB_FULL)
|
|
{
|
|
skygw_message_send(lf->lf_logmes);
|
|
}
|
|
ss_dassert(bb->bb_refcount >= 0);
|
|
}
|
|
|
|
|
|
/**
|
|
* @node (write brief function description here)
|
|
*
|
|
* Parameters:
|
|
* @param id - <usage>
|
|
* <description>
|
|
*
|
|
* @param str_len - <usage>
|
|
* <description>
|
|
*
|
|
* @return
|
|
*
|
|
*
|
|
* @details List mutex now protects both the list and the contents of it.
|
|
* TODO : It should be so that adding and removing nodes of the list is protected
|
|
* by the list mutex. Buffer modifications should be protected by buffer
|
|
* mutex.
|
|
*
|
|
*/
|
|
static char* blockbuf_get_writepos(blockbuf_t** p_bb,
|
|
size_t str_len,
|
|
bool flush)
|
|
{
|
|
logfile_t* lf;
|
|
mlist_t* bb_list;
|
|
char* pos = NULL;
|
|
mlist_node_t* node;
|
|
blockbuf_t* bb;
|
|
#if defined(SS_DEBUG)
|
|
bool succ;
|
|
#endif
|
|
|
|
CHK_LOGMANAGER(lm);
|
|
lf = &lm->lm_logfile;
|
|
CHK_LOGFILE(lf);
|
|
bb_list = &lf->lf_blockbuf_list;
|
|
|
|
/** Lock list */
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
CHK_MLIST(bb_list);
|
|
|
|
if (bb_list->mlist_nodecount > 0)
|
|
{
|
|
/**
|
|
* At least block buffer exists on the list.
|
|
*/
|
|
node = bb_list->mlist_first;
|
|
|
|
/** Loop over blockbuf list to find write position */
|
|
while (true)
|
|
{
|
|
CHK_MLIST_NODE(node);
|
|
|
|
/** Unlock list */
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
|
|
bb = (blockbuf_t *)node->mlnode_data;
|
|
CHK_BLOCKBUF(bb);
|
|
|
|
/** Lock buffer */
|
|
simple_mutex_lock(&bb->bb_mutex, true);
|
|
|
|
if (bb->bb_state == BB_FULL || bb->bb_buf_left < str_len)
|
|
{
|
|
/**
|
|
* This block buffer is too full.
|
|
* Send flush request to file writer thread. This causes
|
|
* flushing all buffers, and (eventually) frees buffer space.
|
|
*/
|
|
blockbuf_register(bb);
|
|
|
|
bb->bb_state = BB_FULL;
|
|
|
|
blockbuf_unregister(bb);
|
|
|
|
/** Unlock buffer */
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
|
|
/** Lock list */
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
|
|
|
|
/**
|
|
* If next node exists move forward. Else check if there is
|
|
* space for a new block buffer on the list.
|
|
*/
|
|
if (node != bb_list->mlist_last)
|
|
{
|
|
node = node->mlnode_next;
|
|
continue;
|
|
}
|
|
/**
|
|
* All buffers on the list are full.
|
|
*/
|
|
if (bb_list->mlist_nodecount < bb_list->mlist_nodecount_max)
|
|
{
|
|
/**
|
|
* New node is created
|
|
*/
|
|
if ((bb = blockbuf_init()) == NULL)
|
|
{
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
return NULL;
|
|
}
|
|
|
|
CHK_BLOCKBUF(bb);
|
|
|
|
/**
|
|
* Increase version to odd to mark list update active
|
|
* update.
|
|
*/
|
|
bb_list->mlist_versno += 1;
|
|
ss_dassert(bb_list->mlist_versno % 2 == 1);
|
|
|
|
ss_debug(succ = ) mlist_add_data_nomutex(bb_list, bb);
|
|
ss_dassert(succ);
|
|
|
|
/**
|
|
* Increase version to even to mark completion of update.
|
|
*/
|
|
bb_list->mlist_versno += 1;
|
|
ss_dassert(bb_list->mlist_versno % 2 == 0);
|
|
}
|
|
else
|
|
{
|
|
/**
|
|
* List and buffers are full.
|
|
* Reset to the beginning of the list, and wait until
|
|
* there is a block buffer with enough space.
|
|
*/
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
|
|
node = bb_list->mlist_first;
|
|
continue;
|
|
}
|
|
|
|
}
|
|
else if (bb->bb_state == BB_CLEARED)
|
|
{
|
|
|
|
/**
|
|
*Move the cleared buffer to the end of the list if it is the first one in the list
|
|
*/
|
|
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
|
|
if (node == bb_list->mlist_first)
|
|
{
|
|
|
|
if ((bb_list->mlist_nodecount > 1) && (node != bb_list->mlist_last))
|
|
{
|
|
bb_list->mlist_last->mlnode_next = bb_list->mlist_first;
|
|
bb_list->mlist_first = bb_list->mlist_first->mlnode_next;
|
|
bb_list->mlist_last->mlnode_next->mlnode_next = NULL;
|
|
bb_list->mlist_last = bb_list->mlist_last->mlnode_next;
|
|
}
|
|
|
|
ss_dassert(node == bb_list->mlist_last);
|
|
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
simple_mutex_lock(&bb->bb_mutex, true);
|
|
|
|
bb->bb_state = BB_READY;
|
|
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
node = bb_list->mlist_first;
|
|
}
|
|
else
|
|
{
|
|
if (node->mlnode_next)
|
|
{
|
|
node = node->mlnode_next;
|
|
}
|
|
else
|
|
{
|
|
node = bb_list->mlist_first;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
}
|
|
else if (bb->bb_state == BB_READY)
|
|
{
|
|
/**
|
|
* There is space for new log string.
|
|
*/
|
|
break;
|
|
}
|
|
} /** while (true) */
|
|
}
|
|
else
|
|
{
|
|
|
|
/**
|
|
* Create the first block buffer to logfile's blockbuf list.
|
|
*/
|
|
|
|
if ((bb = blockbuf_init()) == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
CHK_BLOCKBUF(bb);
|
|
|
|
/** Lock buffer */
|
|
simple_mutex_lock(&bb->bb_mutex, true);
|
|
/**
|
|
* Increase version to odd to mark list update active update.
|
|
*/
|
|
bb_list->mlist_versno += 1;
|
|
ss_dassert(bb_list->mlist_versno % 2 == 1);
|
|
|
|
ss_debug(succ = ) mlist_add_data_nomutex(bb_list, bb);
|
|
ss_dassert(succ);
|
|
|
|
/**
|
|
* Increase version to even to mark completion of update.
|
|
*/
|
|
bb_list->mlist_versno += 1;
|
|
ss_dassert(bb_list->mlist_versno % 2 == 0);
|
|
|
|
/** Unlock list */
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
} /* if (bb_list->mlist_nodecount > 0) */
|
|
|
|
ss_dassert(pos == NULL);
|
|
ss_dassert(!(bb->bb_state == BB_FULL || bb->bb_buf_left < str_len));
|
|
ss_dassert(bb_list->mlist_nodecount <= bb_list->mlist_nodecount_max);
|
|
|
|
/**
|
|
* Registration to blockbuf adds reference for the write operation.
|
|
* It indicates that client has allocated space from the buffer,
|
|
* but not written yet. As long as refcount > 0 buffer can't be
|
|
* written to disk.
|
|
*/
|
|
blockbuf_register(bb);
|
|
*p_bb = bb;
|
|
/**
|
|
* At this point list mutex is held and bb points to a node with
|
|
* enough space available. pos is not yet set.
|
|
*/
|
|
pos = &bb->bb_buf[bb->bb_buf_used];
|
|
bb->bb_buf_used += str_len;
|
|
bb->bb_buf_left -= str_len;
|
|
|
|
ss_dassert((pos >= &bb->bb_buf[0]) && (pos <= &bb->bb_buf[MAX_LOGSTRLEN - str_len]));
|
|
|
|
/** read checkmark */
|
|
/** TODO: add buffer overflow checkmark
|
|
chk_val = (int)bb->bb_buf[bb->bb_buf_used-count_len];
|
|
ss_dassert(chk_val == bb->bb_strcount);
|
|
*/
|
|
|
|
/** TODO : write next checkmark
|
|
bb->bb_strcount += 1;
|
|
memcpy(&bb->bb_buf[bb->bb_buf_used], &bb->bb_strcount, count_len);
|
|
bb->bb_buf_used += count_len;
|
|
bb->bb_buf_left -= count_len;
|
|
*/
|
|
|
|
/**
|
|
* If flush flag is set, set buffer full. As a consequence, no-one
|
|
* can write to it before it is flushed to disk.
|
|
*/
|
|
bb->bb_state = (flush == true ? BB_FULL : bb->bb_state);
|
|
|
|
/** Unlock buffer */
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
return pos;
|
|
}
|
|
|
|
static void blockbuf_node_done(void* bb_data)
|
|
{
|
|
blockbuf_t* bb = (blockbuf_t *)bb_data;
|
|
simple_mutex_done(&bb->bb_mutex);
|
|
}
|
|
|
|
|
|
static blockbuf_t* blockbuf_init()
|
|
{
|
|
blockbuf_t* bb;
|
|
|
|
if ((bb = (blockbuf_t *) calloc(1, sizeof (blockbuf_t))))
|
|
{
|
|
#if defined(SS_DEBUG)
|
|
bb->bb_chk_top = CHK_NUM_BLOCKBUF;
|
|
bb->bb_chk_tail = CHK_NUM_BLOCKBUF;
|
|
#endif
|
|
simple_mutex_init(&bb->bb_mutex, "Blockbuf mutex");
|
|
bb->bb_buf_left = MAX_LOGSTRLEN;
|
|
bb->bb_buf_size = MAX_LOGSTRLEN;
|
|
#if defined(SS_LOG_DEBUG)
|
|
sprintf(bb->bb_buf, "[block:%d]", atomic_add(&block_start_index, 1));
|
|
bb->bb_buf_used += strlen(bb->bb_buf);
|
|
bb->bb_buf_left -= strlen(bb->bb_buf);
|
|
#endif
|
|
CHK_BLOCKBUF(bb);
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "Error: Memory allocation failed when initializing log manager block buffers.");
|
|
}
|
|
return bb;
|
|
}
|
|
|
|
/**
|
|
* Set log augmentation.
|
|
*
|
|
* @param bits One of the log_augmentation_t constants.
|
|
*/
|
|
void mxs_log_set_augmentation(int bits)
|
|
{
|
|
log_config.augmentation = bits & MXS_LOG_AUGMENTATION_MASK;
|
|
}
|
|
|
|
/**
|
|
* Helper for skygw_log_write and friends.
|
|
*
|
|
* @param int The syslog priority.
|
|
* @param file The name of the file where the logging was made.
|
|
* @param int The line where the logging was made.
|
|
* @param function The function where the logging was made.
|
|
* @param prefix_len The length of the text to be stripped away when syslogging.
|
|
* @param len Length of str, including terminating NULL.
|
|
* @param str String
|
|
* @param flush Whether the message should be flushed.
|
|
*
|
|
* @return 0 if the logging to at least one log succeeded.
|
|
*/
|
|
|
|
static int log_write(int priority,
|
|
const char* file,
|
|
int line,
|
|
const char* function,
|
|
size_t prefix_len,
|
|
size_t len,
|
|
const char* str,
|
|
enum log_flush flush)
|
|
{
|
|
int rv = -1;
|
|
|
|
if (logmanager_register(true))
|
|
{
|
|
CHK_LOGMANAGER(lm);
|
|
|
|
rv = logmanager_write_log(priority, flush, prefix_len, len, str);
|
|
|
|
logmanager_unregister();
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
/**
|
|
* @node Register as a logging client to logmanager.
|
|
*
|
|
* Parameters:
|
|
* @param lmgr - <usage>
|
|
* <description>
|
|
*
|
|
* @return
|
|
*
|
|
*
|
|
* @details Link count modify is protected by mutex.
|
|
*
|
|
*/
|
|
static bool logmanager_register(bool writep)
|
|
{
|
|
bool succ = true;
|
|
|
|
acquire_lock(&lmlock);
|
|
|
|
if (lm == NULL || !lm->lm_enabled)
|
|
{
|
|
/**
|
|
* Flush succeeds if logmanager is shut or shutting down.
|
|
* returning false so that flusher doesn't access logmanager
|
|
* and its members which would probabaly lead to NULL pointer
|
|
* reference.
|
|
*/
|
|
if (!writep || fatal_error)
|
|
{
|
|
succ = false;
|
|
goto return_succ;
|
|
}
|
|
|
|
ss_dassert(lm == NULL || (lm != NULL && !lm->lm_enabled));
|
|
|
|
/**
|
|
* Wait until logmanager shut down has completed.
|
|
* logmanager is enabled if someone already restarted
|
|
* it between latest lock release, and acquire.
|
|
*/
|
|
while (lm != NULL && !lm->lm_enabled)
|
|
{
|
|
release_lock(&lmlock);
|
|
pthread_yield();
|
|
acquire_lock(&lmlock);
|
|
}
|
|
|
|
if (lm == NULL)
|
|
{
|
|
// If someone is logging before the log manager has been inited,
|
|
// or after the log manager has been finished, the messages are
|
|
// written to stdout.
|
|
succ = logmanager_init_nomutex(NULL, NULL, MXS_LOG_TARGET_DEFAULT);
|
|
}
|
|
}
|
|
/** if logmanager existed or was succesfully restarted, increase link */
|
|
if (succ)
|
|
{
|
|
lm->lm_nlinks += 1;
|
|
}
|
|
|
|
return_succ:
|
|
|
|
if (!succ)
|
|
{
|
|
fatal_error = true;
|
|
}
|
|
release_lock(&lmlock);
|
|
return succ;
|
|
}
|
|
|
|
/**
|
|
* @node Unregister from logmanager.
|
|
*
|
|
* Parameters:
|
|
* @param lmgr - <usage>
|
|
* <description>
|
|
*
|
|
* @return
|
|
*
|
|
*
|
|
* @details Link count modify is protected by mutex.
|
|
*
|
|
*/
|
|
static void logmanager_unregister(void)
|
|
{
|
|
acquire_lock(&lmlock);
|
|
|
|
lm->lm_nlinks -= 1;
|
|
ss_dassert(lm->lm_nlinks >= 0);
|
|
|
|
release_lock(&lmlock);
|
|
}
|
|
|
|
|
|
/**
|
|
* @node Initialize log file naming parameters from call arguments
|
|
* or from default functions in cases where arguments are not provided.
|
|
*
|
|
* @param fn The fnames_conf_t structure to initialize.
|
|
* @param logdir The directory for the log file. If NULL logging will be made to stdout.
|
|
*
|
|
* @return True if the initialization was performed, false otherwise.
|
|
*
|
|
* @details Note that input parameter lenghts are checked here.
|
|
*
|
|
*/
|
|
static bool fnames_conf_init(fnames_conf_t* fn, const char* logdir)
|
|
{
|
|
bool succ = false;
|
|
|
|
/**
|
|
* When init_started is set, clean must be done for it.
|
|
*/
|
|
fn->fn_state = INIT;
|
|
#if defined(SS_DEBUG)
|
|
fn->fn_chk_top = CHK_NUM_FNAMES;
|
|
fn->fn_chk_tail = CHK_NUM_FNAMES;
|
|
#endif
|
|
const char* dir;
|
|
if (logdir)
|
|
{
|
|
log_config.use_stdout = false;
|
|
dir = logdir;
|
|
}
|
|
else
|
|
{
|
|
log_config.use_stdout = true;
|
|
// TODO: Re-arrange things so that fn->fn_logpath can be NULL.
|
|
dir = "/tmp";
|
|
}
|
|
|
|
fn->fn_logpath = strdup(dir);
|
|
|
|
if (fn->fn_logpath)
|
|
{
|
|
succ = true;
|
|
fn->fn_state = RUN;
|
|
CHK_FNAMES_CONF(fn);
|
|
}
|
|
|
|
return succ;
|
|
}
|
|
|
|
|
|
/**
|
|
* @node Calls logfile initializer for each logfile.
|
|
*
|
|
*
|
|
* Parameters:
|
|
* @param lm Log manager pointer
|
|
*
|
|
* @return true if succeed, otherwise false.
|
|
*
|
|
*
|
|
* @details If logfile is supposed to be located to shared memory
|
|
* it is specified here. In the case of shared memory file, a soft
|
|
* link is created to log directory.
|
|
*
|
|
* Motivation is performance. LOGFILE_DEBUG, for example, has so much data
|
|
* that writing it to disk slows execution down remarkably.
|
|
*
|
|
*/
|
|
static bool logfiles_init(logmanager_t* lm)
|
|
{
|
|
bool store_shmem = (lm->lm_target == MXS_LOG_TARGET_SHMEM);
|
|
|
|
bool succ = logfile_init(&lm->lm_logfile, lm, store_shmem);
|
|
|
|
if (!succ)
|
|
{
|
|
fprintf(stderr, "*\n* Error : Initializing log files failed.\n");
|
|
}
|
|
|
|
return succ;
|
|
}
|
|
|
|
static void logfile_flush(logfile_t* lf)
|
|
{
|
|
CHK_LOGFILE(lf);
|
|
acquire_lock(&lf->lf_spinlock);
|
|
lf->lf_flushflag = true;
|
|
release_lock(&lf->lf_spinlock);
|
|
skygw_message_send(lf->lf_logmes);
|
|
}
|
|
|
|
/**
|
|
* Set rotate flag for a log file and wake up the writer thread which then
|
|
* performs the actual rotation task.
|
|
*
|
|
* @param lf logfile pointer
|
|
*/
|
|
static void logfile_rotate(logfile_t* lf)
|
|
{
|
|
CHK_LOGFILE(lf);
|
|
acquire_lock(&lf->lf_spinlock);
|
|
lf->lf_rotateflag = true;
|
|
release_lock(&lf->lf_spinlock);
|
|
skygw_message_send(lf->lf_logmes);
|
|
}
|
|
|
|
/**
|
|
* Forms complete path name for logfile and tests that the file doesn't conflict
|
|
* with any existing file and it is writable.
|
|
*
|
|
* @param lf logfile pointer
|
|
*
|
|
* @return true if succeed, false if failed
|
|
*
|
|
* @note Log file openings are not TOCTOU-safe. It is not likely that
|
|
* multiple copies of same files are opened in parallel but it is possible by
|
|
* using log manager in parallel with multiple processes and by configuring
|
|
* log manager to use same directories among those processes.
|
|
*/
|
|
static bool logfile_build_name(logfile_t* lf)
|
|
{
|
|
bool namecreatefail;
|
|
bool nameconflicts;
|
|
bool store_shmem;
|
|
bool writable;
|
|
bool succ;
|
|
strpart_t spart[3]; /*< string parts of which the file is composed of */
|
|
|
|
if (log_config.use_stdout)
|
|
{
|
|
// TODO: Refactor so that lf_full_file_name can be NULL in this case.
|
|
lf->lf_full_file_name = strdup("stdout");
|
|
succ = true;
|
|
// TODO: Refactor to get rid of the gotos.
|
|
goto return_succ;
|
|
}
|
|
/**
|
|
* sparts is an array but next pointers are used to walk through
|
|
* the list of string parts.
|
|
*/
|
|
spart[0].sp_next = &spart[1];
|
|
spart[1].sp_next = &spart[2];
|
|
spart[2].sp_next = NULL;
|
|
|
|
spart[1].sp_string = lf->lf_name_prefix;
|
|
spart[2].sp_string = lf->lf_name_suffix;
|
|
|
|
store_shmem = lf->lf_store_shmem;
|
|
|
|
do
|
|
{
|
|
namecreatefail = false;
|
|
nameconflicts = false;
|
|
|
|
spart[0].sp_string = lf->lf_filepath;
|
|
/**
|
|
* Create name for log file. Seqno is added between prefix &
|
|
* suffix (index == 2)
|
|
*/
|
|
lf->lf_full_file_name = form_full_file_name(spart, lf, 2);
|
|
|
|
if (store_shmem)
|
|
{
|
|
spart[0].sp_string = lf->lf_linkpath;
|
|
/**
|
|
* Create name for link file
|
|
*/
|
|
lf->lf_full_link_name = form_full_file_name(spart, lf, 2);
|
|
}
|
|
/**
|
|
* At least one of the files couldn't be created. Increase
|
|
* sequence number and retry until succeeds.
|
|
*/
|
|
if (lf->lf_full_file_name == NULL ||
|
|
(store_shmem && lf->lf_full_link_name == NULL))
|
|
{
|
|
namecreatefail = true;
|
|
goto file_create_fail;
|
|
}
|
|
|
|
/**
|
|
* If file exists but is different type, create fails and
|
|
* new, increased sequence number is added to file name.
|
|
*/
|
|
if (check_file_and_path(lf->lf_full_file_name, &writable, true))
|
|
{
|
|
/** Found similarly named file which isn't writable */
|
|
if (!writable || file_is_symlink(lf->lf_full_file_name))
|
|
{
|
|
nameconflicts = true;
|
|
goto file_create_fail;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/**
|
|
* Opening the file failed for some other reason than
|
|
* existing non-writable file. Shut down.
|
|
*/
|
|
if (!writable)
|
|
{
|
|
succ = false;
|
|
goto return_succ;
|
|
}
|
|
}
|
|
|
|
if (store_shmem)
|
|
{
|
|
if (check_file_and_path(lf->lf_full_link_name, &writable, true))
|
|
{
|
|
/** Found similarly named link which isn't writable */
|
|
if (!writable)
|
|
{
|
|
nameconflicts = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/**
|
|
* Opening the file failed for some other reason than
|
|
* existing non-writable file. Shut down.
|
|
*/
|
|
if (!writable)
|
|
{
|
|
succ = false;
|
|
goto return_succ;
|
|
}
|
|
}
|
|
}
|
|
file_create_fail:
|
|
if (namecreatefail || nameconflicts)
|
|
{
|
|
lf->lf_name_seqno += 1;
|
|
|
|
if (lf->lf_full_file_name != NULL)
|
|
{
|
|
free(lf->lf_full_file_name);
|
|
lf->lf_full_file_name = NULL;
|
|
}
|
|
if (lf->lf_full_link_name != NULL)
|
|
{
|
|
free(lf->lf_full_link_name);
|
|
lf->lf_full_link_name = NULL;
|
|
}
|
|
}
|
|
}
|
|
while (namecreatefail || nameconflicts);
|
|
|
|
succ = true;
|
|
|
|
return_succ:
|
|
return succ;
|
|
}
|
|
|
|
/**
|
|
* Opens a log file and writes header to the beginning of it. File name, FILE*,
|
|
* and file descriptor are stored to skygw_file_t struct which is stored in
|
|
* filewriter strcuture passed as parameter.
|
|
*
|
|
* @param fw filewriter pointer
|
|
* @param lf logfile pointer
|
|
*
|
|
* @return true if succeed; the resulting skygw_file_t is written in filewriter,
|
|
* false if failed.
|
|
*
|
|
*/
|
|
static bool logfile_open_file(filewriter_t* fw, logfile_t* lf)
|
|
{
|
|
bool rv = true;
|
|
|
|
if (log_config.use_stdout)
|
|
{
|
|
fw->fwr_file = skygw_file_alloc(lf->lf_full_file_name);
|
|
fw->fwr_file->sf_file = stdout;
|
|
}
|
|
else if (lf->lf_store_shmem)
|
|
{
|
|
/** Create symlink pointing to log file */
|
|
fw->fwr_file = skygw_file_init(lf->lf_full_file_name, lf->lf_full_link_name);
|
|
}
|
|
else
|
|
{
|
|
/** Create normal disk-resident log file */
|
|
fw->fwr_file = skygw_file_init(lf->lf_full_file_name, NULL);
|
|
}
|
|
|
|
if (fw->fwr_file == NULL)
|
|
{
|
|
fprintf(stderr, "Error : opening logfile %s failed.\n", lf->lf_full_file_name);
|
|
rv = false;
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
/**
|
|
* @node Combine all name parts from left to right.
|
|
*
|
|
* Parameters:
|
|
* @param parts
|
|
*
|
|
* @param seqno specifies the the sequence number which will be added as a part
|
|
* of full file name. seqno == -1 indicates that sequence number won't be used.
|
|
*
|
|
* @param seqnoidx Specifies the seqno position in the 'array' of name parts.
|
|
* If seqno == -1 seqnoidx will be set -1 as well.
|
|
*
|
|
* @return Pointer to filename, of NULL if failed.
|
|
*
|
|
*/
|
|
static char* form_full_file_name(strpart_t* parts, logfile_t* lf, int seqnoidx)
|
|
{
|
|
int i;
|
|
int seqno;
|
|
size_t s;
|
|
size_t fnlen;
|
|
char* filename = NULL;
|
|
char* seqnostr = NULL;
|
|
strpart_t* p;
|
|
|
|
if (lf->lf_name_seqno != -1)
|
|
{
|
|
int file_sn;
|
|
int link_sn = 0;
|
|
const char* tmp = parts[0].sp_string;
|
|
|
|
file_sn = find_last_seqno(parts, lf->lf_name_seqno, seqnoidx);
|
|
|
|
if (lf->lf_linkpath != NULL)
|
|
{
|
|
tmp = parts[0].sp_string;
|
|
parts[0].sp_string = lf->lf_linkpath;
|
|
link_sn = find_last_seqno(parts, lf->lf_name_seqno, seqnoidx);
|
|
parts[0].sp_string = tmp;
|
|
}
|
|
lf->lf_name_seqno = MAX(file_sn, link_sn);
|
|
|
|
seqno = lf->lf_name_seqno;
|
|
s = UINTLEN(seqno);
|
|
seqnostr = (char *)malloc((int)s + 1);
|
|
}
|
|
else
|
|
{
|
|
/**
|
|
* These magic numbers are needed to indicate this and
|
|
* in subroutines that sequence number is not used.
|
|
*/
|
|
s = 0;
|
|
seqnoidx = -1;
|
|
seqno = lf->lf_name_seqno;
|
|
}
|
|
|
|
if (parts == NULL || parts->sp_string == NULL)
|
|
{
|
|
goto return_filename;
|
|
}
|
|
/**
|
|
* Length of path, file name, separating slash, sequence number and
|
|
* terminating character.
|
|
*/
|
|
fnlen = sizeof('/') + s + sizeof('\0');
|
|
p = parts;
|
|
/** Calculate the combined length of all parts put together */
|
|
while (p->sp_string != NULL)
|
|
{
|
|
fnlen += strnlen(p->sp_string, NAME_MAX);
|
|
|
|
if (p->sp_next == NULL)
|
|
{
|
|
break;
|
|
}
|
|
p = p->sp_next;
|
|
}
|
|
|
|
if (fnlen > NAME_MAX)
|
|
{
|
|
fprintf(stderr, "Error : Too long file name= %d.\n", (int)fnlen);
|
|
goto return_filename;
|
|
}
|
|
filename = (char*)calloc(1, fnlen);
|
|
|
|
if (seqnostr != NULL)
|
|
{
|
|
snprintf(seqnostr, s + 1, "%d", seqno);
|
|
}
|
|
|
|
for (i = 0, p = parts; p->sp_string != NULL; i++, p = p->sp_next)
|
|
{
|
|
if (seqnostr != NULL && i == seqnoidx)
|
|
{
|
|
strcat(filename, seqnostr); /*< add sequence number */
|
|
}
|
|
strcat(filename, p->sp_string);
|
|
|
|
if (p->sp_next == NULL)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return_filename:
|
|
if (seqnostr != NULL)
|
|
{
|
|
free(seqnostr);
|
|
}
|
|
|
|
return filename;
|
|
}
|
|
|
|
/**
|
|
* @node Allocate new buffer where argument string with a slash is copied.
|
|
* Original string buffer is freed.
|
|
* added.
|
|
*
|
|
* Parameters:
|
|
* @param str - <usage>
|
|
* <description>
|
|
*
|
|
* @return
|
|
*
|
|
*
|
|
* @details (write detailed description here)
|
|
*
|
|
*/
|
|
static char* add_slash(char* str)
|
|
{
|
|
char* p = str;
|
|
size_t plen = strlen(p);
|
|
|
|
/** Add slash if missing */
|
|
if (p[plen - 1] != '/')
|
|
{
|
|
str = (char *)malloc(plen + 2);
|
|
snprintf(str, plen + 2, "%s/", p);
|
|
free(p);
|
|
}
|
|
return str;
|
|
}
|
|
|
|
|
|
/**
|
|
* @node Check if the path and file exist in the local file system and if they do,
|
|
* check if they are accessible and writable.
|
|
*
|
|
* Parameters:
|
|
* @param filename file to be checked
|
|
*
|
|
* @param writable flag indicating whether file was found writable or not
|
|
* if writable is NULL, check is skipped.
|
|
*
|
|
* @return true & writable if file exists and it is writable,
|
|
* true & not writable if file exists but it can't be written,
|
|
* false & writable if file doesn't exist but directory could be written, and
|
|
* false & not writable if directory can't be written.
|
|
*
|
|
* @details Note, that a space character is written to the end of file.
|
|
* TODO: recall what was the reason for not succeeding with simply
|
|
* calling access, and fstat. vraa 26.11.13
|
|
*/
|
|
static bool check_file_and_path(char* filename, bool* writable, bool do_log)
|
|
{
|
|
bool exists;
|
|
|
|
if (filename == NULL)
|
|
{
|
|
exists = false;
|
|
|
|
if (writable)
|
|
{
|
|
*writable = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (access(filename, F_OK) == 0)
|
|
{
|
|
|
|
exists = true;
|
|
|
|
if (access(filename, W_OK) == 0)
|
|
{
|
|
if (writable)
|
|
{
|
|
*writable = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
if (do_log && file_is_symlink(filename))
|
|
{
|
|
char errbuf[STRERROR_BUFLEN];
|
|
fprintf(stderr,
|
|
"*\n* Error : Can't access "
|
|
"file pointed to by %s due "
|
|
"to %s.\n",
|
|
filename,
|
|
strerror_r(errno, errbuf, sizeof(errbuf)));
|
|
}
|
|
else if (do_log)
|
|
{
|
|
char errbuf[STRERROR_BUFLEN];
|
|
fprintf(stderr,
|
|
"*\n* Error : Can't access %s due "
|
|
"to %s.\n",
|
|
filename,
|
|
strerror_r(errno, errbuf, sizeof(errbuf)));
|
|
}
|
|
|
|
if (writable)
|
|
{
|
|
*writable = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
exists = false;
|
|
if (writable)
|
|
{
|
|
*writable = true;
|
|
}
|
|
}
|
|
}
|
|
return exists;
|
|
}
|
|
|
|
|
|
|
|
static bool file_is_symlink(char* filename)
|
|
{
|
|
int rc;
|
|
bool succ = false;
|
|
struct stat b;
|
|
|
|
if (filename != NULL)
|
|
{
|
|
rc = lstat(filename, &b);
|
|
|
|
if (rc != -1 && S_ISLNK(b.st_mode))
|
|
{
|
|
succ = true;
|
|
}
|
|
}
|
|
return succ;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @node Initialize logfile structure. Form log file name, and optionally
|
|
* link name. Create block buffer for logfile.
|
|
*
|
|
* Parameters:
|
|
* @param logfile log file
|
|
* @param logmanager log manager pointer
|
|
* @param store_shmem flag to indicate whether log is physically written to shmem
|
|
*
|
|
* @return true if succeed, false otherwise
|
|
*/
|
|
static bool logfile_init(logfile_t* logfile,
|
|
logmanager_t* logmanager,
|
|
bool store_shmem)
|
|
{
|
|
bool succ = false;
|
|
fnames_conf_t* fn = &logmanager->lm_fnames_conf;
|
|
logfile->lf_state = INIT;
|
|
#if defined(SS_DEBUG)
|
|
logfile->lf_chk_top = CHK_NUM_LOGFILE;
|
|
logfile->lf_chk_tail = CHK_NUM_LOGFILE;
|
|
#endif
|
|
logfile->lf_logmes = logmanager->lm_logmes;
|
|
logfile->lf_name_prefix = LOGFILE_NAME_PREFIX;
|
|
logfile->lf_name_suffix = LOGFILE_NAME_SUFFIX;
|
|
logfile->lf_npending_writes = 0;
|
|
logfile->lf_name_seqno = 1;
|
|
logfile->lf_lmgr = logmanager;
|
|
logfile->lf_flushflag = false;
|
|
logfile->lf_rotateflag = false;
|
|
logfile->lf_spinlock = 0;
|
|
logfile->lf_store_shmem = store_shmem;
|
|
logfile->lf_buf_size = MAX_LOGSTRLEN;
|
|
/**
|
|
* If file is stored in shared memory in /dev/shm, a link
|
|
* pointing to shm file is created and located to the file
|
|
* directory.
|
|
*/
|
|
if (store_shmem)
|
|
{
|
|
char* c;
|
|
pid_t pid = getpid();
|
|
int len = strlen(shm_pathname_prefix)
|
|
+ strlen("maxscale.") +
|
|
get_decimal_len((size_t)pid) + 1;
|
|
|
|
c = (char *)calloc(len, sizeof(char));
|
|
|
|
if (c == NULL)
|
|
{
|
|
succ = false;
|
|
goto return_with_succ;
|
|
}
|
|
sprintf(c, "%smaxscale.%d", shm_pathname_prefix, pid);
|
|
logfile->lf_filepath = c;
|
|
|
|
if (mkdir(c, S_IRWXU | S_IRWXG) != 0 &&
|
|
errno != EEXIST)
|
|
{
|
|
succ = false;
|
|
goto return_with_succ;
|
|
}
|
|
logfile->lf_linkpath = strdup(fn->fn_logpath);
|
|
logfile->lf_linkpath = add_slash(logfile->lf_linkpath);
|
|
}
|
|
else
|
|
{
|
|
logfile->lf_filepath = strdup(fn->fn_logpath);
|
|
}
|
|
logfile->lf_filepath = add_slash(logfile->lf_filepath);
|
|
|
|
if (!(succ = logfile_build_name(logfile)))
|
|
{
|
|
goto return_with_succ;
|
|
}
|
|
/**
|
|
* Create a block buffer list for log file. Clients' writes go to buffers
|
|
* from where separate log flusher thread writes them to disk.
|
|
*/
|
|
if (mlist_init(&logfile->lf_blockbuf_list,
|
|
NULL,
|
|
strdup("logfile block buffer list"),
|
|
blockbuf_node_done,
|
|
MAXNBLOCKBUFS) == NULL)
|
|
{
|
|
ss_dfprintf(stderr,
|
|
"*\n* Error : Initializing buffers for log files "
|
|
"failed.");
|
|
logfile_free_memory(logfile);
|
|
goto return_with_succ;
|
|
}
|
|
|
|
succ = true;
|
|
logfile->lf_state = RUN;
|
|
CHK_LOGFILE(logfile);
|
|
|
|
return_with_succ:
|
|
if (!succ)
|
|
{
|
|
logfile_done(logfile);
|
|
}
|
|
ss_dassert(logfile->lf_state == RUN || logfile->lf_state == DONE);
|
|
return succ;
|
|
}
|
|
|
|
/**
|
|
* @node Flush logfile and free memory allocated for it.
|
|
*
|
|
* Parameters:
|
|
* @param lf - <usage>
|
|
* <description>
|
|
*
|
|
* @return void
|
|
*
|
|
*
|
|
* @details Operation is not protected. it is assumed that no one tries
|
|
* to call logfile functions when logfile_done is called.
|
|
*
|
|
* It is also assumed that filewriter doesn't exist anymore.
|
|
*
|
|
* Logfile access could be protected by using exit flag and rwlock to protect
|
|
* flag read/write. Lock would be held during log write operation by clients.
|
|
*
|
|
*/
|
|
static void logfile_done(logfile_t* lf)
|
|
{
|
|
switch (lf->lf_state)
|
|
{
|
|
case RUN:
|
|
CHK_LOGFILE(lf);
|
|
ss_dassert(lf->lf_npending_writes == 0);
|
|
/** fallthrough */
|
|
case INIT:
|
|
/** Test if list is initialized before freeing it */
|
|
if (lf->lf_blockbuf_list.mlist_versno != 0)
|
|
{
|
|
mlist_done(&lf->lf_blockbuf_list);
|
|
}
|
|
logfile_free_memory(lf);
|
|
lf->lf_state = DONE;
|
|
/** fallthrough */
|
|
case DONE:
|
|
case UNINIT:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void logfile_free_memory(logfile_t* lf)
|
|
{
|
|
if (lf->lf_filepath != NULL)
|
|
{
|
|
free(lf->lf_filepath);
|
|
}
|
|
if (lf->lf_linkpath != NULL)
|
|
{
|
|
free(lf->lf_linkpath);
|
|
}
|
|
if (lf->lf_full_link_name != NULL)
|
|
{
|
|
free(lf->lf_full_link_name);
|
|
}
|
|
if (lf->lf_full_file_name != NULL)
|
|
{
|
|
free(lf->lf_full_file_name);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @node Initialize filewriter data and open the log file for each log file type.
|
|
*
|
|
* @param logmanager Log manager struct
|
|
* @param fw File writer struct
|
|
*
|
|
* @return true if succeed, false if failed
|
|
*
|
|
*/
|
|
static bool filewriter_init(logmanager_t* logmanager, filewriter_t* fw)
|
|
{
|
|
bool succ = false;
|
|
|
|
CHK_LOGMANAGER(logmanager);
|
|
assert(logmanager->lm_clientmes);
|
|
assert(logmanager->lm_logmes);
|
|
|
|
fw->fwr_state = INIT;
|
|
#if defined(SS_DEBUG)
|
|
fw->fwr_chk_top = CHK_NUM_FILEWRITER;
|
|
fw->fwr_chk_tail = CHK_NUM_FILEWRITER;
|
|
#endif
|
|
fw->fwr_logmgr = logmanager;
|
|
/** Message from filewriter to clients */
|
|
fw->fwr_logmes = logmanager->lm_logmes;
|
|
/** Message from clients to filewriter */
|
|
fw->fwr_clientmes = logmanager->lm_clientmes;
|
|
|
|
logfile_t* lf = logmanager_get_logfile(logmanager);
|
|
|
|
if (logfile_open_file(fw, lf))
|
|
{
|
|
fw->fwr_state = RUN;
|
|
CHK_FILEWRITER(fw);
|
|
succ = true;
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr,
|
|
"Error : opening log file %s failed. Exiting "
|
|
"MaxScale\n",
|
|
lf->lf_full_file_name);
|
|
filewriter_done(fw);
|
|
}
|
|
|
|
ss_dassert(fw->fwr_state == RUN || fw->fwr_state == DONE);
|
|
return succ;
|
|
}
|
|
|
|
static void filewriter_done(filewriter_t* fw)
|
|
{
|
|
switch (fw->fwr_state)
|
|
{
|
|
case RUN:
|
|
CHK_FILEWRITER(fw);
|
|
case INIT:
|
|
fw->fwr_logmes = NULL;
|
|
fw->fwr_clientmes = NULL;
|
|
if (log_config.use_stdout)
|
|
{
|
|
skygw_file_free(fw->fwr_file);
|
|
}
|
|
else
|
|
{
|
|
skygw_file_close(fw->fwr_file, true);
|
|
}
|
|
fw->fwr_state = DONE;
|
|
case DONE:
|
|
case UNINIT:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr)
|
|
{
|
|
/**
|
|
* Get file pointer of current logfile.
|
|
*/
|
|
bool do_flushall = thr_flushall_check();
|
|
skygw_file_t *file = fwr->fwr_file;
|
|
logfile_t *lf = &lm->lm_logfile;
|
|
|
|
/**
|
|
* read and reset logfile's flush- and rotateflag
|
|
*/
|
|
acquire_lock(&lf->lf_spinlock);
|
|
bool flush_logfile = lf->lf_flushflag;
|
|
bool rotate_logfile = lf->lf_rotateflag;
|
|
lf->lf_flushflag = false;
|
|
lf->lf_rotateflag = false;
|
|
release_lock(&lf->lf_spinlock);
|
|
/**
|
|
* Log rotation :
|
|
* Close current, and open a new file for the log.
|
|
*/
|
|
if (rotate_logfile)
|
|
{
|
|
bool succ;
|
|
|
|
lf->lf_name_seqno += 1; /*< new sequence number */
|
|
|
|
if (!(succ = logfile_build_name(lf)))
|
|
{
|
|
lf->lf_name_seqno -= 1; /*< restore */
|
|
}
|
|
else if ((succ = logfile_open_file(fwr, lf)))
|
|
{
|
|
if (log_config.use_stdout)
|
|
{
|
|
skygw_file_free(file);
|
|
}
|
|
else
|
|
{
|
|
skygw_file_close(file, false); /*< close old file */
|
|
}
|
|
}
|
|
|
|
if (!succ)
|
|
{
|
|
MXS_ERROR("Log rotation failed. "
|
|
"Creating replacement file %s "
|
|
"failed. Continuing "
|
|
"logging to existing file.",
|
|
lf->lf_full_file_name);
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* get logfile's block buffer list
|
|
*/
|
|
mlist_t *bb_list = &lf->lf_blockbuf_list;
|
|
#if defined(SS_DEBUG)
|
|
simple_mutex_lock(&bb_list->mlist_mutex, true);
|
|
CHK_MLIST(bb_list);
|
|
simple_mutex_unlock(&bb_list->mlist_mutex);
|
|
#endif
|
|
mlist_node_t *node = bb_list->mlist_first;
|
|
|
|
while (node != NULL)
|
|
{
|
|
int err = 0;
|
|
|
|
CHK_MLIST_NODE(node);
|
|
blockbuf_t *bb = (blockbuf_t *)node->mlnode_data;
|
|
CHK_BLOCKBUF(bb);
|
|
|
|
/** Lock block buffer */
|
|
simple_mutex_lock(&bb->bb_mutex, true);
|
|
|
|
blockbuf_state_t flush_blockbuf = bb->bb_state;
|
|
|
|
if (bb->bb_buf_used != 0 &&
|
|
((flush_blockbuf == BB_FULL) || flush_logfile || do_flushall))
|
|
{
|
|
/**
|
|
* buffer is at least half-full
|
|
* -> write to disk
|
|
*/
|
|
while (bb->bb_refcount > 0)
|
|
{
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
simple_mutex_lock(&bb->bb_mutex, true);
|
|
}
|
|
err = skygw_file_write(file,
|
|
(void *)bb->bb_buf,
|
|
bb->bb_buf_used,
|
|
(flush_logfile || do_flushall));
|
|
if (err)
|
|
{
|
|
// TODO: Log this to syslog.
|
|
char errbuf[STRERROR_BUFLEN];
|
|
fprintf(stderr,
|
|
"Error : Writing to the log-file %s failed due to (%d, %s). "
|
|
"Disabling writing to the log.",
|
|
lf->lf_full_file_name,
|
|
err,
|
|
strerror_r(err, errbuf, sizeof(errbuf)));
|
|
|
|
mxs_log_set_maxlog_enabled(false);
|
|
}
|
|
/**
|
|
* Reset buffer's counters and mark
|
|
* not full.
|
|
*/
|
|
bb->bb_buf_left = bb->bb_buf_size;
|
|
bb->bb_buf_used = 0;
|
|
memset(bb->bb_buf, 0, bb->bb_buf_size);
|
|
bb->bb_state = BB_CLEARED;
|
|
#if defined(SS_LOG_DEBUG)
|
|
sprintf(bb->bb_buf, "[block:%d]", atomic_add(&block_start_index, 1));
|
|
bb->bb_buf_used += strlen(bb->bb_buf);
|
|
bb->bb_buf_left -= strlen(bb->bb_buf);
|
|
#endif
|
|
|
|
}
|
|
/** Release lock to block buffer */
|
|
simple_mutex_unlock(&bb->bb_mutex);
|
|
|
|
size_t vn1;
|
|
size_t vn2;
|
|
/** Consistent lock-free read on the list */
|
|
do
|
|
{
|
|
while ((vn1 = bb_list->mlist_versno) % 2 != 0)
|
|
{
|
|
continue;
|
|
}
|
|
node = node->mlnode_next;
|
|
vn2 = bb_list->mlist_versno;
|
|
}
|
|
while (vn1 != vn2 && node);
|
|
|
|
} /* while (node != NULL) */
|
|
|
|
/**
|
|
* Writer's exit flag was set after checking it.
|
|
* Loop is restarted to ensure that all logfiles are
|
|
* flushed.
|
|
*/
|
|
|
|
bool done = true;
|
|
|
|
if (flushall_started_flag)
|
|
{
|
|
flushall_started_flag = false;
|
|
flushall_done_flag = true;
|
|
done = false;
|
|
}
|
|
|
|
return done;
|
|
}
|
|
|
|
/**
|
|
* @node Writes block buffers of logfiles to physical log files on disk.
|
|
*
|
|
* Parameters:
|
|
* @param data - thread context, skygw_thread_t
|
|
* <description>
|
|
*
|
|
* @return
|
|
*
|
|
*
|
|
* @details Waits until receives wake-up message. Scans through block buffer
|
|
* lists of each logfile object.
|
|
*
|
|
* Block buffer is written to log file if
|
|
* 1. bb_state == true,
|
|
* 2. logfile object's lf_flushflag == true, or
|
|
* 3. skygw_thread_must_exit returns true.
|
|
*
|
|
* Log file is flushed (fsync'd) in cases #2 and #3.
|
|
*
|
|
* Concurrency control : block buffer is accessed by file writer (this) and
|
|
* log clients. File writer reads and sets each logfile object's flushflag
|
|
* with spinlock. Another protected section is when block buffer's metadata is
|
|
* read, and optionally the write operation.
|
|
*
|
|
* When block buffer is marked full, logfile's flushflag is set, other
|
|
* log clients don't try to access buffer(s). There may, however, be
|
|
* active writes, on the block in parallel with file writer operations.
|
|
* Each active write corresponds to bb_refcounter values.
|
|
* On the other hand, file writer doesn't process the block buffer before
|
|
* its refcount is zero.
|
|
*
|
|
* Every log file obj. has its own block buffer (linked) list.
|
|
* List is accessed by log clients, which add nodes if necessary, and
|
|
* by file writer which traverses the list and accesses block buffers
|
|
* included in list nodes.
|
|
* List modifications are protected with version numbers.
|
|
* Before
|
|
modification, version is increased by one to be odd. After the
|
|
* completion, it is increased again to even. List can be read only when
|
|
* version is even and read is consistent only if version hasn't changed
|
|
* during the read.
|
|
*/
|
|
static void* thr_filewriter_fun(void* data)
|
|
{
|
|
skygw_thread_t* thr = (skygw_thread_t *)data;
|
|
filewriter_t* fwr = (filewriter_t *)skygw_thread_get_data(thr);
|
|
|
|
flushall_logfiles(false);
|
|
|
|
CHK_FILEWRITER(fwr);
|
|
ss_debug(skygw_thread_set_state(thr, THR_RUNNING));
|
|
|
|
/** Inform log manager about the state. */
|
|
skygw_message_send(fwr->fwr_clientmes);
|
|
while (!skygw_thread_must_exit(thr))
|
|
{
|
|
/**
|
|
* Wait until new log arrival message appears.
|
|
* Reset message to avoid redundant calls.
|
|
*/
|
|
skygw_message_wait(fwr->fwr_logmes);
|
|
if (skygw_thread_must_exit(thr))
|
|
{
|
|
flushall_logfiles(true);
|
|
}
|
|
|
|
/** Process all logfiles which have buffered writes. */
|
|
bool done = false;
|
|
|
|
while (!done)
|
|
{
|
|
done = thr_flush_file(lm, fwr);
|
|
|
|
if (!thr_flushall_check() && skygw_thread_must_exit(thr))
|
|
{
|
|
flushall_logfiles(true);
|
|
done = false;
|
|
}
|
|
}
|
|
|
|
if (flushall_done_flag)
|
|
{
|
|
flushall_done_flag = false;
|
|
flushall_logfiles(false);
|
|
skygw_message_send(fwr->fwr_clientmes);
|
|
}
|
|
|
|
} /* while (!skygw_thread_must_exit) */
|
|
|
|
ss_debug(skygw_thread_set_state(thr, THR_STOPPED));
|
|
/** Inform log manager that file writer thread has stopped. */
|
|
skygw_message_send(fwr->fwr_clientmes);
|
|
return NULL;
|
|
}
|
|
|
|
|
|
static void fnames_conf_done(fnames_conf_t* fn)
|
|
{
|
|
switch (fn->fn_state)
|
|
{
|
|
case RUN:
|
|
CHK_FNAMES_CONF(fn);
|
|
case INIT:
|
|
fnames_conf_free_memory(fn);
|
|
fn->fn_state = DONE;
|
|
case DONE:
|
|
case UNINIT:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
static void fnames_conf_free_memory(fnames_conf_t* fn)
|
|
{
|
|
free(fn->fn_logpath);
|
|
}
|
|
|
|
/**
|
|
* Find the file with biggest sequence number from given directory and return
|
|
* the sequence number.
|
|
*
|
|
* @param parts string parts of which the file name is composed of
|
|
* @param seqno the sequence number to start with, if seqno is -1 just return
|
|
*
|
|
* @return the biggest sequence number used
|
|
*/
|
|
static int find_last_seqno(strpart_t* parts,
|
|
int seqno,
|
|
int seqnoidx)
|
|
{
|
|
strpart_t* p;
|
|
char* snstr;
|
|
int snstrlen;
|
|
|
|
if (seqno == -1)
|
|
{
|
|
return seqno;
|
|
}
|
|
snstrlen = UINTLEN(INT_MAX);
|
|
snstr = (char *)calloc(1, snstrlen);
|
|
p = parts;
|
|
|
|
while (true)
|
|
{
|
|
int i;
|
|
char filename[NAME_MAX] = {0};
|
|
/** Form name with next seqno */
|
|
snprintf(snstr, snstrlen, "%d", seqno + 1);
|
|
|
|
for (i = 0, p = parts; p->sp_string != NULL; i++, p = p->sp_next)
|
|
{
|
|
if (snstr != NULL && i == seqnoidx)
|
|
{
|
|
strncat(filename, snstr, NAME_MAX - 1); /*< add sequence number */
|
|
}
|
|
strncat(filename, p->sp_string, NAME_MAX - 1);
|
|
|
|
if (p->sp_next == NULL)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (check_file_and_path(filename, NULL, false))
|
|
{
|
|
seqno++;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
free(snstr);
|
|
|
|
return seqno;
|
|
}
|
|
|
|
bool thr_flushall_check()
|
|
{
|
|
bool rval = false;
|
|
simple_mutex_lock(&lm->lm_mutex, true);
|
|
rval = flushall_flag;
|
|
if (rval && !flushall_started_flag && !flushall_done_flag)
|
|
{
|
|
flushall_started_flag = true;
|
|
}
|
|
simple_mutex_unlock(&lm->lm_mutex);
|
|
return rval;
|
|
}
|
|
|
|
void flushall_logfiles(bool flush)
|
|
{
|
|
simple_mutex_lock(&lm->lm_mutex, true);
|
|
flushall_flag = flush;
|
|
simple_mutex_unlock(&lm->lm_mutex);
|
|
}
|
|
|
|
/**
|
|
* Enable/disable syslog logging.
|
|
*
|
|
* @param enabled True, if high precision logging should be enabled, false if it should be disabled.
|
|
*/
|
|
void mxs_log_set_highprecision_enabled(bool enabled)
|
|
{
|
|
log_config.do_highprecision = enabled;
|
|
|
|
MXS_NOTICE("highprecision logging is %s.", enabled ? "enabled" : "disabled");
|
|
}
|
|
|
|
/**
|
|
* Enable/disable syslog logging.
|
|
*
|
|
* @param enabled True, if syslog logging should be enabled, false if it should be disabled.
|
|
*/
|
|
void mxs_log_set_syslog_enabled(bool enabled)
|
|
{
|
|
log_config.do_syslog = enabled;
|
|
|
|
MXS_NOTICE("syslog logging is %s.", enabled ? "enabled" : "disabled");
|
|
}
|
|
|
|
/**
|
|
* Enable/disable maxscale log logging.
|
|
*
|
|
* @param enabled True, if syslog logging should be enabled, false if it should be disabled.
|
|
*/
|
|
void mxs_log_set_maxlog_enabled(bool enabled)
|
|
{
|
|
log_config.do_maxlog = enabled;
|
|
|
|
MXS_NOTICE("maxlog logging is %s.", enabled ? "enabled" : "disabled");
|
|
}
|
|
|
|
|
|
/**
|
|
* Explicitly ensure that all pending log messages are flushed.
|
|
*
|
|
* @return 0 if the flushing was successfully initiated, otherwise -1.
|
|
*
|
|
* Note that the return value only indicates whether the flushing was
|
|
* successfully initiated, not whether the actual flushing has been
|
|
* performed.
|
|
*/
|
|
int mxs_log_flush()
|
|
{
|
|
int err = -1;
|
|
|
|
if (logmanager_register(false))
|
|
{
|
|
CHK_LOGMANAGER(lm);
|
|
|
|
logfile_t *lf = logmanager_get_logfile(lm);
|
|
CHK_LOGFILE(lf);
|
|
|
|
logfile_flush(lf);
|
|
err = 0;
|
|
|
|
logmanager_unregister();
|
|
}
|
|
else
|
|
{
|
|
ss_dfprintf(stderr, "Can't register to logmanager, flushing failed.\n");
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* Explicitly ensure that all pending log messages are flushed.
|
|
*
|
|
* @return 0 if the flushing was successfully performed, otherwise -1.
|
|
*
|
|
* When the function returns 0, the flushing has been initiated and the
|
|
* flushing thread has indicated that the operation has been performed.
|
|
* However, 0 will be returned also in the case that the flushing thread
|
|
* for, whatever reason, failed to actually flush the log.
|
|
*/
|
|
int mxs_log_flush_sync(void)
|
|
{
|
|
int err = 0;
|
|
|
|
if (!log_config.use_stdout)
|
|
{
|
|
MXS_INFO("Starting log flushing to disk.");
|
|
}
|
|
|
|
/** If initialization of the log manager has not been done, lm pointer can be
|
|
* NULL. */
|
|
// TODO: Why is logmanager_register() not called here?
|
|
if (lm)
|
|
{
|
|
flushall_logfiles(true);
|
|
|
|
if (skygw_message_send(lm->lm_logmes) == MES_RC_SUCCESS)
|
|
{
|
|
// TODO: Add error handling to skygw_message_wait. Now void.
|
|
skygw_message_wait(lm->lm_clientmes);
|
|
}
|
|
else
|
|
{
|
|
err = -1;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* Rotate the log-file. That is, close the current one and create a new one
|
|
* with a larger sequence number.
|
|
*
|
|
* @return 0 if the rotating was successfully initiated, otherwise -1.
|
|
*
|
|
* Note that the return value only indicates whether the rotating was
|
|
* successfully initiated, not whether the actual rotation has been
|
|
* performed.
|
|
*/
|
|
int mxs_log_rotate()
|
|
{
|
|
int err = -1;
|
|
|
|
if (logmanager_register(false))
|
|
{
|
|
CHK_LOGMANAGER(lm);
|
|
|
|
logfile_t *lf = logmanager_get_logfile(lm);
|
|
CHK_LOGFILE(lf);
|
|
|
|
MXS_NOTICE("Log rotation is called for %s.", lf->lf_full_file_name);
|
|
|
|
logfile_rotate(lf);
|
|
err = 0;
|
|
|
|
logmanager_unregister();
|
|
}
|
|
else
|
|
{
|
|
ss_dfprintf(stderr, "Can't register to logmanager, rotating failed.\n");
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static const char* priority_name(int priority)
|
|
{
|
|
switch (priority)
|
|
{
|
|
case LOG_EMERG:
|
|
return "emercency";
|
|
case LOG_ALERT:
|
|
return "alert";
|
|
case LOG_CRIT:
|
|
return "critical";
|
|
case LOG_ERR:
|
|
return "error";
|
|
case LOG_WARNING:
|
|
return "warning";
|
|
case LOG_NOTICE:
|
|
return "notice";
|
|
case LOG_INFO:
|
|
return "informational";
|
|
case LOG_DEBUG:
|
|
return "debug";
|
|
default:
|
|
assert(!true);
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enable/disable a particular syslog priority.
|
|
*
|
|
* @param priority One of the LOG_ERR etc. constants from sys/syslog.h.
|
|
* @param enabled True if the priority should be enabled, false if it to be disabled.
|
|
*
|
|
* @return 0 if the priority was valid, -1 otherwise.
|
|
*/
|
|
int mxs_log_set_priority_enabled(int priority, bool enable)
|
|
{
|
|
int rv = -1;
|
|
const char* text = (enable ? "enable" : "disable");
|
|
|
|
if ((priority & ~LOG_PRIMASK) == 0)
|
|
{
|
|
int bit = (1 << priority);
|
|
|
|
if (enable)
|
|
{
|
|
// TODO: Put behind spinlock.
|
|
mxs_log_enabled_priorities |= bit;
|
|
}
|
|
else
|
|
{
|
|
mxs_log_enabled_priorities &= ~bit;
|
|
}
|
|
|
|
MXS_NOTICE("The logging of %s messages has been %sd.", priority_name(priority), text);
|
|
}
|
|
else
|
|
{
|
|
MXS_ERROR("Attempt to %s unknown syslog priority %d.", text, priority);
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
typedef struct log_prefix
|
|
{
|
|
const char* text; // The prefix, e.g. "error: "
|
|
int len; // The length of the prefix without the trailing NULL.
|
|
} log_prefix_t;
|
|
|
|
static const char PREFIX_EMERG[] = "emerg : ";
|
|
static const char PREFIX_ALERT[] = "alert : ";
|
|
static const char PREFIX_CRIT[] = "crit : ";
|
|
static const char PREFIX_ERROR[] = "error : ";
|
|
static const char PREFIX_WARNING[] = "warning: ";
|
|
static const char PREFIX_NOTICE[] = "notice : ";
|
|
static const char PREFIX_INFO[] = "info : ";
|
|
static const char PREFIX_DEBUG[] = "debug : ";
|
|
|
|
static log_prefix_t priority_to_prefix(int priority)
|
|
{
|
|
assert((priority & ~LOG_PRIMASK) == 0);
|
|
|
|
log_prefix_t prefix;
|
|
|
|
switch (priority)
|
|
{
|
|
case LOG_EMERG:
|
|
prefix.text = PREFIX_EMERG;
|
|
prefix.len = sizeof(PREFIX_EMERG);
|
|
break;
|
|
|
|
case LOG_ALERT:
|
|
prefix.text = PREFIX_ALERT;
|
|
prefix.len = sizeof(PREFIX_ALERT);
|
|
break;
|
|
|
|
case LOG_CRIT:
|
|
prefix.text = PREFIX_CRIT;
|
|
prefix.len = sizeof(PREFIX_CRIT);
|
|
break;
|
|
|
|
case LOG_ERR:
|
|
prefix.text = PREFIX_ERROR;
|
|
prefix.len = sizeof(PREFIX_ERROR);
|
|
break;
|
|
|
|
case LOG_WARNING:
|
|
prefix.text = PREFIX_WARNING;
|
|
prefix.len = sizeof(PREFIX_WARNING);
|
|
break;
|
|
|
|
case LOG_NOTICE:
|
|
prefix.text = PREFIX_NOTICE;
|
|
prefix.len = sizeof(PREFIX_NOTICE);
|
|
break;
|
|
|
|
case LOG_INFO:
|
|
prefix.text = PREFIX_INFO;
|
|
prefix.len = sizeof(PREFIX_INFO);
|
|
break;
|
|
|
|
case LOG_DEBUG:
|
|
prefix.text = PREFIX_DEBUG;
|
|
prefix.len = sizeof(PREFIX_DEBUG);
|
|
break;
|
|
|
|
default:
|
|
assert(!true);
|
|
prefix.text = PREFIX_ERROR;
|
|
prefix.len = sizeof(PREFIX_ERROR);
|
|
break;
|
|
}
|
|
|
|
--prefix.len; // Remove trailing NULL.
|
|
|
|
return prefix;
|
|
}
|
|
|
|
static enum log_flush priority_to_flush(int priority)
|
|
{
|
|
assert((priority & ~LOG_PRIMASK) == 0);
|
|
|
|
switch (priority)
|
|
{
|
|
case LOG_EMERG:
|
|
case LOG_ALERT:
|
|
case LOG_CRIT:
|
|
case LOG_ERR:
|
|
return LOG_FLUSH_YES;
|
|
|
|
default:
|
|
assert(!true);
|
|
case LOG_WARNING:
|
|
case LOG_NOTICE:
|
|
case LOG_INFO:
|
|
case LOG_DEBUG:
|
|
return LOG_FLUSH_NO;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Log a message of a particular priority.
|
|
*
|
|
* @param priority One of the syslog constants: LOG_ERR, LOG_WARNING, ...
|
|
* @param file The name of the file where the message was logged.
|
|
* @param line The line where the message was logged.
|
|
* @param function The function where the message was logged.
|
|
* @param format The printf format of the following arguments.
|
|
* @param ... Optional arguments according to the format.
|
|
*/
|
|
int mxs_log_message(int priority,
|
|
const char* file, int line, const char* function,
|
|
const char* format, ...)
|
|
{
|
|
int err = 0;
|
|
|
|
assert((priority & ~LOG_PRIMASK) == 0);
|
|
|
|
if ((priority & ~LOG_PRIMASK) == 0) // Check that the priority is ok,
|
|
{
|
|
if (MXS_LOG_PRIORITY_IS_ENABLED(priority))
|
|
{
|
|
va_list valist;
|
|
|
|
/**
|
|
* Find out the length of log string (to be formatted str).
|
|
*/
|
|
va_start(valist, format);
|
|
int message_len = vsnprintf(NULL, 0, format, valist);
|
|
va_end(valist);
|
|
|
|
if (message_len >= 0)
|
|
{
|
|
log_prefix_t prefix = priority_to_prefix(priority);
|
|
|
|
static const char FORMAT_FUNCTION[] = "(%s): ";
|
|
|
|
// Other thread might change log_config.augmentation.
|
|
int augmentation = log_config.augmentation;
|
|
int augmentation_len = 0;
|
|
|
|
switch (augmentation)
|
|
{
|
|
case MXS_LOG_AUGMENT_WITH_FUNCTION:
|
|
augmentation_len = sizeof(FORMAT_FUNCTION) - 1; // Remove trailing 0
|
|
augmentation_len -= 2; // Remove the %s
|
|
augmentation_len += strlen(function);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
int buffer_len = prefix.len + augmentation_len + message_len + 1; // Trailing NULL
|
|
|
|
if (buffer_len > MAX_LOGSTRLEN)
|
|
{
|
|
message_len -= (buffer_len - MAX_LOGSTRLEN);
|
|
buffer_len = MAX_LOGSTRLEN;
|
|
|
|
assert(prefix.len + augmentation_len + message_len + 1 == buffer_len);
|
|
}
|
|
|
|
char buffer[buffer_len];
|
|
|
|
char *prefix_text = buffer;
|
|
char *augmentation_text = buffer + prefix.len;
|
|
char *message_text = buffer + prefix.len + augmentation_len;
|
|
|
|
strcpy(prefix_text, prefix.text);
|
|
|
|
if (augmentation_len)
|
|
{
|
|
int len = 0;
|
|
|
|
switch (augmentation)
|
|
{
|
|
case MXS_LOG_AUGMENT_WITH_FUNCTION:
|
|
len = sprintf(augmentation_text, FORMAT_FUNCTION, function);
|
|
break;
|
|
|
|
default:
|
|
assert(!true);
|
|
}
|
|
|
|
assert(len == augmentation_len);
|
|
}
|
|
|
|
va_start(valist, format);
|
|
vsnprintf(message_text, message_len + 1, format, valist);
|
|
va_end(valist);
|
|
|
|
enum log_flush flush = priority_to_flush(priority);
|
|
|
|
err = log_write(priority, file, line, function, prefix.len, buffer_len, buffer, flush);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MXS_WARNING("Invalid syslog priority: %d", priority);
|
|
}
|
|
|
|
return err;
|
|
}
|