예제 #1
0
        private void Initialize(string filename, byte maxkeysize, bool AllowDuplicateKeys)
        {
            _MaxKeySize = RDBDataType <T> .GetByteSize(maxkeysize);

            _T = RDBDataType <T> .ByteHandler();

            _Path = Path.GetDirectoryName(filename);
            Directory.CreateDirectory(_Path);

            _FileName = Path.GetFileNameWithoutExtension(filename);
            string db  = _Path + Path.DirectorySeparatorChar + _FileName + _datExtension;
            string idx = _Path + Path.DirectorySeparatorChar + _FileName + _idxExtension;

            LogManager.Configure(_Path + Path.DirectorySeparatorChar + _FileName + ".txt", 500, false);

            _index = new MGIndex <T>(_Path, _FileName + _idxExtension, _MaxKeySize, Global.PageItemCount, AllowDuplicateKeys);

            _archive = new StorageFile <T>(db);

            _deleted = new BoolIndex(_Path, _FileName + "_deleted.idx");

            _archive.SkipDateTime = true;

            log.Debug("Current Count = " + RecordCount().ToString("#,0"));

            CheckIndexState();

            log.Debug("Starting save timer");
            _savetimer           = new System.Timers.Timer();
            _savetimer.Elapsed  += new System.Timers.ElapsedEventHandler(_savetimer_Elapsed);
            _savetimer.Interval  = Global.SaveIndexToDiskTimerSeconds * 1000;
            _savetimer.AutoReset = true;
            _savetimer.Start();
        }
예제 #2
0
파일: MGIndex.cs 프로젝트: utech626/hOOt
        public MGIndex(string path, string filename, byte keysize, bool allowdups)
        {
            if (Global.UseLessMemoryStructures)
            {
                _cache = new SafeSortedList <int, Page <T> >();
            }
            else
            {
                _cache = new SafeDictionary <int, Page <T> >();
            }

            _AllowDuplicates = allowdups;
            if (path.EndsWith(Path.DirectorySeparatorChar.ToString()) == false)
            {
                path += Path.DirectorySeparatorChar;
            }

            _index = new IndexFile <T>(path + filename, keysize);
            // load page list
            _index.GetPageList(_pageListDiskPages, _pageList, out _LastIndexedRecordNumber);
            if (_pageList.Count() == 0)
            {
                Page <T> page = new Page <T>();
                page.FirstKey = (T)RDBDataType <T> .GetEmpty();

                page.DiskPageNumber = _index.GetNewPageNumber();
                page.isDirty        = true;
                _pageList.Add(page.FirstKey, new PageInfo(page.DiskPageNumber, 0, 0));
                _cache.Add(page.DiskPageNumber, page);
            }
        }
예제 #3
0
        /// <summary>
        /// Initialize the Indexer
        /// </summary>
        /// <param name="config"></param>
        /// <param name="maxkeysize"></param>
        /// <param name="AllowDuplicateKeys"></param>
        private void Initialize(String filename, byte maxkeysize, bool AllowDuplicateKeys)
        {
            _MaxKeySize = RDBDataType <T> .GetByteSize(maxkeysize);

            _T = RDBDataType <T> .ByteHandler();

            string db  = Path.ChangeExtension(filename, _datExtension);
            string idx = Path.ChangeExtension(filename, _idxExtension);

            //LogManager.Configure(_Path + Path.DirectorySeparatorChar + _FileName + ".txt", 500, false);

            _index = new MGIndex <T>(idx, _MaxKeySize, /*Global.PageItemCount,*/ AllowDuplicateKeys);

            if (Global.SaveAsBinaryJSON)
            {
                _archive = new StorageFile <T>(db, SF_FORMAT.BSON, false);
            }
            else
            {
                _archive = new StorageFile <T>(db, SF_FORMAT.JSON, false);
            }

            _deleted = new BoolIndex(Path.Combine(Path.GetDirectoryName(filename), "_deleted.idx"));

            log.Debug("Current Count = " + RecordCount().ToString("#,0"));

            CheckIndexState();

            log.Debug("Starting save timer");
            _savetimer           = new System.Timers.Timer();
            _savetimer.Elapsed  += new System.Timers.ElapsedEventHandler(_savetimer_Elapsed);
            _savetimer.Interval  = Global.SaveIndexToDiskTimerSeconds * 1000;
            _savetimer.AutoReset = true;
            _savetimer.Start();
        }
