예제 #1
0
        private async Task LogCommit(CancellationToken c)
        {
            // IMPORTANTE!! SIEMPERE CREATE VARIABLES LOCALES
            var commitIndex = _volatileState.CommitIndex;
            var lastApplied = _volatileState.LastApplied;

            // NOTE: if snapshotting, it should not commit anything
            if (!_isSnapshotting && commitIndex > lastApplied)
            {
                TheTrace.TraceInformation($"[{_meAsAPeer.ShortName}] Applying to the state maquina {commitIndex - lastApplied} entries");

                // TODO: ADD BATCHING LATER
                await _stateMachine.ApplyAsync(
                    _logPersister.GetEntries(lastApplied + 1, (int)(commitIndex - lastApplied))
                    .Select(x => x.Body).ToArray()
                    );

                _volatileState.LastApplied = commitIndex;
            }
        }