예제 #1
0
 public override void setValueWithOldSetting(string value, IDictionary <string, string> rawConfiguration)
 {
     if (StringUtils.isNotEmpty(value))
     {
         string oldSettingDefaultValue = GraphDatabaseSettings.index_sampling_buffer_size.DefaultValue;
         long?  newValue = oldSettingDefaultValue.Equals(value) ? ByteUnit.mebiBytes(8) : Settings.BYTES.apply(value);
         rawConfiguration["dbms.index_sampling.sample_size_limit"] = newValue.ToString();
     }
 }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void trackMemoryAllocations()
        internal virtual void TrackMemoryAllocations()
        {
            LocalMemoryTracker memoryTracker = new LocalMemoryTracker();
            GrabAllocator      allocator     = ( GrabAllocator )MemoryAllocator.createAllocator("2m", memoryTracker);

            assertEquals(0, memoryTracker.UsedDirectMemory());

            long pointer = allocator.AllocateAligned(ByteUnit.mebiBytes(1), 1);

            assertEquals(ByteUnit.mebiBytes(1), memoryTracker.UsedDirectMemory());

            allocator.Close();
            assertEquals(0, memoryTracker.UsedDirectMemory());
        }
예제 #3
0
        public static long DefaultHeuristicPageCacheMemory()
        {
            // First check if we have a default override...
            string defaultMemoryOverride = System.getProperty("dbms.pagecache.memory.default.override");

            if (!string.ReferenceEquals(defaultMemoryOverride, null))
            {
                return(BYTES.apply(defaultMemoryOverride));
            }

            double ratioOfFreeMem             = 0.50;
            string defaultMemoryRatioOverride = System.getProperty("dbms.pagecache.memory.ratio.default.override");

            if (!string.ReferenceEquals(defaultMemoryRatioOverride, null))
            {
                ratioOfFreeMem = double.Parse(defaultMemoryRatioOverride);
            }

            // Try to compute (RAM - maxheap) * 0.50 if we can get reliable numbers...
            long maxHeapMemory = Runtime.Runtime.maxMemory();

            if (0 < maxHeapMemory && maxHeapMemory < long.MaxValue)
            {
                try
                {
                    long physicalMemory = OsBeanUtil.TotalPhysicalMemory;
                    if (0 < physicalMemory && physicalMemory < long.MaxValue && maxHeapMemory < physicalMemory)
                    {
                        long heuristic = ( long )((physicalMemory - maxHeapMemory) * ratioOfFreeMem);
                        long min       = ByteUnit.mebiBytes(32);                               // We'd like at least 32 MiBs.
                        long max       = Math.Min(maxHeapMemory * 70, ByteUnit.gibiBytes(20));
                        // Don't heuristically take more than 20 GiBs, and don't take more than 70 times our max heap.
                        // 20 GiBs of page cache memory is ~2.6 million 8 KiB pages. If each page has an overhead of
                        // 72 bytes, then this will take up ~175 MiBs of heap memory. We should be able to tolerate that
                        // in most environments. The "no more than 70 times heap" heuristic is based on the page size over
                        // the per page overhead, 8192 / 72 ~= 114, plus leaving some extra room on the heap for the rest
                        // of the system. This means that we won't heuristically try to create a page cache that is too
                        // large to fit on the heap.
                        return(Math.Min(max, Math.Max(min, heuristic)));
                    }
                }
                catch (Exception)
                {
                }
            }
            // ... otherwise we just go with 2 GiBs.
            return(ByteUnit.gibiBytes(2));
        }
예제 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void transactions1M(org.neo4j.causalclustering.discovery.Cluster<?> cluster) throws Exception
        private static void Transactions1M <T1>(Cluster <T1> cluster)
        {
            int  numberOfTransactions = 500;
            long sizeOfTransaction    = (ByteUnit.mebiBytes(1) / numberOfTransactions) + 1;

            for (int txId = 0; txId < numberOfTransactions; txId++)
            {
                cluster.CoreTx((coreGraphDatabase, transaction) =>
                {
                    Node node         = coreGraphDatabase.createNode();
                    string longString = LongStream.range(0, sizeOfTransaction).map(l => l % 10).mapToObj(long?.toString).collect(joining(""));
                    node.setProperty("name", longString);
                    coreGraphDatabase.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
                    transaction.success();
                });
            }
        }
예제 #5
0
//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();
        }
