You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/12/28 16:12:13 UTC
[4/4] ignite git commit: test
test
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c41f751b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c41f751b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c41f751b
Branch: refs/heads/ignite-11810
Commit: c41f751bedc0e567b54a2e39b286427444d78ca8
Parents: e3420e9
Author: sboikov <sb...@gridgain.com>
Authored: Wed Dec 28 16:15:19 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Dec 28 18:54:43 2016 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryEnumObjectImpl.java | 7 +
.../internal/binary/BinaryObjectImpl.java | 5 +
.../binary/BinaryObjectOffheapImpl.java | 5 +
.../apache/ignite/internal/pagemem/Page.java | 5 -
.../ignite/internal/pagemem/PageUtils.java | 86 +++--
.../internal/pagemem/impl/PageNoStoreImpl.java | 30 +-
.../internal/processors/cache/CacheObject.java | 2 +
.../processors/cache/CacheObjectAdapter.java | 23 ++
.../cache/CacheObjectByteArrayImpl.java | 5 +
.../cache/database/CacheDataRowAdapter.java | 1 +
.../cache/database/DataStructure.java | 12 +-
.../cache/database/MetadataStorage.java | 34 +-
.../cache/database/freelist/FreeListImpl.java | 28 +-
.../cache/database/freelist/PagesList.java | 146 ++++-----
.../cache/database/tree/BPlusTree.java | 316 ++++++++++---------
.../cache/database/tree/io/BPlusIO.java | 136 ++++----
.../cache/database/tree/io/BPlusInnerIO.java | 44 +--
.../cache/database/tree/io/BPlusLeafIO.java | 8 +-
.../cache/database/tree/io/DataPageIO.java | 48 +--
.../cache/database/tree/util/PageHandler.java | 93 +++---
.../internal/GridAffinityNoCacheSelfTest.java | 5 +
.../pagemem/impl/PageMemoryNoLoadSelfTest.java | 16 +-
.../IgniteIncompleteCacheObjectSelfTest.java | 5 +
.../database/FreeListImplSelfTest.java | 135 ++++----
.../query/h2/database/H2TreeIndex.java | 3 +-
.../query/h2/database/io/H2InnerIO.java | 16 +-
.../query/h2/database/io/H2LeafIO.java | 16 +-
.../query/h2/database/io/H2RowLinkIO.java | 4 +-
.../h2/GridIndexingSpiAbstractSelfTest.java | 5 +
29 files changed, 616 insertions(+), 623 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index 7f3f5e4..ef45ecd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -272,6 +272,13 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
}
/** {@inheritDoc} */
+ @Override public int putValue(long addr) throws IgniteCheckedException {
+ assert valBytes != null : "Value bytes must be initialized before object is stored";
+
+ return CacheObjectAdapter.putValue(addr, cacheObjectType(), valBytes, 0);
+ }
+
+ /** {@inheritDoc} */
@Override public boolean putValue(final ByteBuffer buf, int off, int len) throws IgniteCheckedException {
return CacheObjectAdapter.putValue(cacheObjectType(), buf, off, len, valBytes, 0);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index abb84cf..31dd399 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -165,6 +165,11 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
}
/** {@inheritDoc} */
+ @Override public int putValue(long addr) throws IgniteCheckedException {
+ return CacheObjectAdapter.putValue(addr, cacheObjectType(), arr, start);
+ }
+
+ /** {@inheritDoc} */
@Override public boolean putValue(final ByteBuffer buf, int off, int len) throws IgniteCheckedException {
return CacheObjectAdapter.putValue(cacheObjectType(), buf, off, len, arr, start);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 0ac57fd..e2e1f04 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -140,6 +140,11 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
}
/** {@inheritDoc} */
+ @Override public int putValue(long addr) throws IgniteCheckedException {
+ throw new UnsupportedOperationException("TODO implement");
+ }
+
+ /** {@inheritDoc} */
@Override public boolean putValue(final ByteBuffer buf, final int off, final int len)
throws IgniteCheckedException {
throw new UnsupportedOperationException("TODO implement");
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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 5f9d424..eef61c8 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
@@ -66,11 +66,6 @@ public interface Page extends AutoCloseable {
/**
* @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();
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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
index 6f46cd5..c74fd63 100644
--- 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
@@ -28,89 +28,109 @@ public class PageUtils {
/** */
private static final Unsafe unsafe = GridUnsafe.UNSAFE;
- public static byte getByte(long buf, int off) {
- assert buf > 0 : buf;
+ /**
+ * @param addr Start address.
+ * @param off Offset.
+ * @return Byte value from given address.
+ */
+ public static byte getByte(long addr, int off) {
+ assert addr > 0 : addr;
assert off >= 0;
- return unsafe.getByte(buf + off);
+ return unsafe.getByte(addr + off);
}
- public static byte[] getBytes(long buf, int off, int len) {
- assert buf > 0 : buf;
+ /**
+ * @param addr Start address.
+ * @param off Offset.
+ * @param len Bytes length.
+ * @return Bytes from given address.
+ */
+ public static byte[] getBytes(long addr, int off, int len) {
+ assert addr > 0 : addr;
assert off >= 0;
assert len >= 0;
byte[] bytes = new byte[len];
- unsafe.copyMemory(null, buf + off, bytes, GridUnsafe.BYTE_ARR_OFF, len);
+ unsafe.copyMemory(null, addr + off, bytes, GridUnsafe.BYTE_ARR_OFF, len);
return bytes;
}
- public static void getBytes(long src, int srcOff, byte[] dst, int dstOff, int len) {
- assert src > 0;
+ public static void getBytes(long srcAddr, int srcOff, byte[] dst, int dstOff, int len) {
+ assert srcAddr > 0;
assert srcOff > 0;
assert dst != null;
assert dstOff >= 0;
assert len >= 0;
- unsafe.copyMemory(null, src + srcOff, dst, GridUnsafe.BYTE_ARR_OFF + dstOff, len);
+ unsafe.copyMemory(null, srcAddr + srcOff, dst, GridUnsafe.BYTE_ARR_OFF + dstOff, len);
}
- public static short getShort(long buf, int off) {
- assert buf > 0 : buf;
+ public static short getShort(long addr, int off) {
+ assert addr > 0 : addr;
assert off >= 0;
- return unsafe.getShort(buf + off);
+ return unsafe.getShort(addr + off);
}
- public static int getInt(long buf, int off) {
- assert buf > 0 : buf;
+ public static int getInt(long addr, int off) {
+ assert addr > 0 : addr;
assert off >= 0;
- return unsafe.getInt(buf + off);
+ return unsafe.getInt(addr + off);
}
- public static long getLong(long buf, int off) {
- assert buf > 0 : buf;
+ public static long getLong(long addr, int off) {
+ assert addr > 0 : addr;
assert off >= 0;
- return unsafe.getLong(buf + off);
+ return unsafe.getLong(addr + off);
}
- public static void putBytes(long buf, int off, byte[] bytes) {
- assert buf > 0 : buf;
+ public static void putBytes(long addr, int off, byte[] bytes) {
+ assert addr > 0 : addr;
assert off >= 0;
assert bytes != null;
- unsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF, null, buf + off, bytes.length);
+ unsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF, null, addr + off, bytes.length);
}
- public static void putByte(long buf, int off, byte v) {
- assert buf > 0 : buf;
+ public static void putBytes(long addr, int off, byte[] bytes, int bytesOff) {
+ assert addr > 0 : addr;
+ assert off >= 0;
+ assert bytes != null;
+ assert bytesOff >= 0 && bytesOff < bytes.length : bytesOff;
+
+ unsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF + bytesOff, null, addr + off, bytes.length - bytesOff);
+ }
+
+ public static void putByte(long addr, int off, byte v) {
+ assert addr > 0 : addr;
assert off >= 0;
- unsafe.putByte(buf + off, v);
+ unsafe.putByte(addr + off, v);
}
- public static void putShort(long buf, int off, short v) {
- assert buf > 0 : buf;
+ public static void putShort(long addr, int off, short v) {
+ assert addr > 0 : addr;
assert off >= 0;
- unsafe.putShort(buf + off, v);
+ unsafe.putShort(addr + off, v);
}
- public static void putInt(long buf, int off, int v) {
- assert buf > 0 : buf;
+ public static void putInt(long addr, int off, int v) {
+ assert addr > 0 : addr;
assert off >= 0;
- unsafe.putInt(buf + off, v);
+ unsafe.putInt(addr + off, v);
}
- public static void putLong(long buf, int off, long v) {
- assert buf > 0 : buf;
+ public static void putLong(long addr, int off, long v) {
+ assert addr > 0 : addr;
assert off >= 0;
- unsafe.putLong(buf + off, v);
+ unsafe.putLong(addr + off, v);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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 fd59b52..2fa1caf 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
@@ -47,9 +47,6 @@ public class PageNoStoreImpl implements Page {
/** */
private PageMemoryNoStoreImpl pageMem;
- /** */
- private final ByteBuffer buf;
-
/** Page for memory restore */
private final boolean noTagCheck;
@@ -67,8 +64,6 @@ public class PageNoStoreImpl implements Page {
this.cacheId = cacheId;
this.pageId = pageId;
this.noTagCheck = noTagCheck;
-
- buf = pageMem.wrapPointer(absPtr + PageMemoryNoStoreImpl.PAGE_OVERHEAD, pageMem.pageSize());
}
/** {@inheritDoc} */
@@ -92,10 +87,7 @@ public class PageNoStoreImpl implements Page {
/** {@inheritDoc} */
@Override public ByteBuffer getForRead() {
- if (pageMem.readLockPage(absPtr, PageIdUtils.tag(pageId)))
- return reset(buf.asReadOnlyBuffer());
-
- return null;
+ throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
@@ -113,15 +105,7 @@ public class PageNoStoreImpl implements Page {
/** {@inheritDoc} */
@Override public ByteBuffer getForWrite() {
- int tag = noTagCheck ? OffheapReadWriteLock.TAG_LOCK_ALWAYS : PageIdUtils.tag(pageId);
- boolean locked = pageMem.writeLockPage(absPtr, tag);
-
- if (!locked && !noTagCheck)
- return null;
-
- assert locked;
-
- return reset(buf);
+ throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
@@ -148,16 +132,6 @@ public class PageNoStoreImpl implements Page {
}
/** {@inheritDoc} */
- @Override public ByteBuffer tryGetForWrite() {
- int tag = noTagCheck ? OffheapReadWriteLock.TAG_LOCK_ALWAYS : PageIdUtils.tag(pageId);
-
- if (pageMem.tryWriteLockPage(absPtr, tag))
- return reset(buf);
-
- return null;
- }
-
- /** {@inheritDoc} */
@Override public void releaseWrite(boolean markDirty) {
long updatedPageId = PageIO.getPageId(pointer());
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index 92b72ce..b5604cd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -67,6 +67,8 @@ public interface CacheObject extends Message {
*/
public boolean putValue(ByteBuffer buf) throws IgniteCheckedException;
+ public int putValue(long addr) throws IgniteCheckedException;
+
/**
* @param buf Buffer to write value to.
* @param off Offset in source binary data.
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
index 1394fc2..43cb016 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
@@ -24,6 +24,7 @@ import java.io.ObjectOutput;
import java.nio.ByteBuffer;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.pagemem.PageUtils;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.plugin.extensions.communication.MessageReader;
@@ -77,6 +78,28 @@ public abstract class CacheObjectAdapter implements CacheObject, Externalizable
}
/** {@inheritDoc} */
+ @Override public int putValue(long addr) throws IgniteCheckedException {
+ assert valBytes != null : "Value bytes must be initialized before object is stored";
+
+ return putValue(addr, cacheObjectType(), valBytes, 0);
+ }
+
+ public static int putValue(long addr, byte type, byte[] valBytes, int valOff) {
+ int off = 0;
+
+ PageUtils.putInt(addr, off, valBytes.length);
+ off += 4;
+
+ PageUtils.putByte(addr, off, type);
+ off++;
+
+ PageUtils.putBytes(addr, off, valBytes, valOff);
+ off += valBytes.length - valOff;
+
+ return off;
+ }
+
+ /** {@inheritDoc} */
@Override public boolean putValue(final ByteBuffer buf, int off, int len) throws IgniteCheckedException {
assert valBytes != null : "Value bytes must be initialized before object is stored";
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
index b3a4117..eee6fcc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
@@ -82,6 +82,11 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
}
/** {@inheritDoc} */
+ @Override public int putValue(long addr) throws IgniteCheckedException {
+ return CacheObjectAdapter.putValue(addr, cacheObjectType(), val, 0);
+ }
+
+ /** {@inheritDoc} */
@Override public boolean putValue(final ByteBuffer buf, int off, int len) throws IgniteCheckedException {
assert val != null : "Value is not initialized";
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
index 38b19a1..c989eee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
@@ -70,6 +70,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
// Link can be 0 here.
this.link = link;
}
+
/**
* Read row from data pages.
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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 ce5422f..7997e6f 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
@@ -131,7 +131,7 @@ public abstract class DataStructure implements PageLockListener {
/**
* @param page Page.
- * @return Buffer.
+ * @return Page address.
*/
protected final long tryWriteLock(Page page) {
return PageHandler.writeLock(page, this, true);
@@ -140,7 +140,7 @@ public abstract class DataStructure implements PageLockListener {
/**
* @param page Page.
- * @return Buffer.
+ * @return Page address.
*/
protected final long writeLock(Page page) {
return PageHandler.writeLock(page, this, false);
@@ -148,16 +148,16 @@ public abstract class DataStructure implements PageLockListener {
/**
* @param page Page.
- * @param buf Buffer.
+ * @param pageAddr Page address.
* @param dirty Dirty page.
*/
- protected final void writeUnlock(Page page, long buf, boolean dirty) {
- PageHandler.writeUnlock(page, buf, this, dirty);
+ protected final void writeUnlock(Page page, long pageAddr, boolean dirty) {
+ PageHandler.writeUnlock(page, pageAddr, this, dirty);
}
/**
* @param page Page.
- * @return Buffer.
+ * @return Page address.
*/
protected final long readLock(Page page) {
return PageHandler.readLock(page, this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java
index b19d03d..d1d5ba9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MetadataStorage.java
@@ -198,12 +198,12 @@ public class MetadataStorage implements MetaStore {
int shift = 0;
// Compare index names.
- final byte len = PageUtils.getByte(off, shift);
+ final byte len = PageUtils.getByte(buf, off + shift);
shift += BYTE_LEN;
for (int i = 0; i < len && i < row.idxName.length; i++) {
- final int cmp = Byte.compare(PageUtils.getByte(off, i + shift), row.idxName[i]);
+ final int cmp = Byte.compare(PageUtils.getByte(buf, off + i + shift), row.idxName[i]);
if (cmp != 0)
return cmp;
@@ -253,17 +253,19 @@ public class MetadataStorage implements MetaStore {
*/
private static void storeRow(
final long buf,
- final int off,
+ int off,
final IndexItem row
) {
// Index name length.
PageUtils.putByte(buf, off, (byte)row.idxName.length);
+ off++;
// Index name.
- PageUtils.putBytes(buf, off + 1, row.idxName);
+ PageUtils.putBytes(buf, off, row.idxName);
+ off += row.idxName.length;
// Page ID.
- PageUtils.putLong(buf, off + 1 + row.idxName.length, row.pageId);
+ PageUtils.putLong(buf, off, row.pageId);
}
/**
@@ -276,19 +278,23 @@ public class MetadataStorage implements MetaStore {
*/
private static void storeRow(
final long dst,
- final int dstOff,
+ int dstOff,
final long src,
- final int srcOff
+ int srcOff
) {
// Index name length.
final byte len = PageUtils.getByte(src, srcOff);
+ srcOff++;
PageUtils.putByte(dst, dstOff, len);
+ dstOff++;
- PageHandler.copyMemory(src, srcOff + 1, dst, dstOff + 1, len);
+ PageHandler.copyMemory(src, srcOff, dst, dstOff, len);
+ srcOff += len;
+ dstOff += len;
// Page ID.
- PageUtils.putLong(dst, dstOff + 1 + len, PageUtils.getLong(src, srcOff + 1 + len));
+ PageUtils.putLong(dst, dstOff, PageUtils.getLong(src, srcOff));
}
/**
@@ -298,15 +304,17 @@ public class MetadataStorage implements MetaStore {
* @param off Offset in buf.
* @return Read row.
*/
- private static IndexItem readRow(final long buf, final int off) {
+ private static IndexItem readRow(final long buf, int off) {
// Index name length.
- final int len = PageUtils.getByte(buf, 0) & 0xFF;
+ final int len = PageUtils.getByte(buf, off) & 0xFF;
+ off++;
// Index name.
- final byte[] idxName = PageUtils.getBytes(buf, 1, len);
+ final byte[] idxName = PageUtils.getBytes(buf, off, len);
+ off += len;
// Page ID.
- final long pageId = PageUtils.getLong(buf, off + 1 + len);
+ final long pageId = PageUtils.getLong(buf, off);
return new IndexItem(idxName, pageId);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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 c40656e..5b3e781 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
@@ -73,26 +73,26 @@ 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, long buf, CacheDataRow row, int written)
+ @Override public Integer run(Page page, PageIO iox, long pageAddr, CacheDataRow row, int written)
throws IgniteCheckedException {
DataPageIO io = (DataPageIO)iox;
int rowSize = getRowSize(row);
- int oldFreeSpace = io.getFreeSpace(buf);
+ int oldFreeSpace = io.getFreeSpace(pageAddr);
assert oldFreeSpace > 0 : oldFreeSpace;
// If the full row does not fit into this page write only a fragment.
- written = (written == 0 && oldFreeSpace >= rowSize) ? addRow(page, buf, io, row, rowSize):
- addRowFragment(page, buf, io, row, written, rowSize);
+ written = (written == 0 && oldFreeSpace >= rowSize) ? addRow(page, pageAddr, io, row, rowSize):
+ addRowFragment(page, pageAddr, io, row, written, rowSize);
// Reread free space after update.
- int newFreeSpace = io.getFreeSpace(buf);
+ int newFreeSpace = io.getFreeSpace(pageAddr);
if (newFreeSpace > MIN_PAGE_FREE_SPACE) {
int bucket = bucket(newFreeSpace, false);
- put(null, page, buf, bucket);
+ put(null, page, pageAddr, bucket);
}
// Avoid boxing with garbage generation for usual case.
@@ -159,7 +159,7 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList {
int payloadSize = io.addRowFragment(buf, row, written, rowSize, pageSize());
- assert payloadSize > 0: payloadSize;
+ assert payloadSize > 0 : payloadSize;
if (isWalDeltaRecordNeeded(wal, page)) {
// TODO This record must contain only a reference to a logical WAL record with the actual data.
@@ -178,15 +178,15 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList {
/** */
private final PageHandler<Void, Long> rmvRow = new PageHandler<Void, Long>() {
- @Override public Long run(Page page, PageIO iox, long buf, Void arg, int itemId)
+ @Override public Long run(Page page, PageIO iox, long pageAddr, Void arg, int itemId)
throws IgniteCheckedException {
DataPageIO io = (DataPageIO)iox;
- int oldFreeSpace = io.getFreeSpace(buf);
+ int oldFreeSpace = io.getFreeSpace(pageAddr);
assert oldFreeSpace >= 0: oldFreeSpace;
- long nextLink = io.removeRow(buf, itemId, pageSize());
+ long nextLink = io.removeRow(pageAddr, itemId, pageSize());
if (isWalDeltaRecordNeeded(wal, page))
wal.log(new DataPageRemoveRecord(cacheId, page.id(), itemId));
@@ -199,7 +199,7 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList {
// put(null, page, buf, REUSE_BUCKET);
// }
- int newFreeSpace = io.getFreeSpace(buf);
+ int newFreeSpace = io.getFreeSpace(pageAddr);
if (newFreeSpace > MIN_PAGE_FREE_SPACE) {
int newBucket = bucket(newFreeSpace, false);
@@ -209,12 +209,12 @@ public class FreeListImpl extends PagesList implements FreeList, ReuseList {
if (oldBucket != newBucket) {
// It is possible that page was concurrently taken for put, in this case put will handle bucket change.
- if (removeDataPage(page, buf, io, oldBucket))
- put(null, page, buf, newBucket);
+ if (removeDataPage(page, pageAddr, io, oldBucket))
+ put(null, page, pageAddr, newBucket);
}
}
else
- put(null, page, buf, newBucket);
+ put(null, page, pageAddr, newBucket);
}
// For common case boxed 0L will be cached inside of Long, so no garbage will be produced.
http://git-wip-us.apache.org/repos/asf/ignite/blob/c41f751b/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 91f2ba5..9e7f9ff 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,17 +85,17 @@ public abstract class PagesList extends DataStructure {
/** */
private final PageHandler<Void, Boolean> cutTail = new PageHandler<Void, Boolean>() {
- @Override public Boolean run(Page page, PageIO pageIo, long buf, Void ignore, int bucket)
+ @Override public Boolean run(Page page, PageIO pageIo, long pageAddr, Void ignore, int bucket)
throws IgniteCheckedException {
- assert getPageId(buf) == page.id();
+ assert getPageId(pageAddr) == page.id();
PagesListNodeIO io = (PagesListNodeIO)pageIo;
- long tailId = io.getNextId(buf);
+ long tailId = io.getNextId(pageAddr);
assert tailId != 0;
- io.setNextId(buf, 0L);
+ io.setNextId(pageAddr, 0L);
if (isWalDeltaRecordNeeded(wal, page))
wal.log(new PagesListSetNextRecord(cacheId, page.id(), 0L));
@@ -149,16 +149,16 @@ public abstract class PagesList extends DataStructure {
while (nextPageId != 0) {
try (Page page = page(nextPageId)) {
- long buf = readLock(page); // No concurrent recycling on init.
+ long pageAddr = readLock(page); // No concurrent recycling on init.
- assert buf != 0L;
+ assert pageAddr != 0L;
try {
- PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(buf);
+ PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(pageAddr);
- io.getBucketsData(buf, bucketsData);
+ io.getBucketsData(pageAddr, bucketsData);
- long next0 = io.getNextMetaPageId(buf);
+ long next0 = io.getNextMetaPageId(pageAddr);
assert next0 != nextPageId :
"Loop detected [next=" + U.hexLong(next0) + ", cur=" + U.hexLong(nextPageId) + ']';
@@ -166,7 +166,7 @@ public abstract class PagesList extends DataStructure {
nextPageId = next0;
}
finally {
- readUnlock(page, buf);
+ readUnlock(page, pageAddr);
}
}
}
@@ -198,7 +198,7 @@ public abstract class PagesList extends DataStructure {
assert metaPageId != 0;
Page curPage = null;
- long curBuf = 0L;
+ long curPageAddr = 0L;
PagesListMetaIO curIo = null;
long nextPageId = metaPageId;
@@ -211,39 +211,39 @@ public abstract class PagesList extends DataStructure {
int tailIdx = 0;
while (tailIdx < tails.length) {
- int written = curPage != null ? curIo.addTails(pageMem.pageSize(), curBuf, bucket, tails, tailIdx) : 0;
+ int written = curPage != null ? curIo.addTails(pageMem.pageSize(), curPageAddr, bucket, tails, tailIdx) : 0;
if (written == 0) {
if (nextPageId == 0L) {
nextPageId = allocatePageNoReuse();
if (curPage != null) {
- curIo.setNextMetaPageId(curBuf, nextPageId);
+ curIo.setNextMetaPageId(curPageAddr, nextPageId);
- releaseAndClose(curPage, curBuf);
+ releaseAndClose(curPage, curPageAddr);
curPage = null;
}
curPage = page(nextPageId);
- curBuf = writeLock(curPage);
+ curPageAddr = writeLock(curPage);
curIo = PagesListMetaIO.VERSIONS.latest();
- curIo.initNewPage(curBuf, nextPageId, pageSize());
+ curIo.initNewPage(curPageAddr, nextPageId, pageSize());
}
else {
- releaseAndClose(curPage, curBuf);
+ releaseAndClose(curPage, curPageAddr);
curPage = null;
curPage = page(nextPageId);
- curBuf = writeLock(curPage);
+ curPageAddr = writeLock(curPage);
- curIo = PagesListMetaIO.VERSIONS.forPage(curBuf);
+ curIo = PagesListMetaIO.VERSIONS.forPage(curPageAddr);
- curIo.resetCount(curBuf);
+ curIo.resetCount(curPageAddr);
}
- nextPageId = curIo.getNextMetaPageId(curBuf);
+ nextPageId = curIo.getNextMetaPageId(curPageAddr);
}
else
tailIdx += written;
@@ -252,22 +252,22 @@ public abstract class PagesList extends DataStructure {
}
}
finally {
- releaseAndClose(curPage, curBuf);
+ releaseAndClose(curPage, curPageAddr);
}
while (nextPageId != 0L) {
try (Page page = page(nextPageId)) {
- long buf = writeLock(page);
+ long pageAddr = writeLock(page);
try {
- PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(buf);
+ PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(pageAddr);
- io.resetCount(buf);
+ io.resetCount(pageAddr);
- nextPageId = io.getNextMetaPageId(buf);
+ nextPageId = io.getNextMetaPageId(pageAddr);
}
finally {
- writeUnlock(page, buf, true);
+ writeUnlock(page, pageAddr, true);
}
}
}
@@ -462,19 +462,19 @@ public abstract class PagesList extends DataStructure {
long pageId = tail.tailId;
try (Page page = page(pageId)) {
- long buf = readLock(page); // No correctness guaranties.
+ long pageAddr = readLock(page); // No correctness guaranties.
try {
- PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(buf);
+ PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
- int cnt = io.getCount(buf);
+ int cnt = io.getCount(pageAddr);
assert cnt >= 0;
res += cnt;
}
finally {
- readUnlock(page, buf);
+ readUnlock(page, pageAddr);
}
}
}
@@ -627,17 +627,17 @@ public abstract class PagesList extends DataStructure {
long nextId = allocatePage(null);
try (Page next = page(nextId)) {
- long nextBuf = writeLock(next); // Newly allocated page.
+ long nextPageAddr = writeLock(next); // Newly allocated page.
- assert nextBuf != 0L;
+ assert nextPageAddr != 0L;
try {
- setupNextPage(io, pageId, buf, nextId, nextBuf);
+ setupNextPage(io, pageId, buf, nextId, nextPageAddr);
if (isWalDeltaRecordNeeded(wal, page))
wal.log(new PagesListSetNextRecord(cacheId, pageId, nextId));
- int idx = io.addPage(nextBuf, dataPageId, pageSize());
+ int idx = io.addPage(nextPageAddr, dataPageId, pageSize());
// Here we should never write full page, because it is known to be new.
next.fullPageWalRecordPolicy(FALSE);
@@ -663,7 +663,7 @@ public abstract class PagesList extends DataStructure {
updateTail(bucket, pageId, nextId);
}
finally {
- writeUnlock(next, nextBuf, true);
+ writeUnlock(next, nextPageAddr, true);
}
}
}
@@ -704,9 +704,9 @@ public abstract class PagesList extends DataStructure {
if (idx == -1) { // Attempt to add page failed: the node page is full.
try (Page next = page(nextId)) {
- long nextBuf = writeLock(next); // Page from reuse bag can't be concurrently recycled.
+ long nextPageAddr = writeLock(next); // Page from reuse bag can't be concurrently recycled.
- assert nextBuf != 0L;
+ assert nextPageAddr != 0L;
if (locked == null) {
lockedBufs = new ArrayList<>(2);
@@ -714,9 +714,9 @@ public abstract class PagesList extends DataStructure {
}
locked.add(next);
- lockedBufs.add(nextBuf);
+ lockedBufs.add(nextPageAddr);
- setupNextPage(io, prevId, prevBuf, nextId, nextBuf);
+ setupNextPage(io, prevId, prevBuf, nextId, nextPageAddr);
if (isWalDeltaRecordNeeded(wal, page))
wal.log(new PagesListSetNextRecord(cacheId, prevId, nextId));
@@ -737,7 +737,7 @@ public abstract class PagesList extends DataStructure {
// Switch to this new page, which is now a part of our list
// to add the rest of the bag to the new page.
- prevBuf = nextBuf;
+ prevBuf = nextPageAddr;
prevId = nextId;
page = next;
}
@@ -780,15 +780,15 @@ public abstract class PagesList extends DataStructure {
* @param page Page.
* @param bucket Bucket.
* @param lockAttempt Lock attempts counter.
- * @return Buffer if page is locket of {@code null} if can retry lock.
+ * @return Page address if page is locked of {@code null} if can retry lock.
* @throws IgniteCheckedException If failed.
*/
private long writeLockPage(Page page, int bucket, int lockAttempt)
throws IgniteCheckedException {
- long buf = tryWriteLock(page);
+ long pageAddr = tryWriteLock(page);
- if (buf != 0L)
- return buf;
+ if (pageAddr != 0L)
+ return pageAddr;
if (lockAttempt == TRY_LOCK_ATTEMPTS) {
Stripe[] stripes = getBucket(bucket);
@@ -943,17 +943,17 @@ public abstract class PagesList extends DataStructure {
long recycleId = 0L;
- long buf = writeLock(page); // Explicit check.
+ long pageAddr = writeLock(page); // Explicit check.
- if (buf == 0L)
+ if (pageAddr == 0L)
return false;
boolean rmvd = false;
try {
- PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(buf);
+ PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
- rmvd = io.removePage(buf, dataPageId);
+ rmvd = io.removePage(pageAddr, dataPageId);
if (!rmvd)
return false;
@@ -967,20 +967,20 @@ public abstract class PagesList extends DataStructure {
if (isWalDeltaRecordNeeded(wal, dataPage))
wal.log(new DataPageSetFreeListPageRecord(cacheId, dataPageId, 0L));
- if (!io.isEmpty(buf))
+ if (!io.isEmpty(pageAddr))
return true; // In optimistic case we still have something in the page and can leave it as is.
// If the page is empty, we have to try to drop it and link next and previous with each other.
- nextId = io.getNextId(buf);
- prevId = io.getPreviousId(buf);
+ nextId = io.getNextId(pageAddr);
+ prevId = io.getPreviousId(pageAddr);
// If there are no next page, then we can try to merge without releasing current write lock,
// because if we will need to lock previous page, the locking order will be already correct.
if (nextId == 0L)
- recycleId = mergeNoNext(pageId, page, buf, prevId, bucket);
+ recycleId = mergeNoNext(pageId, page, pageAddr, prevId, bucket);
}
finally {
- writeUnlock(page, buf, rmvd);
+ writeUnlock(page, pageAddr, rmvd);
}
// Perform a fair merge after lock release (to have a correct locking order).
@@ -1040,25 +1040,25 @@ public abstract class PagesList extends DataStructure {
try (Page next = nextId == 0L ? null : page(nextId)) {
boolean write = false;
- long nextBuf = next == null ? 0L : writeLock(next); // Explicit check.
- long buf = writeLock(page); // Explicit check.
+ long nextPageAddr = next == null ? 0L : writeLock(next); // Explicit check.
+ long pageAddr = writeLock(page); // Explicit check.
- if (buf == 0L) {
- if (nextBuf != 0L) // Unlock next page if needed.
- writeUnlock(next, nextBuf, false);
+ if (pageAddr == 0L) {
+ if (nextPageAddr != 0L) // Unlock next page if needed.
+ writeUnlock(next, nextPageAddr, false);
return 0L; // Someone has merged or taken our empty page concurrently. Nothing to do here.
}
try {
- PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(buf);
+ PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
- if (!io.isEmpty(buf))
+ if (!io.isEmpty(pageAddr))
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 == 0L)) {
- long recycleId = doMerge(pageId, page, buf, io, next, nextId, nextBuf, bucket);
+ if (io.getNextId(pageAddr) == nextId && (nextId == 0L) == (nextPageAddr == 0L)) {
+ long recycleId = doMerge(pageId, page, pageAddr, io, next, nextId, nextPageAddr, bucket);
write = true;
@@ -1066,13 +1066,13 @@ public abstract class PagesList extends DataStructure {
}
// Reread next page ID and go for retry.
- nextId = io.getNextId(buf);
+ nextId = io.getNextId(pageAddr);
}
finally {
- if (nextBuf != 0L)
- writeUnlock(next, nextBuf, write);
+ if (nextPageAddr != 0L)
+ writeUnlock(next, nextPageAddr, write);
- writeUnlock(page, buf, write);
+ writeUnlock(page, pageAddr, write);
}
}
}
@@ -1142,19 +1142,19 @@ public abstract class PagesList extends DataStructure {
long nextBuf)
throws IgniteCheckedException {
try (Page prev = page(prevId)) {
- long prevBuf = writeLock(prev); // No check, we keep a reference.
+ long prevPageAddr = writeLock(prev); // No check, we keep a reference.
- assert prevBuf != 0L;
+ assert prevPageAddr != 0L;
try {
- PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevBuf);
+ PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevPageAddr);
PagesListNodeIO nextIO = PagesListNodeIO.VERSIONS.forPage(nextBuf);
// These references must be updated at the same time in write locks.
- assert prevIO.getNextId(prevBuf) == pageId;
+ assert prevIO.getNextId(prevPageAddr) == pageId;
assert nextIO.getPreviousId(nextBuf) == pageId;
- prevIO.setNextId(prevBuf, nextId);
+ prevIO.setNextId(prevPageAddr, nextId);
if (isWalDeltaRecordNeeded(wal, prev))
wal.log(new PagesListSetNextRecord(cacheId, prevId, nextId));
@@ -1165,7 +1165,7 @@ public abstract class PagesList extends DataStructure {
wal.log(new PagesListSetPreviousRecord(cacheId, nextId, prevId));
}
finally {
- writeUnlock(prev, prevBuf, true);
+ writeUnlock(prev, prevPageAddr, true);
}
}
}