Exemple #1
0
        public void Write(string collectionName, IEnumerable <IDictionary> data)
        {
            try
            {
                var collectionId = collectionName.ToHash();
                var job          = new WriteJob(collectionId, data);

                _writeQueue.Enqueue(job);

                _log.Log(string.Format("enqueued job {0} to be written to {1}", job.Id, collectionName));
            }
            catch (Exception ex)
            {
                _log.Log(string.Format("enqueue failed: {0}", ex));

                throw;
            }
        }
Exemple #2
0
 private void Commit(WriteJob job)
 {
     using (var session = _sessionFactory.CreateWriteSession(job.CollectionId))
     {
         if (job.Remove == null && job.Data != null)
         {
             session.Write(job.Data, _tokenizer);
         }
         else if (job.Data == null && job.Remove != null)
         {
             session.Remove(job.Remove, _tokenizer);
         }
         else
         {
             session.Remove(job.Remove, _tokenizer);
             session.Write(job.Data, _tokenizer);
         }
     }
 }
Exemple #3
0
        private void ExecuteWrite(WriteJob job)
        {
            try
            {
                _itemTimer.Restart();

                using (var session = _sessionFactory.CreateWriteSession(job.CollectionId))
                {
                    session.Write(job.Documents);
                }

                _log.Log(string.Format("wrote job {0} in {1}", job.Id, _itemTimer.Elapsed));
            }
            catch (Exception ex)
            {
                _log.Log(string.Format("failed to execute job {0}: {1}", job.Id, ex));

                throw;
            }
        }
Exemple #4
0
        public async Task <Result> Write(string collectionId, HttpRequest request)
        {
            try
            {
                _timer.Restart();

                var payload = new MemoryStream();

                await request.Body.CopyToAsync(payload);

                if (request.ContentLength.Value != payload.Length)
                {
                    throw new DataMisalignedException();
                }

                var data = Deserialize <IEnumerable <IDictionary> >(payload);
                var job  = new WriteJob(collectionId, data);

                _log.Log(string.Format("deserialized write job {0} for collection {1} in {2}", job.Id, collectionId, _timer.Elapsed));

                var docIds = await ExecuteWrite(job);

                var response = new MemoryStream();

                Serialize(docIds, response);

                return(new Result {
                    Data = response, MediaType = "application/json"
                });
            }
            catch (Exception ex)
            {
                _log.Log(string.Format("write failed: {0}", ex));

                throw;
            }
        }
Exemple #5
0
        private async Task <IList <ulong> > ExecuteWrite(WriteJob job)
        {
            try
            {
                _timer.Restart();

                IList <ulong> docIds;

                using (var session = _sessionFactory.CreateWriteSession(job.CollectionId))
                {
                    docIds = await session.Write(job);
                }

                _log.Log(string.Format("executed write job {0} in {1}", job.Id, _timer.Elapsed));

                return(docIds);
            }
            catch (Exception ex)
            {
                _log.Log(string.Format("failed to write job {0}: {1}", job.Id, ex));

                throw;
            }
        }