Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCloseGlobalAllocationsOnClose()
        internal virtual void ShouldCloseGlobalAllocationsOnClose()
        {
            // given
            ByteBufferFactory.Allocator allocator = mock(typeof(ByteBufferFactory.Allocator));
            when(allocator.Allocate(anyInt())).thenAnswer(invocationOnMock => ByteBuffer.allocate(invocationOnMock.getArgument(0)));
            ByteBufferFactory factory = new ByteBufferFactory(() => allocator, 100);

            // when doing some allocations that are counted as global
            factory.AcquireThreadLocalBuffer();
            factory.ReleaseThreadLocalBuffer();
            factory.AcquireThreadLocalBuffer();
            factory.ReleaseThreadLocalBuffer();
            factory.GlobalAllocator().allocate(123);
            factory.GlobalAllocator().allocate(456);
            // and closing it
            factory.Close();

            // then
            InOrder inOrder = inOrder(allocator);

            inOrder.verify(allocator, times(1)).allocate(100);
            inOrder.verify(allocator, times(1)).allocate(123);
            inOrder.verify(allocator, times(1)).allocate(456);
            inOrder.verify(allocator, times(1)).close();
            inOrder.verifyNoMoreInteractions();
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldShareThreadLocalBuffersStressfully() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldShareThreadLocalBuffersStressfully()
        {
            // given
            ByteBufferFactory factory = new ByteBufferFactory(() => HEAP_ALLOCATOR, 1024);
            Race race    = new Race();
            int  threads = 10;
            IList <ISet <ByteBuffer> > seenBuffers = new List <ISet <ByteBuffer> >();

            for (int i = 0; i < threads; i++)
            {
                HashSet <ByteBuffer> seen = new HashSet <ByteBuffer>();
                seenBuffers.Add(seen);
                race.AddContestant(() =>
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        ByteBuffer buffer = factory.AcquireThreadLocalBuffer();
                        assertNotNull(buffer);
                        seen.Add(buffer);
                        factory.ReleaseThreadLocalBuffer();
                    }
                }, 1);
            }

            // when
            race.Go();

            // then
            for (int i = 0; i < threads; i++)
            {
                assertEquals(1, seenBuffers[i].Count);
            }
            factory.Close();
        }
Exemple #3
0
 internal BlockBasedIndexPopulator(PageCache pageCache, FileSystemAbstraction fs, File file, IndexLayout <KEY, VALUE> layout, IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor, IndexSpecificSpaceFillingCurveSettingsCache spatialSettings, IndexDirectoryStructure directoryStructure, IndexDropAction dropAction, bool archiveFailedIndex, ByteBufferFactory bufferFactory, int mergeFactor, BlockStorage.Monitor blockStorageMonitor) : base(pageCache, fs, file, layout, monitor, descriptor, new SpaceFillingCurveSettingsWriter(spatialSettings))
 {
     this._directoryStructure  = directoryStructure;
     this._dropAction          = dropAction;
     this._archiveFailedIndex  = archiveFailedIndex;
     this._mergeFactor         = mergeFactor;
     this._blockStorageMonitor = blockStorageMonitor;
     this._scanUpdates         = ThreadLocal.withInitial(this.newThreadLocalBlockStorage);
     this._bufferFactory       = bufferFactory;
 }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldFailAcquireThreadLocalBufferIfAlreadyAcquired()
        internal virtual void ShouldFailAcquireThreadLocalBufferIfAlreadyAcquired()
        {
            // given
            ByteBufferFactory factory = new ByteBufferFactory(() => HEAP_ALLOCATOR, 1024);

            factory.AcquireThreadLocalBuffer();

            // when/then
            assertThrows(typeof(System.InvalidOperationException), factory.acquireThreadLocalBuffer);
            factory.Close();
        }
