/// <summary> /// Clear data file, close any data stream pool, change password and re-create data factory /// </summary> public void ChangePassword(string password, EngineSettings settings) { if (settings.Password == password) { return; } // empty data file this.SetLength(0, FileOrigin.Data); // close all streams _dataPool.Dispose(); // delete data file _dataFactory.Delete(); settings.Password = password; // new datafile will be created with new password _dataFactory = settings.CreateDataFactory(); // create stream pool _dataPool = new StreamPool(_dataFactory, false); // get initial data file length _dataLength = -PAGE_SIZE; }
public DiskReader(MemoryCache cache, StreamPool streamPool) { _cache = cache; _streamPool = streamPool; // use lazy because you can have transaction that will read only from cache _stream = new Lazy <Stream>(() => _streamPool.Rent()); }
public DiskReader(MemoryCache cache, StreamPool dataPool, StreamPool logPool) { _cache = cache; _dataPool = dataPool; _logPool = logPool; _dataStream = new Lazy <Stream>(() => _dataPool.Rent()); _logStream = new Lazy <Stream>(() => _logPool.Rent()); }
public SortDisk(IStreamFactory factory, int containerSize, EnginePragmas pragmas) { ENSURE(containerSize % PAGE_SIZE == 0, "size must be PAGE_SIZE multiple"); _factory = factory; _containerSize = containerSize; _pragmas = pragmas; _lastContainerPosition = -containerSize; _pool = new StreamPool(_factory, false); }
public SortDisk(IStreamFactory factory, int containerSize, bool utcDate) { ENSURE(containerSize % PAGE_SIZE == 0, "size must be PAGE_SIZE multiple"); _factory = factory; _containerSize = containerSize; _utcDate = utcDate; _lastContainerPosition = -containerSize; _pool = new StreamPool(_factory, false); }
public DiskService(EngineSettings settings, int memorySegmentSize) { _cache = new MemoryCache(memorySegmentSize); // get new stream factory based on settings _dataFactory = settings.CreateDataFactory(); _logFactory = settings.CreateLogFactory(); // create stream pool _dataPool = new StreamPool(_dataFactory, false); _logPool = new StreamPool(_logFactory, true); var isNew = _dataFactory.Exists() == false; // create lazy async writer queue for log file _queue = new Lazy <DiskWriterQueue>(() => new DiskWriterQueue(_logPool.Writer)); // create new database if not exist yet if (isNew) { LOG($"creating new database: '{Path.GetFileName(_dataFactory.Name)}'", "DISK"); this.Initialize(_dataPool.Writer, settings.InitialSize); } // if not readonly, force open writable datafile if (settings.ReadOnly == false) { var dummy = _dataPool.Writer.CanRead; } // get initial data file length _dataLength = _dataFactory.GetLength() - PAGE_SIZE; // get initial log file length if (_logFactory.Exists()) { _logLength = _logFactory.GetLength() - PAGE_SIZE; } else { _logLength = -PAGE_SIZE; } }
public DiskService(EngineSettings settings, int[] memorySegmentSizes) { _cache = new MemoryCache(memorySegmentSizes); // get new stream factory based on settings _streamFactory = settings.CreateDataFactory(); // create stream pool _streamPool = new StreamPool(_streamFactory, settings.ReadOnly); // create async writer queue for log file _queue = new DiskWriterQueue(_streamPool.Writer); // checks if is a new file var isNew = settings.ReadOnly == false && _streamPool.Writer.Length == 0; // create new database if not exist yet if (isNew) { LOG($"creating new database: '{Path.GetFileName(_streamFactory.Name)}'", "DISK"); _header = this.Initialize(_streamPool.Writer, settings.Collation, settings.InitialSize); } else { // load header page from position 0 from file var stream = _streamPool.Rent(); var buffer = new PageBuffer(new byte[PAGE_SIZE], 0, 0) { Position = 0 }; try { stream.Position = 0; stream.Read(buffer.Array, 0, PAGE_SIZE); // if first byte are 1 this datafile are encrypted but has do defined password to open if (buffer[0] == 1) { throw new LiteException(0, "This data file is encrypted and needs a password to open"); } _header = new HeaderPage(buffer); _streamPool.Return(stream); } catch { // return to pool before dispose _streamPool.Return(stream); this.Dispose(); throw; } } // define start/end position for log content _logStartPosition = (_header.LastPageID + 1) * PAGE_SIZE; _logEndPosition = _logStartPosition; // will be updated by RestoreIndex }