protected override void Dispose(bool disposing) { try { if (Disposed != null) { Disposed(this); } } catch (Exception) { } Interlocked.Add(ref Stats.PointsReturned, m_pointCount); m_pointCount = 0; if (m_timeout != null) { m_timeout.Cancel(); m_timeout = null; } if (m_tablesOrigList != null) { m_tablesOrigList.ForEach(x => x.Dispose()); m_tablesOrigList = null; Array.Clear(m_snapshot.Tables, 0, m_snapshot.Tables.Length); } m_timedOut = true; if (m_snapshot != null) { m_snapshot.Dispose(); m_snapshot = null; } if (m_workerThreadSynchronization != null && m_ownsWorkerThreadSynchronization) { m_workerThreadSynchronization.Dispose(); m_workerThreadSynchronization = null; } }
private void OnExecute(object sender, EventArgs <ScheduledTaskRunningReason> e) { //The worker can be disposed either via the Stop() method or //the Dispose() method. If via the dispose method, then //don't do any cleanup. if (m_disposed && e.Argument == ScheduledTaskRunningReason.Disposing) { return; } //go ahead and schedule the next rollover since nothing //will happen until this function exits anyway. //if the task is disposing, the following line does nothing. m_rolloverTask.Start(m_settings.ExecuteTimer); lock (m_syncRoot) { if (m_disposed) { return; } using (ArchiveListSnapshot <TKey, TValue> resource = m_archiveList.CreateNewClientResources()) { resource.UpdateSnapshot(); List <ArchiveTableSummary <TKey, TValue> > list = new List <ArchiveTableSummary <TKey, TValue> >(); List <Guid> listIds = new List <Guid>(); for (int x = 0; x < resource.Tables.Length; x++) { ArchiveTableSummary <TKey, TValue> table = resource.Tables[x]; if (table.SortedTreeTable.BaseFile.Snapshot.Header.Flags.Contains(m_settings.MatchFlag) && table.SortedTreeTable.BaseFile.Snapshot.Header.Flags.Contains(FileFlags.IntermediateFile)) { list.Add(table); listIds.Add(table.FileId); } else { resource.Tables[x] = null; } } bool shouldRollover = list.Count >= m_settings.CombineOnFileCount; long size = 0; for (int x = 0; x < list.Count; x++) { size += list[x].SortedTreeTable.BaseFile.ArchiveSize; if (size > m_settings.CombineOnFileSize) { if (x != list.Count - 1)//If not the last entry { list.RemoveRange(x + 1, list.Count - x - 1); } break; } } if (size > m_settings.CombineOnFileSize) { shouldRollover = true; } if (shouldRollover) { TKey startKey = new TKey(); TKey endKey = new TKey(); startKey.SetMax(); endKey.SetMin(); foreach (Guid fileId in listIds) { ArchiveTableSummary <TKey, TValue> table = resource.TryGetFile(fileId); if (table is null) { throw new Exception("File not found"); } if (!table.IsEmpty) { if (startKey.IsGreaterThan(table.FirstKey)) { table.FirstKey.CopyTo(startKey); } if (endKey.IsLessThan(table.LastKey)) { table.LastKey.CopyTo(endKey); } } } RolloverLogFile logFile = null; Action <Guid> createLog = (x) => { logFile = m_rolloverLog.Create(listIds, x); }; using (UnionReader <TKey, TValue> reader = new UnionReader <TKey, TValue>(list)) { SortedTreeTable <TKey, TValue> dest = m_createNextStageFile.CreateArchiveFile(startKey, endKey, size, reader, createLog); resource.Dispose(); using (ArchiveListEditor <TKey, TValue> edit = m_archiveList.AcquireEditLock()) { //Add the newly created file. edit.Add(dest); foreach (ArchiveTableSummary <TKey, TValue> table in list) { edit.TryRemoveAndDelete(table.FileId); } } } if (logFile != null) { logFile.Delete(); } } resource.Dispose(); } m_rolloverComplete.Set(); } }
public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList, SortedTreeEngineReaderOptions readerOptions = null, SeekFilterBase <TKey> keySeekFilter = null, MatchFilterBase <TKey, TValue> keyMatchFilter = null, WorkerThreadSynchronization workerThreadSynchronization = null) { if (readerOptions is null) { readerOptions = SortedTreeEngineReaderOptions.Default; } if (keySeekFilter is null) { keySeekFilter = new SeekFilterUniverse <TKey>(); } if (keyMatchFilter is null) { keyMatchFilter = new MatchFilterUniverse <TKey, TValue>(); } if (workerThreadSynchronization is null) { m_ownsWorkerThreadSynchronization = true; workerThreadSynchronization = new WorkerThreadSynchronization(); } m_workerThreadSynchronization = workerThreadSynchronization; m_pointCount = 0; m_keySeekFilter = keySeekFilter; m_keyMatchFilter = keyMatchFilter; m_keyMatchIsUniverse = m_keyMatchFilter as MatchFilterUniverse <TKey, TValue> != null; if (readerOptions.Timeout.Ticks > 0) { m_timeout = new TimeoutOperation(); m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true); } m_snapshot = archiveList.CreateNewClientResources(); m_snapshot.UpdateSnapshot(); m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >(); for (int x = 0; x < m_snapshot.Tables.Count(); x++) { ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x]; if (table != null) { if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange)) { try { m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table)); } catch (Exception e) { //ToDo: Make sure firstkey.tostring doesn't ever throw an exception. StringBuilder sb = new StringBuilder(); sb.AppendLine($"Archive ID {table.FileId}"); sb.AppendLine($"First Key {table.FirstKey.ToString()}"); sb.AppendLine($"Last Key {table.LastKey.ToString()}"); sb.AppendLine($"File Size {table.SortedTreeTable.BaseFile.ArchiveSize}"); sb.AppendLine($"File Name {table.SortedTreeTable.BaseFile.FilePath}"); Log.Publish(MessageLevel.Error, "Error while reading file", sb.ToString(), null, e); } } else { m_snapshot.Tables[x] = null; } } } m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan); m_keySeekFilter.Reset(); if (m_keySeekFilter.NextWindow()) { SeekToKey(m_keySeekFilter.StartOfFrame); } else { Dispose(); } }
public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList, SortedTreeEngineReaderOptions readerOptions = null, SeekFilterBase <TKey> keySeekFilter = null, MatchFilterBase <TKey, TValue> keyMatchFilter = null, WorkerThreadSynchronization workerThreadSynchronization = null) { if (readerOptions == null) { readerOptions = SortedTreeEngineReaderOptions.Default; } if (keySeekFilter == null) { keySeekFilter = new SeekFilterUniverse <TKey>(); } if (keyMatchFilter == null) { keyMatchFilter = new MatchFilterUniverse <TKey, TValue>(); } if (workerThreadSynchronization == null) { m_ownsWorkerThreadSynchronization = true; workerThreadSynchronization = new WorkerThreadSynchronization(); } m_workerThreadSynchronization = workerThreadSynchronization; m_pointCount = 0; m_keySeekFilter = keySeekFilter; m_keyMatchFilter = keyMatchFilter; m_keyMatchIsUniverse = (m_keyMatchFilter as MatchFilterUniverse <TKey, TValue>) != null; if (readerOptions.Timeout.Ticks > 0) { m_timeout = new TimeoutOperation(); m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true); } m_snapshot = archiveList.CreateNewClientResources(); m_snapshot.UpdateSnapshot(); m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >(); for (int x = 0; x < m_snapshot.Tables.Count(); x++) { ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x]; if (table != null) { if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange)) { m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table)); } else { m_snapshot.Tables[x] = null; } } } m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan); m_keySeekFilter.Reset(); if (m_keySeekFilter.NextWindow()) { SeekToKey(m_keySeekFilter.StartOfFrame); } else { Dispose(); } }