Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ThreadLocalBlockStorage(int id) throws java.io.IOException
            internal ThreadLocalBlockStorage(BlockBasedIndexPopulator <KEY, VALUE> outerInstance, int id) : base(outerInstance.blockStorageMonitor)
            {
                this._outerInstance = outerInstance;
                File blockFile = new File(storeFile.ParentFile, storeFile.Name + ".scan-" + id);

                this.BlockStorage = new BlockStorage <KEY, VALUE>(layout, outerInstance.bufferFactory, fileSystem, blockFile, this);
            }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void mergeScanUpdates() throws InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
        private void MergeScanUpdates()
        {
            ExecutorService executorService = Executors.newFixedThreadPool(_allScanUpdates.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<java.util.concurrent.Future<?>> mergeFutures = new java.util.ArrayList<>();
            IList <Future <object> > mergeFutures = new List <Future <object> >();

            foreach (ThreadLocalBlockStorage part in _allScanUpdates)
            {
                BlockStorage <KEY, VALUE> scanUpdates = part.BlockStorage;
                // Call doneAdding here so that the buffer it allocates if it needs to flush something will be shared with other indexes
                scanUpdates.DoneAdding();
                mergeFutures.Add(executorService.submit(() =>
                {
                    scanUpdates.Merge(_mergeFactor, _cancellation);
                    return(null);
                }));
            }
            executorService.shutdown();
            while (!executorService.awaitTermination(1, TimeUnit.SECONDS))
            {
                // just wait longer
            }
            // Let potential exceptions in the merge threads have a chance to propagate
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> mergeFuture : mergeFutures)
            foreach (Future <object> mergeFuture in mergeFutures)
            {
                mergeFuture.get();
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNoticeCancelRequest() throws java.io.IOException, java.util.concurrent.ExecutionException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNoticeCancelRequest()
        {
            // given
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
            TrackingMonitor monitor     = new TrackingMonitorAnonymousInnerClass(this, barrier);
            int             blocks      = 10;
            int             mergeFactor = 2;
            MutableLongSet  uniqueKeys  = new LongHashSet();
            AtomicBoolean   cancelled   = new AtomicBoolean();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, monitor), OtherThreadExecutor <Void> t2 = new OtherThreadExecutor <Void>("T2", null))
            {
                while (monitor.BlockFlushedCallCount < blocks)
                {
                    storage.Add(UniqueKey(uniqueKeys), new MutableLong());
                }
                storage.DoneAdding();

                // when starting to merge
                Future <object> merge = t2.ExecuteDontWait(command(() => storage.merge(mergeFactor, cancelled.get)));
                barrier.AwaitUninterruptibly();
                // one merge iteration have now been done, set the cancellation flag
                cancelled.set(true);
                barrier.Release();
                merge.get();
            }

            // then there should not be any more merge iterations done, i.e. merge was cancelled
            assertEquals(1, monitor.MergeIterationCallCount);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSortAndAddMultipleEntriesInLastBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSortAndAddMultipleEntriesInLastBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;
            IList <BlockEntry <MutableLong, MutableLong> > expected = new List <BlockEntry <MutableLong, MutableLong> >();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                for (int i = 0; i < 10; i++)
                {
                    long        keyNumber = Random.nextLong(10_000_000);
                    MutableLong key       = new MutableLong(keyNumber);
                    MutableLong value     = new MutableLong(i);
                    storage.Add(key, value);
                    expected.Add(new BlockEntry <>(key, value));
                }
                storage.DoneAdding();

                // then
                Sort(expected);
                AssertContents(_layout, storage, singletonList(expected));
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCreateAndCloseTheBlockFile() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldCreateAndCloseTheBlockFile()
        {
            // given
            assertFalse(_fileSystem.fileExists(_file));
            using (BlockStorage <MutableLong, MutableLong> ignored = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, NO_MONITOR))
            {
                // then
                assertTrue(_fileSystem.fileExists(_file));
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotAcceptAddedEntriesAfterDoneAdding() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotAcceptAddedEntriesAfterDoneAdding()
        {
            // given
            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, NO_MONITOR))
            {
                // when
                storage.DoneAdding();

                // then
                assertThrows(typeof(System.InvalidOperationException), () => storage.add(new MutableLong(0), new MutableLong(1)));
            }
        }
