solidDB Help : Samples : Logreader sample
  
Logreader sample
This sample Java application demonstrates the usage of the solidDB transaction log reader (Logreader).
A Java application LogSniffer reads the server transaction log (SYS_LOG system table, see SYS_LOG) and extracts records that relate to SQL DML statements. By using solidDB system tables to access user table metadata, LogSniffer reconstructs the statements into plain-text SQL strings and displays them as output.
The sample can be used as a general utility to listen for and display any log traffic.
The files for the sample are located in the soliddb-installdir\samples\logreader directory. The main program is LogSnifferMain.java.
Note To run the sample, you must install JDK 1.7 or later and set the PATH and CLASSPATH settings for the Java compiler.
For general information about running the samples, see Samples.
LogSniffer
The LogSniffer application consists of a number of Java classes that are called from the main program LogSnifferMain.
The LogSnifferMain program completes the following actions:
1 Register the driver by using JDBC driver manager services.
2 Connect to a solidDB server with two connections: one for reading the log and the other for accessing solidDB system tables.
3 Start reading the log and, for each detected DML (Data Manipulation Language) record, perform the following steps:
a Get the table names and column names from the system tables.
b Reconstruct the query as an SQL statement with parameter markers.
c Get column data types from the system tables.
d Extract the column values and format them in a parameter value array.
e Merge the statement and the parameter values to produce the final full text statement.
f Print the statement to output.
4 Stop reading the log when ADMIN COMMAND 'logreader stop' is detected.
5 Close the statements and connections.
Running the sample
To demonstrate the use of the application, run the runme script (runme.bat on Windows), which completes the following actions:
1 Compile the Java classes.
2 Start a solidDB server.
3 Runs the initialize.sql script, which completes the following steps:
a creates two tables, one with a primary key and one without,
b defines a Logreader partition and assigns the tables to the partition,
c populates the tables with some initial data.
4 Start the LogSniffer application and point it at the Logreader partition.
5 Runs the statements.sql script, which performs a number of insert, update, and delete operations (that are read from the log by the LogSniffer application and output to the screen) and then stop Logreader.
6 Shut down the solidDB database.
Note If you want to run the LogSniffer application manually, use the following syntax:
java LogSnifferMain [options]
where options are:
-s: prompt for the server JDBC URL
-p:partition_name: use partition filtering on the specified partition
-verbose: print more output
-debug: print even more output
-h, -usage: print usage
Go up to
Samples