internal long LoadUncommittedEventsFromJournal(JournalReader _jreader) { long journalsn = 0; while (_jreader.HasCommandsPending()) { var cmd = _jreader.ReadCommand(); if (cmd != null) { if (cmd.CommandSN > LastExecutedCommandSN) { _waitingevents.Enqueue(cmd); } journalsn = Math.Max(journalsn, cmd.CommandSN); } } return journalsn; }
internal EventStore(string dbname, long lastcommittedcommandsn) { DatabaseName = dbname; LastExecutedCommandSN = lastcommittedcommandsn; JournalReader _jreader = new JournalReader(Configuration.BasePath, dbname); long jsn = LoadUncommittedEventsFromJournal(_jreader); _jreader.CloseFile(); _eventHandlerThread = new Thread(new ThreadStart(ExecuteEventCommands)); _eventHandlerThread.Start(); _jwriter = new JournalWriter(Configuration.BasePath, dbname); if (Configuration.EnableOperationsLog) _operationsLog = new JournalWriter(Configuration.BasePath, dbname, true); // The journal can be empty so i have to evaluate the last committed command serial number // and reset Command Serial number in the journal to ensure command execution coherency. _jwriter.CommandSN = Math.Max(jsn, lastcommittedcommandsn); }