Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void add(org.neo4j.kernel.api.index.IndexEntryUpdate<?> update, org.neo4j.io.pagecache.PageCursor pageCursor) throws java.io.IOException
        public override void Add <T1>(IndexEntryUpdate <T1> update, PageCursor pageCursor)
        {
            int        entrySize  = TYPE_SIZE;
            UpdateMode updateMode = update.UpdateMode();

            switch (updateMode.innerEnumValue)
            {
            case UpdateMode.InnerEnum.ADDED:
                initializeKeyAndValueFromUpdate(_key1, _value, update.EntityId, update.Values());
                entrySize += BlockEntry.EntrySize(_layout, _key1, _value);
                break;

            case UpdateMode.InnerEnum.REMOVED:
                initializeKeyFromUpdate(_key1, update.EntityId, update.Values());
                entrySize += BlockEntry.KeySize(_layout, _key1);
                break;

            case UpdateMode.InnerEnum.CHANGED:
                initializeKeyFromUpdate(_key1, update.EntityId, update.BeforeValues());
                initializeKeyAndValueFromUpdate(_key2, _value, update.EntityId, update.Values());
                entrySize += BlockEntry.KeySize(_layout, _key1) + BlockEntry.EntrySize(_layout, _key2, _value);
                break;

            default:
                throw new System.ArgumentException("Unknown update mode " + updateMode);
            }

            prepareWrite(entrySize);

            pageCursor.PutByte(( sbyte )updateMode.ordinal());
            IndexUpdateEntry.Write(pageCursor, _layout, updateMode, _key1, _key2, _value);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean next() throws java.io.IOException
        public virtual bool Next()
        {
            if (_readEntries >= _entryCount)
            {
                return(false);
            }
            BlockEntry.Read(_pageCursor, _layout, _key, _value);
            _readEntries++;
            return(true);
        }
Esempio n. 3
0
        public override bool Next()
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (_entries.hasNext())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                _next = _entries.next();
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void add(KEY key, VALUE value) throws java.io.IOException
        public virtual void Add(KEY key, VALUE value)
        {
            Preconditions.checkState(!_doneAdding, "Cannot add more after done adding");

            int entrySize = BlockEntry.EntrySize(_layout, key, value);

            if (_currentBufferSize + entrySize > _blockSize)
            {
                // append buffer to file and clear buffers
                FlushAndResetBuffer();
                _numberOfBlocksInCurrentFile++;
            }

            _bufferedEntries.add(new BlockEntry <>(key, value));
            _currentBufferSize += entrySize;
            _monitor.entryAdded(entrySize);
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadWriteMultipleEntries()
        internal virtual void ShouldReadWriteMultipleEntries()
        {
            IList <BlockEntry <MutableLong, MutableLong> > expectedEntries = new List <BlockEntry <MutableLong, MutableLong> >();
            int nbrOfEntries = 10;
            int offset       = _pageCursor.Offset;

            for (int i = 0; i < nbrOfEntries; i++)
            {
                BlockEntry <MutableLong, MutableLong> entry = new BlockEntry <MutableLong, MutableLong>(_layout.key(Rnd.nextLong()), _layout.value(Rnd.nextLong()));
                BlockEntry.Write(_pageCursor, _layout, entry);
                expectedEntries.Add(entry);
            }

            _pageCursor.Offset = offset;
            foreach (BlockEntry <MutableLong, MutableLong> expectedEntry in expectedEntries)
            {
                BlockEntry <MutableLong, MutableLong> actualEntry = BlockEntry.Read(_pageCursor, _layout);
                AssertBlockEquals(expectedEntry, actualEntry);
            }
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadWriteSingleEntry()
        internal virtual void ShouldReadWriteSingleEntry()
        {
            // given
            MutableLong writeKey   = _layout.key(Rnd.nextLong());
            MutableLong writeValue = _layout.value(Rnd.nextLong());
            int         offset     = _pageCursor.Offset;

            BlockEntry.Write(_pageCursor, _layout, writeKey, writeValue);

            // when
            MutableLong readKey   = _layout.newKey();
            MutableLong readValue = _layout.newValue();

            _pageCursor.Offset = offset;
            BlockEntry.Read(_pageCursor, _layout, readKey, readValue);

            // then
            assertEquals(0, _layout.Compare(writeKey, readKey));
            assertEquals(0, _layout.Compare(writeValue, readValue));
        }
Esempio n. 7
0
        public static void Write <KEY, VALUE>(PageCursor cursor, Layout <KEY, VALUE> layout, UpdateMode updateMode, KEY key1, KEY key2, VALUE value)
        {
            switch (updateMode.innerEnumValue)
            {
            case UpdateMode.InnerEnum.ADDED:
                BlockEntry.Write(cursor, layout, key1, value);
                break;

            case UpdateMode.InnerEnum.REMOVED:
                BlockEntry.Write(cursor, layout, key1);
                break;

            case UpdateMode.InnerEnum.CHANGED:
                BlockEntry.Write(cursor, layout, key1);
                BlockEntry.Write(cursor, layout, key2, value);
                break;

            default:
                throw new System.ArgumentException("Unknown update mode " + updateMode);
            }
        }
Esempio n. 8
0
//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);
        }
Esempio n. 9
0
 private static void AssertBlockEquals(BlockEntry <MutableLong, MutableLong> expected, BlockEntry <MutableLong, MutableLong> actual)
 {
     assertEquals(0, _layout.Compare(expected.Key(), actual.Key()));
     assertEquals(0, _layout.Compare(expected.Value(), actual.Value()));
 }
Esempio n. 10
0
 internal static void Write <KEY, VALUE>(PageCursor pageCursor, Layout <KEY, VALUE> layout, BlockEntry <KEY, VALUE> entry)
 {
     Write(pageCursor, layout, entry.Key(), entry.Value());
 }