//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); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private byte[] writeRandomBytes(org.neo4j.io.fs.StoreChannel writer, int size) throws java.io.IOException private sbyte[] WriteRandomBytes(StoreChannel writer, int size) { sbyte[] bytes = new sbyte[size]; _random.NextBytes(bytes); writer.WriteAll(ByteBuffer.wrap(bytes)); return(bytes); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void streamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void StreamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting() { File a = ExistingFile("a"); File b = ExistingFile("b"); GenerateFileWithRecords(a, _recordCount); GenerateFileWithRecords(b, _recordCount + _recordsPerFilePage); // Fill 'b' with random data using (StoreChannel channel = Fsa.open(b, OpenMode.ReadWrite)) { ThreadLocalRandom rng = ThreadLocalRandom.current(); int fileSize = ( int )channel.size(); ByteBuffer buffer = ByteBuffer.allocate(fileSize); for (int i = 0; i < fileSize; i++) { buffer.put(i, ( sbyte )rng.Next()); } buffer.rewind(); channel.WriteAll(buffer); } // Do the rename FileHandle handle = Fsa.streamFilesRecursive(a).findAny().get(); handle.Rename(b, REPLACE_EXISTING); // Then verify that the old random data we put in 'b' has been replaced with the contents of 'a' VerifyRecordsInFile(b, _recordCount); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void write(org.neo4j.io.fs.StoreChannel channel, long time, long identifier, long version, long lastCommittedTxId, long indexVersion) throws java.io.IOException private void Write(StoreChannel channel, long time, long identifier, long version, long lastCommittedTxId, long indexVersion) { _buf.clear(); _buf.putLong(time).putLong(identifier).putLong(version).putLong(lastCommittedTxId).putLong(indexVersion); _buf.flip(); channel.WriteAll(_buf, 0); channel.Force(true); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void createFileOfSize(java.io.File file, int size) throws java.io.IOException private void CreateFileOfSize(File file, int size) { using (StoreChannel storeChannel = _fs.create(file)) { sbyte[] bytes = new sbyte[size]; ByteBuffer buffer = ByteBuffer.wrap(bytes); storeChannel.WriteAll(buffer); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writeIntegerIntoFile(java.io.File targetFile) throws java.io.IOException private void WriteIntegerIntoFile(File targetFile) { StoreChannel storeChannel = Fsa.create(targetFile); ByteBuffer byteBuffer = ByteBuffer.allocate((sizeof(int) * 8)).putInt(7); byteBuffer.flip(); storeChannel.WriteAll(byteBuffer); storeChannel.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private byte[] fileWithContent() throws java.io.IOException private sbyte[] FileWithContent() { int size = 1000; fs.mkdirs(IndexFile.ParentFile); using (StoreChannel storeChannel = fs.create(IndexFile)) { sbyte[] someBytes = new sbyte[size]; random.NextBytes(someBytes); storeChannel.WriteAll(ByteBuffer.wrap(someBytes)); return(someBytes); } }
/// <summary> /// Create/reserve an empty failure file for the given indexId. /// /// This will overwrite any pre-existing failure file. /// </summary> /// <exception cref="IOException"> if the failure file could not be created </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void reserveForIndex() throws java.io.IOException public virtual void ReserveForIndex() { lock (this) { _fs.mkdirs(_folderLayout.IndexFolder); File failureFile = failureFile(); using (StoreChannel channel = _fs.create(failureFile)) { channel.WriteAll(ByteBuffer.wrap(new sbyte[MAX_FAILURE_SIZE])); channel.Force(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void mustZeroFillPageBeyondEndOfFile(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void MustZeroFillPageBeyondEndOfFile(int noChannelStriping) { sbyte[] bytes = new sbyte[] { 1, 2, 3, 4, 5, 6 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(bytes)); channel.close(); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); long target = CreatePage(4); swapper.Read(1, target, SizeOfAsInt(target)); assertThat(Array(target), byteArray(new sbyte[] { 5, 6, 0, 0 })); }
/// <summary> /// External synchronization between this method and close is required so that they aren't called concurrently. /// Currently that's done by acquiring the PhysicalLogFile monitor. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public java.io.Flushable prepareForFlush() throws java.io.IOException public override Flushable PrepareForFlush() { Buffer.flip(); StoreChannel channel = this.ChannelConflict; try { channel.WriteAll(Buffer); } catch (ClosedChannelException e) { HandleClosedChannelException(e); } Buffer.clear(); return(channel); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void swappingInMustFillPageWithData(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void SwappingInMustFillPageWithData(int noChannelStriping) { sbyte[] bytes = new sbyte[] { 1, 2, 3, 4 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(bytes)); channel.close(); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); long target = CreatePage(4); swapper.Read(0, target, SizeOfAsInt(target)); assertThat(Array(target), byteArray(bytes)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int swapOut(long bufferAddress, long fileOffset, org.neo4j.io.fs.StoreChannel channel) throws java.io.IOException private int SwapOut(long bufferAddress, long fileOffset, StoreChannel channel) { try { ByteBuffer bufferProxy = Proxy(bufferAddress, _filePageSize); channel.WriteAll(bufferProxy, fileOffset); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } return(_filePageSize); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void allowStoreThatExceedDefaultSize() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void AllowStoreThatExceedDefaultSize() { File aFile = new File("test"); StoreChannel channel = _fs.open(aFile, OpenMode.READ_WRITE); ByteBuffer buffer = allocate(Long.BYTES); int mebiBytes = ( int )ByteUnit.mebiBytes(1); for (int position = mebiBytes + 42; position < 10_000_000; position += mebiBytes) { buffer.putLong(1); buffer.flip(); channel.WriteAll(buffer, position); buffer.clear(); } channel.close(); }
/// <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(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void writeLastEntriesWithPadding(org.neo4j.io.fs.StoreChannel channel, ByteBuffer byteBuffer, long padding) throws java.io.IOException private static void WriteLastEntriesWithPadding(StoreChannel channel, ByteBuffer byteBuffer, long padding) { bool didWrite; do { int toPadThisTime = ( int )Math.Min(byteBuffer.remaining(), padding); sbyte[] padArray = new sbyte[toPadThisTime]; byteBuffer.put(padArray); padding -= toPadThisTime; didWrite = byteBuffer.position() > 0; if (didWrite) { byteBuffer.flip(); channel.WriteAll(byteBuffer); byteBuffer.clear(); } } while (didWrite); }
/// <summary> /// Creates a new channel for the specified version, creating the backing file if it doesn't already exist. /// If the file exists then the header is verified to be of correct version. Having an existing file there /// could happen after a previous crash in the middle of rotation, where the new file was created, /// but the incremented log version changed hadn't made it to persistent storage. /// </summary> /// <param name="forVersion"> log version for the file/channel to create. </param> /// <param name="mode"> mode in which open log file </param> /// <param name="lastTransactionIdSupplier"> supplier of last transaction id that was written into previous log file </param> /// <returns> <seealso cref="PhysicalLogVersionedStoreChannel"/> for newly created/opened log file. </returns> /// <exception cref="IOException"> if there's any I/O related error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel createLogChannelForVersion(long forVersion, org.neo4j.io.fs.OpenMode mode, System.Func<long> lastTransactionIdSupplier) throws java.io.IOException internal virtual PhysicalLogVersionedStoreChannel CreateLogChannelForVersion(long forVersion, OpenMode mode, System.Func <long> lastTransactionIdSupplier) { File toOpen = GetLogFileForVersion(forVersion); StoreChannel storeChannel = _fileSystem.open(toOpen, mode); ByteBuffer headerBuffer = ByteBuffer.allocate(LOG_HEADER_SIZE); LogHeader header = readLogHeader(headerBuffer, storeChannel, false, toOpen); if (header == null) { // Either the header is not there in full or the file was new. Don't care long lastTxId = lastTransactionIdSupplier(); writeLogHeader(headerBuffer, forVersion, lastTxId); _logHeaderCache.putHeader(forVersion, lastTxId); storeChannel.WriteAll(headerBuffer); _monitor.created(toOpen, forVersion, lastTxId); } sbyte formatVersion = header == null ? CURRENT_LOG_VERSION : header.LogFormatVersion; return(new PhysicalLogVersionedStoreChannel(storeChannel, forVersion, formatVersion)); }
private void Write(File file) { StoreChannel channel = null; try { channel = _fileSystem.open(file, OpenMode.READ_WRITE); channel.WriteAll(ByteBuffer.wrap(_magic)); IoPrimitiveUtils.writeInt(channel, Buffer(4), VERSION); WriteMap(channel, _nodeConfig); WriteMap(channel, _relConfig); channel.Force(false); } catch (IOException e) { throw new Exception(e); } finally { Close(channel); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static <KEY, VALUE> long writeEntries(org.neo4j.io.fs.StoreChannel targetChannel, ByteBuffer byteBuffer, org.neo4j.index.internal.gbptree.Layout<KEY,VALUE> layout, BlockEntryCursor<KEY,VALUE> blockEntryCursor, Cancellation cancellation, System.Action<int> entryCountReporter) throws java.io.IOException private static long WriteEntries <KEY, VALUE>(StoreChannel targetChannel, ByteBuffer byteBuffer, Layout <KEY, VALUE> layout, BlockEntryCursor <KEY, VALUE> blockEntryCursor, Cancellation cancellation, System.Action <int> entryCountReporter) { // Loop over block entries long actualDataSize = BlockHeaderSize; ByteArrayPageCursor pageCursor = new ByteArrayPageCursor(byteBuffer); int entryCountToReport = 0; while (blockEntryCursor.Next()) { KEY key = blockEntryCursor.Key(); VALUE value = blockEntryCursor.Value(); int entrySize = BlockEntry.EntrySize(layout, key, value); actualDataSize += entrySize; entryCountToReport++; if (byteBuffer.remaining() < entrySize) { // First check if this merge have been cancelled, if so just break here, it's fine. if (cancellation.Cancelled()) { break; } // flush and reset + DON'T PAD!!! byteBuffer.flip(); targetChannel.WriteAll(byteBuffer); byteBuffer.clear(); entryCountReporter(entryCountToReport); entryCountToReport = 0; } BlockEntry.Write(pageCursor, layout, key, value); } if (entryCountToReport > 0) { entryCountReporter(entryCountToReport); } return(actualDataSize); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void swappingOutMustNotOverwriteDataBeyondPage(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void SwappingOutMustNotOverwriteDataBeyondPage(int noChannelStriping) { sbyte[] initialData = new sbyte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; sbyte[] finalData = new sbyte[] { 1, 2, 3, 4, 8, 7, 6, 5, 9, 10 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(initialData)); channel.close(); sbyte[] change = new sbyte[] { 8, 7, 6, 5 }; long page = CreatePage(change); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); swapper.Write(1, page); Stream stream = Fs.openAsInputStream(File); sbyte[] actual = new sbyte[( int )Fs.getFileSize(File)]; assertThat(stream.Read(actual, 0, actual.Length), @is(actual.Length)); assertThat(actual, byteArray(finalData)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writeAll(ByteBuffer src, long position) throws java.io.IOException public override void WriteAll(ByteBuffer src, long position) { @delegate.WriteAll(src, Offset(position)); }
//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()); } }