private void TestPersistence(ulong count, ExpandableArrayOfKeys keys) { using (var validEntries = new BitVector(_pool)) { validEntries.EnsureCapacity(count); validEntries.ChangeAll(true); using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Create, FileAccess.ReadWrite)) { using (var writer = new BinaryWriter(stream)) { keys.Write(writer, (ulong)count, validEntries); } } using (var keys2 = new ExpandableArrayOfKeys(_pool)) { using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Open, FileAccess.Read)) { using (var reader = new BinaryReader(stream)) { { keys2.Read(reader, (ulong)count, validEntries); } } } } } }
private void TestPersistence(ulong count, ExpandableArrayOfKeys keys) { using (var validEntries = new BitVector(_pool)) { validEntries.EnsureCapacity(count); validEntries.ChangeAll(true); using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Create, FileAccess.ReadWrite)) { using (var writer = new BinaryWriter(stream)) { keys.Write(writer, (ulong) count, validEntries); } } using (var keys2 = new ExpandableArrayOfKeys(_pool)) { using (var stream = new FileStream(@"c:\temp\data.d", FileMode.Open, FileAccess.Read)) { using (var reader = new BinaryReader(stream)) { { keys2.Read(reader, (ulong) count, validEntries); } } } } } }
public void FlushDataToStore(string docRootPath) { CheckState(); if (docRootPath == null || !Directory.Exists(docRootPath)) { throw new ArgumentException("Storage root is invalid: " + docRootPath); } StructureLock.EnterWriteLock(); try { var tasks = new Task[2 + FieldIdToColumnStore.Count * 2]; var count = 0; tasks[count] = new Task( () => { using (var writer = new BinaryWriter( new FileStream( Path.Combine(docRootPath, "_keysvalid.dat"), FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1 << 22, FileOptions.None))) { //WriteBitVectorToStore(writer, ValidDocumentsBitmap, m_untrimmedDocumentCount); ValidDocumentsBitmap.Write(writer, (ulong)m_untrimmedDocumentCount); } }, TaskCreationOptions.LongRunning); count++; tasks[count] = tasks[count - 1].ContinueWith( prev => { using (var writer = new BinaryWriter( new FileStream( Path.Combine(docRootPath, "_keys.dat"), FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1 << 22, FileOptions.None))) { DocumentKeys.Write(writer, (ulong)m_untrimmedDocumentCount, ValidDocumentsBitmap); } }, CancellationToken.None, TaskContinuationOptions.LongRunning, TaskScheduler.Default); count++; tasks[count - 2].Start(); foreach (var pair in FieldIdToColumnStore) { var field = DataContainerDescriptor.RequireField(pair.Key); var colStore = ColumnStores[FieldIdToColumnStore[pair.Key]]; var colDataPath = Path.Combine(docRootPath, GetColumnDataFileName(field)); var colNotNullsPath = Path.Combine(docRootPath, GetColumnNotNullsFileName(field)); tasks[count] = new Task( () => { using ( var writer = new BinaryWriter(new FileStream( colNotNullsPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1 << 22, FileOptions.None)) ) { colStore.NotNulls.Write(writer, (ulong)m_untrimmedDocumentCount); writer.Flush(); } }, TaskCreationOptions.LongRunning); count++; tasks[count] = tasks[count - 1].ContinueWith( prev => { using ( var writer = new BinaryWriter(new FileStream( colDataPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1 << 22, FileOptions.None)) ) { colStore.WriteData(writer, m_untrimmedDocumentCount); writer.Flush(); } }, CancellationToken.None, TaskContinuationOptions.LongRunning, TaskScheduler.Default); count++; tasks[count - 2].Start(); } Task.WaitAll(tasks); } finally { StructureLock.ExitWriteLock(); } }