示例#1
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();
            }
        }
示例#2
0
        /// <summary>
        /// Store failure in failure file for index with the given id
        /// </summary>
        /// <param name="failure"> message describing the failure that needs to be stored </param>
        /// <exception cref="IOException"> if the failure could not be stored </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void storeIndexFailure(String failure) throws java.io.IOException
        public virtual void StoreIndexFailure(string failure)
        {
            lock (this)
            {
                File failureFile = failureFile();
                using (StoreChannel channel = _fs.open(failureFile, OpenMode.READ_WRITE))
                {
                    sbyte[] existingData = new sbyte[( int )channel.size()];
                    channel.ReadAll(ByteBuffer.wrap(existingData));
                    channel.Position(LengthOf(existingData));

                    sbyte[] data = UTF8.encode(failure);
                    channel.WriteAll(ByteBuffer.wrap(data, 0, Math.Min(data.Length, MAX_FAILURE_SIZE)));

                    channel.Force(true);
                    channel.close();
                }
            }
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public StoreChannel position(long newPosition) throws java.io.IOException
        public override StoreChannel Position(long newPosition)
        {
            return(@delegate.Position(Offset(newPosition)));
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotPickCorruptStoreFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotPickCorruptStoreFile()
        {
            // given
            Store            store    = CreateTestStore();
            RotationStrategy rotation = store.RotationStrategy;

            // when
            File[] files = new File[10];
            {
                Pair <File, KeyValueStoreFile> file = rotation.Create(EMPTY_DATA_PROVIDER, 1);
                files[0] = file.First();
                for (int txId = 2, i = 1; i < Files.Length; txId <<= 1, i++)
                {
                    KeyValueStoreFile old = file.Other();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int data = txId;
                    int data = txId;
                    file = rotation.Next(file.First(), Headers.HeadersBuilder().put(TX_ID, (long)txId).headers(), data((Entry)(key, value) =>
                    {
                        key.putByte(0, ( sbyte )'f');
                        key.putByte(1, ( sbyte )'o');
                        key.putByte(2, ( sbyte )'o');
                        value.putInt(0, data);
                    }));
                    old.Dispose();
                    files[i] = file.First();
                }
                file.Other().Dispose();
            }
            // Corrupt the last files
            using (StoreChannel channel = _resourceManager.fileSystem().open(files[9], OpenMode.READ_WRITE))
            {               // ruin the header
                channel.Position(16);
                ByteBuffer value = ByteBuffer.allocate(16);
                value.put(( sbyte )0);
                value.flip();
                channel.WriteAll(value);
            }
            using (StoreChannel channel = _resourceManager.fileSystem().open(files[8], OpenMode.READ_WRITE))
            {               // ruin the header
                channel.Position(32);
                ByteBuffer value = ByteBuffer.allocate(16);
                value.put(( sbyte )17);
                value.flip();
                channel.WriteAll(value);
            }
            using (StoreChannel channel = _resourceManager.fileSystem().open(files[7], OpenMode.READ_WRITE))
            {               // ruin the header
                channel.Position(32 + 32 + 32 + 16);
                ByteBuffer value = ByteBuffer.allocate(16);
                value.putLong(0);
                value.putLong(0);
                value.flip();
                channel.WriteAll(value);
            }

            // then
            using (Lifespan life = new Lifespan())
            {
                life.Add(store);

                assertEquals(64L, store.Headers().get(TX_ID).longValue());
            }
        }