//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private <R extends org.neo4j.kernel.impl.store.record.AbstractBaseRecord> void verifyWriteAndRead(System.Func<RecordFormat<R>> formatSupplier, System.Func<org.neo4j.kernel.impl.store.format.RecordGenerators_Generator<R>> generatorSupplier, System.Func<RecordKey<R>> keySupplier, boolean assertPostReadOffset) throws java.io.IOException private void VerifyWriteAndRead <R>(System.Func <RecordFormat <R> > formatSupplier, System.Func <RecordGenerators_Generator <R> > generatorSupplier, System.Func <RecordKey <R> > keySupplier, bool assertPostReadOffset) where R : Org.Neo4j.Kernel.impl.store.record.AbstractBaseRecord { // GIVEN using (PagedFile storeFile = _pageCache.map(new File("store-" + Name.MethodName), _pageSize, CREATE)) { RecordFormat <R> format = formatSupplier(); RecordKey <R> key = keySupplier(); RecordGenerators_Generator <R> generator = generatorSupplier(); int recordSize = format.GetRecordSize(new IntStoreHeader(DATA_SIZE)); BatchingIdSequence idSequence = new BatchingIdSequence(_random.nextBoolean() ? IdSureToBeOnTheNextPage(_pageSize, recordSize) : 10); // WHEN long time = currentTimeMillis(); long endTime = time + TEST_TIME; long i = 0; for ( ; i < TEST_ITERATIONS && currentTimeMillis() < endTime; i++) { R written = generator.Get(recordSize, format, i % 5); R read = format.NewRecord(); try { WriteRecord(written, format, storeFile, recordSize, idSequence); ReadAndVerifyRecord(written, read, format, key, storeFile, recordSize, assertPostReadOffset); idSequence.Reset(); } catch (Exception t) { Exceptions.setMessage(t, t.Message + " : written:" + written + ", read:" + read + ", seed:" + _random.seed() + ", iteration:" + i); throw t; } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean next() throws java.io.IOException public override bool Next() { UnpinCurrentPage(); long lastPageId = AssertPagedFileStillMappedAndGetIdOfLastPage(); if (NextPageId < 0) { return(false); } if (NextPageId > lastPageId) { if (NoGrow) { return(false); } else { PagedFile.increaseLastPageIdTo(NextPageId); } } CurrentPageIdConflict = NextPageId; NextPageId++; Pin(CurrentPageIdConflict, true); return(true); }
public override void Swap(long fromIndex, long toIndex) { long fromPageId = PageId(fromIndex); int fromOffset = Offset(fromIndex); long toPageId = PageId(toIndex); int toOffset = Offset(toIndex); try { using (PageCursor fromCursor = PagedFile.io(fromPageId, PF_SHARED_WRITE_LOCK), PageCursor toCursor = PagedFile.io(toPageId, PF_SHARED_WRITE_LOCK)) { fromCursor.Next(); toCursor.Next(); for (int i = 0; i < EntrySize; i++, fromOffset++, toOffset++) { sbyte intermediary = fromCursor.GetByte(fromOffset); fromCursor.PutByte(fromOffset, toCursor.GetByte(toOffset)); toCursor.PutByte(toOffset, intermediary); } } } catch (IOException e) { throw new UncheckedIOException(e); } }
public override void Get(long index, sbyte[] into) { long pageId = pageId(index); int offset = offset(index); try { using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK)) { cursor.Next(); do { for (int i = 0; i < into.Length; i++) { into[i] = cursor.GetByte(offset + i); } } while (cursor.ShouldRetry()); CheckBounds(cursor); } } catch (IOException e) { throw new UncheckedIOException(e); } }
public override int Get3ByteInt(long index, int offset) { long pageId = pageId(index); offset += offset(index); try { using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK)) { cursor.Next(); int result; do { int lowWord = cursor.GetShort(offset) & 0xFFFF; int highByte = cursor.GetByte(offset + Short.BYTES) & 0xFF; result = lowWord | (highByte << (sizeof(short) * 8)); } while (cursor.ShouldRetry()); CheckBounds(cursor); return(result == 0xFFFFFF ? -1 : result); } } catch (IOException e) { throw new UncheckedIOException(e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: PageCacheByteArray(org.neo4j.io.pagecache.PagedFile pagedFile, long length, byte[] defaultValue, long super) throws java.io.IOException internal PageCacheByteArray(PagedFile pagedFile, long length, sbyte[] defaultValue, long @base) : base(pagedFile, defaultValue.Length, length, @base) { // Default value is handled locally in this class, in contrast to its siblings, which lets the superclass // handle it. this._defaultValue = defaultValue; DefaultValue = -1; }
public override long Get6ByteLong(long index, int offset) { long pageId = pageId(index); offset += offset(index); try { using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK)) { cursor.Next(); long result; do { long low4b = cursor.GetInt(offset) & 0xFFFFFFFFL; long high2b = cursor.GetShort(offset + Integer.BYTES) & 0xFFFF; result = low4b | (high2b << (sizeof(int) * 8)); } while (cursor.ShouldRetry()); CheckBounds(cursor); return(result == 0xFFFFFFFFFFFFL ? -1 : result); } } catch (IOException e) { throw new UncheckedIOException(e); } }
/* * This test acts as a test group for whoever uses BaseHighLimitRecordFormat base class, * the logic for marking both units as unused when deleting exists there. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMarkBothUnitsAsUnusedWhenDeletingRecordWhichHasSecondaryUnit() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldMarkBothUnitsAsUnusedWhenDeletingRecordWhichHasSecondaryUnit() { // GIVEN a record which requires two units PagedFile storeFile = mock(typeof(PagedFile)); when(storeFile.PageSize()).thenReturn(cursor.CurrentPageSize); long hugeValue = 1L << 48; RelationshipRecord record = (new RelationshipRecord(5)).initialize(true, hugeValue + 1, hugeValue + 2, hugeValue + 3, 4, hugeValue + 5, hugeValue + 6, hugeValue + 7, hugeValue + 8, true, true); record.SecondaryUnitId = 17; record.RequiresSecondaryUnit = true; cursor.Offset = offsetForId(record.Id, cursor.CurrentPageSize, _recordSize); _format.write(record, cursor, _recordSize); // WHEN deleting that record record.InUse = false; cursor.Offset = offsetForId(record.Id, cursor.CurrentPageSize, _recordSize); _format.write(record, cursor, _recordSize); // THEN both units should have been marked as unused cursor.Offset = offsetForId(record.Id, cursor.CurrentPageSize, _recordSize); assertFalse(RecordInUse(cursor)); cursor.Offset = offsetForId(record.SecondaryUnitId, cursor.CurrentPageSize, _recordSize); assertFalse(RecordInUse(cursor)); }
private static FreeListIdProvider GetFreelist(PagedFile pagedFile, TreeState treeState) { FreeListIdProvider freelist = new FreeListIdProvider(pagedFile, pagedFile.PageSize(), treeState.LastId(), FreeListIdProvider.NO_MONITOR); freelist.Initialize(treeState.LastId(), treeState.FreeListWritePageId(), treeState.FreeListReadPageId(), treeState.FreeListWritePos(), freelist.ReadPos()); return(freelist); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void perform() throws Exception public override void Perform() { PagedFile pagedFile = outerInstance.fileMap[File]; if (pagedFile != null) { // We use tryLock to avoid any deadlock scenarios. if (outerInstance.recordLocks.TryLock(RecordId)) { try { using (PageCursor cursor = pagedFile.Io(PageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock)) { if (cursor.Next()) { cursor.Offset = PageOffset; outerInstance.recordFormat.Write(Record, cursor); PerformInnerAction(); } } } finally { outerInstance.recordLocks.Unlock(RecordId); } } } else { PerformInnerAction(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long profile(org.neo4j.io.pagecache.PagedFile file, Profile[] existingProfiles) throws java.io.IOException private long Profile(PagedFile file, Profile[] existingProfiles) { long pagesInMemory = 0; //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: Profile nextProfile = FilterRelevant(existingProfiles, file).max(naturalOrder()).map(Profile::next).orElse(Profile.First(file.File())); using (Stream output = nextProfile.Write(_fs), PageCursor cursor = file.Io(0, PF_SHARED_READ_LOCK | PF_NO_FAULT)) { int stepper = 0; int b = 0; while (cursor.Next()) { if (cursor.CurrentPageId != PageCursor.UNBOUND_PAGE_ID) { pagesInMemory++; b |= 1 << stepper; } stepper++; if (stepper == 8) { output.WriteByte(b); b = 0; stepper = 0; } } output.WriteByte(b); output.Flush(); } // Delete previous profile files. FilterRelevant(existingProfiles, file).filter(profile => !_refCounts.contains(profile)).forEach(profile => profile.delete(_fs)); return(pagesInMemory); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private org.neo4j.io.pagecache.randomharness.Phase filesAreCorrectlyWrittenVerification(final org.neo4j.io.pagecache.randomharness.RecordFormat recordFormat, final int filePageCount) private Phase FilesAreCorrectlyWrittenVerification(RecordFormat recordFormat, int filePageCount) { return((cache, fs1, filesTouched) => { foreach (File file in filesTouched) { using (PagedFile pf = cache.map(file, cache.pageSize()), PageCursor cursor = pf.Io(0, PF_SHARED_READ_LOCK)) { for (int pageId = 0; pageId < filePageCount && cursor.Next(); pageId++) { try { recordFormat.AssertRecordsWrittenCorrectly(cursor); } catch (Exception th) { th.addSuppressed(new Exception("pageId = " + pageId)); throw th; } } } using (StoreChannel channel = fs1.open(file, OpenMode.READ)) { recordFormat.AssertRecordsWrittenCorrectly(file, channel); } } }); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyUpdateResults(int filePages, PagedFile pagedFile, java.util.List<java.util.concurrent.Future<UpdateResult>> futures) throws InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException private void VerifyUpdateResults(int filePages, PagedFile pagedFile, IList <Future <UpdateResult> > futures) { UpdateResult[] results = new UpdateResult[futures.Count]; for (int i = 0; i < results.Length; i++) { results[i] = futures[i].get(); } foreach (UpdateResult result in results) { using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK)) { for (int i = 0; i < filePages; i++) { assertTrue(cursor.Next()); int threadId = result.ThreadId; int expectedCount = result.PageCounts[i]; int actualCount; do { cursor.Offset = threadId * 4; actualCount = cursor.Int; } while (cursor.ShouldRetry()); assertThat("wrong count for threadId:" + threadId + ", aka. real threadId:" + result.RealThreadId + ", filePageId:" + i, actualCount, @is(expectedCount)); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void concurrentPageFaultingMustNotPutInterleavedDataIntoPages() internal virtual void ConcurrentPageFaultingMustNotPutInterleavedDataIntoPages() { assertTimeout(ofMillis(LONG_TIMEOUT_MILLIS), () => { const int filePageCount = 11; RecordFormat recordFormat = new PageCountRecordFormat(); using (RandomPageCacheTestHarness harness = new RandomPageCacheTestHarness()) { harness.ConcurrencyLevel = 11; harness.UseAdversarialIO = false; harness.CachePageCount = 3; harness.FilePageCount = filePageCount; harness.InitialMappedFiles = 1; harness.CommandCount = 10000; harness.RecordFormat = recordFormat; harness.FileSystem = fs; harness.useProfiler(Profiler); harness.disableCommands(FlushCache, FlushFile, MapFile, UnmapFile, WriteRecord, WriteMulti); harness.Preparation = (cache, fs, filesTouched) => { File file = filesTouched.GetEnumerator().next(); using (PagedFile pf = cache.map(file, cache.pageSize()), PageCursor cursor = pf.Io(0, PF_SHARED_WRITE_LOCK)) { for (int pageId = 0; pageId < filePageCount; pageId++) { cursor.Next(); recordFormat.fillWithRecords(cursor); } } }; harness.run(LONG_TIMEOUT_MILLIS, MILLISECONDS); } }); }
internal ParallelPageLoader(PagedFile file, Executor executor, PageCache pageCache) { this._file = file; this._executor = executor; this._pageCache = pageCache; _received = new AtomicLong(); _processed = new AtomicLong(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void write(org.neo4j.io.pagecache.PagedFile pagedFile, org.neo4j.io.pagecache.PageCursor cursor, TreeNode<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> node, Layout<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> layout, TreeState checkpointedTreeState, TreeState unstableTreeState) throws java.io.IOException internal virtual void Write(PagedFile pagedFile, PageCursor cursor, TreeNode <MutableLong, MutableLong> node, Layout <MutableLong, MutableLong> layout, TreeState checkpointedTreeState, TreeState unstableTreeState) { Type.write(cursor, node, layout, checkpointedTreeState); foreach (GBPTreeCorruption.PageCorruption <MutableLong, MutableLong> pc in PageCorruptions) { pc.Corrupt(cursor, layout, node, unstableTreeState); } }
internal UpdateWorker(int threadId, int filePages, AtomicBoolean shouldStop, PagedFile pagedFile) { this.ThreadId = threadId; this.FilePages = filePages; this.ShouldStop = shouldStop; this.PagedFile = pagedFile; PageCounts = new int[filePages]; Offset = threadId * 4; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.io.pagecache.PageCache mockPageCache() throws java.io.IOException private PageCache MockPageCache() { PageCache pageCacheMock = mock(typeof(PageCache)); PagedFile pagedFileMock = mock(typeof(PagedFile)); when(pagedFileMock.LastPageId).thenReturn(1L); when(pageCacheMock.Map(any(typeof(File)), anyInt())).thenThrow(new IOException()).thenThrow(new IOException()).thenReturn(pagedFileMock); return(pageCacheMock); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void perform() throws Exception public override void perform() { PagedFile pagedFile = _outerInstance.fileMap[_file]; if (pagedFile != null) { pagedFile.FlushAndForce(); } }
public RecordStresser(PagedFile pagedFile, Condition condition, int maxRecords, RecordFormat format, int threadId, TinyLockManager locks) { this._pagedFile = pagedFile; this._condition = condition; this._maxRecords = maxRecords; this._format = format; this._threadId = threadId; this._locks = locks; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyAdversarialPagedContent(PagedFile pagedFile) throws java.io.IOException private void VerifyAdversarialPagedContent(PagedFile pagedFile) { using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK)) { while (cursor.Next()) { ReadAndVerifyAdversarialPage(cursor, pagedFile.PageSize()); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void close() throws java.io.IOException public virtual void Close() { foreach (File mappedFile in _mappedFiles) { PagedFile pagedFile = _fileMap[mappedFile]; if (pagedFile != null) { pagedFile.Close(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void initializeFile(org.neo4j.io.pagecache.PagedFile pagedFile, Page... pages) throws java.io.IOException private void InitializeFile(PagedFile pagedFile, params Page[] pages) { using (PageCursor cursor = pagedFile.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock)) { foreach (Page page in pages) { cursor.Next(); page.Write(pagedFile, cursor, _treeNode, _layout, _checkpointedTreeState, _unstableTreeState); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void ensureAllPagesExists(int filePages, PagedFile pagedFile) throws java.io.IOException private void EnsureAllPagesExists(int filePages, PagedFile pagedFile) { using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK)) { for (int i = 0; i < filePages; i++) { assertTrue(cursor.Next(), "failed to initialise file page " + i); } } pageCache.flushAndForce(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @BeforeEach void getPageCursor() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void getPageCursor() { PageCache mockedPageCache = mock(typeof(PageCache)); PagedFile mockedPagedFile = mock(typeof(PagedFile)); PageCursor mockedCursor = mock(typeof(PageCursor)); when(mockedPagedFile.Io(anyLong(), anyInt())).thenReturn(mockedCursor); when(mockedPageCache.Map(any(typeof(File)), anyInt(), any())).thenReturn(mockedPagedFile); _pageCache = new AccessCheckingPageCache(mockedPageCache); PagedFile file = _pageCache.map(new File("some file"), 512); _cursor = file.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK); }
private IList <RecordStresser> Prepare(Condition condition, PagedFile pagedFile, RecordFormat format) { int maxRecords = Math.multiplyExact(_maxPages, format.RecordsPerPage); TinyLockManager locks = new TinyLockManager(); IList <RecordStresser> recordStressers = new LinkedList <RecordStresser>(); for (int threadId = 0; threadId < _numberOfThreads; threadId++) { recordStressers.Add(new RecordStresser(pagedFile, condition, maxRecords, format, threadId, locks)); } return(recordStressers); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: protected Runnable closePageFile(final PagedFile file) protected internal virtual ThreadStart ClosePageFile(PagedFile file) { return(() => { try { file.Close(); } catch (IOException e) { throw new AssertionError(e); } }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void setUpgradeTransactionMustBeAtomic() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SetUpgradeTransactionMustBeAtomic() { using (MetaDataStore store = NewMetaDataStore()) { PagedFile pf = store.PagedFile; store.SetUpgradeTransaction(0, 0, 0); AtomicLong writeCount = new AtomicLong(); AtomicLong fileReadCount = new AtomicLong(); AtomicLong apiReadCount = new AtomicLong(); int upperLimit = 10_000; int lowerLimit = 100; long endTime = currentTimeMillis() + SECONDS.toMillis(10); Race race = new Race(); race.WithEndCondition(() => writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit); race.WithEndCondition(() => writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime); // writers race.AddContestants(3, () => { long count = writeCount.incrementAndGet(); store.SetUpgradeTransaction(count, count, count); }); // file readers race.AddContestants(3, throwing(() => { using (PageCursor cursor = pf.Io(0, PagedFile.PF_SHARED_READ_LOCK)) { assertTrue(cursor.next()); long id; long checksum; do { id = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionId); checksum = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionChecksum); } while (cursor.shouldRetry()); AssertIdEqualsChecksum(id, checksum, "file"); fileReadCount.incrementAndGet(); } })); race.AddContestants(3, () => { TransactionId transaction = store.UpgradeTransaction; AssertIdEqualsChecksum(transaction.TransactionIdConflict(), transaction.Checksum(), "API"); apiReadCount.incrementAndGet(); }); race.Go(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.io.pagecache.PagedFile map(java.io.File file, int pageSize, java.nio.file.OpenOption... openOptions) throws java.io.IOException public override PagedFile Map(File file, int pageSize, params OpenOption[] openOptions) { if (ArrayUtils.contains(openOptions, StandardOpenOption.CREATE)) { _adversary.injectFailure(typeof(IOException), typeof(SecurityException)); } else { _adversary.injectFailure(typeof(FileNotFoundException), typeof(IOException), typeof(SecurityException)); } PagedFile pagedFile = @delegate.Map(file, pageSize, openOptions); return(new AdversarialPagedFile(pagedFile, _adversary)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyResults(RecordFormat format, org.neo4j.io.pagecache.PagedFile pagedFile, java.util.List<RecordStresser> recordStressers) throws java.io.IOException private void VerifyResults(RecordFormat format, PagedFile pagedFile, IList <RecordStresser> recordStressers) { foreach (RecordStresser stresser in recordStressers) { stresser.VerifyCounts(); } using (PageCursor cursor = pagedFile.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK)) { while (cursor.Next()) { format.VerifyCheckSums(cursor); } } }