예제 #4
0
        public IndexFile(string filename, byte maxKeySize)//, ushort pageNodeCount)
        {
            _T = RDBDataType <T> .ByteHandler();

            if (typeof(T) == typeof(string) && Global.EnableOptimizedStringIndex)
            {
                _externalStrings = true;
                _maxKeySize      = 4;// blocknum:int
            }
            else
            {
                _maxKeySize = maxKeySize;
            }

            _PageNodeCount = Global.PageItemCount;// pageNodeCount;
            _rowSize       = (_maxKeySize + 1 + 4 + 4);

            _FileName = filename.Substring(0, filename.LastIndexOf('.'));
            string path = Path.GetDirectoryName(filename);

            Directory.CreateDirectory(path);
            if (File.Exists(filename))
            {
                // if file exists open and read header
                _file = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                ReadFileHeader();
                if (_externalStrings == false)// if the file says different
                {
                    _rowSize = (_maxKeySize + 1 + 4 + 4);
                }
                // compute last page number from file length
                _PageLength     = (_BlockHeader.Length + _rowSize * (_PageNodeCount));
                _LastPageNumber = (int)((_file.Length - _FileHeader.Length) / _PageLength);
            }
            else
            {
                // else create new file
                _file = File.Open(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

                _PageLength = (_BlockHeader.Length + _rowSize * (_PageNodeCount));

                CreateFileHeader(0);

                _LastPageNumber = (int)((_file.Length - _FileHeader.Length) / _PageLength);
            }
            if (_externalStrings)
            {
                _strings = new KeyStoreHF(path, Path.GetFileNameWithoutExtension(filename) + ".strings");
            }
            if (_LastPageNumber == 0)
            {
                _LastPageNumber = 1;
            }
            // bitmap duplicates
            if (_allowDups)
            {
                _bitmap = new BitmapIndex(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));
            }
        }
