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@scivics-lab.com
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final Connectionprivate static final intprivate static final Loggerprivate final AtomicBooleanprivate final BlockingQueue<H2LogStore.LogTask> private final Thread -
Constructor Summary
ConstructorsConstructorDescriptionCreates an in-memory H2LogStore (for testing).H2LogStore(String host, int port, String dbPath) Creates an H2LogStore connected to a remote TCP server.H2LogStore(Path dbPath) Creates an H2LogStore with the specified database path. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static H2LogStorecreateWithFallback(String logServer, Path embeddedPath) Factory method that attempts TCP connection with fallback to embedded mode.voidendSession(long sessionId, SessionStatus status) Ends a session with the given status.private voidlongGets 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 voidlistSessions(int limit) Lists all sessions.voidRecords a log entry.voidRecords a log entry with vertex context.voidlogAction(long sessionId, String nodeId, String vertexName, String actionName, int exitCode, long durationMs, String output) Records an action result.private LogEntrymapLogEntry(ResultSet rs) 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 voidprocessBatch(List<H2LogStore.LogTask> batch) 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.private voidVerifies the database schema exists (for TCP connections).private voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DistributedLogStore
getErrors
-
Field Details
-
LOG
-
connection
-
writeQueue
-
writerThread
-
running
-
BATCH_SIZE
- See Also:
-
DEFAULT_TCP_PORT
- See Also:
-
-
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
-
H2LogStore
Creates an H2LogStore connected to a remote TCP server.The server should be started using the
log-servercommand before connecting. Schema is expected to be initialized by the server.- Parameters:
host- H2 server hostname (typically "localhost")port- H2 server TCP portdbPath- database path on the server- Throws:
SQLException- if connection fails
-
-
Method Details
-
createWithFallback
public static H2LogStore createWithFallback(String logServer, Path embeddedPath) throws SQLException Factory method that attempts TCP connection with fallback to embedded mode.If a log server address is specified and reachable, connects via TCP. Otherwise, falls back to embedded mode with AUTO_SERVER=TRUE.
- Parameters:
logServer- server address in "host:port" format (may be null)embeddedPath- path for embedded database fallback- Returns:
- H2LogStore instance
- Throws:
SQLException- if both TCP and embedded connections fail
-
verifySchema
Verifies the database schema exists (for TCP connections).- Throws:
SQLException- if schema is not initialized
-
initSchema
- Throws:
SQLException
-
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
-
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 vertex context.- Specified by:
login interfaceDistributedLogStore- Parameters:
sessionId- session ID from startSession()nodeId- identifier of the nodevertexName- current vertex name in workflowlevel- log levelmessage- log message
-
logAction
public void logAction(long sessionId, String nodeId, String vertexName, 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 identifiervertexName- vertex nameactionName- 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
-
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
-
mapLogEntry
- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-