示例#1
0
 private BatchWrite <TKey, TEntry> GetBatchToWrite()
 {
     lock ( _sync )
     {
         BatchWrite <TKey, TEntry> batch = null;
         if (_batches.Count != 0)
         {
             batch = _batches.Dequeue();
         }
         else if (_currentBatch != null)
         {
             batch         = _currentBatch;
             _currentBatch = null;
         }
         return(batch);
     }
 }
示例#2
0
        public Task Write(ISerie <TKey, TEntry> serie)
        {
            lock ( _sync )
            {
                if (_currentBatch == null)
                {
                    _currentBatch = new BatchWrite <TKey, TEntry>();
                }
                if (_currentBatch.Count + serie.GetEntries().Count > _maxBatchSize)
                {
                    _batches.Enqueue(_currentBatch);
                    _currentBatch = new BatchWrite <TKey, TEntry>();
                }

                _currentBatch.Add(serie);

                return(_currentBatch.Task);
            }
        }
示例#3
0
        public Task Write(ISerie <TKey, TEntry> serie)
        {
            lock ( _sync )
            {
                var key = serie.GetKey();
                if (!_queued.TryGetValue(key, out var existingBatchWrite))
                {
                    existingBatchWrite = new BatchWrite <TKey, TEntry>(serie);
                    _queued.Add(key, existingBatchWrite);
                    _keys.AddLast(key);
                }
                else
                {
                    existingBatchWrite.Add(serie);
                }

                _queuedCount += serie.GetEntries().Count;

                return(existingBatchWrite.Task);
            }
        }