예제 #1
0
        public static Tran WithDocuments(IEnumerable <Document> docs)
        {
            var tran = new Tran();

            tran._docs.AddRange(docs);
            return(tran);
        }
예제 #2
0
        public static Tran WithSingleDocument(Document doc)
        {
            var tran = new Tran();

            tran.AddDocument(doc);
            return(tran);
        }
예제 #3
0
        private async Task Recover()
        {
            var docIdInDataFile = await _dataFile.GetLastDocId();

            var docsFromWal = await _wal.ReadDocsAfter(docIdInDataFile);

            await _dataFile.Apply(Tran.WithDocuments(docsFromWal));
        }
예제 #4
0
        public async Task <DataFileCommitInfo> Apply(Tran tran)
        {
            foreach (var doc in tran.Documents)
            {
                _nonPersistedQ.Enqueue(doc);
            }

            return(await CommitIfRequired().ConfigureAwait(false));
        }
예제 #5
0
        private async Task CommitTran(Tran tran)
        {
            // persist in write ahead log
            await _wal.CommitTran(tran).ConfigureAwait(false);

            // add new records to datafile (it may not get committed to disk right away)
            var commitInfo = await _dataFile.Apply(tran).ConfigureAwait(false);

            if (commitInfo != null)
            {
                // some data was committed to datafile, need to update inverted index
                await UpdateIndex(commitInfo.DocsByOffsets).ConfigureAwait(false);

                await _wal.Checkpoint(commitInfo.LastCommittedDocId);
            }
        }
예제 #6
0
        public async Task CommitTran(Tran tran)
        {
            await _commitLock.WaitAsync().ConfigureAwait(false);

            try
            {
                using (Measured.Operation("wal_commit"))
                {
                    foreach (var doc in tran.Documents)
                    {
                        doc.Id = _docIdGenerator.GetNextId();
                    }

                    await DocumentSerializer.SerializeBatch(tran.Documents, _file).ConfigureAwait(false);

                    await _file.FlushAsync().ConfigureAwait(false);
                }
            }
            finally
            {
                _commitLock.Release();
            }
        }
예제 #7
0
        public async Task AddDocuments(IReadOnlyCollection <Document> docs)
        {
            var tran = Tran.WithDocuments(docs);

            await CommitTran(tran).ConfigureAwait(false);
        }
예제 #8
0
        public async Task AddDocument(Document doc)
        {
            var tran = Tran.WithSingleDocument(doc);

            await CommitTran(tran).ConfigureAwait(false);
        }