Ejemplo n.º 7
0
        public override void Add <T1>(ICollection <T1> updates) where T1 : Org.Neo4j.Kernel.Api.Index.IndexEntryUpdate <T1>
        {
            if (updates.Count > 0)
            {
                BlockStorage <KEY, VALUE> blockStorage = _scanUpdates.get().blockStorage;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (org.neo4j.kernel.api.index.IndexEntryUpdate<?> update : updates)
                foreach (IndexEntryUpdate <object> update in updates)
                {
                    StoreUpdate(update, blockStorage);
                }
            }
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCalculateCorrectNumberOfEntriesToWriteDuringMerge()
        internal virtual void ShouldCalculateCorrectNumberOfEntriesToWriteDuringMerge()
        {
            // when
            long entryCountForOneBlock                      = BlockStorage.CalculateNumberOfEntriesWrittenDuringMerges(100, 1, 2);
            long entryCountForMergeFactorBlocks             = BlockStorage.CalculateNumberOfEntriesWrittenDuringMerges(100, 4, 4);
            long entryCountForMoreThanMergeFactorBlocks     = BlockStorage.CalculateNumberOfEntriesWrittenDuringMerges(100, 5, 4);
            long entryCountForThreeFactorsMergeFactorBlocks = BlockStorage.CalculateNumberOfEntriesWrittenDuringMerges(100, 4 * 4 * 4 - 3, 4);

            // then
            assertEquals(0, entryCountForOneBlock);
            assertEquals(100, entryCountForMergeFactorBlocks);
            assertEquals(200, entryCountForMoreThanMergeFactorBlocks);
            assertEquals(300, entryCountForThreeFactorsMergeFactorBlocks);
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotFlushAnythingOnEmptyBufferInDoneAdding() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotFlushAnythingOnEmptyBufferInDoneAdding()
        {
            // given
            TrackingMonitor monitor = new TrackingMonitor();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, monitor))
            {
                // when
                storage.DoneAdding();

                // then
                assertEquals(0, monitor.BlockFlushedCallCount);
            }
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<BlockEntry<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>> addEntries(BlockStorage<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> storage, int numberOfEntries) throws java.io.IOException
        private IList <BlockEntry <MutableLong, MutableLong> > AddEntries(BlockStorage <MutableLong, MutableLong> storage, int numberOfEntries)
        {
            MutableLongSet uniqueKeys = LongSets.mutable.empty();
            IList <BlockEntry <MutableLong, MutableLong> > entries = new List <BlockEntry <MutableLong, MutableLong> >();

            for (int i = 0; i < numberOfEntries; i++)
            {
                MutableLong key   = UniqueKey(uniqueKeys);
                MutableLong value = new MutableLong(Random.nextLong(10_000_000));
                storage.Add(key, value);
                entries.Add(new BlockEntry <>(key, value));
            }
            Sort(entries);
            return(entries);
        }
Ejemplo n.º 11
0
 private void StoreUpdate(long entityId, Value[] values, BlockStorage <KEY, VALUE> blockStorage)
 {
     try
     {
         KEY   key   = layout.newKey();
         VALUE value = layout.newValue();
         initializeKeyFromUpdate(key, entityId, values);
         value.From(values);
         blockStorage.Add(key, value);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSortAndAddMultipleEntriesInMultipleBlocks() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSortAndAddMultipleEntriesInMultipleBlocks()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = AddACoupleOfBlocksOfEntries(monitor, storage, 3);

                // then
                AssertContents(_layout, storage, expectedBlocks);
            }
        }
Ejemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeWhenEmpty() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeWhenEmpty()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                assertEquals(0, monitor.MergeIterationCallCount);
                AssertContents(_layout, storage, emptyList());
            }
        }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldOnlyLeaveSingleFileAfterMerge() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldOnlyLeaveSingleFileAfterMerge()
        {
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                int numberOfBlocks = Random.Next(100) + 2;
                AddACoupleOfBlocksOfEntries(monitor, storage, numberOfBlocks);
                storage.DoneAdding();

                // when
                storage.Merge(2, NOT_CANCELLABLE);

                // then
                File[] files = _fileSystem.listFiles(Directory.directory());
                assertEquals(1, Files.Length, "Expected only a single file to exist after merge.");
            }
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeSingleBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeSingleBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = singletonList(AddEntries(storage, 4));
                storage.DoneAdding();

                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                assertEquals(0, monitor.MergeIterationCallCount);
                AssertContents(_layout, storage, expectedBlocks);
            }
        }