Exemple #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: BlockStorage(org.neo4j.index.internal.gbptree.Layout<KEY,VALUE> layout, ByteBufferFactory bufferFactory, org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File blockFile, Monitor monitor) throws java.io.IOException
        internal BlockStorage(Layout <KEY, VALUE> layout, ByteBufferFactory bufferFactory, FileSystemAbstraction fs, File blockFile, Monitor monitor)
        {
            this._layout          = layout;
            this._fs              = fs;
            this._blockFile       = blockFile;
            this._monitor         = monitor;
            this._blockSize       = bufferFactory.BufferSize();
            this._bufferedEntries = Lists.mutable.empty();
            this._bufferFactory   = bufferFactory;
            this._comparator      = (e0, e1) => layout.Compare(e0.key(), e1.key());
            this._storeChannel    = fs.Create(blockFile);
            ResetBufferedEntries();
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCreateNewInstancesOfLocalAllocators()
        internal virtual void ShouldCreateNewInstancesOfLocalAllocators()
        {
            // given
            System.Func <ByteBufferFactory.Allocator> allocator = mock(typeof(System.Func));
            when(allocator()).thenAnswer(invocationOnMock => mock(typeof(ByteBufferFactory.Allocator)));
            ByteBufferFactory factory = new ByteBufferFactory(allocator, 100);

            // when
            ByteBufferFactory.Allocator localAllocator1 = factory.NewLocalAllocator();
            ByteBufferFactory.Allocator localAllocator2 = factory.NewLocalAllocator();
            localAllocator2.Close();
            ByteBufferFactory.Allocator localAllocator3 = factory.NewLocalAllocator();

            // then
            assertNotSame(localAllocator1, localAllocator2);
            assertNotSame(localAllocator2, localAllocator3);
            assertNotSame(localAllocator1, localAllocator3);
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeallocateAllAllocatedMemoryOnDrop() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDeallocateAllAllocatedMemoryOnDrop()
        {
            // given
            ThreadSafePeakMemoryAllocationTracker memoryTracker = new ThreadSafePeakMemoryAllocationTracker(new LocalMemoryTracker());
            ByteBufferFactory bufferFactory = new ByteBufferFactory(() => new UnsafeDirectByteBufferAllocator(memoryTracker), 100);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR, bufferFactory);
            bool closed = false;

            try
            {
                // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Collection<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = batchOfUpdates();
                ICollection <IndexEntryUpdate <object> > updates = BatchOfUpdates();
                populator.Add(updates);
                int nextId = updates.Count;
                ExternalUpdates(populator, nextId, nextId + 10);
                nextId = nextId + 10;
                long memoryBeforeScanCompleted = memoryTracker.UsedDirectMemory();
                populator.ScanCompleted(nullInstance);
                ExternalUpdates(populator, nextId, nextId + 10);

                // then
                assertTrue("expected some memory to have been temporarily allocated in scanCompleted", memoryTracker.PeakMemoryUsage() > memoryBeforeScanCompleted);
                populator.Drop();
                closed = true;
                assertEquals("expected all allocated memory to have been freed on drop", memoryBeforeScanCompleted, memoryTracker.UsedDirectMemory());

                bufferFactory.Close();
                assertEquals(0, memoryTracker.UsedDirectMemory());
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #8
0
 internal GenericBlockBasedIndexPopulator(PageCache pageCache, FileSystemAbstraction fs, File file, IndexLayout <GenericKey, NativeIndexValue> layout, IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor, IndexSpecificSpaceFillingCurveSettingsCache spatialSettings, IndexDirectoryStructure directoryStructure, SpaceFillingCurveConfiguration configuration, IndexDropAction dropAction, bool archiveFailedIndex, ByteBufferFactory bufferFactory) : base(pageCache, fs, file, layout, monitor, descriptor, spatialSettings, directoryStructure, dropAction, archiveFailedIndex, bufferFactory)
 {
     this._spatialSettings = spatialSettings;
     this._configuration   = configuration;
 }
        public override IndexPopulator GetPopulator(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory)
        {
            if (_readOnly)
            {
                throw new System.NotSupportedException("Can't create populator for read only index");
            }
            TemporalIndexFiles files = new TemporalIndexFiles(DirectoryStructure(), descriptor, _fs);

            return(new TemporalIndexPopulator(descriptor, samplingConfig, files, _pageCache, _fs, _monitor));
        }
Exemple #10
0
 protected internal override IndexPopulator NewIndexPopulator(File storeFile, GenericLayout layout, StoreIndexDescriptor descriptor, ByteBufferFactory bufferFactory)
 {
     if (_blockBasedPopulation)
     {
         return(new GenericBlockBasedIndexPopulator(PageCache, Fs, storeFile, layout, Monitor, descriptor, layout.SpaceFillingCurveSettings, directoryStructure(), _configuration, _dropAction, _archiveFailedIndex, bufferFactory));
     }
     return(new WorkSyncedNativeIndexPopulator <>(new GenericNativeIndexPopulator(PageCache, Fs, storeFile, layout, Monitor, descriptor, layout.SpaceFillingCurveSettings, directoryStructure(), _configuration, _dropAction, _archiveFailedIndex)));
 }
Exemple #11
0
        private BlockBasedIndexPopulator <GenericKey, NativeIndexValue> InstantiatePopulator(BlockStorage.Monitor monitor, ByteBufferFactory bufferFactory)
        {
            Config config = Config.defaults();
            ConfiguredSpaceFillingCurveSettingsCache    settingsCache   = new ConfiguredSpaceFillingCurveSettingsCache(config);
            IndexSpecificSpaceFillingCurveSettingsCache spatialSettings = new IndexSpecificSpaceFillingCurveSettingsCache(settingsCache, new Dictionary <Org.Neo4j.Values.Storable.CoordinateReferenceSystem, SpaceFillingCurveSettings>());
            GenericLayout layout = new GenericLayout(1, spatialSettings);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = new BlockBasedIndexPopulatorAnonymousInnerClass(this, Storage.pageCache(), _fs, _indexFile, layout, EMPTY, _indexDescriptor, spatialSettings, _directoryStructure, _dropAction, bufferFactory, monitor);

            populator.Create();
            return(populator);
        }
 protected internal override IndexPopulator NewIndexPopulator(File storeFile, NumberLayout layout, StoreIndexDescriptor descriptor, ByteBufferFactory bufferFactory)
 {
     return(new WorkSyncedNativeIndexPopulator <>(new NumberIndexPopulator(PageCache, Fs, storeFile, layout, Monitor, descriptor)));
 }
 protected internal abstract IndexPopulator NewIndexPopulator(File storeFile, LAYOUT layout, StoreIndexDescriptor descriptor, ByteBufferFactory bufferFactory);
        public override IndexPopulator GetPopulator(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory)
        {
            if (ReadOnly)
            {
                throw new System.NotSupportedException("Can't create populator for read only index");
            }

            File storeFile = NativeIndexFileFromIndexId(descriptor.Id);

            return(NewIndexPopulator(storeFile, Layout(descriptor, null), descriptor, bufferFactory));
        }
Exemple #15
0
 internal BlockBasedIndexPopulator(PageCache pageCache, FileSystemAbstraction fs, File file, IndexLayout <KEY, VALUE> layout, IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor, IndexSpecificSpaceFillingCurveSettingsCache spatialSettings, IndexDirectoryStructure directoryStructure, IndexDropAction dropAction, bool archiveFailedIndex, ByteBufferFactory bufferFactory) : this(pageCache, fs, file, layout, monitor, descriptor, spatialSettings, directoryStructure, dropAction, archiveFailedIndex, bufferFactory, FeatureToggles.getInteger(typeof(BlockBasedIndexPopulator), "mergeFactor", 8), NO_MONITOR)
 {
 }