ignite-gg-11810
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8fcac6f2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8fcac6f2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8fcac6f2 Branch: refs/heads/ignite-gg-11810 Commit: 8fcac6f29c0fdad1b6af4acad232a5b24a71bbb7 Parents: 53e2cd2 Author: sboikov <sboi...@gridgain.com> Authored: Wed Dec 21 17:34:38 2016 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Wed Dec 21 18:25:19 2016 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/pagemem/Page.java | 15 +++ .../ignite/internal/pagemem/PageMemory.java | 2 +- .../ignite/internal/pagemem/PageUtils.java | 66 ++++++++++++ .../internal/pagemem/impl/PageNoStoreImpl.java | 40 +++++++- .../wal/record/delta/MetaPageAddRootRecord.java | 2 +- .../wal/record/delta/MetaPageCutRootRecord.java | 2 +- .../record/delta/MetaPageInitRootRecord.java | 2 +- .../cache/database/DataStructure.java | 18 ++-- .../cache/database/freelist/FreeListImpl.java | 4 +- .../cache/database/freelist/PagesList.java | 100 +++++++++---------- .../database/freelist/io/PagesListMetaIO.java | 41 ++++---- .../database/freelist/io/PagesListNodeIO.java | 56 +++++------ .../cache/database/tree/BPlusTree.java | 14 +-- .../cache/database/tree/io/BPlusIO.java | 73 ++++++-------- .../cache/database/tree/io/BPlusInnerIO.java | 32 +++--- .../cache/database/tree/io/BPlusLeafIO.java | 6 +- .../cache/database/tree/io/BPlusMetaIO.java | 38 +++---- .../cache/database/tree/io/CacheVersionIO.java | 32 +++--- .../cache/database/tree/io/DataPageIO.java | 16 +-- .../cache/database/tree/io/IOVersions.java | 4 +- .../cache/database/tree/io/PageIO.java | 50 +++++----- .../cache/database/tree/io/PageMetaIO.java | 61 ++++++----- .../database/tree/io/PagePartitionMetaIO.java | 39 ++++---- .../cache/database/tree/io/TrackingPageIO.java | 49 ++++----- .../cache/database/tree/util/PageHandler.java | 79 +++++++-------- .../database/tree/util/PageLockListener.java | 8 +- .../apache/ignite/internal/util/GridUnsafe.java | 2 +- 27 files changed, 480 insertions(+), 371 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/Page.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/Page.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/Page.java index e08fad6..89848cc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/Page.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/Page.java @@ -44,6 +44,11 @@ public interface Page extends AutoCloseable { public ByteBuffer getForRead(); /** + * @return Pointer for modifying the page. + */ + public long getForReadPointer(); + + /** * Releases reserved page. Released page can be evicted from RAM after flushing modifications to disk. */ public void releaseRead(); @@ -54,11 +59,21 @@ public interface Page extends AutoCloseable { public ByteBuffer getForWrite(); /** + * @return ByteBuffer for modifying the page. + */ + public long getForWritePointer(); + + /** * @return ByteBuffer for modifying the page of {@code null} if failed to get write lock. */ @Nullable public ByteBuffer tryGetForWrite(); /** + * @return ByteBuffer for modifying the page of {@code null} if failed to get write lock. + */ + public long tryGetForWritePointer(); + + /** * Releases reserved page. Released page can be evicted from RAM after flushing modifications to disk. */ public void releaseWrite(boolean markDirty); http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java index 53b37f6..27c090e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java @@ -25,7 +25,7 @@ import org.apache.ignite.lifecycle.LifecycleAware; */ public interface PageMemory extends LifecycleAware, PageIdAllocator { /** */ - ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder(); + public ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder(); /** * Gets the page associated with the given page ID. Each page obtained with this method must be released by http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java new file mode 100644 index 0000000..69719e1 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.pagemem; + +import org.apache.ignite.internal.util.GridUnsafe; +import sun.misc.Unsafe; + +/** + * + */ +@SuppressWarnings("deprecation") +public class PageUtils { + /** */ + private static final Unsafe unsafe = GridUnsafe.UNSAFE; + + public static byte getByte(long buf, int off) { + return unsafe.getByte(buf, off); + } + + public static short getShort(long buf, int off) { + return unsafe.getShort(buf, off); + } + + public static int getInt(long buf, int off) { + return unsafe.getInt(buf, off); + } + + public static long getLong(long buf, int off) { + return unsafe.getLong(buf, off); + } + + public static void putBytes(long buf, int off, byte[] bytes) { + unsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF, null, buf + off, bytes.length); + } + + public static void putByte(long buf, int off, byte v) { + unsafe.putByte(buf, off, v); + } + + public static void putShort(long buf, int off, short v) { + unsafe.putShort(buf, off, v); + } + + public static void putInt(long buf, int off, int v) { + unsafe.putInt(buf, off, v); + } + + public static void putLong(long buf, int off, long v) { + unsafe.putLong(buf, off, v); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageNoStoreImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageNoStoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageNoStoreImpl.java index 404c0b2..0ad206b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageNoStoreImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageNoStoreImpl.java @@ -26,6 +26,7 @@ import org.apache.ignite.internal.util.OffheapReadWriteLock; import org.apache.ignite.internal.util.typedef.internal.SB; import java.nio.ByteBuffer; +import org.jetbrains.annotations.Nullable; /** * @@ -70,6 +71,10 @@ public class PageNoStoreImpl implements Page { buf = pageMem.wrapPointer(absPtr + PageMemoryNoStoreImpl.PAGE_OVERHEAD, pageMem.pageSize()); } + private long pointer() { + return absPtr + PageMemoryNoStoreImpl.PAGE_OVERHEAD; + } + /** {@inheritDoc} */ @Override public long id() { return pageId; @@ -89,6 +94,14 @@ public class PageNoStoreImpl implements Page { } /** {@inheritDoc} */ + @Override public long getForReadPointer() { + if (pageMem.readLockPage(absPtr, PageIdUtils.tag(pageId))) + return pointer(); + + return 0L; + } + + /** {@inheritDoc} */ @Override public void releaseRead() { pageMem.readUnlockPage(absPtr); } @@ -107,8 +120,31 @@ public class PageNoStoreImpl implements Page { } /** {@inheritDoc} */ - @Override public ByteBuffer tryGetForWrite() { + @Override public long getForWritePointer() { int tag = noTagCheck ? OffheapReadWriteLock.TAG_LOCK_ALWAYS : PageIdUtils.tag(pageId); + boolean locked = pageMem.writeLockPage(absPtr, tag); + + if (!locked && !noTagCheck) + return 0L; + + assert locked; + + return pointer(); + } + + /** {@inheritDoc} */ + @Override public long tryGetForWritePointer() { + int tag = noTagCheck ? OffheapReadWriteLock.TAG_LOCK_ALWAYS : PageIdUtils.tag(pageId); + + if (pageMem.tryWriteLockPage(absPtr, tag)) + return pointer(); + + return 0L; + } + + /** {@inheritDoc} */ + @Override public ByteBuffer tryGetForWrite() { + int tag = noTagCheck ? OffheapReadWriteLock.TAG_LOCK_ALWAYS : PageIdUtils.tag(pageId); if (pageMem.tryWriteLockPage(absPtr, tag)) return reset(buf); @@ -118,7 +154,7 @@ public class PageNoStoreImpl implements Page { /** {@inheritDoc} */ @Override public void releaseWrite(boolean markDirty) { - long updatedPageId = PageIO.getPageId(buf); + long updatedPageId = PageIO.getPageId(pointer()); pageMem.writeUnlockPage(absPtr, PageIdUtils.tag(updatedPageId)); } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java index 75aaca4..a84933c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageAddRootRecord.java @@ -43,7 +43,7 @@ public class MetaPageAddRootRecord extends PageDeltaRecord { @Override public void applyDelta(ByteBuffer buf) throws IgniteCheckedException { BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(buf); - io.addRoot(buf, rootId); + io.addRoot(0, buf, rootId); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java index ba1d04d..1145736 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageCutRootRecord.java @@ -37,7 +37,7 @@ public class MetaPageCutRootRecord extends PageDeltaRecord { @Override public void applyDelta(ByteBuffer buf) throws IgniteCheckedException { BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(buf); - io.cutRoot(buf); + io.cutRoot(0, buf); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java index a9d2677..96bc949 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/delta/MetaPageInitRootRecord.java @@ -44,7 +44,7 @@ public class MetaPageInitRootRecord extends PageDeltaRecord { throws IgniteCheckedException { BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(buf); - io.initRoot(buf, rootId); + io.initRoot(0, buf, rootId); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java index 5fd64b0..26df029 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java @@ -133,7 +133,7 @@ public abstract class DataStructure implements PageLockListener { * @param page Page. * @return Buffer. */ - protected final ByteBuffer tryWriteLock(Page page) { + protected final long tryWriteLock(Page page) { return PageHandler.writeLock(page, this, true); } @@ -142,7 +142,7 @@ public abstract class DataStructure implements PageLockListener { * @param page Page. * @return Buffer. */ - protected final ByteBuffer writeLock(Page page) { + protected final long writeLock(Page page) { return PageHandler.writeLock(page, this, false); } @@ -151,7 +151,7 @@ public abstract class DataStructure implements PageLockListener { * @param buf Buffer. * @param dirty Dirty page. */ - protected final void writeUnlock(Page page, ByteBuffer buf, boolean dirty) { + protected final void writeUnlock(Page page, long buf, boolean dirty) { PageHandler.writeUnlock(page, buf, this, dirty); } @@ -159,7 +159,7 @@ public abstract class DataStructure implements PageLockListener { * @param page Page. * @return Buffer. */ - protected final ByteBuffer readLock(Page page) { + protected final long readLock(Page page) { return PageHandler.readLock(page, this); } @@ -167,7 +167,7 @@ public abstract class DataStructure implements PageLockListener { * @param page Page. * @param buf Buffer. */ - protected final void readUnlock(Page page, ByteBuffer buf) { + protected final void readUnlock(Page page, long buf) { PageHandler.readUnlock(page, buf, this); } @@ -177,12 +177,12 @@ public abstract class DataStructure implements PageLockListener { } /** {@inheritDoc} */ - @Override public void onWriteLock(Page page, ByteBuffer buf) { + @Override public void onWriteLock(Page page, long buf) { // No-op. } /** {@inheritDoc} */ - @Override public void onWriteUnlock(Page page, ByteBuffer buf) { + @Override public void onWriteUnlock(Page page, long buf) { // No-op. } @@ -192,12 +192,12 @@ public abstract class DataStructure implements PageLockListener { } /** {@inheritDoc} */ - @Override public void onReadLock(Page page, ByteBuffer buf) { + @Override public void onReadLock(Page page, long buf) { // No-op. } /** {@inheritDoc} */ - @Override public void onReadUnlock(Page page, ByteBuffer buf) { + @Override public void onReadUnlock(Page page, long buf) { // No-op. } } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java index 6a29027..af20d15 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeListImpl.java @@ -72,7 +72,7 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList { /** */ private final PageHandler<CacheDataRow, Integer> writeRow = new PageHandler<CacheDataRow, Integer>() { - @Override public Integer run(Page page, PageIO iox, ByteBuffer buf, CacheDataRow row, int written) + @Override public Integer run(Page page, PageIO iox, long buf, CacheDataRow row, int written) throws IgniteCheckedException { DataPageIO io = (DataPageIO)iox; @@ -380,7 +380,7 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList { @Override public void addForRecycle(ReuseBag bag) throws IgniteCheckedException { assert reuseList == this: "not allowed to be a reuse list"; - put(bag, null, null, REUSE_BUCKET); + put(bag, null, 0L, REUSE_BUCKET); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java index cc85412..8311b65 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/PagesList.java @@ -85,7 +85,7 @@ public abstract class PagesList extends DataStructure { /** */ private final PageHandler<Void, Boolean> cutTail = new PageHandler<Void, Boolean>() { - @Override public Boolean run(Page page, PageIO pageIo, ByteBuffer buf, Void ignore, int bucket) + @Override public Boolean run(Page page, PageIO pageIo, long buf, Void ignore, int bucket) throws IgniteCheckedException { assert getPageId(buf) == page.id(); @@ -149,9 +149,9 @@ public abstract class PagesList extends DataStructure { while (nextPageId != 0) { try (Page page = page(nextPageId)) { - ByteBuffer buf = readLock(page); // No concurrent recycling on init. + long buf = readLock(page); // No concurrent recycling on init. - assert buf != null; + assert buf != 0L; try { PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(buf); @@ -198,7 +198,7 @@ public abstract class PagesList extends DataStructure { assert metaPageId != 0; Page curPage = null; - ByteBuffer curBuf = null; + long curBuf = 0L; PagesListMetaIO curIo = null; long nextPageId = metaPageId; @@ -211,7 +211,7 @@ public abstract class PagesList extends DataStructure { int tailIdx = 0; while (tailIdx < tails.length) { - int written = curPage != null ? curIo.addTails(curBuf, bucket, tails, tailIdx) : 0; + int written = curPage != null ? curIo.addTails(pageMem.pageSize(), curBuf, bucket, tails, tailIdx) : 0; if (written == 0) { if (nextPageId == 0L) { @@ -257,7 +257,7 @@ public abstract class PagesList extends DataStructure { while (nextPageId != 0L) { try (Page page = page(nextPageId)) { - ByteBuffer buf = writeLock(page); + long buf = writeLock(page); try { PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(buf); @@ -277,7 +277,7 @@ public abstract class PagesList extends DataStructure { * @param page Page. * @param buf Buffer. */ - private void releaseAndClose(Page page, ByteBuffer buf) { + private void releaseAndClose(Page page, long buf) { if (page != null) { try { // No special WAL record because we most likely changed the whole page. @@ -318,7 +318,7 @@ public abstract class PagesList extends DataStructure { * @param nextId Next page ID. * @param next Next page buffer. */ - private void setupNextPage(PagesListNodeIO io, long prevId, ByteBuffer prev, long nextId, ByteBuffer next) { + private void setupNextPage(PagesListNodeIO io, long prevId, long prev, long nextId, long next) { assert io.getNextId(prev) == 0L; io.initNewPage(next, nextId); @@ -462,7 +462,7 @@ public abstract class PagesList extends DataStructure { long pageId = tail.tailId; try (Page page = page(pageId)) { - ByteBuffer buf = readLock(page); // No correctness guaranties. + long buf = readLock(page); // No correctness guaranties. try { PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(buf); @@ -489,9 +489,9 @@ public abstract class PagesList extends DataStructure { * @param bucket Bucket. * @throws IgniteCheckedException If failed. */ - protected final void put(ReuseBag bag, Page dataPage, ByteBuffer dataPageBuf, int bucket) + protected final void put(ReuseBag bag, Page dataPage, long dataPageBuf, int bucket) throws IgniteCheckedException { - assert bag == null ^ dataPageBuf == null; + assert bag == null ^ dataPageBuf == 0L; for (int lockAttempt = 0; ;) { Stripe stripe = getPageForPut(bucket); @@ -499,9 +499,9 @@ public abstract class PagesList extends DataStructure { long tailId = stripe.tailId; try (Page tail = page(tailId)) { - ByteBuffer buf = writeLockPage(tail, bucket, lockAttempt++); // Explicit check. + long buf = writeLockPage(tail, bucket, lockAttempt++); // Explicit check. - if (buf == null) + if (buf == 0L) continue; assert PageIO.getPageId(buf) == tailId : "bufPageId = " + PageIO.getPageId(buf) + ", tailId = " + tailId; @@ -547,10 +547,10 @@ public abstract class PagesList extends DataStructure { private boolean putDataPage( long pageId, Page page, - ByteBuffer buf, + long buf, PagesListNodeIO io, Page dataPage, - ByteBuffer dataPageBuf, + long dataPageBuf, int bucket ) throws IgniteCheckedException { if (io.getNextId(buf) != 0L) @@ -558,7 +558,7 @@ public abstract class PagesList extends DataStructure { long dataPageId = dataPage.id(); - int idx = io.addPage(buf, dataPageId); + int idx = io.addPage(pageMem.pageSize(), buf, dataPageId); if (idx == -1) handlePageFull(pageId, page, buf, io, dataPage, dataPageBuf, bucket); @@ -589,10 +589,10 @@ public abstract class PagesList extends DataStructure { private void handlePageFull( long pageId, Page page, - ByteBuffer buf, + long buf, PagesListNodeIO io, Page dataPage, - ByteBuffer dataPageBuf, + long dataPageBuf, int bucket ) throws IgniteCheckedException { long dataPageId = dataPage.id(); @@ -627,9 +627,9 @@ public abstract class PagesList extends DataStructure { long nextId = allocatePage(null); try (Page next = page(nextId)) { - ByteBuffer nextBuf = writeLock(next); // Newly allocated page. + long nextBuf = writeLock(next); // Newly allocated page. - assert nextBuf != null; + assert nextBuf != 0L; try { setupNextPage(io, pageId, buf, nextId, nextBuf); @@ -637,7 +637,7 @@ public abstract class PagesList extends DataStructure { if (isWalDeltaRecordNeeded(wal, page)) wal.log(new PagesListSetNextRecord(cacheId, pageId, nextId)); - int idx = io.addPage(nextBuf, dataPageId); + int idx = io.addPage(pageMem.pageSize(), nextBuf, dataPageId); // Here we should never write full page, because it is known to be new. next.fullPageWalRecordPolicy(FALSE); @@ -683,7 +683,7 @@ public abstract class PagesList extends DataStructure { private boolean putReuseBag( final long pageId, Page page, - final ByteBuffer buf, + final long buf, PagesListNodeIO io, ReuseBag bag, int bucket @@ -692,21 +692,21 @@ public abstract class PagesList extends DataStructure { return false; // Splitted. long nextId; - ByteBuffer prevBuf = buf; + long prevBuf = buf; long prevId = pageId; List<Page> locked = null; // TODO may be unlock right away and do not keep all these pages locked? - List<ByteBuffer> lockedBufs = null; + List<Long> lockedBufs = null; try { while ((nextId = bag.pollFreePage()) != 0L) { - int idx = io.addPage(prevBuf, nextId); + int idx = io.addPage(pageMem.pageSize(), prevBuf, nextId); if (idx == -1) { // Attempt to add page failed: the node page is full. try (Page next = page(nextId)) { - ByteBuffer nextBuf = writeLock(next); // Page from reuse bag can't be concurrently recycled. + long nextBuf = writeLock(next); // Page from reuse bag can't be concurrently recycled. - assert nextBuf != null; + assert nextBuf != 0L; if (locked == null) { lockedBufs = new ArrayList<>(2); @@ -783,11 +783,11 @@ public abstract class PagesList extends DataStructure { * @return Buffer if page is locket of {@code null} if can retry lock. * @throws IgniteCheckedException If failed. */ - @Nullable private ByteBuffer writeLockPage(Page page, int bucket, int lockAttempt) + private long writeLockPage(Page page, int bucket, int lockAttempt) throws IgniteCheckedException { - ByteBuffer buf = tryWriteLock(page); + long buf = tryWriteLock(page); - if (buf != null) + if (buf != 0L) return buf; if (lockAttempt == TRY_LOCK_ATTEMPTS) { @@ -796,11 +796,11 @@ public abstract class PagesList extends DataStructure { if (stripes == null || stripes.length < MAX_STRIPES_PER_BUCKET) { addStripe(bucket, false); - return null; + return 0L; } } - return lockAttempt < TRY_LOCK_ATTEMPTS ? null : writeLock(page); // Must be explicitly checked further. + return lockAttempt < TRY_LOCK_ATTEMPTS ? 0L : writeLock(page); // Must be explicitly checked further. } /** @@ -819,9 +819,9 @@ public abstract class PagesList extends DataStructure { long tailId = stripe.tailId; try (Page tail = page(tailId)) { - ByteBuffer tailBuf = writeLockPage(tail, bucket, lockAttempt++); // Explicit check. + long tailBuf = writeLockPage(tail, bucket, lockAttempt++); // Explicit check. - if (tailBuf == null) + if (tailBuf == 0L) continue; assert PageIO.getPageId(tailBuf) == tailId : "tailId = " + tailId + ", tailBufId = " + PageIO.getPageId(tailBuf); @@ -929,7 +929,7 @@ public abstract class PagesList extends DataStructure { * @throws IgniteCheckedException If failed. * @return {@code True} if page was removed. */ - protected final boolean removeDataPage(Page dataPage, ByteBuffer dataPageBuf, DataPageIO dataIO, int bucket) + protected final boolean removeDataPage(Page dataPage, long dataPageBuf, DataPageIO dataIO, int bucket) throws IgniteCheckedException { long dataPageId = dataPage.id(); @@ -943,9 +943,9 @@ public abstract class PagesList extends DataStructure { long recycleId = 0L; - ByteBuffer buf = writeLock(page); // Explicit check. + long buf = writeLock(page); // Explicit check. - if (buf == null) + if (buf == 0L) return false; boolean rmvd = false; @@ -1003,7 +1003,7 @@ public abstract class PagesList extends DataStructure { * @return Page ID to recycle. * @throws IgniteCheckedException If failed. */ - private long mergeNoNext(long pageId, Page page, ByteBuffer buf, long prevId, int bucket) + private long mergeNoNext(long pageId, Page page, long buf, long prevId, int bucket) throws IgniteCheckedException { // If we do not have a next page (we are tail) and we are on reuse bucket, // then we can leave as is as well, because it is normal to have an empty tail page here. @@ -1040,11 +1040,11 @@ public abstract class PagesList extends DataStructure { try (Page next = nextId == 0L ? null : page(nextId)) { boolean write = false; - ByteBuffer nextBuf = next == null ? null : writeLock(next); // Explicit check. - ByteBuffer buf = writeLock(page); // Explicit check. + long nextBuf = next == null ? 0L : writeLock(next); // Explicit check. + long buf = writeLock(page); // Explicit check. - if (buf == null) { - if (nextBuf != null) // Unlock next page if needed. + if (buf == 0L) { + if (nextBuf != 0L) // Unlock next page if needed. writeUnlock(next, nextBuf, false); return 0L; // Someone has merged or taken our empty page concurrently. Nothing to do here. @@ -1057,7 +1057,7 @@ public abstract class PagesList extends DataStructure { return 0L; // No need to merge anymore. // Check if we see a consistent state of the world. - if (io.getNextId(buf) == nextId && (nextId == 0L) == (nextBuf == null)) { + if (io.getNextId(buf) == nextId && (nextId == 0L) == (nextBuf == 0L)) { long recycleId = doMerge(pageId, page, buf, io, next, nextId, nextBuf, bucket); write = true; @@ -1069,7 +1069,7 @@ public abstract class PagesList extends DataStructure { nextId = io.getNextId(buf); } finally { - if (nextBuf != null) + if (nextBuf != 0L) writeUnlock(next, nextBuf, write); writeUnlock(page, buf, write); @@ -1093,11 +1093,11 @@ public abstract class PagesList extends DataStructure { private long doMerge( long pageId, Page page, - ByteBuffer buf, + long buf, PagesListNodeIO io, Page next, long nextId, - ByteBuffer nextBuf, + long nextBuf, int bucket ) throws IgniteCheckedException { long prevId = io.getPreviousId(buf); @@ -1139,12 +1139,12 @@ public abstract class PagesList extends DataStructure { long pageId, long nextId, Page next, - ByteBuffer nextBuf) + long nextBuf) throws IgniteCheckedException { try (Page prev = page(prevId)) { - ByteBuffer prevBuf = writeLock(prev); // No check, we keep a reference. + long prevBuf = writeLock(prev); // No check, we keep a reference. - assert prevBuf != null; + assert prevBuf != 0L; try { PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevBuf); @@ -1177,7 +1177,7 @@ public abstract class PagesList extends DataStructure { * @return Rotated page ID. * @throws IgniteCheckedException If failed. */ - private long recyclePage(long pageId, Page page, ByteBuffer buf) throws IgniteCheckedException { + private long recyclePage(long pageId, Page page, long buf) throws IgniteCheckedException { pageId = PageIdUtils.rotatePageId(pageId); PageIO.setPageId(buf, pageId); http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java index b525a01..6ac8cde 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListMetaIO.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.cache.database.freelist.io; -import java.nio.ByteBuffer; import java.util.Map; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.database.freelist.PagesList; import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; @@ -53,7 +53,7 @@ public class PagesListMetaIO extends PageIO { } /** {@inheritDoc} */ - @Override public void initNewPage(ByteBuffer buf, long pageId) { + @Override public void initNewPage(long buf, long pageId) { super.initNewPage(buf, pageId); setCount(buf, 0); @@ -64,55 +64,56 @@ public class PagesListMetaIO extends PageIO { * @param buf Buffer. * @return Stored items count. */ - private int getCount(ByteBuffer buf) { - return buf.getShort(CNT_OFF); + private int getCount(long buf) { + return PageUtils.getShort(buf, CNT_OFF); } /** * @param buf Buffer, * @param cnt Stored items count. */ - private void setCount(ByteBuffer buf, int cnt) { + private void setCount(long buf, int cnt) { assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt; - buf.putShort(CNT_OFF, (short)cnt); + PageUtils.putShort(buf, CNT_OFF, (short)cnt); } /** * @param buf Buffer. * @return Next meta page ID. */ - public long getNextMetaPageId(ByteBuffer buf) { - return buf.getLong(NEXT_META_PAGE_OFF); + public long getNextMetaPageId(long buf) { + return PageUtils.getLong(buf, NEXT_META_PAGE_OFF); } /** * @param buf Buffer. * @param metaPageId Next meta page ID. */ - public void setNextMetaPageId(ByteBuffer buf, long metaPageId) { - buf.putLong(NEXT_META_PAGE_OFF, metaPageId); + public void setNextMetaPageId(long buf, long metaPageId) { + PageUtils.putLong(buf, NEXT_META_PAGE_OFF, metaPageId); } /** * @param buf Buffer. */ - public void resetCount(ByteBuffer buf) { + public void resetCount(long buf) { setCount(buf, 0); } /** + * @param pageSize Page size. * @param buf Buffer. * @param bucket Bucket number. * @param tails Tails. * @param tailsOff Tails offset. * @return Number of items written. */ - public int addTails(ByteBuffer buf, int bucket, PagesList.Stripe[] tails, int tailsOff) { + public int addTails(int pageSize, long buf, int bucket, PagesList.Stripe[] tails, int tailsOff) { assert bucket >= 0 && bucket <= Short.MAX_VALUE : bucket; int cnt = getCount(buf); - int cap = getCapacity(buf); + int cap = getCapacity(pageSize, buf); if (cnt == cap) return 0; @@ -122,8 +123,8 @@ public class PagesListMetaIO extends PageIO { int write = Math.min(cap - cnt, tails.length - tailsOff); for (int i = 0; i < write; i++) { - buf.putShort(off, (short)bucket); - buf.putLong(off + 2, tails[tailsOff].tailId); + PageUtils.putShort(buf, off, (short)bucket); + PageUtils.putLong(buf, off + 2, tails[tailsOff].tailId); tailsOff++; @@ -139,7 +140,7 @@ public class PagesListMetaIO extends PageIO { * @param buf Buffer. * @param res Results map. */ - public void getBucketsData(ByteBuffer buf, Map<Integer, GridLongList> res) { + public void getBucketsData(long buf, Map<Integer, GridLongList> res) { int cnt = getCount(buf); assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt; @@ -150,10 +151,10 @@ public class PagesListMetaIO extends PageIO { int off = offset(0); for (int i = 0; i < cnt; i++) { - Integer bucket = (int)buf.getShort(off); + Integer bucket = (int)PageUtils.getShort(buf, off); assert bucket >= 0 && bucket <= Short.MAX_VALUE : bucket; - long tailId = buf.getLong(off + 2); + long tailId = PageUtils.getLong(buf, off + 2); assert tailId != 0; GridLongList list = res.get(bucket); @@ -171,8 +172,8 @@ public class PagesListMetaIO extends PageIO { * @param buf Buffer. * @return Maximum number of items which can be stored in buffer. */ - private int getCapacity(ByteBuffer buf) { - return (buf.capacity() - ITEMS_OFF) / ITEM_SIZE; + private int getCapacity(int pageSize, long buf) { + return (pageSize - ITEMS_OFF) / ITEM_SIZE; } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java index 2349fa1..c92e4a9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/io/PagesListNodeIO.java @@ -17,14 +17,14 @@ package org.apache.ignite.internal.processors.cache.database.freelist.io; -import java.nio.ByteBuffer; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions; import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO; import static org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler.copyMemory; /** - * TODO optimize: now we have slow {@link #removePage(ByteBuffer, long)} + * TODO optimize: now we have slow {@link #removePage(long, long)} */ public class PagesListNodeIO extends PageIO { /** */ @@ -52,7 +52,7 @@ public class PagesListNodeIO extends PageIO { } /** {@inheritDoc} */ - @Override public void initNewPage(ByteBuffer buf, long pageId) { + @Override public void initNewPage(long buf, long pageId) { super.initNewPage(buf, pageId); setEmpty(buf); @@ -64,7 +64,7 @@ public class PagesListNodeIO extends PageIO { /** * @param buf Buffer. */ - private void setEmpty(ByteBuffer buf) { + private void setEmpty(long buf) { setCount(buf, 0); } @@ -72,32 +72,32 @@ public class PagesListNodeIO extends PageIO { * @param buf Buffer. * @return Next page ID. */ - public long getNextId(ByteBuffer buf) { - return buf.getLong(NEXT_PAGE_ID_OFF); + public long getNextId(long buf) { + return PageUtils.getLong(buf, NEXT_PAGE_ID_OFF); } /** * @param buf Buffer. * @param nextId Next page ID. */ - public void setNextId(ByteBuffer buf, long nextId) { - buf.putLong(NEXT_PAGE_ID_OFF, nextId); + public void setNextId(long buf, long nextId) { + PageUtils.putLong(buf, NEXT_PAGE_ID_OFF, nextId); } /** * @param buf Buffer. * @return Previous page ID. */ - public long getPreviousId(ByteBuffer buf) { - return buf.getLong(PREV_PAGE_ID_OFF); + public long getPreviousId(long buf) { + return PageUtils.getLong(buf, PREV_PAGE_ID_OFF); } /** * @param buf Page buffer. * @param prevId Previous page ID. */ - public void setPreviousId(ByteBuffer buf, long prevId) { - buf.putLong(PREV_PAGE_ID_OFF, prevId); + public void setPreviousId(long buf, long prevId) { + PageUtils.putLong(buf, PREV_PAGE_ID_OFF, prevId); } /** @@ -106,8 +106,8 @@ public class PagesListNodeIO extends PageIO { * @param buf Page buffer to get count from. * @return Total number of entries. */ - public int getCount(ByteBuffer buf) { - return buf.getShort(CNT_OFF); + public int getCount(long buf) { + return PageUtils.getShort(buf, CNT_OFF); } /** @@ -116,20 +116,20 @@ public class PagesListNodeIO extends PageIO { * @param buf Page buffer to write to. * @param cnt Count. */ - private void setCount(ByteBuffer buf, int cnt) { + private void setCount(long buf, int cnt) { assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt; - buf.putShort(CNT_OFF, (short)cnt); + PageUtils.putShort(buf, CNT_OFF, (short)cnt); } /** * Gets capacity of this page in items. * - * @param buf Page buffer to get capacity. + * @param pageSize Page size. * @return Capacity of this page in items. */ - private int getCapacity(ByteBuffer buf) { - return (buf.capacity() - PAGE_IDS_OFF) >>> 3; // /8 + private int getCapacity(int pageSize) { + return (pageSize - PAGE_IDS_OFF) >>> 3; // /8 } /** @@ -145,8 +145,8 @@ public class PagesListNodeIO extends PageIO { * @param idx Item index. * @return Item at the given index. */ - private long getAt(ByteBuffer buf, int idx) { - return buf.getLong(offset(idx)); + private long getAt(long buf, int idx) { + return PageUtils.getLong(buf, offset(idx)); } /** @@ -154,8 +154,8 @@ public class PagesListNodeIO extends PageIO { * @param idx Item index. * @param pageId Item value to write. */ - private void setAt(ByteBuffer buf, int idx, long pageId) { - buf.putLong(offset(idx), pageId); + private void setAt(long buf, int idx, long pageId) { + PageUtils.putLong(buf, offset(idx), pageId); } /** @@ -165,10 +165,10 @@ public class PagesListNodeIO extends PageIO { * @param pageId Page ID. * @return Total number of items in this page. */ - public int addPage(ByteBuffer buf, long pageId) { + public int addPage(int pageSize, long buf, long pageId) { int cnt = getCount(buf); - if (cnt == getCapacity(buf)) + if (cnt == getCapacity(pageSize)) return -1; setAt(buf, cnt, pageId); @@ -183,7 +183,7 @@ public class PagesListNodeIO extends PageIO { * @param buf Page buffer. * @return Removed page ID. */ - public long takeAnyPage(ByteBuffer buf) { + public long takeAnyPage(long buf) { int cnt = getCount(buf); if (cnt == 0) @@ -201,7 +201,7 @@ public class PagesListNodeIO extends PageIO { * @param dataPageId Page ID to remove. * @return {@code true} if page was in the list and was removed, {@code false} otherwise. */ - public boolean removePage(ByteBuffer buf, long dataPageId) { + public boolean removePage(long buf, long dataPageId) { assert dataPageId != 0; int cnt = getCount(buf); @@ -224,7 +224,7 @@ public class PagesListNodeIO extends PageIO { * @param buf Page buffer. * @return {@code true} if there are no items in this page. */ - public boolean isEmpty(ByteBuffer buf) { + public boolean isEmpty(long buf) { return getCount(buf) == 0; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java index 0e41307..6ea1bff 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java @@ -409,7 +409,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { // We may need to replace inner key or want to merge this leaf with sibling after the remove -> keep lock. if (needReplaceInner || // We need to make sure that we have back or forward to be able to merge. - ((r.fwdId != 0 || r.backId != 0) && mayMerge(cnt - 1, io.getMaxCount(buf)))) { + ((r.fwdId != 0 || r.backId != 0) && mayMerge(cnt - 1, io.getMaxCount(pageMem.pageSize(), buf)))) { // If we have backId then we've already locked back page, nothing to do here. if (r.fwdId != 0 && r.backId == 0) { Result res = r.lockForward(0); @@ -528,7 +528,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { assert lvl == io.getRootLevel(buf); // Can drop only root. - io.cutRoot(buf); + io.cutRoot(pageMem.pageSize(), buf); if (needWalDeltaRecord(meta)) wal.log(new MetaPageCutRootRecord(cacheId, meta.id())); @@ -548,7 +548,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { assert lvl == io.getLevelsCount(buf); - io.addRoot(buf, rootPageId); + io.addRoot(pageMem.pageSize(), buf, rootPageId); if (needWalDeltaRecord(meta)) wal.log(new MetaPageAddRootRecord(cacheId, meta.id(), rootPageId)); @@ -566,7 +566,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { // Safe cast because we should never recycle meta page until the tree is destroyed. BPlusMetaIO io = (BPlusMetaIO)iox; - io.initRoot(buf, rootId); + io.initRoot(pageMem.pageSize(), buf, rootId); if (needWalDeltaRecord(meta)) wal.log(new MetaPageInitRootRecord(cacheId, meta.id(), rootId)); @@ -2185,7 +2185,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { */ private L insert(Page page, BPlusIO<L> io, ByteBuffer buf, int idx, int lvl) throws IgniteCheckedException { - int maxCnt = io.getMaxCount(buf); + int maxCnt = io.getMaxCount(pageMem.pageSize(), buf); int cnt = io.getCount(buf); if (cnt == maxCnt) // Need to split page. @@ -2625,7 +2625,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { // Exit: we are done. } else if (tail.sibling != null && - tail.getCount() + tail.sibling.getCount() < tail.io.getMaxCount(tail.buf)) { + tail.getCount() + tail.sibling.getCount() < tail.io.getMaxCount(pageMem.pageSize(), tail.buf)) { // Release everything lower than tail, we've already merged this path. doReleaseTail(tail.down); tail.down = null; @@ -2940,7 +2940,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure { boolean emptyBranch = needMergeEmptyBranch == TRUE || needMergeEmptyBranch == READY; - if (!left.io.merge(prnt.io, prnt.buf, prntIdx, left.buf, right.buf, emptyBranch)) + if (!left.io.merge(pageMem.pageSize(), prnt.io, prnt.buf, prntIdx, left.buf, right.buf, emptyBranch)) return false; // Invalidate indexes after successful merge. http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java index 5fc3d25..6c739a5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree; /** @@ -72,7 +72,7 @@ public abstract class BPlusIO<L> extends PageIO { } /** {@inheritDoc} */ - @Override public void initNewPage(ByteBuffer buf, long pageId) { + @Override public void initNewPage(long buf, long pageId) { super.initNewPage(buf, pageId); setCount(buf, 0); @@ -84,16 +84,16 @@ public abstract class BPlusIO<L> extends PageIO { * @param buf Buffer. * @return Forward page ID. */ - public final long getForward(ByteBuffer buf) { - return buf.getLong(FORWARD_OFF); + public final long getForward(long buf) { + return PageUtils.getLong(buf, FORWARD_OFF); } /** * @param buf Buffer. * @param pageId Forward page ID. */ - public final void setForward(ByteBuffer buf, long pageId) { - buf.putLong(FORWARD_OFF, pageId); + public final void setForward(long buf, long pageId) { + PageUtils.putLong(buf, FORWARD_OFF, pageId); assert getForward(buf) == pageId; } @@ -102,16 +102,16 @@ public abstract class BPlusIO<L> extends PageIO { * @param buf Buffer. * @return Remove ID. */ - public final long getRemoveId(ByteBuffer buf) { - return buf.getLong(REMOVE_ID_OFF); + public final long getRemoveId(long buf) { + return PageUtils.getLong(buf, REMOVE_ID_OFF); } /** * @param buf Buffer. * @param rmvId Remove ID. */ - public final void setRemoveId(ByteBuffer buf, long rmvId) { - buf.putLong(REMOVE_ID_OFF, rmvId); + public final void setRemoveId(long buf, long rmvId) { + PageUtils.putLong(buf, REMOVE_ID_OFF, rmvId); assert getRemoveId(buf) == rmvId; } @@ -120,8 +120,8 @@ public abstract class BPlusIO<L> extends PageIO { * @param buf Buffer. * @return Items count in the page. */ - public final int getCount(ByteBuffer buf) { - int cnt = buf.getShort(CNT_OFF) & 0xFFFF; + public final int getCount(long buf) { + int cnt = PageUtils.getShort(buf, CNT_OFF) & 0xFFFF; assert cnt >= 0: cnt; @@ -132,17 +132,17 @@ public abstract class BPlusIO<L> extends PageIO { * @param buf Buffer. * @param cnt Count. */ - public final void setCount(ByteBuffer buf, int cnt) { + public final void setCount(long buf, int cnt) { assert cnt >= 0: cnt; - buf.putShort(CNT_OFF, (short)cnt); + PageUtils.putShort(buf, CNT_OFF, (short)cnt); assert getCount(buf) == cnt; } /** * @return {@code true} If we can get the full row from this page using - * method {@link BPlusTree#getRow(BPlusIO, ByteBuffer, int)}. + * method {@link BPlusTree#getRow(BPlusIO, long, int)}. * Must always be {@code true} for leaf pages. */ public final boolean canGetRow() { @@ -160,7 +160,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param buf Buffer. * @return Max items count. */ - public abstract int getMaxCount(ByteBuffer buf); + public abstract int getMaxCount(int pageSize, long buf); /** * Store the needed info about the row in the page. Leaf and inner pages can store different info. @@ -171,7 +171,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param rowBytes Row bytes. * @throws IgniteCheckedException If failed. */ - public final void store(ByteBuffer buf, int idx, L row, byte[] rowBytes) throws IgniteCheckedException { + public final void store(long buf, int idx, L row, byte[] rowBytes) throws IgniteCheckedException { int off = offset(idx); if (rowBytes == null) @@ -194,7 +194,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param row Lookup or full row. * @throws IgniteCheckedException If failed. */ - public abstract void storeByOffset(ByteBuffer buf, int off, L row) throws IgniteCheckedException; + public abstract void storeByOffset(long buf, int off, L row) throws IgniteCheckedException; /** * Store row info from the given source. @@ -206,7 +206,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param srcIdx Source index. * @throws IgniteCheckedException If failed. */ - public abstract void store(ByteBuffer dst, int dstIdx, BPlusIO<L> srcIo, ByteBuffer src, int srcIdx) + public abstract void store(long dst, int dstIdx, BPlusIO<L> srcIo, long src, int srcIdx) throws IgniteCheckedException; /** @@ -218,7 +218,7 @@ public abstract class BPlusIO<L> extends PageIO { * @return Lookup row. * @throws IgniteCheckedException If failed. */ - public abstract L getLookupRow(BPlusTree<L, ?> tree, ByteBuffer buf, int idx) throws IgniteCheckedException; + public abstract L getLookupRow(BPlusTree<L, ?> tree, long buf, int idx) throws IgniteCheckedException; /** * Copy items from source buffer to destination buffer. @@ -232,7 +232,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param cpLeft Copy leftmost link (makes sense only for inner pages). * @throws IgniteCheckedException If failed. */ - public abstract void copyItems(ByteBuffer src, ByteBuffer dst, int srcIdx, int dstIdx, int cnt, boolean cpLeft) + public abstract void copyItems(long src, long dst, int srcIdx, int dstIdx, int cnt, boolean cpLeft) throws IgniteCheckedException; // Methods for B+Tree logic. @@ -245,7 +245,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param rightId Page ID which will be to the right child for the inserted item. * @throws IgniteCheckedException If failed. */ - public void insert(ByteBuffer buf, int idx, L row, byte[] rowBytes, long rightId) + public void insert(long buf, int idx, L row, byte[] rowBytes, long rightId) throws IgniteCheckedException { int cnt = getCount(buf); @@ -266,9 +266,9 @@ public abstract class BPlusIO<L> extends PageIO { * @throws IgniteCheckedException If failed. */ public void splitForwardPage( - ByteBuffer buf, + long buf, long fwdId, - ByteBuffer fwdBuf, + long fwdBuf, int mid, int cnt ) throws IgniteCheckedException { @@ -291,7 +291,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param mid Bisection index. * @param fwdId New forward page ID. */ - public void splitExistingPage(ByteBuffer buf, int mid, long fwdId) { + public void splitExistingPage(long buf, int mid, long fwdId) { setCount(buf, mid); setForward(buf, fwdId); } @@ -302,7 +302,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param cnt Count. * @throws IgniteCheckedException If failed. */ - public void remove(ByteBuffer buf, int idx, int cnt) throws IgniteCheckedException { + public void remove(long buf, int idx, int cnt) throws IgniteCheckedException { cnt--; copyItems(buf, buf, idx + 1, idx, cnt - idx, false); @@ -320,11 +320,12 @@ public abstract class BPlusIO<L> extends PageIO { * @throws IgniteCheckedException If failed. */ public boolean merge( + int pageSize, BPlusIO<L> prntIo, - ByteBuffer prnt, + long prnt, int prntIdx, - ByteBuffer left, - ByteBuffer right, + long left, + long right, boolean emptyBranch ) throws IgniteCheckedException { int prntCnt = prntIo.getCount(prnt); @@ -337,7 +338,7 @@ public abstract class BPlusIO<L> extends PageIO { if (!isLeaf() && !emptyBranch) newCnt++; - if (newCnt > getMaxCount(left)) { + if (newCnt > getMaxCount(pageSize, left)) { assert !emptyBranch; return false; @@ -373,15 +374,7 @@ public abstract class BPlusIO<L> extends PageIO { * @param pos Position in buffer. * @param bytes Bytes. */ - private static void putBytes(ByteBuffer buf, int pos, byte[] bytes) { - int oldPos = buf.position(); - - try { - buf.position(pos); - buf.put(bytes); - } - finally { - buf.position(oldPos); - } + private static void putBytes(long buf, int pos, byte[] bytes) { + PageUtils.putBytes(buf, pos, bytes); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java index 90b0f37..d0ead51 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; /** @@ -45,11 +45,11 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { } /** {@inheritDoc} */ - @Override public int getMaxCount(ByteBuffer buf) { + @Override public int getMaxCount(int pageSize, long buf) { // The structure of the page is the following: // |ITEMS_OFF|w|A|x|B|y|C|z| // where capital letters are data items, lowercase letters are 8 byte page references. - return (buf.capacity() - ITEMS_OFF - 8) / (itemSize + 8); + return (pageSize - ITEMS_OFF - 8) / (itemSize + 8); } /** @@ -57,8 +57,8 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { * @param idx Index. * @return Page ID. */ - public final long getLeft(ByteBuffer buf, int idx) { - return buf.getLong(offset(idx, SHIFT_LEFT)); + public final long getLeft(long buf, int idx) { + return PageUtils.getLong(buf, (offset(idx, SHIFT_LEFT))); } /** @@ -66,8 +66,8 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { * @param idx Index. * @param pageId Page ID. */ - public final void setLeft(ByteBuffer buf, int idx, long pageId) { - buf.putLong(offset(idx, SHIFT_LEFT), pageId); + public final void setLeft(long buf, int idx, long pageId) { + PageUtils.putLong(buf, offset(idx, SHIFT_LEFT), pageId); assert pageId == getLeft(buf, idx); } @@ -77,8 +77,8 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { * @param idx Index. * @return Page ID. */ - public final long getRight(ByteBuffer buf, int idx) { - return buf.getLong(offset(idx, SHIFT_RIGHT)); + public final long getRight(long buf, int idx) { + return PageUtils.getLong(buf, offset(idx, SHIFT_RIGHT)); } /** @@ -86,14 +86,14 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { * @param idx Index. * @param pageId Page ID. */ - public final void setRight(ByteBuffer buf, int idx, long pageId) { - buf.putLong(offset(idx, SHIFT_RIGHT), pageId); + public final void setRight(long buf, int idx, long pageId) { + PageUtils.putLong(buf, offset(idx, SHIFT_RIGHT), pageId); assert pageId == getRight(buf, idx); } /** {@inheritDoc} */ - @Override public final void copyItems(ByteBuffer src, ByteBuffer dst, int srcIdx, int dstIdx, int cnt, + @Override public final void copyItems(long src, long dst, int srcIdx, int dstIdx, int cnt, boolean cpLeft) throws IgniteCheckedException { assert srcIdx != dstIdx || src != dst; @@ -103,11 +103,11 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { PageHandler.copyMemory(src, dst, offset(srcIdx), offset(dstIdx), cnt); if (cpLeft) - dst.putLong(offset(dstIdx, SHIFT_LEFT), src.getLong(offset(srcIdx, SHIFT_LEFT))); + PageUtils.putLong(dst, offset(dstIdx, SHIFT_LEFT), PageUtils.getLong(src, (offset(srcIdx, SHIFT_LEFT)))); } else { if (cpLeft) - dst.putLong(offset(dstIdx, SHIFT_LEFT), src.getLong(offset(srcIdx, SHIFT_LEFT))); + PageUtils.putLong(dst, offset(dstIdx, SHIFT_LEFT), PageUtils.getLong(src, (offset(srcIdx, SHIFT_LEFT)))); PageHandler.copyMemory(src, dst, offset(srcIdx), offset(dstIdx), cnt); } @@ -131,7 +131,7 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { /** {@inheritDoc} */ @Override public void insert( - ByteBuffer buf, + long buf, int idx, L row, byte[] rowBytes, @@ -152,7 +152,7 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> { * @throws IgniteCheckedException If failed. */ public void initNewRoot( - ByteBuffer newRootBuf, + long newRootBuf, long newRootId, long leftChildId, L row, http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java index 824c943..76c621c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java @@ -35,12 +35,12 @@ public abstract class BPlusLeafIO<L> extends BPlusIO<L> { } /** {@inheritDoc} */ - @Override public int getMaxCount(ByteBuffer buf) { - return (buf.capacity() - ITEMS_OFF) / itemSize; + @Override public int getMaxCount(int pageSize, long buf) { + return (pageSize - ITEMS_OFF) / itemSize; } /** {@inheritDoc} */ - @Override public final void copyItems(ByteBuffer src, ByteBuffer dst, int srcIdx, int dstIdx, int cnt, + @Override public final void copyItems(long src, long dst, int srcIdx, int dstIdx, int cnt, boolean cpLeft) throws IgniteCheckedException { assert srcIdx != dstIdx || src != dst; http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java index 15a49ef..ccaa952 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusMetaIO.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; +import org.apache.ignite.internal.pagemem.PageUtils; /** * IO routines for B+Tree meta pages. @@ -45,8 +45,8 @@ public class BPlusMetaIO extends PageIO { * @param buf Buffer. * @param rootId Root page ID. */ - public void initRoot(ByteBuffer buf, long rootId) { - setLevelsCount(buf, 1); + public void initRoot(int pageSize, long buf, long rootId) { + setLevelsCount(pageSize, buf, 1); setFirstPageId(buf, 0, rootId); } @@ -54,26 +54,26 @@ public class BPlusMetaIO extends PageIO { * @param buf Buffer. * @return Number of levels in this tree. */ - public int getLevelsCount(ByteBuffer buf) { - return buf.get(LVLS_OFF); + public int getLevelsCount(long buf) { + return PageUtils.getByte(buf, LVLS_OFF); } /** * @param buf Buffer. * @return Max levels possible for this page size. */ - public int getMaxLevels(ByteBuffer buf) { - return (buf.capacity() - REFS_OFF) / 8; + public int getMaxLevels(int pageSize, long buf) { + return (pageSize - REFS_OFF) / 8; } /** * @param buf Buffer. * @param lvls Number of levels in this tree. */ - public void setLevelsCount(ByteBuffer buf, int lvls) { - assert lvls >= 0 && lvls <= getMaxLevels(buf): lvls; + public void setLevelsCount(int pageSize, long buf, int lvls) { + assert lvls >= 0 && lvls <= getMaxLevels(pageSize, buf) : lvls; - buf.put(LVLS_OFF, (byte)lvls); + PageUtils.putByte(buf, LVLS_OFF, (byte)lvls); assert getLevelsCount(buf) == lvls; } @@ -91,8 +91,8 @@ public class BPlusMetaIO extends PageIO { * @param lvl Level. * @return First page ID at that level. */ - public long getFirstPageId(ByteBuffer buf, int lvl) { - return buf.getLong(offset(lvl)); + public long getFirstPageId(long buf, int lvl) { + return PageUtils.getLong(buf, offset(lvl)); } /** @@ -100,10 +100,10 @@ public class BPlusMetaIO extends PageIO { * @param lvl Level. * @param pageId Page ID. */ - public void setFirstPageId(ByteBuffer buf, int lvl, long pageId) { + public void setFirstPageId(long buf, int lvl, long pageId) { assert lvl >= 0 && lvl < getLevelsCount(buf); - buf.putLong(offset(lvl), pageId); + PageUtils.putLong(buf, offset(lvl), pageId); assert getFirstPageId(buf, lvl) == pageId; } @@ -112,7 +112,7 @@ public class BPlusMetaIO extends PageIO { * @param buf Buffer. * @return Root level. */ - public int getRootLevel(ByteBuffer buf) { + public int getRootLevel(long buf) { int lvls = getLevelsCount(buf); // The highest level page is root. assert lvls > 0 : lvls; @@ -124,19 +124,19 @@ public class BPlusMetaIO extends PageIO { * @param buf Buffer. * @param rootPageId New root page ID. */ - public void addRoot(ByteBuffer buf, long rootPageId) { + public void addRoot(int pageSize, long buf, long rootPageId) { int lvl = getLevelsCount(buf); - setLevelsCount(buf, lvl + 1); + setLevelsCount(pageSize, buf, lvl + 1); setFirstPageId(buf, lvl, rootPageId); } /** * @param buf Buffer. */ - public void cutRoot(ByteBuffer buf) { + public void cutRoot(int pageSize, long buf) { int lvl = getRootLevel(buf); - setLevelsCount(buf, lvl); // Decrease tree height. + setLevelsCount(pageSize, buf, lvl); // Decrease tree height. } } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java index 5e9fd6d..ed75d12 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; /** @@ -58,21 +58,21 @@ public class CacheVersionIO { * @param ver Version to write. * @param allowNull Is {@code null} version allowed. */ - public static void write(ByteBuffer buf, GridCacheVersion ver, boolean allowNull) { + public static void write(long buf, GridCacheVersion ver, boolean allowNull) { if (ver == null) { if (allowNull) - buf.put(NULL_PROTO_VER); + PageUtils.putByte(buf, 0, NULL_PROTO_VER); else throw new IllegalStateException("Cache version is null"); } else { byte protoVer = 1; // Version of serialization protocol. - buf.put(protoVer); - buf.putInt(ver.topologyVersion()); - buf.putInt(ver.nodeOrderAndDrIdRaw()); - buf.putLong(ver.globalTime()); - buf.putLong(ver.order()); + PageUtils.putByte(buf, 0, protoVer); + PageUtils.putInt(buf, 1, ver.topologyVersion()); + PageUtils.putInt(buf, 5, ver.nodeOrderAndDrIdRaw()); + PageUtils.putLong(buf, 9, ver.globalTime()); + PageUtils.putLong(buf, 17, ver.order()); } } @@ -102,8 +102,8 @@ public class CacheVersionIO { * @return Size of serialized version. * @throws IgniteCheckedException If failed. */ - public static int readSize(ByteBuffer buf, boolean allowNull) throws IgniteCheckedException { - byte protoVer = checkProtocolVersion(buf.get(buf.position()), allowNull); + public static int readSize(long buf, boolean allowNull) throws IgniteCheckedException { + byte protoVer = checkProtocolVersion(PageUtils.getByte(buf, 0), allowNull); switch (protoVer) { case NULL_PROTO_VER: @@ -126,16 +126,16 @@ public class CacheVersionIO { * @return Version. * @throws IgniteCheckedException If failed. */ - public static GridCacheVersion read(ByteBuffer buf, boolean allowNull) throws IgniteCheckedException { - byte protoVer = checkProtocolVersion(buf.get(), allowNull); + public static GridCacheVersion read(long buf, boolean allowNull) throws IgniteCheckedException { + byte protoVer = checkProtocolVersion(PageUtils.getByte(buf, 0), allowNull); if (protoVer == NULL_PROTO_VER) return null; - int topVer = buf.getInt(); - int nodeOrderDrId = buf.getInt(); - long globalTime = buf.getLong(); - long order = buf.getLong(); + int topVer = PageUtils.getInt(buf, 1); + int nodeOrderDrId = PageUtils.getInt(buf, 5); + long globalTime = PageUtils.getLong(buf, 9); + long order = PageUtils.getLong(buf, 17); return new GridCacheVersion(topVer, nodeOrderDrId, globalTime, order); } http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java index a69caab..e1bab5f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java @@ -17,12 +17,12 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageIdUtils; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.database.CacheDataRow; import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler; @@ -109,16 +109,16 @@ public class DataPageIO extends PageIO { * @param buf Byte buffer. * @param freeListPageId Free list page ID. */ - public void setFreeListPageId(ByteBuffer buf, long freeListPageId) { - buf.putLong(FREE_LIST_PAGE_ID_OFF, freeListPageId); + public void setFreeListPageId(long buf, long freeListPageId) { + PageUtils.putLong(buf, FREE_LIST_PAGE_ID_OFF, freeListPageId); } /** * @param buf Byte buffer. * @return Free list page ID. */ - public long getFreeListPageId(ByteBuffer buf) { - return buf.getLong(FREE_LIST_PAGE_ID_OFF); + public long getFreeListPageId(long buf) { + return PageUtils.getLong(buf, FREE_LIST_PAGE_ID_OFF); } /** @@ -213,7 +213,7 @@ public class DataPageIO extends PageIO { /** * @return {@code true} If there is no useful data in this page. */ - public boolean isEmpty(ByteBuffer buf) { + public boolean isEmpty(long buf) { return getDirectCount(buf) == 0; } @@ -241,8 +241,8 @@ public class DataPageIO extends PageIO { * @param buf Buffer. * @return Direct count. */ - private int getDirectCount(ByteBuffer buf) { - return buf.get(DIRECT_CNT_OFF) & 0xFF; + private int getDirectCount(long buf) { + return PageUtils.getByte(buf, DIRECT_CNT_OFF) & 0xFF; } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java index bd1139d..f5eb4b0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; - /** * Registry for IO versions. */ @@ -83,7 +81,7 @@ public final class IOVersions<V extends PageIO> { * @param buf Buffer. * @return IO. */ - public V forPage(ByteBuffer buf) { + public V forPage(long buf) { int ver = PageIO.getVersion(buf); V res = forVersion(ver); http://git-wip-us.apache.org/repos/asf/ignite/blob/8fcac6f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java index aa2d368..12646ae 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java @@ -17,9 +17,9 @@ package org.apache.ignite.internal.processors.cache.database.tree.io; -import java.nio.ByteBuffer; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.Page; +import org.apache.ignite.internal.pagemem.PageUtils; import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl; import org.apache.ignite.internal.processors.cache.database.MetadataStorage; @@ -36,10 +36,10 @@ import org.apache.ignite.internal.processors.cache.database.tree.util.PageLockLi * 1. IO should not have any `public static` methods. * We have versioned IOs and any static method will mean that it have to always work in backward * compatible way between all the IO versions. The base class {@link PageIO} has - * static methods (like {@code {@link #getPageId(ByteBuffer)}}) intentionally: + * static methods (like {@code {@link #getPageId(long)}}) intentionally: * this base format can not be changed between versions. * - * 2. IO must correctly override {@link #initNewPage(ByteBuffer, long)} method and call super. + * 2. IO must correctly override {@link #initNewPage(long, long)} method and call super. * We have logic that relies on this behavior. * * 3. Page IO type ID constant must be declared in this class to have a list of all the @@ -166,16 +166,16 @@ public abstract class PageIO { /** * @return Page type. */ - public static int getType(ByteBuffer buf) { - return buf.getShort(TYPE_OFF) & 0xFFFF; + public static int getType(long buf) { + return PageUtils.getShort(buf, TYPE_OFF) & 0xFFFF; } /** * @param buf Buffer. * @param type Type. */ - public static void setType(ByteBuffer buf, int type) { - buf.putShort(TYPE_OFF, (short)type); + public static void setType(long buf, int type) { + PageUtils.putShort(buf, TYPE_OFF, (short)type); assert getType(buf) == type; } @@ -184,16 +184,16 @@ public abstract class PageIO { * @param buf Buffer. * @return Version. */ - public static int getVersion(ByteBuffer buf) { - return buf.getShort(VER_OFF) & 0xFFFF; + public static int getVersion(long buf) { + return PageUtils.getShort(buf, VER_OFF) & 0xFFFF; } /** * @param buf Buffer. * @param ver Version. */ - public static void setVersion(ByteBuffer buf, int ver) { - buf.putShort(VER_OFF, (short)ver); + public static void setVersion(long buf, int ver) { + PageUtils.putShort(buf, VER_OFF, (short)ver); assert getVersion(buf) == ver; } @@ -202,16 +202,16 @@ public abstract class PageIO { * @param buf Buffer. * @return Page ID. */ - public static long getPageId(ByteBuffer buf) { - return buf.getLong(PAGE_ID_OFF); + public static long getPageId(long buf) { + return PageUtils.getLong(buf, PAGE_ID_OFF); } /** * @param buf Buffer. * @param pageId Page ID. */ - public static void setPageId(ByteBuffer buf, long pageId) { - buf.putLong(PAGE_ID_OFF, pageId); + public static void setPageId(long buf, long pageId) { + PageUtils.putLong(buf, PAGE_ID_OFF, pageId); assert getPageId(buf) == pageId; } @@ -220,16 +220,16 @@ public abstract class PageIO { * @param buf Buffer. * @return Checksum. */ - public static int getCrc(ByteBuffer buf) { - return buf.getInt(CRC_OFF); + public static int getCrc(long buf) { + return PageUtils.getInt(buf, CRC_OFF); } /** * @param buf Buffer. * @param crc Checksum. */ - public static void setCrc(ByteBuffer buf, int crc) { - buf.putInt(CRC_OFF, crc); + public static void setCrc(long buf, int crc) { + PageUtils.putInt(buf, CRC_OFF, crc); } /** @@ -275,15 +275,15 @@ public abstract class PageIO { * @param buf Buffer. * @param pageId Page ID. */ - public void initNewPage(ByteBuffer buf, long pageId) { + public void initNewPage(long buf, long pageId) { setType(buf, getType()); setVersion(buf, getVersion()); setPageId(buf, pageId); setCrc(buf, 0); - buf.putLong(RESERVED_1_OFF, 0L); - buf.putLong(RESERVED_2_OFF, 0L); - buf.putLong(RESERVED_3_OFF, 0L); + PageUtils.putLong(buf, RESERVED_1_OFF, 0L); + PageUtils.putLong(buf, RESERVED_2_OFF, 0L); + PageUtils.putLong(buf, RESERVED_3_OFF, 0L); } /** {@inheritDoc} */ @@ -296,7 +296,7 @@ public abstract class PageIO { * @return IO. * @throws IgniteCheckedException If failed. */ - public static <Q extends PageIO> Q getPageIO(ByteBuffer buf) throws IgniteCheckedException { + public static <Q extends PageIO> Q getPageIO(long buf) throws IgniteCheckedException { int type = getType(buf); int ver = getVersion(buf); @@ -343,7 +343,7 @@ public abstract class PageIO { * @return IO for either inner or leaf B+Tree page. * @throws IgniteCheckedException If failed. */ - public static <Q extends BPlusIO<?>> Q getBPlusIO(ByteBuffer buf) throws IgniteCheckedException { + public static <Q extends BPlusIO<?>> Q getBPlusIO(long buf) throws IgniteCheckedException { int type = getType(buf); int ver = getVersion(buf);