public static Tran WithDocuments(IEnumerable <Document> docs) { var tran = new Tran(); tran._docs.AddRange(docs); return(tran); }
public static Tran WithSingleDocument(Document doc) { var tran = new Tran(); tran.AddDocument(doc); return(tran); }
private async Task Recover() { var docIdInDataFile = await _dataFile.GetLastDocId(); var docsFromWal = await _wal.ReadDocsAfter(docIdInDataFile); await _dataFile.Apply(Tran.WithDocuments(docsFromWal)); }
public async Task <DataFileCommitInfo> Apply(Tran tran) { foreach (var doc in tran.Documents) { _nonPersistedQ.Enqueue(doc); } return(await CommitIfRequired().ConfigureAwait(false)); }
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); } }
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(); } }
public async Task AddDocuments(IReadOnlyCollection <Document> docs) { var tran = Tran.WithDocuments(docs); await CommitTran(tran).ConfigureAwait(false); }
public async Task AddDocument(Document doc) { var tran = Tran.WithSingleDocument(doc); await CommitTran(tran).ConfigureAwait(false); }