public UInt64LinksTransactionsLayer(ILinks <ulong> links, string logAddress) : base(links) { if (string.IsNullOrWhiteSpace(logAddress)) { throw new ArgumentNullException(nameof(logAddress)); } // В первой строке файла хранится последняя закоммиченную транзакцию. // При запуске это используется для проверки удачного закрытия файла лога. // In the first line of the file the last committed transaction is stored. // On startup, this is used to check that the log file is successfully closed. var lastCommitedTransition = FileHelpers.ReadFirstOrDefault <Transition>(logAddress); var lastWrittenTransition = FileHelpers.ReadLastOrDefault <Transition>(logAddress); if (!lastCommitedTransition.Equals(lastWrittenTransition)) { Dispose(); throw new NotSupportedException("Database is damaged, autorecovery is not supported yet."); } if (lastCommitedTransition == default) { FileHelpers.WriteFirst(logAddress, lastCommitedTransition); } _lastCommitedTransition = lastCommitedTransition; // TODO: Think about a better way to calculate or store this value var allTransitions = FileHelpers.ReadAll <Transition>(logAddress); _lastCommitedTransactionId = allTransitions.Length > 0 ? allTransitions.Max(x => x.TransactionId) : 0; _uniqueTimestampFactory = new UniqueTimestampFactory(); _logAddress = logAddress; _log = FileHelpers.Append(logAddress); _transitions = new Queue <Transition>(); _transitionsPusher = new Task(TransitionsPusher); _transitionsPusher.Start(); }