Пример #1
0
        /// <summary>
        /// Visit key value pairs that are greater than or equal to the specified key. Visitation will continue as long as
        /// the visitor <seealso cref="KeyValueVisitor.visit(ReadableBuffer, ReadableBuffer) returns true"/>.
        /// </summary>
        /// <returns> {@code true} if an exact match was found, meaning that the first visited key/value pair was a perfect
        /// match for the specified key. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean scan(SearchKey search, KeyValueVisitor visitor) throws java.io.IOException
        public virtual bool Scan(SearchKey search, KeyValueVisitor visitor)
        {
            BigEndianByteArrayBuffer searchKey = newBuffer(_keySize);
            BigEndianByteArrayBuffer key       = newBuffer(_keySize);
            BigEndianByteArrayBuffer value     = newBuffer(_valueSize);

            search.SearchKeyConflict(searchKey);
            int page = FindPage(searchKey, _pageCatalogue);

            if (page < 0 || (page >= _pageCatalogue.Length / (_keySize * 2)))
            {
                return(false);
            }
            using (PageCursor cursor = _file.io(page, PF_SHARED_READ_LOCK))
            {
                if (!cursor.Next())
                {
                    return(false);
                }
                // finds and reads the first key/value pair
                int offset = FindByteOffset(cursor, searchKey, key, value);
                try
                {
                    return(Arrays.Equals(searchKey.Buffer, key.Buffer));
                }
                finally
                {
                    VisitKeyValuePairs(_file.pageSize(), cursor, offset, visitor, false, key, value);
                }
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void performReadOrUpdate(java.util.concurrent.ThreadLocalRandom rng, boolean updateCounter, int pf_flags) throws java.io.IOException
            protected internal override void performReadOrUpdate(ThreadLocalRandom rng, bool updateCounter, int pfFlags)
            {
                try
                {
                    int   pageCount = rng.Next(1, _maxCursorsPerThread);
                    int[] pageIds   = new int[pageCount];
                    for (int j = 0; j < pageCount; j++)
                    {
                        pageIds[j] = rng.Next(0, _filePages);
                    }
                    PageCursor[] cursors = new PageCursor[pageCount];
                    for (int j = 0; j < pageCount; j++)
                    {
                        cursors[j] = _pagedFile.io(pageIds[j], pfFlags);
                        assertTrue(cursors[j].Next());
                    }
                    for (int j = 0; j < pageCount; j++)
                    {
                        int        pageId = pageIds[j];
                        PageCursor cursor = cursors[j];
                        int        counter;
                        do
                        {
                            cursor.Offset = offset;
                            counter       = cursor.Int;
                        } while (cursor.ShouldRetry());
                        string lockName = updateCounter ? "PF_SHARED_WRITE_LOCK" : "PF_SHARED_READ_LOCK";
                        string reason   = string.Format("inconsistent page read from filePageId = {0}, with {1}, workerId = {2} [t:{3}]", pageId, lockName, threadId, Thread.CurrentThread.Id);
                        assertThat(reason, counter, @is(pageCounts[pageId]));
                        if (updateCounter)
                        {
                            counter++;
                            pageCounts[pageId]++;
                            cursor.Offset = offset;
                            cursor.PutInt(counter);
                        }
                    }
                    foreach (PageCursor cursor in cursors)
                    {
                        cursor.Close();
                    }
                }
                catch (Exception throwable)
                {
                    _shouldStop.set(true);
                    throw throwable;
                }
            }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void initializeAfterCreation() throws java.io.IOException
        internal virtual void InitializeAfterCreation()
        {
            // Allocate a new free-list page id and set both write/read free-list page id to it.
            _writePageId = NextLastId();
            _readPageId  = _writePageId;

            using (PageCursor cursor = _pagedFile.io(_writePageId, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
            {
                goTo(cursor, "free-list", _writePageId);
                FreelistNode.Initialize(cursor);
                checkOutOfBounds(cursor);
            }
        }
Пример #4
0
        public override void Set(long index, long value)
        {
            long pageId = pageId(index);
            int  offset = offset(index);

            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW))
                {
                    cursor.Next();
                    cursor.PutLong(offset, value);
                    CheckBounds(cursor);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Пример #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void performReadOrUpdate(java.util.concurrent.ThreadLocalRandom rng, boolean updateCounter, int pf_flags) throws java.io.IOException
            protected internal override void performReadOrUpdate(ThreadLocalRandom rng, bool updateCounter, int pfFlags)
            {
                int pageId = rng.Next(0, _filePages);

                using (PageCursor cursor = _pagedFile.io(pageId, pfFlags))
                {
                    int counter;
                    try
                    {
                        assertTrue(cursor.Next());
                        do
                        {
                            cursor.Offset = offset;
                            counter       = cursor.Int;
                        } while (cursor.ShouldRetry());
                        string lockName = updateCounter ? "PF_SHARED_WRITE_LOCK" : "PF_SHARED_READ_LOCK";
                        string reason   = string.Format("inconsistent page read from filePageId:{0}, with {1}, threadId:{2}", pageId, lockName, Thread.CurrentThread.Id);
                        assertThat(reason, counter, @is(pageCounts[pageId]));
                    }
                    catch (Exception throwable)
                    {
                        _shouldStop.set(true);
                        throw throwable;
                    }
                    if (updateCounter)
                    {
                        counter++;
                        pageCounts[pageId]++;
                        cursor.Offset = offset;
                        cursor.PutInt(counter);
                    }
                    if (cursor.CheckAndClearBoundsFlag())
                    {
                        _shouldStop.set(true);
                        throw new System.IndexOutOfRangeException("offset = " + offset + ", filPageId:" + pageId + ", threadId: " + threadId + ", updateCounter = " + updateCounter);
                    }
                }
            }
Пример #6
0
        public override long Get(long index)
        {
            long pageId = pageId(index);
            int  offset = offset(index);

            try
            {
                using (PageCursor cursor = PagedFile.io(pageId, PF_SHARED_READ_LOCK))
                {
                    cursor.Next();
                    long result;
                    do
                    {
                        result = cursor.GetLong(offset);
                    } while (cursor.ShouldRetry());
                    CheckBounds(cursor);
                    return(result);
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }