Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB logger sample #4759

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

DB logger sample #4759

wants to merge 16 commits into from

Conversation

matejk
Copy link
Contributor

@matejk matejk commented Nov 6, 2024

Resolves #4750

@matejk matejk added this to the Release 1.14.0 milestone Nov 6, 2024
@matejk matejk requested a review from aleks-f November 6, 2024 16:51
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Show resolved Hide resolved
Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
@aleks-f aleks-f marked this pull request as draft November 8, 2024 06:50
@matejk matejk requested a review from aleks-f November 8, 2024 18:12
Copy link
Member

@aleks-f aleks-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality ok, but it should be tidied up a bit, there's too much functionality crammed into a single class. Something along these lines:

TaskManager tm;
tm.start(new SampleTask);
waitForTerminationRequest();
tm.cancelAll();
tm.joinAll();

Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
@matejk
Copy link
Contributor Author

matejk commented Nov 9, 2024

Functionality ok, but it should be tidied up a bit, there's too much functionality crammed into a single class. Something along these lines:

TaskManager tm;
tm.start(new SampleTask);
waitForTerminationRequest();
tm.cancelAll();
tm.joinAll();

Extracted scanning and inserting functionality to a separate class SQLLogInserter.

Is that what you had in mind by tidying up?

Data/samples/DBLogger/src/DBLogger.cpp Outdated Show resolved Hide resolved
Data/samples/DBLogger/src/SQLLogInserter.h Outdated Show resolved Hide resolved
@matejk matejk requested a review from aleks-f November 11, 2024 19:45
@matejk matejk marked this pull request as ready for review November 11, 2024 22:16
Copy link
Member

@aleks-f aleks-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to have DBLogger.properties file, with all the commend option settings and logger settings, something like this:

logging.loggers.root.channel = appSplitter
logging.loggers.root.level = information

logging.channels.appFile.class = FileChannel
logging.channels.appFile.pattern = %L%Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t
logging.channels.appFile.path = ${application.baseName}.log
logging.channels.appFile.times = local
logging.channels.appFile.rotation = daily
logging.channels.appFile.archive = number
logging.channels.appFile.purgeCount = 10

logging.channels.sql.class = SQLChannel
logging.channels.sql.name = DBLogger
logging.channels.sql.connector = SQLite
logging.channels.sql.connect = DBLogger.db3
logging.channels.sql.timeout = 3000
logging.channels.sql.minBatch = 5
logging.channels.sql.maxBatch = 1000
logging.channels.sql.bulk = true
logging.channels.sql.table = T_LOG
logging.channels.sql.async = false
logging.channels.sql.throw = false
logging.channels.sql.file = ${application.baseName}.sql

logging.channels.console.class = ColorConsoleChannel
logging.channels.console.pattern = %L%Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t

logging.channels.appSplitter.class = SplitterChannel
logging.channels.appSplitter.channels = console, appFile, sql

@matejk matejk requested a review from aleks-f November 12, 2024 15:42
Copy link
Member

@aleks-f aleks-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Sample should work out of the box, but it doesn't:
$ bin/Linux/aarch64/DBLogger
Directory: 
Database: , 
Number of workers: 2
Not found
Created 0 messages, processed 0 messages in 0 ms.
  • There should be a reasonable initial default setup so that workers can keep up with sql file generation; as it is now, the filesystem gets clogged with sql files.

  • logging configuration, as mentioned here

  • SQL statements in the files should insert more than a single row; should be achievable with minBatch property

@matejk
Copy link
Contributor Author

matejk commented Nov 14, 2024

* [ ]  SQL statements in the files should insert more than a single row; should be achievable with `minBatch` property

@aleks-f :

Is it a matter of SQL channel configuration to insert multiple SQL statements into the same file or shall DB logger have its own configuration to merge multiple sql files together?

@aleks-f
Copy link
Member

aleks-f commented Nov 15, 2024

* [ ]  SQL statements in the files should insert more than a single row; should be achievable with `minBatch` property

@aleks-f :

Is it a matter of SQL channel configuration to insert multiple SQL statements into the same file or shall DB logger have its own configuration to merge multiple sql files together?

Number of rows inserted in one statement should be controllable with minBatch, maxBatch and maxSQL property, when >1 the channel should concatenate multiple rows so they are inserted in one execution:

const std::string SQLChannel::SQL_INSERT_STMT = "INSERT INTO %s " \
"(Source, Name, ProcessId, Thread, ThreadId, Priority, Text, DateTime)" \
" VALUES %s";

The maxSQL property should be set not to exceed the max SQL statement length allowed by back end:

if (++batch == _maxBatch || (os.str().length() + tmp.str().length()) >= _maxSQL)
{
os << ";\n";
doLog();
os.str(""); sql.clear();
Poco::format(sql, SQL_INSERT_STMT, _table, std::string());
os << sql << '\n' << tmp.str();
batch = 0;
}

See eg. Batch size for SQL Server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

DBLogger sample
2 participants