コード例 #1
0
ファイル: Tran.cs プロジェクト: maxtyutmanov/simplefts
        public static Tran WithDocuments(IEnumerable <Document> docs)
        {
            var tran = new Tran();

            tran._docs.AddRange(docs);
            return(tran);
        }
コード例 #2
0
ファイル: Tran.cs プロジェクト: maxtyutmanov/simplefts
        public static Tran WithSingleDocument(Document doc)
        {
            var tran = new Tran();

            tran.AddDocument(doc);
            return(tran);
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: maxtyutmanov/simplefts
        private async Task Recover()
        {
            var docIdInDataFile = await _dataFile.GetLastDocId();

            var docsFromWal = await _wal.ReadDocsAfter(docIdInDataFile);

            await _dataFile.Apply(Tran.WithDocuments(docsFromWal));
        }
コード例 #4
0
ファイル: DataFile.cs プロジェクト: maxtyutmanov/simplefts
        public async Task <DataFileCommitInfo> Apply(Tran tran)
        {
            foreach (var doc in tran.Documents)
            {
                _nonPersistedQ.Enqueue(doc);
            }

            return(await CommitIfRequired().ConfigureAwait(false));
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: maxtyutmanov/simplefts
        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
ファイル: Database.cs プロジェクト: maxtyutmanov/simplefts
        public async Task AddDocuments(IReadOnlyCollection <Document> docs)
        {
            var tran = Tran.WithDocuments(docs);

            await CommitTran(tran).ConfigureAwait(false);
        }
コード例 #8
0
ファイル: Database.cs プロジェクト: maxtyutmanov/simplefts
        public async Task AddDocument(Document doc)
        {
            var tran = Tran.WithSingleDocument(doc);

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