示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private int scrambleIndexFiles(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File fileOrDir) throws java.io.IOException
        private int ScrambleIndexFiles(FileSystemAbstraction fs, File fileOrDir)
        {
            if (fs.IsDirectory(fileOrDir))
            {
                int    count    = 0;
                File[] children = fs.ListFiles(fileOrDir);
                if (children != null)
                {
                    foreach (File child in children)
                    {
                        count += ScrambleIndexFiles(fs, child);
                    }
                }
                return(count);
            }
            else
            {
                // Completely scramble file, assuming small files
                using (StoreChannel channel = fs.Open(fileOrDir, OpenMode.READ_WRITE))
                {
                    if (channel.size() > mebiBytes(10))
                    {
                        throw new System.ArgumentException("Was expecting small files here");
                    }
                    sbyte[] bytes = new sbyte[( int )channel.size()];
                    _random.NextBytes(bytes);
                    channel.WriteAll(ByteBuffer.wrap(bytes));
                }
                return(1);
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustDisableStripingIfToldTo() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustDisableStripingIfToldTo()
        {
            // given
            int bytesPerPage = 32;
            PageSwapperFactory    factory = CreateSwapperFactory();
            FileSystemAbstraction fs      = mock(typeof(FileSystemAbstraction));
            StoreChannel          channel = mock(typeof(StoreChannel));

            when(channel.TryLock()).thenReturn(mock(typeof(FileLock)));
            when(fs.Create(any(typeof(File)))).thenReturn(channel);
            when(fs.Open(any(typeof(File)), any())).thenReturn(channel);

            // when
            factory.Open(fs, Configuration.EMPTY);
            PageSwapper swapper = CreateSwapper(factory, _file, bytesPerPage, NoCallback, true, true);

            try
            {
                // then
                verify(fs, times(1)).open(eq(_file), any(typeof(OpenMode)));
            }
            finally
            {
                swapper.Close();
            }
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public SingleFilePageSwapper(java.io.File file, org.neo4j.io.fs.FileSystemAbstraction fs, int filePageSize, org.neo4j.io.pagecache.PageEvictionCallback onEviction, boolean noChannelStriping) throws java.io.IOException
        public SingleFilePageSwapper(File file, FileSystemAbstraction fs, int filePageSize, PageEvictionCallback onEviction, bool noChannelStriping)
        {
            this._fs   = fs;
            this._file = file;
            if (noChannelStriping)
            {
                this._channelStripeCount = 1;
                this._channelStripeMask  = StripeMask(_channelStripeCount);
            }
            else
            {
                this._channelStripeCount = _globalChannelStripeCount;
                this._channelStripeMask  = _globalChannelStripeMask;
            }
            this._channels = new StoreChannel[_channelStripeCount];
            for (int i = 0; i < _channelStripeCount; i++)
            {
                _channels[i] = fs.Open(file, OpenMode.READ_WRITE);
            }
            this._filePageSize = filePageSize;
            this._onEviction   = onEviction;
            IncreaseFileSizeTo(_channels[TOKEN_CHANNEL_STRIPE].size());

            try
            {
                AcquireLock();
            }
            catch (IOException e)
            {
                CloseAndCollectExceptions(0, e);
            }
            _hasPositionLock = _channels[0].GetType() == typeof(StoreFileChannel) && StoreFileChannelUnwrapper.unwrap(_channels[0]).GetType() == typeof(FileChannelImpl);
        }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static SegmentHeader loadHeader(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
        private static SegmentHeader LoadHeader(FileSystemAbstraction fileSystem, File file)
        {
            using (StoreChannel channel = fileSystem.Open(file, OpenMode.READ))
            {
                return(_headerMarshal.unmarshal(new ReadAheadChannel <>(channel, SegmentHeader.Size)));
            }
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void writeHeader(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file, SegmentHeader header) throws java.io.IOException
        private static void WriteHeader(FileSystemAbstraction fileSystem, File file, SegmentHeader header)
        {
            using (StoreChannel channel = fileSystem.Open(file, OpenMode.READ_WRITE))
            {
                channel.Position(0);
                PhysicalFlushableChannel writer = new PhysicalFlushableChannel(channel, SegmentHeader.Size);
                _headerMarshal.marshal(header, writer);
                writer.PrepareForFlush().flush();
            }
        }
示例#6
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?
                    }
                }
            }
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static long dumpFile(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File file, Dumper dumper, TxFilter txFilter, long session) throws java.io.IOException
        private static long DumpFile(FileSystemAbstraction fs, File file, Dumper dumper, TxFilter txFilter, long session)
        {
            try
            {
                using (ReadableChannel channel = new ReadAheadChannel <>(fs.Open(file, OpenMode.READ)))
                {
                    long range   = -1;
                    int  labelId = -1;
                    long flush   = 0;
                    while (true)
                    {
                        sbyte type = channel.Get();
                        switch (type)
                        {
                        case TYPE_RANGE:
                            range   = channel.Long;
                            labelId = channel.Int;
                            if (txFilter != null)
                            {
                                txFilter.Clear();
                            }
                            break;

                        case TYPE_PREPARE_ADD:
                        case TYPE_PREPARE_REMOVE:
                            DumpPrepare(dumper, type, channel, range, labelId, txFilter, session, flush);
                            break;

                        case TYPE_MERGE_ADD:
                        case TYPE_MERGE_REMOVE:
                            DumpMerge(dumper, type, channel, range, labelId, txFilter, session, flush);
                            break;

                        case TYPE_FLUSH:
                            flush++;
                            break;

                        case TYPE_SESSION_END:
                            session++;
                            flush = 0;
                            break;

                        default:
                            Console.WriteLine("Unknown type " + type + " at " + (( ReadAheadChannel )channel).position());
                            break;
                        }
                    }
                }
            }
            catch (ReadPastEndException)
            {
                // This is OK. we're done with this file
            }
            return(session);
        }
示例#8
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);
            }
        }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.util.List<org.neo4j.kernel.impl.transaction.log.entry.LogEntry> logEntries(org.neo4j.io.fs.FileSystemAbstraction fileSystem, String logPath) throws java.io.IOException
        public static IList <LogEntry> LogEntries(FileSystemAbstraction fileSystem, string logPath)
        {
            File         logFile     = new File(logPath);
            StoreChannel fileChannel = fileSystem.Open(logFile, OpenMode.READ);

            // Always a header
            LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), fileChannel, true, logFile);

            // Read all log entries
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileChannel, header.LogVersion, header.LogFormatVersion);
            ReadableLogChannel logChannel     = new ReadAheadLogChannel(versionedStoreChannel);
            LogEntryCursor     logEntryCursor = new LogEntryCursor(new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), logChannel);

            return(Iterables.asList(new IOCursorAsResourceIterable <>(logEntryCursor)));
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void readStore(org.neo4j.io.fs.FileSystemAbstraction fileSystem, org.neo4j.kernel.impl.store.RecordStore store, long fromId, long toId, java.util.regex.Pattern pattern) throws java.io.IOException
        private static void ReadStore(FileSystemAbstraction fileSystem, RecordStore store, long fromId, long toId, Pattern pattern)
        {
            toId = Math.Min(toId, store.HighId);
            using (StoreChannel channel = fileSystem.Open(store.StorageFile, OpenMode.READ))
            {
                int        recordSize = store.RecordSize;
                ByteBuffer buf        = ByteBuffer.allocate(recordSize);
                for (long i = fromId; i <= toId; i++)
                {
                    buf.clear();
                    long offset = recordSize * i;
                    int  count  = channel.Read(buf, offset);
                    if (count == -1)
                    {
                        break;
                    }
                    sbyte[] bytes = new sbyte[count];
                    buf.clear();
                    buf.get(bytes);
                    string hex           = HexString.encodeHexString(bytes);
                    int    paddingNeeded = (recordSize * 2 - Math.Max(count * 2, 0)) + 1;
                    string format        = "%s %6s 0x%08X %s%" + paddingNeeded + "s%s%n";
                    string str;
                    string use;

                    try
                    {
                        AbstractBaseRecord record = RecordStore.getRecord(store, i, CHECK);
                        use = record.InUse() ? "+" : "-";
                        str = record.ToString();
                    }
                    catch (InvalidRecordException)
                    {
                        str = StringHelper.NewString(bytes, 0, count, "ASCII");
                        use = "?";
                    }

                    if (pattern == null || pattern.matcher(str).find())
                    {
                        _console.printf(format, use, i, offset, hex, " ", str);
                    }
                }
            }
        }
示例#11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createFile(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File file) throws java.io.IOException
        private void CreateFile(FileSystemAbstraction fs, File file)
        {
            fs.Mkdirs(file.ParentFile);
            fs.Open(file, OpenMode.READ_WRITE).close();
        }
示例#12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static StreamToDisk fromFile(org.neo4j.io.fs.FileSystemAbstraction fsa, java.io.File file) throws java.io.IOException
        internal static StreamToDisk FromFile(FileSystemAbstraction fsa, File file)
        {
            return(new StreamToDisk(fsa.Open(file, OpenMode.READ_WRITE)));
        }