Skip to content

Commit

Permalink
IGNITE-6701: SQL: eliminated unnecessary deserialization in GridH2Tab…
Browse files Browse the repository at this point in the history
…le.doUpdate. This closes #2956.
  • Loading branch information
rkondakov authored and devozerov committed Nov 8, 2017
1 parent 0df6eaf commit a58393d
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 121 deletions.
Expand Up @@ -217,9 +217,10 @@ public void registerCache(String cacheName, String schemaName, GridCacheContext<
* @param cctx Cache context.
* @param type Type descriptor.
* @param row New row.
* @param prevRow Previous row.
* @throws IgniteCheckedException If failed.
*/
public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)
public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row, CacheDataRow prevRow)
throws IgniteCheckedException;

/**
Expand Down
Expand Up @@ -1734,14 +1734,18 @@ public void store(GridCacheContext cctx, CacheDataRow newRow, @Nullable CacheDat
prevRow.value(),
false);

if (prevValDesc != null && prevValDesc != desc)
idx.remove(cctx, prevValDesc, prevRow);
if (prevValDesc != desc) {
if (prevValDesc != null)
idx.remove(cctx, prevValDesc, prevRow);

prevRow = null; // Row has already been removed from another table indexes
}
}

if (desc == null)
return;

idx.store(cctx, desc, newRow);
idx.store(cctx, desc, newRow, prevRow);
}
finally {
busyLock.leaveBusy();
Expand Down
Expand Up @@ -310,7 +310,8 @@ private static class FailedIndexing implements GridQueryIndexing {
}

/** {@inheritDoc} */
@Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow val) {
@Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row,
CacheDataRow prevRow) {
// No-op.
}

Expand Down
Expand Up @@ -202,6 +202,13 @@ private void checkClosed() {
}
}

/** {@inheritDoc} */
@Override public boolean putx(GridH2Row row) {
GridH2Row old = put(row);

return old != null;
}

/**
* @param row Row.
* @param rowId Row id.
Expand Down Expand Up @@ -251,6 +258,13 @@ private SpatialKey getEnvelope(SearchRow row, long rowId) {
}
}

/** {@inheritDoc} */
@Override public boolean removex(SearchRow row) {
GridH2Row old = remove(row);

return old != null;
}

/** {@inheritDoc} */
@Override public void destroy(boolean rmIndex) {
Lock l = lock.writeLock();
Expand Down
Expand Up @@ -565,16 +565,16 @@ private void onSqlException() {
}

/** {@inheritDoc} */
@Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)
throws IgniteCheckedException {
@Override public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row,
@Nullable CacheDataRow prevRow) throws IgniteCheckedException {
String cacheName = cctx.name();

H2TableDescriptor tbl = tableDescriptor(schema(cacheName), cacheName, type.name());

if (tbl == null)
return; // Type was rejected.

tbl.table().update(row, false);
tbl.table().update(row, prevRow);

if (tbl.luceneIndex() != null) {
long expireTime = row.expireTime();
Expand Down Expand Up @@ -603,7 +603,7 @@ private void onSqlException() {
if (tbl == null)
return;

if (tbl.table().update(row, true)) {
if (tbl.table().remove(row)) {
if (tbl.luceneIndex() != null)
tbl.luceneIndex().remove(row.key());
}
Expand Down Expand Up @@ -701,7 +701,7 @@ private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, Grid
@Override public void apply(CacheDataRow row) throws IgniteCheckedException {
GridH2Row h2Row = rowDesc.createRow(row);

h2Idx.put(h2Row);
h2Idx.putx(h2Row);
}
};

Expand Down
Expand Up @@ -130,6 +130,14 @@ public H2PkHashIndex(
throw DbException.getUnsupportedException("put");
}

/** {@inheritDoc} */
@Override public boolean putx(GridH2Row row) {
// Should not be called directly. Rows are inserted into underlying cache data stores.
assert false;

throw DbException.getUnsupportedException("putx");
}

/** {@inheritDoc} */
@Override public GridH2Row remove(SearchRow row) {
// Should not be called directly. Rows are removed from underlying cache data stores.
Expand All @@ -139,6 +147,14 @@ public H2PkHashIndex(
throw DbException.getUnsupportedException("remove");
}

/** {@inheritDoc} */
@Override public boolean removex(SearchRow row) {
// Should not be called directly. Rows are removed from underlying cache data stores.
assert false;

throw DbException.getUnsupportedException("removex");
}

/** {@inheritDoc} */
@Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) {
return Double.MAX_VALUE;
Expand Down
Expand Up @@ -204,6 +204,25 @@ private List<InlineIndexHelper> getAvailableInlineColumns(IndexColumn[] cols) {
}
}

/** {@inheritDoc} */
@Override public boolean putx(GridH2Row row) {
try {
InlineIndexHelper.setCurrentInlineIndexes(inlineIdxs);

int seg = segmentForRow(row);

H2Tree tree = treeForRead(seg);

return tree.putx(row);
}
catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
finally {
InlineIndexHelper.clearCurrentInlineIndexes();
}
}

/** {@inheritDoc} */
@Override public GridH2Row remove(SearchRow row) {
try {
Expand All @@ -224,15 +243,15 @@ private List<InlineIndexHelper> getAvailableInlineColumns(IndexColumn[] cols) {
}

/** {@inheritDoc} */
@Override public void removex(SearchRow row) {
@Override public boolean removex(SearchRow row) {
try {
InlineIndexHelper.setCurrentInlineIndexes(inlineIdxs);

int seg = segmentForRow(row);

H2Tree tree = treeForRead(seg);

tree.removex(row);
return tree.removex(row);
}
catch (IgniteCheckedException e) {
throw DbException.convert(e);
Expand Down
Expand Up @@ -198,6 +198,14 @@ protected int threadLocalSegment() {
*/
public abstract GridH2Row put(GridH2Row row);

/**
* Puts row.
*
* @param row Row.
* @return {@code True} if existing row row has been replaced.
*/
public abstract boolean putx(GridH2Row row);

/**
* Remove row from index.
*
Expand All @@ -207,13 +215,12 @@ protected int threadLocalSegment() {
public abstract GridH2Row remove(SearchRow row);

/**
* Remove row from index, does not return removed row.
* Removes row from index.
*
* @param row Row.
* @return {@code True} if row has been removed.
*/
public void removex(SearchRow row) {
remove(row);
}
public abstract boolean removex(SearchRow row);

/**
* @param ses Session.
Expand Down

0 comments on commit a58393d

Please sign in to comment.