Class H2LogStore
java.lang.Object
com.scivicslab.actoriac.log.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
- Author:
- devteam@scivicslab.com
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface DistributedLogStore
DistributedLogStore.InstanceHolder -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final Connectionprivate static final DateTimeFormatterprivate static final Loggerprivate final H2LogReaderprivate final AtomicBooleanprivate static final ZoneIdprivate PrintWriterOptional text log file writer.private final BlockingQueue<H2LogStore.LogTask> private final Thread -
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()voidDisables text file logging.voidendSession(long sessionId, SessionStatus status) Ends a session with the given status.private voidGets 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.private voidstatic 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.private LogLevelparseLogLevelFromLabel(String label, int exitCode) Parses log level from the label parameter.private voidprocessBatch(List<H2LogStore.LogTask> batch) 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 actorIacVersion, String actorIacCommit) Starts a new workflow execution session with full execution context.private voidprivate voidwriteToTextLog(String nodeId, String label, LogLevel level, String message) Writes a log entry to the text log file if enabled.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DistributedLogStore
getErrors
-
Field Details
-
LOG
-
ISO_FORMATTER
-
SYSTEM_ZONE
-
connection
-
reader
-
writeQueue
-
writerThread
-
running
-
BATCH_SIZE
- See Also:
-
textLogWriter
Optional text log file writer. When set, log entries are also written to this text file.
-
-
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.This connection is shared and should NOT be closed by the caller. The connection will be closed when the H2LogStore is closed.
- Specified by:
getConnectionin interfaceDistributedLogStore- Returns:
- the JDBC connection
-
setTextLogFile
Sets the text log file for additional text-based logging.When a text log file is set, all log entries written to the database are also appended to this text file in a human-readable format.
- Parameters:
textLogPath- path to the text log file- Throws:
IOException- if the file cannot be opened for writing
-
disableTextLog
Disables text file logging. -
initSchema
- Throws:
SQLException
-
initSchema
Initializes the log database schema on the given connection.This method can be called from external components (e.g., log server) to ensure consistent schema across all database access points.
- Parameters:
conn- the database connection- Throws:
SQLException- if schema initialization fails
-
writerLoop
-
processBatch
-
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 actorIacVersion, String actorIacCommit) 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 actor-IaCactorIacVersion- actor-IaC versionactorIacCommit- actor-IaC 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
-
parseLogLevelFromLabel
Parses log level from the label parameter.Maps java.util.logging levels to LogLevel:
- SEVERE → ERROR
- WARNING → WARN
- INFO → INFO
- CONFIG, FINE, FINER, FINEST → DEBUG
-
writeToTextLog
Writes a log entry to the text log file if enabled.- Parameters:
nodeId- the node identifierlabel- the workflow label (may be null)level- the log levelmessage- the log 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
-
flushWrites
-
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
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
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-