public void ConcurrentAppend(string streamName, byte[] data, OnCommit commit, long expectedStreamVersion = -1) { _thread.EnterWriteLock(); try { var list = _cacheByKey.GetOrAdd(streamName, s => new DataWithKey[0]); var actualStreamVersion = list.Length; if (expectedStreamVersion >= 0) { if (actualStreamVersion != expectedStreamVersion) { throw new AppendOnlyStoreConcurrencyException(expectedStreamVersion, actualStreamVersion, streamName); } } long newStreamVersion = actualStreamVersion + 1; long newStoreVersion = StoreVersion + 1; commit(newStreamVersion, newStoreVersion); // update in-memory cache only after real commit completed var dataWithKey = new DataWithKey(streamName, data, newStreamVersion, newStoreVersion); _cacheFull = ImmutableAdd(_cacheFull, dataWithKey); _cacheByKey.AddOrUpdate(streamName, s => new[] { dataWithKey }, (s, records) => ImmutableAdd(records, dataWithKey)); StoreVersion = newStoreVersion; } finally { _thread.ExitWriteLock(); } }
public void Commit() { OnCommit?.Invoke(this, EventArgs.Empty); if (!noeffect) { tr.Commit(); } iscommited = true; }
public bool Commit() { if (!CanCommit()) { return(false); } WhitelistModel.Submit(_newWhitelist); OnCommit?.Invoke(); _newWhitelist = new Whitelist(); return(true); }
private void CommitInput(string text) { KeepInCmd(text); showText.Append(text.ToString() + "\n"); CmdCanvas.ShowBar.value = 0; isChange = true; CmdCanvas.CmdShowText.text = showText.ToString(); CmdCanvas.ShowContent.sizeDelta = new Vector2(0, CmdCanvas.CmdShowText.preferredHeight + Screen.height / 5); //Debug.Log(CmdCanvas.CmdShowText.text.he) OnCommit.Invoke(text); }
public void ConcurrentAppend(string streamName, byte[] data, OnCommit commit, long expectedStreamVersion = -1) { this._thread.EnterWriteLock(); try { var list = this._cacheByKey.GetOrAdd(streamName, s => new List <DataWithKey>()); var actualStreamVersion = list.Count; if (expectedStreamVersion >= 0) { if (actualStreamVersion != expectedStreamVersion) { throw new AppendOnlyStoreConcurrencyException(expectedStreamVersion, actualStreamVersion, streamName); } } long newStreamVersion = actualStreamVersion + 1; var newStoreVersion = this.StoreVersion + 1; commit(newStreamVersion, newStoreVersion); // update in-memory cache only after real commit completed if (streamName != "audit" && streamName != "func") { var dataWithKey = new DataWithKey(streamName, data, newStreamVersion, newStoreVersion); this._cacheFull.Add(newStoreVersion, dataWithKey); this._cacheByKey.GetOrAdd(streamName, s => new List <DataWithKey> { dataWithKey }).Add(dataWithKey); } this.StoreVersion = newStoreVersion; } finally { this._thread.ExitWriteLock(); } }
protected override void OnFocusLost(InputState state) { UnbindInput(); cursor.ClearTransformations(); cursor.FadeOut(200); if (state.Keyboard.Keys.Contains(Key.Enter)) { background.Colour = BackgroundUnfocused; background.ClearTransformations(); background.FlashColour(BackgroundCommit, 400); Game.Audio.Sample.Get(@"Keyboard/key-confirm")?.Play(); OnCommit?.Invoke(this, true); } else { background.ClearTransformations(); background.FadeColour(BackgroundUnfocused, 200, EasingTypes.OutExpo); } cursorAndLayout.Invalidate(); }
public void Commit() { if (_disposed) { throw new ObjectDisposedException("Transaction"); } if (Flags != (TransactionFlags.ReadWrite)) { return; // nothing to do } if (Committed) { throw new InvalidOperationException("Cannot commit already committed transaction."); } if (RolledBack) { throw new InvalidOperationException("Cannot commit rolled-back transaction."); } while (_pagesToFreeOnCommit.Count > 0) { FreePage(_pagesToFreeOnCommit.Pop()); } _txHeader->LastPageNumber = _state.NextPageNumber - 1; _state.Root.CopyTo(&_txHeader->Root); _txHeader->TxMarker |= TransactionMarker.Commit; var totalNumberOfAllocatedPages = _allocatedPagesInTransaction + _overflowPagesInTransaction; if (totalNumberOfAllocatedPages > 0 || // nothing changed in this transaction // allow call to writeToJournal for flushing lazy tx (IsLazyTransaction == false && _journal?.HasDataInLazyTxBuffer() == true)) { // In the case of non-lazy transactions, we must flush the data from older lazy transactions // to ensure the sequentiality of the data. var numberOfWrittenPages = _journal.WriteToJournal(this, totalNumberOfAllocatedPages + PagesTakenByHeader); FlushedToJournal = true; if (_requestedCommitStats != null) { _requestedCommitStats.NumberOfModifiedPages = totalNumberOfAllocatedPages + PagesTakenByHeader; _requestedCommitStats.NumberOfPagesWrittenToDisk = numberOfWrittenPages; } } // an exception being throw after the transaction has been committed to disk // will corrupt the in memory state, and require us to restart (and recover) to // be in a valid state try { ValidateAllPages(); // release scratch file page allocated for the transaction header _env.ScratchBufferPool.Free(_transactionHeaderPage.ScratchFileNumber, _transactionHeaderPage.PositionInScratchBuffer, null); Committed = true; _env.TransactionAfterCommit(this); } catch (Exception e) { _env.CatastrophicFailure = ExceptionDispatchInfo.Capture(e); throw; } OnCommit?.Invoke(this); }
public void WhenInboundHasProblemsOutboundJustKeepsOnTrucking(int numberOfMessages) { // arrange var receivedMessageCount = 0; var messageTracker = new ConcurrentDictionary <Guid, int>(); var resetEvent = new ManualResetEvent(false); orderSystemHandlerActivator.Handle <PlaceOrderRequest>(req => { if (req.What != "beer" || req.HowMuch != 12) { return; } OnCommit.Do(() => { messageTracker.AddOrUpdate(req.MsgId, 1, (id, count) => count + 1); var newValue = Interlocked.Increment(ref receivedMessageCount); if (newValue >= numberOfMessages) { resetEvent.Set(); } }); }); var timeout = numberOfMessages.Seconds(); var keepMakingChaos = true; var chaosMonkey = new Thread(() => { while (keepMakingChaos) { Thread.Sleep(0.1.Seconds()); inbound.Stop(); Console.WriteLine("Inbound stopped - {0} messages processed...", receivedMessageCount); Thread.Sleep(0.2.Seconds()); inbound.Start(); Thread.Sleep(2.2331.Seconds()); } }); // act chaosMonkey.Start(); numberOfMessages.Times(() => pricedesk.Send(CreateMessage())); // assert var resetEventWasSet = resetEvent.WaitOne(timeout + 5.Seconds()); keepMakingChaos = false; chaosMonkey.Join(); // chill, be more sure to empty the queue completely Thread.Sleep(1.Seconds()); Assert.That(resetEventWasSet, Is.True, "Request was not received in order system within timeout of {0}", timeout); receivedMessageCount.ShouldBeGreaterThanOrEqualTo(numberOfMessages); Console.WriteLine("Actual number of received messages: {0}", receivedMessageCount); if (messageTracker.Any(t => t.Value > 1)) { Console.WriteLine(@"The following IDs were received more than once: {0}", string.Join(Environment.NewLine, messageTracker.Where(t => t.Value > 1).Select(kvp => " " + kvp.Key + ": " + kvp.Value))); } messageTracker.Count.ShouldBe(numberOfMessages); }
protected virtual void Commit() { OnCommit?.Invoke(this, _events); _events.Clear(); }
protected void InvokeOnCommit(bool newText) { AudioEngine.PlaySample(@"key-confirm"); OnCommit?.Invoke(this, newText); }
public void Commit() { _transaction.Commit(); OnCommit?.Invoke(); }
private void DumpMessages <M>(IEnumerable <M> messages, Func <M, Message <K, T> > getMessage, CancellationToken cancellationToken) { var producerBuilder = new ProducerBuilder <K, T>(producerConfig); producerBuilder.SetKeySerializer(keySerializer); producerBuilder.SetValueSerializer(valueSerializer); producerBuilder.SetErrorHandler((_, e) => OnError?.Invoke(new StreamingError { IsFatal = e.IsFatal, Reason = e.Reason })); producerBuilder.SetStatisticsHandler((_, statistics) => OnStatistics?.Invoke(statistics)); Stopwatch processTime = Stopwatch.StartNew(); using (var p = producerBuilder.Build()) { foreach (M message in messages) { if (cancellationToken.IsCancellationRequested) { break; } Policy.Handle <ProduceException <K, T> >() .WaitAndRetryForever(retryAttempt => TimeSpan.FromMilliseconds(Math.Min(100 * Math.Pow(2, retryAttempt), 10000)), (exception, timespan) => { var kafkaException = exception as ProduceException <K, T>; OnError?.Invoke(new StreamingError { IsFatal = kafkaException.Error.IsFatal, Reason = $"{kafkaException.Error.Reason}. The message with key {kafkaException.DeliveryResult.Key} in topic {kafkaException.DeliveryResult.Topic} will be resent on {timespan.TotalMilliseconds} ms." }); }) .Execute(() => { if (!cancellationToken.IsCancellationRequested) { p.Produce(this.topic, getMessage.Invoke(message), r => { if (r.Error.IsError) { OnError?.Invoke(new StreamingError { IsFatal = r.Error.IsFatal, Reason = r.Error.Reason }); } }); } }); if (processTime.ElapsedMilliseconds >= CommitTimeoutMs) { p.Flush(cancellationToken); if (!cancellationToken.IsCancellationRequested) { OnCommit?.Invoke(); processTime.Restart(); } } } p.Flush(cancellationToken); if (!cancellationToken.IsCancellationRequested) { OnCommit?.Invoke(); } } }