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 2017/01/18 13:44:07 UTC
[50/50] [abbrv] ignite git commit: Do not init old value when not
needed.
Do not init old value when not needed.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/13bb2de7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/13bb2de7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/13bb2de7
Branch: refs/heads/ignite-gg-11810-2
Commit: 13bb2de70feb1ca35616ab9a418fc33006127d11
Parents: adeb943
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jan 18 16:12:12 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jan 18 16:43:02 2017 +0300
----------------------------------------------------------------------
.../cache/IgniteCacheOffheapManagerImpl.java | 47 +++----
.../cache/database/tree/BPlusTree.java | 139 ++++++++-----------
.../query/h2/database/H2TreeIndex.java | 21 ++-
.../query/h2/opt/GridH2IndexBase.java | 21 ++-
.../processors/query/h2/opt/GridH2Table.java | 2 +-
5 files changed, 119 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/13bb2de7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
index 43ccbaa..9221990 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
@@ -900,7 +900,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
assert dataRow.link() != 0 : dataRow;
- Long old = dataTree.put(dataRow, CacheDataTree.linkC);
+ CacheDataRow old = dataTree.put(dataRow);
if (old == null)
storageSize.incrementAndGet();
@@ -910,19 +910,19 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
assert qryMgr.enabled();
-// if (old != null)
-// qryMgr.store(key, p, old.value(), old.version(), val, ver, expireTime, dataRow.link());
-// else
-// qryMgr.store(key, p, null, null, val, ver, expireTime, dataRow.link());
+ if (old != null)
+ qryMgr.store(key, p, old.value(), old.version(), val, ver, expireTime, dataRow.link());
+ else
+ qryMgr.store(key, p, null, null, val, ver, expireTime, dataRow.link());
}
if (old != null) {
-// assert old.link() != 0 : old;
-//
-// if (pendingEntries != null && old.expireTime() != 0)
-// pendingEntries.remove(new PendingRow(old.expireTime(), old.link()));
+ assert old.link() != 0 : old;
+
+ if (pendingEntries != null && old.expireTime() != 0)
+ pendingEntries.removex(new PendingRow(old.expireTime(), old.link()));
- rowStore.removeRow(old);
+ rowStore.removeRow(old.link());
}
if (pendingEntries != null && expireTime != 0)
@@ -948,7 +948,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
assert dataRow.link() != 0 : dataRow;
if (pendingEntries != null && dataRow.expireTime() != 0)
- pendingEntries.remove(new PendingRow(dataRow.expireTime(), dataRow.link()));
+ pendingEntries.removex(new PendingRow(dataRow.expireTime(), dataRow.link()));
storageSize.decrementAndGet();
@@ -1147,13 +1147,6 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
/** */
private final GridCacheContext cctx;
- /** */
- private static final BPlusTree.RowClosure<CacheSearchRow, Long> linkC = new RowClosure<CacheSearchRow, Long>() {
- @Override public Long oldRow(BPlusIO<CacheSearchRow> io, long pageAddr, int idx) throws IgniteCheckedException {
- return ((RowLinkIO)io).getLink(pageAddr, idx);
- }
- };
-
/**
* @param name Tree name.
* @param reuseList Reuse list.
@@ -1238,11 +1231,14 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
int len = PageUtils.getInt(addr, 0);
- int size = Math.min(bytes.length, len);
+ int lenCmp = Integer.compare(len, bytes.length);
+
+ if (lenCmp != 0)
+ return lenCmp;
addr += 5; // Skip length and type byte.
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < len; i++) {
byte b1 = PageUtils.getByte(addr, i);
byte b2 = bytes[i];
@@ -1250,7 +1246,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
return b1 > b2 ? 1 : -1;
}
- return Integer.compare(len, bytes.length);
+ return 0;
}
}
finally {
@@ -1265,9 +1261,12 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
byte[] bytes1 = other.key().valueBytes(cctx.cacheObjectContext());
byte[] bytes2 = key.valueBytes(cctx.cacheObjectContext());
- int len = Math.min(bytes1.length, bytes2.length);
+ int lenCmp = Integer.compare(bytes1.length, bytes2.length);
+
+ if (lenCmp != 0)
+ return lenCmp;
- for (int i = 0; i < len; i++) {
+ for (int i = 0; i < bytes1.length; i++) {
byte b1 = bytes1[i];
byte b2 = bytes2[i];
@@ -1275,7 +1274,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple
return b1 > b2 ? 1 : -1;
}
- return Integer.compare(bytes1.length, bytes2.length);
+ return 0;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/13bb2de7/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 6aa41c3..9c50fac 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
@@ -106,6 +106,9 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
private final long metaPageId;
/** */
+ private volatile TreeMetaData treeMeta;
+
+ /** */
private final boolean canGetRowFromInner;
/** */
@@ -118,26 +121,6 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
private final AtomicLong globalRmvId;
/** */
- private final RowClosure<L, T> oldRowC = new RowClosure<L, T>() {
- @Override public T oldRow(BPlusIO<L> io, long pageAddr, int idx) throws IgniteCheckedException {
- return getRow(io, pageAddr, idx);
- }
- };
-
- public RowClosure<L, T> noOldValue() {
- return (RowClosure)NO_OLD_VAL;
- }
-
- private static final BPlusTree.RowClosure<Object, Object> NO_OLD_VAL = new RowClosure<Object, Object>() {
- @Override public Object oldRow(BPlusIO<Object> io, long pageAddr, int idx) throws IgniteCheckedException {
- return null;
- }
- };
-
- /** */
- private volatile TreeMetaData treeMeta;
-
- /** */
private final GridTreePrinter<Long> treePrinter = new GridTreePrinter<Long>() {
/** */
private boolean keys = true;
@@ -339,7 +322,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
assert p.oldRow == null;
// Get old row in leaf page to reduce contention at upper level.
- p.oldRow = p.oldRowC.oldRow(io, pageAddr, idx);
+ p.oldRow = p.needOld ? getRow(io, pageAddr, idx) : (T)Boolean.TRUE;
p.finish();
@@ -1309,13 +1292,12 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
/**
* @param row Lookup row.
- * @param bag Reuse bag.
* @return Removed row.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unused")
- public final T removeCeil(L row, ReuseBag bag) throws IgniteCheckedException {
- return doRemove(row, true, bag);
+ public final T removeCeil(L row) throws IgniteCheckedException {
+ return doRemove(row, true, true);
}
/**
@@ -1324,20 +1306,31 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
* @throws IgniteCheckedException If failed.
*/
@Override public final T remove(L row) throws IgniteCheckedException {
- return doRemove(row, false, null);
+ return doRemove(row, false, true);
+ }
+
+ /**
+ * @param row Lookup row.
+ * @throws IgniteCheckedException If failed.
+ * @return {@code True} if removed row.
+ */
+ public final boolean removex(L row) throws IgniteCheckedException {
+ Boolean res = (Boolean)doRemove(row, false, false);
+
+ return res != null ? res : false;
}
/**
* @param row Lookup row.
* @param ceil If we can remove ceil row when we can not find exact.
- * @param bag Reuse bag.
+ * @param needOld {@code True} if need return removed row.
* @return Removed row.
* @throws IgniteCheckedException If failed.
*/
- private T doRemove(L row, boolean ceil, ReuseBag bag) throws IgniteCheckedException {
+ private T doRemove(L row, boolean ceil, boolean needOld) throws IgniteCheckedException {
checkDestroyed();
- Remove r = new Remove(row, ceil, bag);
+ Remove r = new Remove(row, ceil, needOld);
try {
for (;;) {
@@ -1372,7 +1365,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
assert r.isFinished();
- return r.removed;
+ return r.rmvd;
}
}
}
@@ -1581,33 +1574,31 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
* {@inheritDoc}
*/
@Override public final T put(T row) throws IgniteCheckedException {
- return put(row, (ReuseBag)null);
- }
-
- public void putx(T row) throws IgniteCheckedException {
- put(row, noOldValue());
- }
-
- public final <R> R put(T row, RowClosure<L, R> c) throws IgniteCheckedException {
- Put p = new Put(row, null, c);
-
- return (R)put0(p);
+ return put(row, true);
}
- public final T put(T row, ReuseBag bag) throws IgniteCheckedException {
- Put p = new Put(row, bag, oldRowC);
+ /**
+ * @param row New value.
+ * @throws IgniteCheckedException If failed.
+ * @return {@code True} if replaced existing row.
+ */
+ public boolean putx(T row) throws IgniteCheckedException {
+ Boolean res = (Boolean)put(row, false);
- return (T)put0(p);
+ return res != null ? res : false;
}
/**
- * @param p Put operation.
+ * @param row New value.
+ * @param needOld {@code True} If need return old value.
* @return Old row.
* @throws IgniteCheckedException If failed.
*/
- private Object put0(Put p) throws IgniteCheckedException {
+ private T put(T row, boolean needOld) throws IgniteCheckedException {
checkDestroyed();
+ Put p = new Put(row, needOld);
+
try {
for (;;) { // Go down with retries.
p.init();
@@ -1642,13 +1633,13 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
}
}
catch (IgniteCheckedException e) {
- throw new IgniteCheckedException("Runtime failure on row: " + p.row, e);
+ throw new IgniteCheckedException("Runtime failure on row: " + row, e);
}
catch (RuntimeException e) {
- throw new IgniteException("Runtime failure on row: " + p.row, e);
+ throw new IgniteException("Runtime failure on row: " + row, e);
}
catch (AssertionError e) {
- throw new AssertionError("Assertion error on row: " + p.row, e);
+ throw new AssertionError("Assertion error on row: " + row, e);
}
}
@@ -2125,7 +2116,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
private long rightId;
/** Replaced row if any. */
- private Object oldRow;
+ private T oldRow;
/**
* This page is kept locked after split until insert to the upper level will not be finished.
@@ -2146,20 +2137,16 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
Bool needReplaceInner = FALSE;
/** */
- private ReuseBag bag;
-
- /** */
- private final RowClosure<L, ?> oldRowC;
+ private final boolean needOld;
/**
* @param row Row.
- * @param bag Reuse bag.
+ * @param needOld {@code True} If need return old value.
*/
- private Put(T row, ReuseBag bag, RowClosure<L, ?> oldRowC) {
+ private Put(T row, boolean needOld) {
super(row);
- this.bag = bag;
- this.oldRowC = oldRowC;
+ this.needOld = needOld;
}
/** {@inheritDoc} */
@@ -2268,7 +2255,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
*/
private L insertWithSplit(Page page, BPlusIO<L> io, final long pageAddr, int idx, int lvl)
throws IgniteCheckedException {
- long fwdId = allocatePage(bag);
+ long fwdId = allocatePage(null);
try (Page fwd = page(fwdId)) {
// Need to check this before the actual split, because after the split we will have new forward page here.
@@ -2315,7 +2302,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
}
if (!hadFwd && lvl == getRootLevel()) { // We are splitting root.
- long newRootId = allocatePage(bag);
+ long newRootId = allocatePage(null);
try (Page newRoot = page(newRootId)) {
if (io.isLeaf())
@@ -2384,7 +2371,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
Bool needMergeEmptyBranch = FALSE;
/** Removed row. */
- private T removed;
+ private T rmvd;
/** Current page. */
private Page page;
@@ -2393,31 +2380,23 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
private Object freePages;
/** */
- private ReuseBag bag;
+ private final boolean needOld;
/**
* @param row Row.
* @param ceil If we can remove ceil row when we can not find exact.
+ * @param needOld {@code True} If need return old value.
*/
- private Remove(L row, boolean ceil, ReuseBag bag) {
+ private Remove(L row, boolean ceil, boolean needOld) {
super(row);
this.ceil = ceil;
- this.bag = bag;
- }
-
- /**
- * @return Reuse bag.
- */
- private ReuseBag bag() {
- return bag != null ? bag : this;
+ this.needOld = needOld;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public long pollFreePage() {
- assert bag == null;
-
if (freePages == null)
return 0;
@@ -2438,7 +2417,6 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
@SuppressWarnings("unchecked")
@Override public void addFreePage(long pageId) {
assert pageId != 0;
- assert bag == null; // Otherwise we have to add the given pageId to that bag.
if (freePages == null)
freePages = pageId;
@@ -2557,7 +2535,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
* @return {@code true} If already removed from leaf.
*/
private boolean isRemoved() {
- return removed != null;
+ return rmvd != null;
}
/**
@@ -2833,7 +2811,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
assert !isRemoved(): "already removed";
// Detach the row.
- removed = getRow(io, pageAddr, idx);
+ rmvd = needOld ? getRow(io, pageAddr, idx) : (T)Boolean.TRUE;
doRemove(page, io, pageAddr, cnt, idx);
@@ -3034,7 +3012,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
if (release)
writeUnlockAndClose(page, pageAddr);
- bag().addFreePage(pageId);
+ addFreePage(pageId);
}
/**
@@ -3055,7 +3033,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
@SuppressWarnings("unchecked")
private void reuseFreePages() throws IgniteCheckedException {
// If we have a bag, then it will be processed at the upper level.
- if (reuseList != null && bag == null && freePages != null)
+ if (reuseList != null && freePages != null)
reuseList.addForRecycle(this);
}
@@ -3499,13 +3477,6 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
protected abstract T getRow(BPlusIO<L> io, long pageAddr, int idx) throws IgniteCheckedException;
/**
- *
- */
- public interface RowClosure<L, R> {
- public R oldRow(BPlusIO<L> io, long pageAddr, int idx) throws IgniteCheckedException;
- }
-
- /**
* Forward cursor.
*/
@SuppressWarnings("unchecked")
http://git-wip-us.apache.org/repos/asf/ignite/blob/13bb2de7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
index 6cabd77..33379b0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
@@ -136,7 +136,6 @@ public class H2TreeIndex extends GridH2IndexBase {
}
/** {@inheritDoc} */
- @SuppressWarnings("StatementWithEmptyBody")
@Override public GridH2Row put(GridH2Row row) {
try {
return tree.put(row);
@@ -147,6 +146,16 @@ public class H2TreeIndex extends GridH2IndexBase {
}
/** {@inheritDoc} */
+ @Override public boolean putx(GridH2Row row) {
+ try {
+ return tree.putx(row);
+ }
+ catch (IgniteCheckedException e) {
+ throw DbException.convert(e);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public GridH2Row remove(SearchRow row) {
try {
return tree.remove(row);
@@ -157,6 +166,16 @@ public class H2TreeIndex extends GridH2IndexBase {
}
/** {@inheritDoc} */
+ @Override public void removex(SearchRow row) {
+ try {
+ tree.removex(row);
+ }
+ catch (IgniteCheckedException e) {
+ throw DbException.convert(e);
+ }
+ }
+
+ /** {@inheritDoc} */
@Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder) {
long rowCnt = getRowCountApproximation();
http://git-wip-us.apache.org/repos/asf/ignite/blob/13bb2de7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index 4ef015b..ea7173c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -178,7 +178,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
}
/**
- * Put row if absent.
+ * Puts row.
*
* @param row Row.
* @return Existing row or {@code null}.
@@ -186,6 +186,16 @@ public abstract class GridH2IndexBase extends BaseIndex {
public abstract GridH2Row put(GridH2Row row);
/**
+ * Puts row.
+ *
+ * @param row Row.
+ * @return {@code True} if replaced existing row.
+ */
+ public boolean putx(GridH2Row row) {
+ return put(row) != null;
+ }
+
+ /**
* Remove row from index.
*
* @param row Row.
@@ -194,6 +204,15 @@ public abstract class GridH2IndexBase extends BaseIndex {
public abstract GridH2Row remove(SearchRow row);
/**
+ * Remove row from index, does not return removed row.
+ *
+ * @param row Row.
+ */
+ public void removex(SearchRow row) {
+ remove(row);
+ }
+
+ /**
* Finds a single row by the given row.
*
* @param row Search row.
http://git-wip-us.apache.org/repos/asf/ignite/blob/13bb2de7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index 3251b3d..5024959 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -615,7 +615,7 @@ public class GridH2Table extends TableBase {
"not supported [idx=" + idx + ", old=" + old + ", old2=" + old2 + ']');
}
else if (old != null) // Row was not replaced, need to remove manually.
- idx.remove(old);
+ idx.removex(old);
}
}
else {