예제 #5
0
        private void Initialize(string filename, bool SkipChecking)
        {
            _T = RDBDataType <T> .ByteHandler();

            _filename = filename;
            if (File.Exists(filename) == false)
            {
                _datawrite = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            }
            else
            {
                _datawrite = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            }

            _dataread = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (SkipChecking == false)
            {
                // load rec pointers
                _recfilename = filename.Substring(0, filename.LastIndexOf('.')) + ".mgrec";
                if (File.Exists(_recfilename) == false)
                {
                    _recfilewrite = new FileStream(_recfilename, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite);
                }
                else
                {
                    _recfilewrite = new FileStream(_recfilename, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
                }

                _recfileread = new FileStream(_recfilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                if (_datawrite.Length == 0)
                {
                    // new file
                    _datawrite.Write(_fileheader, 0, _fileheader.Length);
                    _datawrite.Flush();
                    _lastWriteOffset = _fileheader.Length;
                }
                else
                {
                    _lastWriteOffset = _datawrite.Seek(0L, SeekOrigin.End);
                }
                _lastRecordNum = (int)(_recfilewrite.Length / 8);
                _recfilewrite.Seek(0L, SeekOrigin.End);
            }
        }
예제 #6
0
        //private int _maxPageItems = 0;

        public MGIndex(string path, string filename, byte keysize, /*ushort maxcount,*/ bool allowdups)
        {
            _AllowDuplicates = allowdups;
            _index           = new IndexFile <T>(path + Path.DirectorySeparatorChar + filename, keysize);//, maxcount);
            //_maxPageItems = maxcount;
            // load page list
            _index.GetPageList(_pageListDiskPages, _pageList, out _LastIndexedRecordNumber);
            if (_pageList.Count == 0)
            {
                Page <T> page = new Page <T>();
                page.FirstKey = (T)RDBDataType <T> .GetEmpty();

                page.DiskPageNumber = _index.GetNewPageNumber();
                page.isDirty        = true;
                _pageList.Add(page.FirstKey, new PageInfo(page.DiskPageNumber, 0, 0));
                _cache.Add(page.DiskPageNumber, page);
            }
        }
예제 #7
0
        public StorageFile(string filename, int maxkeylen)
        {
            _T = RDBDataType <T> .ByteHandler();

            _filename = filename;
            if (File.Exists(filename) == false)
            {
                _writefile = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            }
            else
            {
                _writefile = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            }

            // load rec pointers
            _recfilename = filename.Substring(0, filename.LastIndexOf('.')) + ".mgrec";
            if (File.Exists(_recfilename) == false)
            {
                _recordfile = new FileStream(_recfilename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            }
            else
            {
                _recordfile = new FileStream(_recfilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            }

            _maxKeyLen = maxkeylen;
            if (_writefile.Length == 0)
            {
                // new file
                byte b = (byte)maxkeylen;
                _fileheader[5] = b;
                _writefile.Write(_fileheader, 0, _fileheader.Length);
                _writefile.Flush();
            }

            bw = new BinaryWriter(ms, Encoding.UTF8);

            _lastRecordNum = (int)(_recordfile.Length / 8);
            _recordfile.Seek(0L, SeekOrigin.End);
            _lastWriteOffset = _writefile.Seek(0L, SeekOrigin.End);
        }
예제 #8
0
        public IndexFile(string filename, byte maxKeySize, ushort pageNodeCount)
        {
            _T = RDBDataType <T> .ByteHandler();

            _maxKeySize    = maxKeySize;
            _PageNodeCount = pageNodeCount;
            _rowSize       = (_maxKeySize + 1 + 4 + 4);

            string path = Path.GetDirectoryName(filename);

            Directory.CreateDirectory(path);
            if (File.Exists(filename))
            {
                // if file exists open and read header
                _file = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                ReadFileHeader();
                // compute last page number from file length
                _PageLength     = (_BlockHeader.Length + _rowSize * (_PageNodeCount));
                _LastPageNumber = (int)((_file.Length - _FileHeader.Length) / _PageLength);
            }
            else
            {
                // else create new file
                _file = File.Open(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

                _PageLength = (_BlockHeader.Length + _rowSize * (_PageNodeCount));

                CreateFileHeader(0);

                _LastPageNumber = (int)((_file.Length - _FileHeader.Length) / _PageLength);
            }
            if (_LastPageNumber == 0)
            {
                _LastPageNumber = 1;
            }
            // bitmap duplicates
            _bitmap = new BitmapIndex(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));
        }
예제 #9
0
        private void Initialize(string filename, bool StorageOnlyMode)
        {
            _T = RDBDataType <T> .ByteHandler();

            _filename = filename;

            // search for mgdat00000 extensions -> split files load
            if (File.Exists(filename + _splitfileExtension))
            {
                LoadSplitFiles(filename);
            }

            if (File.Exists(filename) == false)
            {
                _datawrite = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            }
            else
            {
                _datawrite = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            }

            _dataread = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (_datawrite.Length == 0)
            {
                // new file
                _datawrite.Write(_fileheader, 0, _fileheader.Length);
                _datawrite.Flush();
                _lastWriteOffset = _fileheader.Length;
            }
            else
            {
                long i = _datawrite.Seek(0L, SeekOrigin.End);
                if (_files.Count == 0)
                {
                    _lastWriteOffset = i;
                }
                else
                {
                    _lastWriteOffset += i; // add to the splits
                }
            }

            if (StorageOnlyMode == false)
            {
                // load rec pointers
                _recfilename = filename.Substring(0, filename.LastIndexOf('.')) + ".mgrec";
                if (File.Exists(_recfilename) == false)
                {
                    _recfilewrite = new FileStream(_recfilename, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite);
                }
                else
                {
                    _recfilewrite = new FileStream(_recfilename, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
                }

                _recfileread = new FileStream(_recfilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                _lastRecordNum = (int)(_recfilewrite.Length / 8);
                _recfilewrite.Seek(0L, SeekOrigin.End);
            }
        }