Class H2LogStore
java.lang.Object
com.scivicslab.turingworkflow.plugins.logdb.H2LogStore
- All Implemented Interfaces:
DistributedLogStore,AutoCloseable
H2 Database implementation of DistributedLogStore.
Uses H2 embedded database for storing logs from distributed workflow execution. Supports concurrent access from multiple threads and provides efficient querying by node, level, and time.
Features:
- Pure Java - no native dependencies
- Single file storage (.mv.db)
- Asynchronous batch writing for performance
- SQL-based querying
- Since:
- 1.0
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.scivicslab.turingworkflow.plugins.logdb.DistributedLogStore
DistributedLogStore.InstanceHolder -
Constructor Summary
ConstructorsConstructorDescriptionCreates an in-memory H2LogStore (for testing).H2LogStore(Path dbPath) Creates an H2LogStore with the specified database path. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down the log store, stopping the writer thread and closing all connections.voidDisables text file logging.voidendSession(long sessionId, SessionStatus status) Ends a session with the given status.Gets the database connection for read-only operations.longGets the most recent session ID.getLogsByLevel(long sessionId, LogLevel minLevel) Retrieves log entries filtered by level.getLogsByNode(long sessionId, String nodeId) Retrieves all log entries for a specific node in a session.getSummary(long sessionId) Gets a summary of the session.static voidinitSchema(Connection conn) Initializes the log database schema on the given connection.listSessions(int limit) Lists all sessions.voidRecords a log entry.voidRecords a log entry with transition context.voidlogAction(long sessionId, String nodeId, String label, String actionName, int exitCode, long durationMs, String output) Records an action result.voidmarkNodeFailed(long sessionId, String nodeId, String reason) Marks a node as failed in this session.voidmarkNodeSuccess(long sessionId, String nodeId) Marks a node as succeeded in this session.voidsetTextLogFile(Path textLogPath) Sets the text log file for additional text-based logging.longstartSession(String workflowName, int nodeCount) Starts a new workflow execution session.longstartSession(String workflowName, String overlayName, String inventoryName, int nodeCount) Starts a new workflow execution session with overlay and inventory info.longstartSession(String workflowName, String overlayName, String inventoryName, int nodeCount, String cwd, String gitCommit, String gitBranch, String commandLine, String pluginVersion, String pluginCommit) Starts a new workflow execution session with full execution context.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.scivicslab.turingworkflow.plugins.logdb.DistributedLogStore
getErrors
-
Constructor Details
-
H2LogStore
Creates an H2LogStore with the specified database path.- Parameters:
dbPath- path to the database file (without extension)- Throws:
SQLException- if database connection fails
-
H2LogStore
Creates an in-memory H2LogStore (for testing).- Throws:
SQLException- if database connection fails
-
-
Method Details
-
getConnection
Gets the database connection for read-only operations.Components should NOT close this connection. The connection is owned by the store and will be closed when execution ends.
- Specified by:
getConnectionin interfaceDistributedLogStore- Returns:
- the JDBC connection
-
setTextLogFile
Sets the text log file for additional text-based logging.- Parameters:
textLogPath- path to the text log file- Throws:
IOException- if the file cannot be opened for writing
-
disableTextLog
public void disableTextLog()Disables text file logging. -
initSchema
Initializes the log database schema on the given connection.- Parameters:
conn- the database connection- Throws:
SQLException- if schema initialization fails
-
startSession
Description copied from interface:DistributedLogStoreStarts a new workflow execution session.- Specified by:
startSessionin interfaceDistributedLogStore- Parameters:
workflowName- name of the workflow being executednodeCount- number of nodes participating in this session- Returns:
- session ID for subsequent log entries
-
startSession
public long startSession(String workflowName, String overlayName, String inventoryName, int nodeCount) Description copied from interface:DistributedLogStoreStarts a new workflow execution session with overlay and inventory info.- Specified by:
startSessionin interfaceDistributedLogStore- Parameters:
workflowName- name of the workflow being executedoverlayName- name of the overlay being used (may be null)inventoryName- name of the inventory file being used (may be null)nodeCount- number of nodes participating in this session- Returns:
- session ID for subsequent log entries
-
startSession
public long startSession(String workflowName, String overlayName, String inventoryName, int nodeCount, String cwd, String gitCommit, String gitBranch, String commandLine, String pluginVersion, String pluginCommit) Description copied from interface:DistributedLogStoreStarts a new workflow execution session with full execution context.- Specified by:
startSessionin interfaceDistributedLogStore- Parameters:
workflowName- name of the workflow being executedoverlayName- name of the overlay being used (may be null)inventoryName- name of the inventory file being used (may be null)nodeCount- number of nodes participating in this sessioncwd- current working directorygitCommit- git commit hash of the workflow directory (may be null)gitBranch- git branch name (may be null)commandLine- the command line used to invoke the workflowpluginVersion- plugin versionpluginCommit- plugin git commit hash (may be null)- Returns:
- session ID for subsequent log entries
-
log
Description copied from interface:DistributedLogStoreRecords a log entry.- Specified by:
login interfaceDistributedLogStore- Parameters:
sessionId- session ID from startSession()nodeId- identifier of the node generating this loglevel- log levelmessage- log message
-
log
Description copied from interface:DistributedLogStoreRecords a log entry with transition context.- Specified by:
login interfaceDistributedLogStore- Parameters:
sessionId- session ID from startSession()nodeId- identifier of the nodelabel- current label in workflowlevel- log levelmessage- log message
-
logAction
public void logAction(long sessionId, String nodeId, String label, String actionName, int exitCode, long durationMs, String output) Description copied from interface:DistributedLogStoreRecords an action result.- Specified by:
logActionin interfaceDistributedLogStore- Parameters:
sessionId- session IDnodeId- node identifierlabel- labelactionName- action/method nameexitCode- command exit code (0 for success)durationMs- execution duration in millisecondsoutput- command output or result message
-
markNodeSuccess
Description copied from interface:DistributedLogStoreMarks a node as succeeded in this session.- Specified by:
markNodeSuccessin interfaceDistributedLogStore- Parameters:
sessionId- session IDnodeId- node identifier
-
markNodeFailed
Description copied from interface:DistributedLogStoreMarks a node as failed in this session.- Specified by:
markNodeFailedin interfaceDistributedLogStore- Parameters:
sessionId- session IDnodeId- node identifierreason- failure reason
-
endSession
Description copied from interface:DistributedLogStoreEnds a session with the given status.- Specified by:
endSessionin interfaceDistributedLogStore- Parameters:
sessionId- session IDstatus- final status
-
getLogsByNode
Description copied from interface:DistributedLogStoreRetrieves all log entries for a specific node in a session.- Specified by:
getLogsByNodein interfaceDistributedLogStore- Parameters:
sessionId- session IDnodeId- node identifier- Returns:
- list of log entries
-
getLogsByLevel
Description copied from interface:DistributedLogStoreRetrieves log entries filtered by level.- Specified by:
getLogsByLevelin interfaceDistributedLogStore- Parameters:
sessionId- session IDminLevel- minimum log level to include- Returns:
- list of log entries
-
getSummary
Description copied from interface:DistributedLogStoreGets a summary of the session.- Specified by:
getSummaryin interfaceDistributedLogStore- Parameters:
sessionId- session ID- Returns:
- session summary
-
getLatestSessionId
public long getLatestSessionId()Description copied from interface:DistributedLogStoreGets the most recent session ID.- Specified by:
getLatestSessionIdin interfaceDistributedLogStore- Returns:
- latest session ID, or -1 if no sessions exist
-
listSessions
Description copied from interface:DistributedLogStoreLists all sessions.- Specified by:
listSessionsin interfaceDistributedLogStore- Parameters:
limit- maximum number of sessions to return- Returns:
- list of session summaries
-
close
Shuts down the log store, stopping the writer thread and closing all connections.Waits up to 5 seconds for the writer thread to finish processing remaining tasks before closing connections. Also closes the text log writer if enabled.
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- if an error occurs while closing connections
-