示例#1
0
        private static void AssertNumberOfFreeIdsEquals(File databaseDirectory, FileSystemAbstraction fs, long numberOfFreeIds)
        {
            long fileSize = fs.GetFileSize(new File(databaseDirectory, "neostore.propertystore.db.strings.id"));
            long fileSizeWithoutHeader = fileSize - 9;
            long actualFreeIds         = fileSizeWithoutHeader / 8;

            assertThat("Id file should at least have a 9 byte header", fileSize, greaterThanOrEqualTo(9L));
            assertThat("File should contain the expected number of free ids", actualFreeIds, @is(numberOfFreeIds));
            assertThat("File size should not contain more bytes than expected", 8 * numberOfFreeIds, @is(fileSizeWithoutHeader));
        }
示例#2
0
        public IndexProviderStore(File file, FileSystemAbstraction fileSystem, long expectedVersion, bool allowUpgrade)
        {
            this._file   = file;
            this._random = new Random(DateTimeHelper.CurrentUnixTimeMillis());
            StoreChannel channel = null;
            bool         success = false;

            try
            {
                // Create it if it doesn't exist
                if (!fileSystem.FileExists(file) || fileSystem.GetFileSize(file) == 0)
                {
                    Create(file, fileSystem, expectedVersion);
                }

                // Read all the records in the file
                channel = fileSystem.Open(file, OpenMode.READ_WRITE);
                long?[] records = ReadRecordsWithNullDefaults(channel, RECORD_COUNT, allowUpgrade);
                _creationTime     = records[0].Value;
                _randomIdentifier = records[1].Value;
                _version          = records[2].Value;
                _lastCommittedTx  = records[3].Value;
                long?readIndexVersion = records[4];
                _fileChannel = channel;

                // Compare version and throw exception if there's a mismatch, also considering "allow upgrade"
                bool versionDiffers = CompareExpectedVersionWithStoreVersion(expectedVersion, allowUpgrade, readIndexVersion);

                // Here we know that either the version matches or we just upgraded to the expected version
                _indexVersion = expectedVersion;
                if (versionDiffers)
                {
                    // We have upgraded the version, let's write it
                    WriteOut();
                }
                success = true;
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
            finally
            {
                if (!success && channel != null)
                {
                    try
                    {
                        channel.close();
                    }
                    catch (IOException)
                    {                              // What to do?
                    }
                }
            }
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void create(java.io.File file, org.neo4j.io.fs.FileSystemAbstraction fileSystem, long indexVersion) throws java.io.IOException
        private void Create(File file, FileSystemAbstraction fileSystem, long indexVersion)
        {
            if (fileSystem.FileExists(file) && fileSystem.GetFileSize(file) > 0)
            {
                throw new System.ArgumentException(file + " already exist");
            }

            using (StoreChannel fileChannel = fileSystem.Open(file, OpenMode.READ_WRITE))
            {
                Write(fileChannel, DateTimeHelper.CurrentUnixTimeMillis(), _random.nextLong(), 0, 1, indexVersion);
            }
        }
示例#4
0
 /// <summary>
 /// Calculates the size of a given directory or file given the provided abstract filesystem.
 /// </summary>
 /// <param name="fs"> the filesystem abstraction to use </param>
 /// <param name="file"> to the file or directory. </param>
 /// <returns> the size, in bytes, of the file or the total size of the content in the directory, including
 /// subdirectories. </returns>
 public static long Size(FileSystemAbstraction fs, File file)
 {
     if (fs.IsDirectory(file))
     {
         long   size  = 0L;
         File[] files = fs.ListFiles(file);
         if (files == null)
         {
             return(0L);
         }
         foreach (File child in files)
         {
             size += size(fs, child);
         }
         return(size);
     }
     else
     {
         return(fs.GetFileSize(file));
     }
 }
示例#5
0
        private long SizeOfFileIfExists(File file)
        {
            FileSystemAbstraction fileSystem = _outsideWorld.fileSystem();

            return(fileSystem.FileExists(file) ? fileSystem.GetFileSize(file) : 0);
        }