Exemple #1
0
        public WriteSession(string directory, Compression compression)
        {
            var version = LockUtil.GetNextChronologicalFileId();

            _version             = CreateNewSegmentInfo(version);
            _version.Compression = compression;

            Log.InfoFormat("begin writing {0}", _version.Version);

            var docFileName       = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName() + ".dtbl");
            var docAddressFn      = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName() + ".da");
            var docHashesFileName = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName() + ".pk");

            _directory        = directory;
            _keyIndexFileName = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName() + ".kix");
            _addressWriter    = new BlockInfoWriter(
                new FileStream(docAddressFn, FileMode.CreateNew, FileAccess.ReadWrite,
                               FileShare.None, 4096, FileOptions.DeleteOnClose));

            _docWriter = new DocumentWriter(
                new FileStream(docFileName, FileMode.CreateNew, FileAccess.ReadWrite,
                               FileShare.None, 4096, FileOptions.DeleteOnClose), compression);

            _docHashesStream = new FileStream(
                docHashesFileName, FileMode.CreateNew, FileAccess.ReadWrite,
                FileShare.None, 4096, FileOptions.DeleteOnClose);

            _keyIndex   = new Dictionary <string, short>();
            _fieldNames = new List <string>();
        }
Exemple #2
0
        protected Stream OpenDataFileStream(out FileStream lockFile)
        {
            Stream dataFile;

            if (!LockUtil.TryAquireWriteLock(_directory, out lockFile))
            {
                var dataFileName = Path.Combine(_directory, _version + ".rdb");

                dataFile = new FileStream(
                    dataFileName,
                    FileMode.CreateNew,
                    FileAccess.Write,
                    FileShare.ReadWrite,
                    4096
                    );
            }
            else
            {
                var ixFileName = LockUtil.GetFirstIndexFileNameInChronologicalOrder(_directory);

                long dataFileVersion = ixFileName == null ?
                                       _version.Version :
                                       long.Parse(Path.GetFileNameWithoutExtension(ixFileName));

                var dataFileName = Path.Combine(_directory, dataFileVersion + ".rdb");

                dataFile = new FileStream(
                    dataFileName,
                    FileMode.Append,
                    FileAccess.Write,
                    FileShare.ReadWrite,
                    4096
                    );
            }
            return(dataFile);
        }