Ejemplo n.º 16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertContents(org.neo4j.index.internal.gbptree.SimpleLongLayout layout, BlockStorage<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> storage, Iterable<java.util.List<BlockEntry<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>>> expectedBlocks) throws java.io.IOException
        private void AssertContents(SimpleLongLayout layout, BlockStorage <MutableLong, MutableLong> storage, IEnumerable <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks)
        {
            using (BlockReader <MutableLong, MutableLong> reader = storage.Reader())
            {
                foreach (IList <BlockEntry <MutableLong, MutableLong> > expectedBlock in expectedBlocks)
                {
                    using (BlockEntryReader <MutableLong, MutableLong> block = reader.NextBlock(HEAP_ALLOCATOR.allocate(1024)))
                    {
                        assertNotNull(block);
                        assertEquals(expectedBlock.Count, block.EntryCount());
                        foreach (BlockEntry <MutableLong, MutableLong> expectedEntry in expectedBlock)
                        {
                            assertTrue(block.Next());
                            assertEquals(0, layout.Compare(expectedEntry.Key(), block.Key()));
                            assertEquals(expectedEntry.Value(), block.Value());
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeMultipleBlocks() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeMultipleBlocks()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                int numberOfBlocks = Random.Next(100) + 2;
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = AddACoupleOfBlocksOfEntries(monitor, storage, numberOfBlocks);
                storage.DoneAdding();

                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                AssertContents(_layout, storage, AsOneBigBlock(expectedBlocks));
                assertThat(monitor.TotalEntriesToMerge, greaterThanOrEqualTo(monitor.EntryAddedCallCount));
                assertEquals(monitor.TotalEntriesToMerge, monitor.EntriesMergedConflict);
            }
        }
Ejemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddSingleEntryInLastBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldAddSingleEntryInLastBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 100;
            MutableLong     key       = new MutableLong(10);
            MutableLong     value     = new MutableLong(20);

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                storage.Add(key, value);
                storage.DoneAdding();

                // then
                assertEquals(1, monitor.BlockFlushedCallCount);
                assertEquals(1, monitor.LastKeyCount);
                assertEquals(BlockStorage.BlockHeaderSize + monitor.TotalEntrySize, monitor.LastNumberOfBytes);
                assertEquals(blockSize, monitor.LastPositionAfterFlush);
                assertThat(monitor.LastNumberOfBytes, lessThan(blockSize));
                AssertContents(_layout, storage, singletonList(singletonList(new BlockEntry <>(key, value))));
            }
        }
Ejemplo n.º 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<java.util.List<BlockEntry<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>>> addACoupleOfBlocksOfEntries(TrackingMonitor monitor, BlockStorage<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> storage, int numberOfBlocks) throws java.io.IOException
        private IList <IList <BlockEntry <MutableLong, MutableLong> > > AddACoupleOfBlocksOfEntries(TrackingMonitor monitor, BlockStorage <MutableLong, MutableLong> storage, int numberOfBlocks)
        {
            Debug.Assert(numberOfBlocks != 1);

            MutableLongSet uniqueKeys = LongSets.mutable.empty();
            IList <IList <BlockEntry <MutableLong, MutableLong> > > expected        = new List <IList <BlockEntry <MutableLong, MutableLong> > >();
            IList <BlockEntry <MutableLong, MutableLong> >          currentExpected = new List <BlockEntry <MutableLong, MutableLong> >();
            long currentBlock = 0;

            while (monitor.BlockFlushedCallCount < numberOfBlocks - 1)
            {
                MutableLong key   = UniqueKey(uniqueKeys);
                MutableLong value = new MutableLong(Random.nextLong(10_000_000));

                storage.Add(key, value);
                if (monitor.BlockFlushedCallCount > currentBlock)
                {
                    Sort(currentExpected);
                    expected.Add(currentExpected);
                    currentExpected = new List <BlockEntry <MutableLong, MutableLong> >();
                    currentBlock    = monitor.BlockFlushedCallCount;
                }
                currentExpected.Add(new BlockEntry <>(key, value));
            }
            storage.DoneAdding();
            if (currentExpected.Count > 0)
            {
                expected.Add(currentExpected);
            }
            return(expected);
        }
Ejemplo n.º 20
0
 private void StoreUpdate <T1>(IndexEntryUpdate <T1> update, BlockStorage <KEY, VALUE> blockStorage)
 {
     StoreUpdate(update.EntityId, update.Values(), blockStorage);
 }
Ejemplo n.º 21
0
 public Monitor_Fields(BlockStorage <KEY, VALUE> outerInstance)
 {
     this._outerInstance = outerInstance;
 }
Ejemplo n.º 22
0
 public Monitor_Adapter(BlockStorage <KEY, VALUE> outerInstance)
 {
     this._outerInstance = outerInstance;
 }
Ejemplo n.º 23
0
 internal Monitor_Delegate(BlockStorage <KEY, VALUE> outerInstance, Monitor actual)
 {
     this._outerInstance = outerInstance;
     this.Actual         = actual;
 }