예제 #6
0
        private static void Transactions1M(GraphDatabaseService db)
        {
            int  numberOfTransactions = 500;
            long sizeOfTransaction    = (ByteUnit.mebiBytes(1) / numberOfTransactions) + 1;

            for (int txId = 0; txId < numberOfTransactions; txId++)
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node   node       = Db.createNode();
                    string longString = LongStream.range(0, sizeOfTransaction).map(l => l % 10).mapToObj(long?.toString).collect(joining(""));
                    node.SetProperty("name", longString);
                    Db.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
                    tx.Success();
                }
            }
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void growEphemeralFileBuffer()
        internal virtual void GrowEphemeralFileBuffer()
        {
            EphemeralFileSystemAbstraction.DynamicByteBuffer byteBuffer = new EphemeralFileSystemAbstraction.DynamicByteBuffer();

            sbyte[] testBytes = new sbyte[] { 1, 2, 3, 4 };
            int     length    = testBytes.Length;

            byteBuffer.Put(0, testBytes, 0, length);
            assertEquals(( int )ByteUnit.kibiBytes(1), byteBuffer.Buf().capacity());

            byteBuffer.Put(( int )(ByteUnit.kibiBytes(1) + 2), testBytes, 0, length);
            assertEquals(( int )ByteUnit.kibiBytes(2), byteBuffer.Buf().capacity());

            byteBuffer.Put(( int )(ByteUnit.kibiBytes(5) + 2), testBytes, 0, length);
            assertEquals(( int )ByteUnit.kibiBytes(8), byteBuffer.Buf().capacity());

            byteBuffer.Put(( int )(ByteUnit.mebiBytes(2) + 2), testBytes, 0, length);
            assertEquals(( int )ByteUnit.mebiBytes(4), byteBuffer.Buf().capacity());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending()
        {
            // GIVEN
            LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            LogFiles             logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean            end           = new AtomicBoolean();
            AllTheMonitoring         monitoring    = new AllTheMonitoring(end, 100);
            TransactionIdStore       txIdStore     = new SimpleTransactionIdStore();
            TransactionMetadataCache metadataCache = new TransactionMetadataCache();

            monitoring.LogFile = logFiles.LogFile;
            DatabaseHealth health   = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogRotation    rotation = new LogRotationImpl(monitoring, logFiles, health);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));
            TransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));

            // WHEN
            Race race = new Race();

            for (int i = 0; i < 10; i++)
            {
                race.AddContestant(() =>
                {
                    while (!end.get())
                    {
                        try
                        {
                            appender.Append(new TransactionToApply(SillyTransaction(1_000)), NULL);
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace(System.out);
                            end.set(true);
                            fail(e.Message);
                        }
                    }
                });
            }
            race.AddContestant(EndAfterMax(10, SECONDS, end));
            race.Go();

            // THEN
            assertTrue(monitoring.NumberOfRotations() > 0);
        }
예제 #9
0
        /// <summary>
        /// Trigger store flush (checkpoint) and write <seealso cref="NeoStoreDataSource.listStoreFiles(bool) store files"/> to the
        /// given <seealso cref="StoreWriter"/>.
        /// </summary>
        /// <param name="triggerName"> name of the component asks for store files. </param>
        /// <param name="writer"> store writer to write files to. </param>
        /// <param name="includeLogs"> <code>true</code> if transaction logs should be copied, <code>false</code> otherwise. </param>
        /// <returns> a <seealso cref="RequestContext"/> specifying at which point the store copy started. </returns>
        public virtual RequestContext FlushStoresAndStreamStoreFiles(string triggerName, StoreWriter writer, bool includeLogs)
        {
            try
            {
                string storeCopyIdentifier = Thread.CurrentThread.Name;
                ThrowingAction <IOException> checkPointAction = () =>
                {
                    _monitor.startTryCheckPoint(storeCopyIdentifier);
                    _checkPointer.tryCheckPoint(new SimpleTriggerInfo(triggerName));
                    _monitor.finishTryCheckPoint(storeCopyIdentifier);
                };

                // Copy the store files
                long lastAppliedTransaction;
                StoreCopyCheckPointMutex mutex = _dataSource.StoreCopyCheckPointMutex;
                try
                {
                    using (Resource @lock = mutex.StoreCopy(checkPointAction), ResourceIterator <StoreFileMetadata> files = _dataSource.listStoreFiles(includeLogs))
                    {
                        lastAppliedTransaction = _checkPointer.lastCheckPointedTransactionId();
                        _monitor.startStreamingStoreFiles(storeCopyIdentifier);
                        ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(( int )ByteUnit.mebiBytes(1));
                        while (Files.MoveNext())
                        {
                            StoreFileMetadata meta = Files.Current;
                            File file       = meta.File();
                            bool isLogFile  = meta.LogFile;
                            int  recordSize = meta.RecordSize();

                            using (ReadableByteChannel fileChannel = _fileSystem.open(file, OpenMode.READ))
                            {
                                long fileSize = _fileSystem.getFileSize(file);
                                DoWrite(writer, temporaryBuffer, file, recordSize, fileChannel, fileSize, storeCopyIdentifier, isLogFile);
                            }
                        }
                    }
                }
                finally
                {
                    _monitor.finishStreamingStoreFiles(storeCopyIdentifier);
                }

                return(anonymous(lastAppliedTransaction));
            }
            catch (IOException e)
            {
                throw new ServerFailureException(e);
            }
        }