You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/06/11 20:04:07 UTC

[41/47] ignite git commit: IGNITE-5267 - Moved ignite-ps module to ignite-core

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/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
deleted file mode 100644
index 3545b32..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-/**
- * Registry for IO versions.
- */
-public final class IOVersions<V extends PageIO> {
-    /** */
-    private final V[] vers;
-
-    /** */
-    private final int type;
-
-    /** */
-    private final V latest;
-
-    /**
-     * @param vers Versions.
-     */
-    @SafeVarargs
-    public IOVersions(V... vers) {
-        assert vers != null;
-        assert vers.length > 0;
-
-        this.vers = vers;
-        this.type = vers[0].getType();
-
-        latest = vers[vers.length - 1];
-
-        assert checkVersions();
-    }
-
-    /**
-     * @return Type.
-     */
-    public int getType() {
-        return type;
-    }
-
-    /**
-     * @return {@code true} If versions are correct.
-     */
-    private boolean checkVersions() {
-        for (int i = 0; i < vers.length; i++) {
-            V v = vers[i];
-
-            if (v.getType() != type || v.getVersion() != i + 1)
-                return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * @return Latest IO version.
-     */
-    public V latest() {
-        return latest;
-    }
-
-    /**
-     * @param ver Version.
-     * @return IO.
-     */
-    public V forVersion(int ver) {
-        return vers[ver - 1];
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return IO.
-     */
-    public V forPage(long pageAddr) {
-        int ver = PageIO.getVersion(pageAddr);
-
-        V res = forVersion(ver);
-
-        assert res.getType() == PageIO.getType(pageAddr) : "resType=" + res.getType() +
-            ", pageType=" + PageIO.getType(pageAddr);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/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
deleted file mode 100644
index dd6a503..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
+++ /dev/null
@@ -1,548 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.PageMemory;
-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;
-import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListMetaIO;
-import org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO;
-import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
-import org.apache.ignite.internal.processors.cache.database.tree.util.PageLockListener;
-
-/**
- * Base format for all the page types.
- *
- * Checklist for page IO implementations and usage (The Rules):
- *
- * 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(long)}}) intentionally:
- *    this base format can not be changed between versions.
- *
- * 2. IO must correctly override {@link #initNewPage(long, long, int)} 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
- *    existing IO types in a single place.
- *
- * 4. IO must be added to {@link #getBPlusIO(int, int)} or to {@link #getPageIO(int, int)}.
- *
- * 5. Always keep in mind that IOs are versioned and their format can change from version
- *    to version. In this respect it is a good practice to avoid exposing details
- *    of IO internal format on it's API. The API should be minimalistic and abstract, so that
- *    internal format in future IO version can be completely changed without any changes
- *    to the API of this page IO.
- *
- * 6. Page IO API should not have any version dependent semantics and should not change API
- *    semantics in newer versions.
- *
- * 7. It is almost always preferable to read or write (especially write) page contents using
- *    static methods on {@link PageHandler}. To just initialize new page use
- *    {@link PageHandler#initPage(PageMemory, int, long, PageIO, IgniteWriteAheadLogManager, PageLockListener)}
- *    method with needed IO instance.
- */
-public abstract class PageIO {
-    /** */
-    private static BPlusInnerIO<?> innerTestIO;
-
-    /** */
-    private static BPlusLeafIO<?> leafTestIO;
-
-    /** */
-    private static IOVersions<? extends BPlusInnerIO<?>> h2InnerIOs;
-
-    /** */
-    private static IOVersions<? extends BPlusLeafIO<?>> h2LeafIOs;
-
-    /** Maximum payload size. */
-    public static final short MAX_PAYLOAD_SIZE = 2048;
-
-    /** */
-    private static List<IOVersions<? extends BPlusInnerIO<?>>> h2ExtraInnerIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);
-
-    /** */
-    private static List<IOVersions<? extends BPlusLeafIO<?>>> h2ExtraLeafIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);
-
-    /** */
-    public static final int TYPE_OFF = 0;
-
-    /** */
-    public static final int VER_OFF = TYPE_OFF + 2;
-
-    /** */
-    public static final int CRC_OFF = VER_OFF + 2;
-
-    /** */
-    public static final int PAGE_ID_OFF = CRC_OFF + 4;
-
-    /** */
-    private static final int RESERVED_1_OFF = PAGE_ID_OFF + 8;
-
-    /** */
-    private static final int RESERVED_2_OFF = RESERVED_1_OFF + 8;
-
-    /** */
-    private static final int RESERVED_3_OFF = RESERVED_2_OFF + 8;
-
-    /** */
-    public static final int COMMON_HEADER_END = RESERVED_3_OFF + 8; // 40=type(2)+ver(2)+crc(4)+pageId(8)+reserved(3*8)
-
-    /* All the page types. */
-
-    /** */
-    public static final short T_DATA = 1;
-
-    /** */
-    public static final short T_BPLUS_META = 2;
-
-    /** */
-    public static final short T_H2_REF_LEAF = 3;
-
-    /** */
-    public static final short T_H2_REF_INNER = 4;
-
-    /** */
-    public static final short T_DATA_REF_INNER = 5;
-
-    /** */
-    public static final short T_DATA_REF_LEAF = 6;
-
-    /** */
-    public static final short T_METASTORE_INNER = 7;
-
-    /** */
-    public static final short T_METASTORE_LEAF = 8;
-
-    /** */
-    public static final short T_PENDING_REF_INNER = 9;
-
-    /** */
-    public static final short T_PENDING_REF_LEAF = 10;
-
-    /** */
-    public static final short T_META = 11;
-
-    /** */
-    public static final short T_PAGE_LIST_META = 12;
-
-    /** */
-    public static final short T_PAGE_LIST_NODE = 13;
-
-    /** */
-    public static final short T_PART_META = 14;
-
-    /** */
-    public static final short T_PAGE_UPDATE_TRACKING = 15;
-
-    /** */
-    public static final short T_CACHE_ID_AWARE_DATA_REF_INNER = 16;
-
-    /** */
-    public static final short T_CACHE_ID_AWARE_DATA_REF_LEAF = 17;
-
-    /** */
-    public static final short T_CACHE_ID_AWARE_PENDING_REF_INNER = 18;
-
-    /** */
-    public static final short T_CACHE_ID_AWARE_PENDING_REF_LEAF = 19;
-
-    /** */
-    public static final short T_PART_CNTRS = 20;
-
-    /** Index for payload == 1. */
-    public static final short T_H2_EX_REF_LEAF_START = 10000;
-
-    /** */
-    public static final short T_H2_EX_REF_LEAF_END = T_H2_EX_REF_LEAF_START + MAX_PAYLOAD_SIZE - 1;
-
-    /** */
-    public static final short T_H2_EX_REF_INNER_START = 20000;
-
-    /** */
-    public static final short T_H2_EX_REF_INNER_END = T_H2_EX_REF_INNER_START + MAX_PAYLOAD_SIZE - 1;
-
-    /** */
-    private final int ver;
-
-    /** */
-    private final int type;
-
-    /**
-     * @param type Page type.
-     * @param ver Page format version.
-     */
-    protected PageIO(int type, int ver) {
-        assert ver > 0 && ver < 65535: ver;
-        assert type > 0 && type < 65535: type;
-
-        this.type = type;
-        this.ver = ver;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @return Page type.
-     */
-    public static int getType(ByteBuffer buf) {
-        return buf.getShort(TYPE_OFF) & 0xFFFF;
-    }
-
-    /**
-     * @param pageAddr Page addres.
-     * @return Page type.
-     */
-    public static int getType(long pageAddr) {
-        return PageUtils.getShort(pageAddr, TYPE_OFF) & 0xFFFF;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param type Type.
-     */
-    public static void setType(long pageAddr, int type) {
-        PageUtils.putShort(pageAddr, TYPE_OFF, (short)type);
-
-        assert getType(pageAddr) == type;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @return Version.
-     */
-    public static int getVersion(ByteBuffer buf) {
-        return buf.getShort(VER_OFF) & 0xFFFF;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Version.
-     */
-    public static int getVersion(long pageAddr) {
-        return PageUtils.getShort(pageAddr, VER_OFF) & 0xFFFF;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param ver Version.
-     */
-    private static void setVersion(long pageAddr, int ver) {
-        PageUtils.putShort(pageAddr, VER_OFF, (short)ver);
-
-        assert getVersion(pageAddr) == ver;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @return Page ID.
-     */
-    public static long getPageId(ByteBuffer buf) {
-        return buf.getLong(PAGE_ID_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Page ID.
-     */
-    public static long getPageId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, PAGE_ID_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param pageId Page ID.
-     */
-    public static void setPageId(long pageAddr, long pageId) {
-        PageUtils.putLong(pageAddr, PAGE_ID_OFF, pageId);
-
-        assert getPageId(pageAddr) == pageId;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Checksum.
-     */
-    public static int getCrc(long pageAddr) {
-        return PageUtils.getInt(pageAddr, CRC_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param crc Checksum.
-     */
-    public static void setCrc(long pageAddr, int crc) {
-        PageUtils.putInt(pageAddr, CRC_OFF, crc);
-    }
-
-    /**
-     * @param buf Buffer.
-     * @return Checksum.
-     */
-    public static int getCrc(ByteBuffer buf) {
-        return buf.getInt(CRC_OFF);
-    }
-
-    /**
-     * @param buf Buffer.
-     * @param crc Checksum.
-     */
-    public static void setCrc(ByteBuffer buf, int crc) {
-        buf.putInt(CRC_OFF, crc);
-    }
-
-    /**
-     * Registers this B+Tree IO versions.
-     *
-     * @param innerIOs Inner IO versions.
-     * @param leafIOs Leaf IO versions.
-     */
-    public static void registerH2(
-        IOVersions<? extends BPlusInnerIO<?>> innerIOs,
-        IOVersions<? extends BPlusLeafIO<?>> leafIOs
-    ) {
-        h2InnerIOs = innerIOs;
-        h2LeafIOs = leafIOs;
-    }
-
-    /**
-     * Registers extra inner IO versions.
-     *
-     * @param innerExtIOs Extra versions.
-     */
-    public static void registerH2ExtraInner(IOVersions<? extends BPlusInnerIO<?>> innerExtIOs) {
-        h2ExtraInnerIOs.add(innerExtIOs);
-    }
-
-    /**
-     * Registers extra inner IO versions.
-     *
-     * @param leafExtIOs Extra versions.
-     */
-    public static void registerH2ExtraLeaf(IOVersions<? extends BPlusLeafIO<?>> leafExtIOs) {
-        h2ExtraLeafIOs.add(leafExtIOs);
-    }
-
-    /**
-     * @param idx Index.
-     * @return IOVersions for given idx.
-     */
-    public static IOVersions<? extends BPlusInnerIO<?>> getInnerVersions(int idx) {
-        return h2ExtraInnerIOs.get(idx);
-    }
-
-    /**
-     * @param idx Index.
-     * @return IOVersions for given idx.
-     */
-    public static IOVersions<? extends BPlusLeafIO<?>> getLeafVersions(int idx) {
-        return h2ExtraLeafIOs.get(idx);
-    }
-
-    /**
-     * Registers IOs for testing.
-     *
-     * @param innerIO Inner IO.
-     * @param leafIO Leaf IO.
-     */
-    public static void registerTest(BPlusInnerIO<?> innerIO, BPlusLeafIO<?> leafIO) {
-        innerTestIO = innerIO;
-        leafTestIO = leafIO;
-    }
-
-    /**
-     * @return Type.
-     */
-    public final int getType() {
-        return type;
-    }
-
-    /**
-     * @return Version.
-     */
-    public final int getVersion() {
-        return ver;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param pageId Page ID.
-     * @param pageSize Page size.
-     */
-    public void initNewPage(long pageAddr, long pageId, int pageSize) {
-        setType(pageAddr, getType());
-        setVersion(pageAddr, getVersion());
-        setPageId(pageAddr, pageId);
-        setCrc(pageAddr, 0);
-
-        PageUtils.putLong(pageAddr, RESERVED_1_OFF, 0L);
-        PageUtils.putLong(pageAddr, RESERVED_2_OFF, 0L);
-        PageUtils.putLong(pageAddr, RESERVED_3_OFF, 0L);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return getClass().getSimpleName() + "[ver=" + getVersion() + "]";
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return IO.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <Q extends PageIO> Q getPageIO(long pageAddr) throws IgniteCheckedException {
-        int type = getType(pageAddr);
-        int ver = getVersion(pageAddr);
-
-        return getPageIO(type, ver);
-    }
-
-    /**
-     * @param type IO Type.
-     * @param ver IO Version.
-     * @return Page IO.
-     * @throws IgniteCheckedException If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public static <Q extends PageIO> Q getPageIO(int type, int ver) throws IgniteCheckedException {
-        switch (type) {
-            case T_DATA:
-                return (Q)DataPageIO.VERSIONS.forVersion(ver);
-
-            case T_BPLUS_META:
-                return (Q)BPlusMetaIO.VERSIONS.forVersion(ver);
-
-            case T_PAGE_LIST_NODE:
-                return (Q)PagesListNodeIO.VERSIONS.forVersion(ver);
-
-            case T_PAGE_LIST_META:
-                return (Q)PagesListMetaIO.VERSIONS.forVersion(ver);
-
-            case T_META:
-                return (Q)PageMetaIO.VERSIONS.forVersion(ver);
-
-            case T_PART_META:
-                return (Q)PagePartitionMetaIO.VERSIONS.forVersion(ver);
-
-            case T_PART_CNTRS:
-                return (Q)PagePartitionCountersIO.VERSIONS.forVersion(ver);
-
-            case T_PAGE_UPDATE_TRACKING:
-                return (Q)TrackingPageIO.VERSIONS.forVersion(ver);
-
-            default:
-                return (Q)getBPlusIO(type, ver);
-        }
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return IO for either inner or leaf B+Tree page.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <Q extends BPlusIO<?>> Q getBPlusIO(long pageAddr) throws IgniteCheckedException {
-        int type = getType(pageAddr);
-        int ver = getVersion(pageAddr);
-
-        return getBPlusIO(type, ver);
-    }
-
-    /**
-     * @param type IO Type.
-     * @param ver IO Version.
-     * @return IO for either inner or leaf B+Tree page.
-     * @throws IgniteCheckedException If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public static <Q extends BPlusIO<?>> Q getBPlusIO(int type, int ver) throws IgniteCheckedException {
-
-        if (type >= T_H2_EX_REF_LEAF_START && type <= T_H2_EX_REF_LEAF_END)
-            return (Q)h2ExtraLeafIOs.get(type - T_H2_EX_REF_LEAF_START).forVersion(ver);
-
-        if (type >= T_H2_EX_REF_INNER_START && type <= T_H2_EX_REF_INNER_END)
-            return (Q)h2ExtraInnerIOs.get(type - T_H2_EX_REF_INNER_START).forVersion(ver);
-
-        switch (type) {
-            case T_H2_REF_INNER:
-                if (h2InnerIOs == null)
-                    break;
-
-                return (Q)h2InnerIOs.forVersion(ver);
-
-            case T_H2_REF_LEAF:
-                if (h2LeafIOs == null)
-                    break;
-
-                return (Q)h2LeafIOs.forVersion(ver);
-
-            case T_DATA_REF_INNER:
-                return (Q)IgniteCacheOffheapManagerImpl.DataInnerIO.VERSIONS.forVersion(ver);
-
-            case T_DATA_REF_LEAF:
-                return (Q)IgniteCacheOffheapManagerImpl.DataLeafIO.VERSIONS.forVersion(ver);
-
-            case T_CACHE_ID_AWARE_DATA_REF_INNER:
-                return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwareDataInnerIO.VERSIONS.forVersion(ver);
-
-            case T_CACHE_ID_AWARE_DATA_REF_LEAF:
-                return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwareDataLeafIO.VERSIONS.forVersion(ver);
-
-            case T_METASTORE_INNER:
-                return (Q)MetadataStorage.MetaStoreInnerIO.VERSIONS.forVersion(ver);
-
-            case T_METASTORE_LEAF:
-                return (Q)MetadataStorage.MetaStoreLeafIO.VERSIONS.forVersion(ver);
-
-            case T_PENDING_REF_INNER:
-                return (Q) IgniteCacheOffheapManagerImpl.PendingEntryInnerIO.VERSIONS.forVersion(ver);
-
-            case T_PENDING_REF_LEAF:
-                return (Q)IgniteCacheOffheapManagerImpl.PendingEntryLeafIO.VERSIONS.forVersion(ver);
-
-            case T_CACHE_ID_AWARE_PENDING_REF_INNER:
-                return (Q) IgniteCacheOffheapManagerImpl.CacheIdAwarePendingEntryInnerIO.VERSIONS.forVersion(ver);
-
-            case T_CACHE_ID_AWARE_PENDING_REF_LEAF:
-                return (Q)IgniteCacheOffheapManagerImpl.CacheIdAwarePendingEntryLeafIO.VERSIONS.forVersion(ver);
-
-            default:
-                // For tests.
-                if (innerTestIO != null && innerTestIO.getType() == type && innerTestIO.getVersion() == ver)
-                    return (Q)innerTestIO;
-
-                if (leafTestIO != null && leafTestIO.getType() == type && leafTestIO.getVersion() == ver)
-                    return (Q)leafTestIO;
-        }
-
-        throw new IgniteCheckedException("Unknown page IO type: " + type);
-    }
-
-    /**
-     * @param type Type to test.
-     * @return {@code True} if data page.
-     */
-    public static boolean isDataPageType(int type) {
-        return type == T_DATA;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
deleted file mode 100644
index b04baf3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-import java.nio.ByteBuffer;
-import org.apache.ignite.internal.pagemem.PageUtils;
-import org.jetbrains.annotations.NotNull;
-
-/**
- *
- */
-public class PageMetaIO extends PageIO {
-    /** */
-    private static final int TREE_ROOT_OFF = PageIO.COMMON_HEADER_END + 8;
-
-    /** */
-    private static final int REUSE_LIST_ROOT_OFF = TREE_ROOT_OFF + 8;
-
-    /** Last successful snapshot id offset. */
-    private static final int LAST_SUCCESSFUL_SNAPSHOT_ID_OFF = REUSE_LIST_ROOT_OFF + 8;
-
-    /** Last successful full snapshot id offset. */
-    private static final int LAST_SUCCESSFUL_FULL_SNAPSHOT_ID_OFF = LAST_SUCCESSFUL_SNAPSHOT_ID_OFF + 8;
-
-    /** Next snapshot id offset. */
-    private static final int NEXT_SNAPSHOT_TAG_OFF = LAST_SUCCESSFUL_FULL_SNAPSHOT_ID_OFF + 8;
-
-    /** Last successful full snapshot tag offset. */
-    private static final int LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF = NEXT_SNAPSHOT_TAG_OFF + 8;
-
-    /** Last allocated index offset. */
-    private static final int LAST_PAGE_COUNT_OFF = LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF + 8;
-
-    /** Candidate allocated index offset. */
-    private static final int CANDIDATE_PAGE_COUNT_OFF = LAST_PAGE_COUNT_OFF + 4;
-
-    /** End of page meta. */
-    static final int END_OF_PAGE_META = CANDIDATE_PAGE_COUNT_OFF + 4;
-
-    /** */
-    public static final IOVersions<PageMetaIO> VERSIONS = new IOVersions<>(
-        new PageMetaIO(1)
-    );
-
-    /**
-     * @param ver Page format version.
-     */
-    public PageMetaIO(int ver) {
-        super(PageIO.T_META, ver);
-    }
-
-    /**
-     * @param type Type.
-     * @param ver Version.
-     */
-    protected PageMetaIO(int type, int ver) {
-        super(type, ver);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void initNewPage(long pageAddr, long pageId, int pageSize) {
-        super.initNewPage(pageAddr, pageId, pageSize);
-
-        setTreeRoot(pageAddr, 0);
-        setReuseListRoot(pageAddr, 0);
-        setLastSuccessfulFullSnapshotId(pageAddr, 0);
-        setLastSuccessfulSnapshotId(pageAddr, 0);
-        setNextSnapshotTag(pageAddr, 1);
-        setLastSuccessfulSnapshotTag(pageAddr, 0);
-        setLastPageCount(pageAddr, 0);
-        setCandidatePageCount(pageAddr, 0);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Tree root page.
-     */
-    public long getTreeRoot(long pageAddr) {
-        return PageUtils.getLong(pageAddr, TREE_ROOT_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param treeRoot Tree root
-     */
-    public void setTreeRoot(long pageAddr, long treeRoot) {
-        PageUtils.putLong(pageAddr, TREE_ROOT_OFF, treeRoot);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Reuse list root page.
-     */
-    public long getReuseListRoot(long pageAddr) {
-        return PageUtils.getLong(pageAddr, REUSE_LIST_ROOT_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param pageId Root page ID.
-     */
-    public void setReuseListRoot(long pageAddr, long pageId) {
-        PageUtils.putLong(pageAddr, REUSE_LIST_ROOT_OFF, pageId);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param lastSuccessfulSnapshotId Last successful snapshot id.
-     */
-    public void setLastSuccessfulSnapshotId(long pageAddr, long lastSuccessfulSnapshotId) {
-        PageUtils.putLong(pageAddr, LAST_SUCCESSFUL_SNAPSHOT_ID_OFF, lastSuccessfulSnapshotId);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public long getLastSuccessfulSnapshotId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, LAST_SUCCESSFUL_SNAPSHOT_ID_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param lastSuccessfulFullSnapshotId Last successful full snapshot id.
-     */
-    public void setLastSuccessfulFullSnapshotId(long pageAddr, long lastSuccessfulFullSnapshotId) {
-        PageUtils.putLong(pageAddr, LAST_SUCCESSFUL_FULL_SNAPSHOT_ID_OFF, lastSuccessfulFullSnapshotId);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public long getLastSuccessfulFullSnapshotId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, LAST_SUCCESSFUL_FULL_SNAPSHOT_ID_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param nextSnapshotId Next snapshot id.
-     */
-    public void setNextSnapshotTag(long pageAddr, long nextSnapshotId) {
-        PageUtils.putLong(pageAddr, NEXT_SNAPSHOT_TAG_OFF, nextSnapshotId);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public long getLastSuccessfulSnapshotTag(long pageAddr) {
-        return PageUtils.getLong(pageAddr, LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param lastSuccessfulSnapshotTag Last successful snapshot tag.
-     */
-    public void setLastSuccessfulSnapshotTag(long pageAddr, long lastSuccessfulSnapshotTag) {
-        PageUtils.putLong(pageAddr, LAST_SUCCESSFUL_FULL_SNAPSHOT_TAG_OFF, lastSuccessfulSnapshotTag);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public long getNextSnapshotTag(long pageAddr) {
-        return PageUtils.getLong(pageAddr, NEXT_SNAPSHOT_TAG_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param pageCnt Last allocated index.
-     */
-    public void setLastPageCount(long pageAddr, int pageCnt) {
-        PageUtils.putInt(pageAddr, LAST_PAGE_COUNT_OFF, pageCnt);
-    }
-
-    /**
-     * @param buf Buffer.
-     */
-    public int getLastPageCount(@NotNull ByteBuffer buf) {
-        return buf.getInt(LAST_PAGE_COUNT_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public int getLastPageCount(long pageAddr) {
-        return PageUtils.getInt(pageAddr, LAST_PAGE_COUNT_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param pageCnt Last page count.
-     */
-    public boolean setCandidatePageCount(long pageAddr, int pageCnt) {
-        if (getCandidatePageCount(pageAddr) == pageCnt)
-            return false;
-
-        PageUtils.putInt(pageAddr, CANDIDATE_PAGE_COUNT_OFF, pageCnt);
-
-        return true;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public int getCandidatePageCount(long pageAddr) {
-        return PageUtils.getInt(pageAddr, CANDIDATE_PAGE_COUNT_OFF);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java
deleted file mode 100644
index 015b8ff..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionCountersIO.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-import java.util.Map;
-import org.apache.ignite.internal.pagemem.PageUtils;
-
-/**
- *
- */
-public class PagePartitionCountersIO extends PageIO {
-    /** */
-    private static final int CNT_OFF = COMMON_HEADER_END;
-
-    /** */
-    private static final int LAST_FLAG_OFF = CNT_OFF + 2;
-
-    /** */
-    private static final int NEXT_COUNTERS_PAGE_OFF = LAST_FLAG_OFF + 1;
-
-    /** */
-    private static final int ITEMS_OFF = NEXT_COUNTERS_PAGE_OFF + 8;
-
-    /** */
-    private static final int ITEM_SIZE = 12;
-
-    /** */
-    private static final byte LAST_FLAG = 0b1;
-
-    /** */
-    public static final IOVersions<PagePartitionCountersIO> VERSIONS = new IOVersions<>(
-        new PagePartitionCountersIO(1)
-    );
-
-    /**
-     * @param ver Page format version.
-     */
-    public PagePartitionCountersIO(int ver) {
-        super(T_PART_CNTRS, ver);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void initNewPage(long pageAddr, long pageId, int pageSize) {
-        super.initNewPage(pageAddr, pageId, pageSize);
-
-        setCount(pageAddr, 0);
-        setNextCountersPageId(pageAddr, 0);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Next counters page ID or {@code 0} if it does not exist.
-     */
-    public long getNextCountersPageId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, NEXT_COUNTERS_PAGE_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param partMetaPageId Next counters page ID.
-     */
-    public void setNextCountersPageId(long pageAddr, long partMetaPageId) {
-        PageUtils.putLong(pageAddr, NEXT_COUNTERS_PAGE_OFF, partMetaPageId);
-    }
-
-    /**
-     * @param pageSize Page size.
-     * @param pageAddr Page address.
-     * @param cacheSizes Serialized cache size items (pairs of cache ID and its size).
-     * @return Number of written pairs.
-     */
-    public int writeCacheSizes(int pageSize, long pageAddr, byte[] cacheSizes, int itemsOff) {
-        assert cacheSizes != null;
-        assert cacheSizes.length % ITEM_SIZE == 0 : cacheSizes.length;
-
-        int cap = getCapacity(pageSize);
-
-        int items = (cacheSizes.length / ITEM_SIZE) - itemsOff;
-        int write = Math.min(cap, items);
-
-        if (write > 0)
-            // This can happen in case there are no items in a given partition for all caches in the group.
-            PageUtils.putBytes(pageAddr, ITEMS_OFF, cacheSizes, itemsOff * ITEM_SIZE, write * ITEM_SIZE);
-
-        setCount(pageAddr, write);
-
-        setLastFlag(pageAddr, write == items);
-
-        return write;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param res Result map of cache sizes.
-     * @return {@code True} if the map was fully read.
-     */
-    public boolean readCacheSizes(long pageAddr, Map<Integer, Long> res) {
-        int cnt = getCount(pageAddr);
-
-        assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt;
-
-        if (cnt == 0)
-            return true;
-
-        int off = ITEMS_OFF;
-
-        for (int i = 0; i < cnt; i++) {
-            int cacheId = PageUtils.getInt(pageAddr, off);
-            off += 4;
-
-            assert cacheId != 0;
-
-            long cacheSize = PageUtils.getLong(pageAddr, off);
-            off += 8;
-
-            assert cacheSize > 0 : cacheSize;
-
-            Long old = res.put(cacheId, cacheSize);
-
-            assert old == null;
-        }
-
-        return getLastFlag(pageAddr);
-    }
-
-    private boolean getLastFlag(long pageAddr) {
-        return PageUtils.getByte(pageAddr, LAST_FLAG_OFF) == LAST_FLAG;
-    }
-
-    private void setLastFlag(long pageAddr, boolean last) {
-        PageUtils.putByte(pageAddr, LAST_FLAG_OFF, last ? LAST_FLAG : ~LAST_FLAG);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Stored items count.
-     */
-    private int getCount(long pageAddr) {
-        return PageUtils.getShort(pageAddr, CNT_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param cnt Stored items count.
-     */
-    private void setCount(long pageAddr, int cnt) {
-        assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt;
-
-        PageUtils.putShort(pageAddr, CNT_OFF, (short)cnt);
-    }
-
-    /**
-     * @param pageSize Page size.
-     * @return Maximum number of items which can be stored in buffer.
-     */
-    private int getCapacity(int pageSize) {
-        return (pageSize - ITEMS_OFF) / ITEM_SIZE;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
deleted file mode 100644
index ddacf69..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-import org.apache.ignite.internal.pagemem.PageUtils;
-
-/**
- *
- */
-public class PagePartitionMetaIO extends PageMetaIO {
-    /** */
-    private static final int SIZE_OFF = PageMetaIO.END_OF_PAGE_META;
-
-    /** */
-    private static final int UPDATE_CNTR_OFF = SIZE_OFF + 8;
-
-    /** */
-    private static final int GLOBAL_RMV_ID_OFF = UPDATE_CNTR_OFF + 8;
-
-    /** */
-    private static final int PARTITION_STATE_OFF = GLOBAL_RMV_ID_OFF + 8;
-
-    /** */
-    private static final int NEXT_PART_META_PAGE_OFF = PARTITION_STATE_OFF + 1;
-
-    /** */
-    public static final IOVersions<PagePartitionMetaIO> VERSIONS = new IOVersions<>(
-        new PagePartitionMetaIO(1)
-    );
-
-    /** {@inheritDoc} */
-    @Override public void initNewPage(long pageAddr, long pageId, int pageSize) {
-        super.initNewPage(pageAddr, pageId, pageSize);
-
-        setSize(pageAddr, 0);
-        setUpdateCounter(pageAddr, 0);
-        setGlobalRemoveId(pageAddr, 0);
-        setPartitionState(pageAddr, (byte)-1);
-        setCountersPageId(pageAddr, 0);
-    }
-
-    /**
-     * @param ver Version.
-     */
-    public PagePartitionMetaIO(int ver) {
-        super(T_PART_META, ver);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Partition size.
-     */
-    public long getSize(long pageAddr) {
-        return PageUtils.getLong(pageAddr, SIZE_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param size Partition size.
-     */
-    public boolean setSize(long pageAddr, long size) {
-        if (getSize(pageAddr) == size)
-            return false;
-
-        PageUtils.putLong(pageAddr, SIZE_OFF, size);
-
-        return true;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Partition update counter.
-     */
-    public long getUpdateCounter(long pageAddr) {
-        return PageUtils.getLong(pageAddr, UPDATE_CNTR_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param cntr Partition update counter.
-     */
-    public boolean setUpdateCounter(long pageAddr, long cntr) {
-        if (getUpdateCounter(pageAddr) == cntr)
-            return false;
-
-        PageUtils.putLong(pageAddr, UPDATE_CNTR_OFF, cntr);
-
-        return true;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Global remove ID.
-     */
-    public long getGlobalRemoveId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, GLOBAL_RMV_ID_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param rmvId Global remove ID.
-     */
-    public boolean setGlobalRemoveId(long pageAddr, long rmvId) {
-        if (getGlobalRemoveId(pageAddr) == rmvId)
-            return false;
-
-        PageUtils.putLong(pageAddr, GLOBAL_RMV_ID_OFF, rmvId);
-
-        return true;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     */
-    public byte getPartitionState(long pageAddr) {
-        return PageUtils.getByte(pageAddr, PARTITION_STATE_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address
-     * @param state State.
-     */
-    public boolean setPartitionState(long pageAddr, byte state) {
-        if (getPartitionState(pageAddr) == state)
-            return false;
-
-        PageUtils.putByte(pageAddr, PARTITION_STATE_OFF, state);
-
-        return true;
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @return Next meta partial page ID or {@code 0} if it does not exist.
-     */
-    public long getCountersPageId(long pageAddr) {
-        return PageUtils.getLong(pageAddr, NEXT_PART_META_PAGE_OFF);
-    }
-
-    /**
-     * @param pageAddr Page address.
-     * @param metaPageId Next partial meta page ID.
-     */
-    public void setCountersPageId(long pageAddr, long metaPageId) {
-        PageUtils.putLong(pageAddr, NEXT_PART_META_PAGE_OFF, metaPageId);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
deleted file mode 100644
index 136ebff..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * 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.processors.cache.database.tree.io;
-
-import java.nio.ByteBuffer;
-import org.apache.ignite.internal.pagemem.PageIdUtils;
-import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
-
-/**
- * We use dedicated page for tracking pages updates.
- * Also we divide such 'tracking' pages on two half, first is used for check that page was changed or not
- * (during incremental snapshot), second - to accumulate changed for next snapshot.
- *
- * You cannot test change for not started snapshot! because it will cause of preparation for snapshot.
- *
- * Implementation. For each page there is own bit in both half. Tracking page is used for tracking N page after it.
- * N depends on page size (how many bytes we can use for tracking).
- *
- *
- *                      +-----------------------------------------+-----------------------------------------+
- *                      |                left half                |               right half                |
- * +---------+----------+----+------------------------------------+----+------------------------------------+
- * |  HEADER | Last     |size|                                    |size|                                    |
- * |         |SnapshotId|2b. |  tracking bits                     |2b. |  tracking bits                     |
- * +---------+----------+----+------------------------------------+----+------------------------------------+
- *
- */
-public class TrackingPageIO extends PageIO {
-    /** */
-    public static final IOVersions<TrackingPageIO> VERSIONS = new IOVersions<>(
-        new TrackingPageIO(1)
-    );
-
-    /** Last snapshot offset. */
-    public static final int LAST_SNAPSHOT_TAG_OFFSET = COMMON_HEADER_END;
-
-    /** Size field offset. */
-    public static final int SIZE_FIELD_OFFSET = LAST_SNAPSHOT_TAG_OFFSET + 8;
-
-    /** 'Size' field size. */
-    public static final int SIZE_FIELD_SIZE = 2;
-
-    /** Bitmap offset. */
-    public static final int BITMAP_OFFSET = SIZE_FIELD_OFFSET + SIZE_FIELD_SIZE;
-
-    /** Count of extra page. */
-    public static final int COUNT_OF_EXTRA_PAGE = 1;
-
-    /**
-     * @param ver Page format version.
-     */
-    protected TrackingPageIO(int ver) {
-        super(PageIO.T_PAGE_UPDATE_TRACKING, ver);
-    }
-
-    /**
-     * Will mark pageId as changed for next (!) snapshotId
-     *
-     * @param buf Buffer.
-     * @param pageId Page id.
-     * @param nextSnapshotTag tag of next snapshot.
-     * @param pageSize Page size.
-     */
-    public boolean markChanged(ByteBuffer buf, long pageId, long nextSnapshotTag, long lastSuccessfulSnapshotTag, int pageSize) {
-        validateSnapshotId(buf, nextSnapshotTag, lastSuccessfulSnapshotTag, pageSize);
-
-        int cntOfPage = countOfPageToTrack(pageSize);
-
-        int idxToUpdate = (PageIdUtils.pageIndex(pageId) - COUNT_OF_EXTRA_PAGE) % cntOfPage;
-
-        int sizeOff = useLeftHalf(nextSnapshotTag) ? SIZE_FIELD_OFFSET : BITMAP_OFFSET + (cntOfPage >> 3);
-
-        int idx = sizeOff + SIZE_FIELD_SIZE + (idxToUpdate >> 3);
-
-        byte byteToUpdate = buf.get(idx);
-
-        int updateTemplate = 1 << (idxToUpdate & 0b111);
-
-        byte newVal =  (byte) (byteToUpdate | updateTemplate);
-
-        if (byteToUpdate == newVal)
-            return false;
-
-        buf.put(idx, newVal);
-
-        short newSize = (short)(buf.getShort(sizeOff) + 1);
-
-        buf.putShort(sizeOff, newSize);
-
-        assert newSize == countOfChangedPage(buf, nextSnapshotTag, pageSize);
-
-        return true;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @param nextSnapshotTag Next snapshot id.
-     * @param lastSuccessfulSnapshotId Last successful snapshot id.
-     * @param pageSize Page size.
-     */
-    private void validateSnapshotId(ByteBuffer buf, long nextSnapshotTag, long lastSuccessfulSnapshotId, int pageSize) {
-        assert nextSnapshotTag != lastSuccessfulSnapshotId : "nextSnapshotTag = " + nextSnapshotTag +
-            ", lastSuccessfulSnapshotId = " + lastSuccessfulSnapshotId;
-
-        long last = getLastSnapshotTag(buf);
-
-        assert last <= nextSnapshotTag : "last = " + last + ", nextSnapshotTag = " + nextSnapshotTag;
-
-        if (nextSnapshotTag == last) //everything is ok
-            return;
-
-        int cntOfPage = countOfPageToTrack(pageSize);
-
-        if (last <= lastSuccessfulSnapshotId) { //we can drop our data
-            buf.putLong(LAST_SNAPSHOT_TAG_OFFSET, nextSnapshotTag);
-
-            PageHandler.zeroMemory(buf, SIZE_FIELD_OFFSET, buf.capacity() - SIZE_FIELD_OFFSET);
-        } else { //we can't drop data, it is still necessary for incremental snapshots
-            int len = cntOfPage >> 3;
-
-            int sizeOff = useLeftHalf(nextSnapshotTag) ? SIZE_FIELD_OFFSET : BITMAP_OFFSET + len;
-            int sizeOff2 = !useLeftHalf(nextSnapshotTag) ? SIZE_FIELD_OFFSET : BITMAP_OFFSET + len;
-
-            if (last - lastSuccessfulSnapshotId == 1) { //we should keep only data in last half
-                //new data will be written in the same half, we should move old data to another half
-                if ((nextSnapshotTag - last) % 2 == 0)
-                    PageHandler.copyMemory(buf, buf, sizeOff, sizeOff2, len + SIZE_FIELD_SIZE);
-            } else { //last - lastSuccessfulSnapshotId > 1, e.g. we should merge two half in one
-                int newSize = 0;
-                int i = 0;
-
-                for (; i < len - 8; i += 8) {
-                    long newVal = buf.getLong(sizeOff + SIZE_FIELD_SIZE + i) | buf.getLong(sizeOff2 + SIZE_FIELD_SIZE + i);
-
-                    newSize += Long.bitCount(newVal);
-
-                    buf.putLong(sizeOff2 + SIZE_FIELD_SIZE + i, newVal);
-                }
-
-                for (; i < len; i ++) {
-                    byte newVal = (byte) (buf.get(sizeOff + SIZE_FIELD_SIZE + i) | buf.get(sizeOff2 + SIZE_FIELD_SIZE + i));
-
-                    newSize += Integer.bitCount(newVal & 0xFF);
-
-                    buf.put(sizeOff2 + SIZE_FIELD_SIZE + i, newVal);
-                }
-
-                buf.putShort(sizeOff2, (short)newSize);
-            }
-
-            buf.putLong(LAST_SNAPSHOT_TAG_OFFSET, nextSnapshotTag);
-
-            PageHandler.zeroMemory(buf, sizeOff, len + SIZE_FIELD_SIZE);
-        }
-    }
-
-    /**
-     * @param buf Buffer.
-     */
-    long getLastSnapshotTag(ByteBuffer buf) {
-        return buf.getLong(LAST_SNAPSHOT_TAG_OFFSET);
-    }
-
-    /**
-     * Check that pageId was marked as changed between previous snapshot finish and current snapshot start.
-     *
-     * @param buf Buffer.
-     * @param pageId Page id.
-     * @param curSnapshotTag Snapshot tag.
-     * @param pageSize Page size.
-     */
-    public boolean wasChanged(ByteBuffer buf, long pageId, long curSnapshotTag, long lastSuccessfulSnapshotTag, int pageSize) {
-        validateSnapshotId(buf, curSnapshotTag + 1, lastSuccessfulSnapshotTag, pageSize);
-
-        if (countOfChangedPage(buf, curSnapshotTag, pageSize) < 1)
-            return false;
-
-        int cntOfPage = countOfPageToTrack(pageSize);
-
-        int idxToTest = (PageIdUtils.pageIndex(pageId) - COUNT_OF_EXTRA_PAGE) % cntOfPage;
-
-        byte byteToTest;
-
-        if (useLeftHalf(curSnapshotTag))
-            byteToTest = buf.get(BITMAP_OFFSET + (idxToTest >> 3));
-        else
-            byteToTest = buf.get(BITMAP_OFFSET + SIZE_FIELD_SIZE + ((idxToTest + cntOfPage) >> 3));
-
-        int testTemplate = 1 << (idxToTest & 0b111);
-
-        return ((byteToTest & testTemplate) ^ testTemplate) == 0;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @param snapshotTag Snapshot tag.
-     * @param pageSize Page size.
-     *
-     * @return count of pages which were marked as change for given snapshotTag
-     */
-    public short countOfChangedPage(ByteBuffer buf, long snapshotTag, int pageSize) {
-        long dif = getLastSnapshotTag(buf) - snapshotTag;
-
-        if (dif != 0 && dif != 1)
-            return -1;
-
-        if (useLeftHalf(snapshotTag))
-            return buf.getShort(SIZE_FIELD_OFFSET);
-        else
-            return buf.getShort(BITMAP_OFFSET + (countOfPageToTrack(pageSize) >> 3));
-    }
-
-    /**
-     * @param snapshotTag Snapshot id.
-     *
-     * @return true if snapshotTag is odd, otherwise - false
-     */
-    boolean useLeftHalf(long snapshotTag) {
-        return (snapshotTag & 0b1) == 0;
-    }
-
-    /**
-     * @param pageId Page id.
-     * @param pageSize Page size.
-     * @return pageId of tracking page which set pageId belongs to
-     */
-    public long trackingPageFor(long pageId, int pageSize) {
-        assert PageIdUtils.pageIndex(pageId) > 0;
-
-        int pageIdx = ((PageIdUtils.pageIndex(pageId) - COUNT_OF_EXTRA_PAGE) /
-            countOfPageToTrack(pageSize)) * countOfPageToTrack(pageSize) + COUNT_OF_EXTRA_PAGE;
-
-        long trackingPageId = PageIdUtils.pageId(PageIdUtils.partId(pageId), PageIdUtils.flag(pageId), pageIdx);
-
-        assert PageIdUtils.pageIndex(trackingPageId) <= PageIdUtils.pageIndex(pageId);
-
-        return trackingPageId;
-    }
-
-    /**
-     * @param pageSize Page size.
-     *
-     * @return how many page we can track with 1 page
-     */
-    public int countOfPageToTrack(int pageSize) {
-        return ((pageSize - SIZE_FIELD_OFFSET) / 2 - SIZE_FIELD_SIZE)  << 3;
-    }
-
-    /**
-     * @param buf Buffer.
-     * @param start Start.
-     * @param curSnapshotTag Snapshot id.
-     * @param pageSize Page size.
-     * @return set pageId if it was changed or next closest one, if there is no changed page null will be returned
-     */
-    public Long findNextChangedPage(ByteBuffer buf, long start, long curSnapshotTag, long lastSuccessfulSnapshotTag, int pageSize) {
-        validateSnapshotId(buf, curSnapshotTag + 1, lastSuccessfulSnapshotTag, pageSize);
-
-        int cntOfPage = countOfPageToTrack(pageSize);
-
-        long trackingPage = trackingPageFor(start, pageSize);
-
-        if (start == trackingPage)
-            return trackingPage;
-
-        if (countOfChangedPage(buf, curSnapshotTag, pageSize) <= 0)
-            return null;
-
-        int idxToStartTest = (PageIdUtils.pageIndex(start) - COUNT_OF_EXTRA_PAGE) % cntOfPage;
-
-        int zeroIdx = useLeftHalf(curSnapshotTag)? BITMAP_OFFSET : BITMAP_OFFSET + SIZE_FIELD_SIZE + (cntOfPage >> 3);
-
-        int startIdx = zeroIdx + (idxToStartTest >> 3);
-
-        int idx = startIdx;
-
-        int stopIdx = zeroIdx + (cntOfPage >> 3);
-
-        while (idx < stopIdx) {
-            byte byteToTest = buf.get(idx);
-
-            if (byteToTest != 0) {
-                int foundSetBit;
-                if ((foundSetBit = foundSetBit(byteToTest, idx == startIdx ? (idxToStartTest & 0b111) : 0)) != -1) {
-                    long foundPageId = PageIdUtils.pageId(
-                        PageIdUtils.partId(start),
-                        PageIdUtils.flag(start),
-                        PageIdUtils.pageIndex(trackingPage) + ((idx - zeroIdx) << 3) + foundSetBit);
-
-                    assert wasChanged(buf, foundPageId, curSnapshotTag, lastSuccessfulSnapshotTag, pageSize);
-                    assert trackingPageFor(foundPageId, pageSize) == trackingPage;
-
-                    return foundPageId;
-                }
-            }
-
-            idx++;
-        }
-
-        return null;
-    }
-
-    /**
-     * @param byteToTest Byte to test.
-     * @param firstBitToTest First bit to test.
-     */
-    private static int foundSetBit(byte byteToTest, int firstBitToTest) {
-        assert firstBitToTest < 8;
-
-        for (int i = firstBitToTest; i < 8; i++) {
-            int testTemplate = 1 << i;
-
-            if (((byteToTest & testTemplate) ^ testTemplate) == 0)
-                return i;
-        }
-
-        return -1;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java
deleted file mode 100644
index 903e93f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseBag.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.processors.cache.database.tree.reuse;
-
-/**
- * Reuse bag for free index pages.
- */
-public interface ReuseBag {
-    /**
-     * @param pageId Free page ID for reuse.
-     */
-    public void addFreePage(long pageId);
-
-    /**
-     * @return Free page ID for reuse or {@code 0} if empty.
-     */
-    public long pollFreePage();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java
deleted file mode 100644
index 801f89a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseList.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.processors.cache.database.tree.reuse;
-
-import org.apache.ignite.IgniteCheckedException;
-
-/**
- * Reuse list.
- */
-public interface ReuseList {
-    /**
-     * @param bag Reuse bag.
-     * @throws IgniteCheckedException If failed.
-     */
-    public void addForRecycle(ReuseBag bag) throws IgniteCheckedException;
-
-    /**
-     * @return Page ID or {@code 0} if none available.
-     * @throws IgniteCheckedException If failed.
-     */
-    public long takeRecycledPage() throws IgniteCheckedException;
-
-    /**
-     * @return Number of recycled pages it contains.
-     * @throws IgniteCheckedException If failed.
-     */
-    public long recycledPagesCount() throws IgniteCheckedException;
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
deleted file mode 100644
index 1c6c8d5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.processors.cache.database.tree.reuse;
-
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.PageMemory;
-import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
-import org.apache.ignite.internal.processors.cache.database.freelist.PagesList;
-
-/**
- * Reuse list.
- */
-public class ReuseListImpl extends PagesList implements ReuseList {
-    /** */
-    private static final AtomicReferenceFieldUpdater<ReuseListImpl, Stripe[]> bucketUpdater =
-        AtomicReferenceFieldUpdater.newUpdater(ReuseListImpl.class, Stripe[].class, "bucket");
-
-    /** */
-    private volatile Stripe[] bucket;
-
-    /**
-     * @param cacheId   Cache ID.
-     * @param name Name (for debug purpose).
-     * @param pageMem   Page memory.
-     * @param wal       Write ahead log manager.
-     * @param metaPageId Metadata page ID.
-     * @param initNew {@code True} if new metadata should be initialized.
-     * @throws IgniteCheckedException If failed.
-     */
-    public ReuseListImpl(int cacheId,
-        String name,
-        PageMemory pageMem,
-        IgniteWriteAheadLogManager wal,
-        long metaPageId,
-        boolean initNew) throws IgniteCheckedException {
-        super(cacheId, name, pageMem, 1, wal, metaPageId);
-
-        reuseList = this;
-
-        init(metaPageId, initNew);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean isReuseBucket(int bucket) {
-        assert bucket == 0: bucket;
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void addForRecycle(ReuseBag bag) throws IgniteCheckedException {
-        put(bag, 0, 0, 0, 0);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long takeRecycledPage() throws IgniteCheckedException {
-        return takeEmptyPage(0, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long recycledPagesCount() throws IgniteCheckedException {
-        return storedPagesCount(0);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Stripe[] getBucket(int bucket) {
-        return this.bucket;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean casBucket(int bucket, Stripe[] exp, Stripe[] upd) {
-        return bucketUpdater.compareAndSet(this, exp, upd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return "ReuseList [name=" + name + ']';
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
deleted file mode 100644
index 0d331e7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- * 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.processors.cache.database.tree.util;
-
-import java.nio.ByteBuffer;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.PageMemory;
-import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
-import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord;
-import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
-import org.apache.ignite.internal.util.GridUnsafe;
-
-import static java.lang.Boolean.FALSE;
-import static java.lang.Boolean.TRUE;
-
-/**
- * Page handler.
- */
-public abstract class PageHandler<X, R> {
-    /** */
-    private static final PageHandler<Void, Boolean> NO_OP = new PageHandler<Void, Boolean>() {
-        @Override public Boolean run(int cacheId, long pageId, long page, long pageAddr, PageIO io, Boolean walPlc,
-            Void arg,
-            int intArg) throws IgniteCheckedException {
-            return Boolean.TRUE;
-        }
-    };
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page absolute pointer.
-     * @param pageAddr Page address.
-     * @param io IO.
-     * @param walPlc Full page WAL record policy.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @return Result.
-     * @throws IgniteCheckedException If failed.
-     */
-    public abstract R run(
-        int cacheId,
-        long pageId,
-        long page,
-        long pageAddr,
-        PageIO io,
-        Boolean walPlc,
-        X arg,
-        int intArg)
-        throws IgniteCheckedException;
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @return {@code true} If release.
-     */
-    public boolean releaseAfterWrite(
-        int cacheId,
-        long pageId,
-        long page,
-        long pageAddr,
-        X arg,
-        int intArg) {
-        return true;
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param lsnr Lock listener.
-     * @param h Handler.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @param lockFailed Result in case of lock failure due to page recycling.
-     * @return Handler result.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <X, R> R readPage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        PageLockListener lsnr,
-        PageHandler<X, R> h,
-        X arg,
-        int intArg,
-        R lockFailed
-    ) throws IgniteCheckedException {
-        long page = pageMem.acquirePage(cacheId, pageId);
-        try {
-            long pageAddr = readLock(pageMem, cacheId, pageId, page, lsnr);
-
-            if (pageAddr == 0L)
-                return lockFailed;
-            try {
-                PageIO io = PageIO.getPageIO(pageAddr);
-                return h.run(cacheId, pageId, page, pageAddr, io, null, arg, intArg);
-            }
-            finally {
-                readUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr);
-            }
-        }
-        finally {
-            pageMem.releasePage(cacheId, pageId, page);
-        }
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param lsnr Lock listener.
-     * @param h Handler.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @param lockFailed Result in case of lock failure due to page recycling.
-     * @return Handler result.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <X, R> R readPage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        PageLockListener lsnr,
-        PageHandler<X, R> h,
-        X arg,
-        int intArg,
-        R lockFailed
-    ) throws IgniteCheckedException {
-        long pageAddr = readLock(pageMem, cacheId, pageId, page, lsnr);
-
-        if (pageAddr == 0L)
-            return lockFailed;
-        try {
-            PageIO io = PageIO.getPageIO(pageAddr);
-            return h.run(cacheId, pageId, page, pageAddr, io, null, arg, intArg);
-        }
-        finally {
-            readUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr);
-        }
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param lsnr Lock listener.
-     * @return Page address.
-     */
-    public static long readLock(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        PageLockListener lsnr) {
-        lsnr.onBeforeReadLock(cacheId, pageId, page);
-
-        long pageAddr = pageMem.readLock(cacheId, pageId, page);
-
-        lsnr.onReadLock(cacheId, pageId, page, pageAddr);
-
-        return pageAddr;
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address (for-write pointer)
-     * @param lsnr Lock listener.
-     */
-    public static void readUnlock(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        long pageAddr,
-        PageLockListener lsnr) {
-        lsnr.onReadUnlock(cacheId, pageId, page, pageAddr);
-
-        pageMem.readUnlock(cacheId, pageId, page);
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param init IO for new page initialization.
-     * @param wal Write ahead log.
-     * @param lsnr Lock listener.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static void initPage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        PageIO init,
-        IgniteWriteAheadLogManager wal,
-        PageLockListener lsnr
-    ) throws IgniteCheckedException {
-        Boolean res = writePage(pageMem, cacheId, pageId, lsnr, PageHandler.NO_OP, init, wal, null, null, 0, FALSE);
-
-        assert res != FALSE;
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param lsnr Lock listener.
-     * @param h Handler.
-     * @param init IO for new page initialization or {@code null} if it is an existing page.
-     * @param wal Write ahead log.
-     * @param walPlc Full page WAL record policy.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @param lockFailed Result in case of lock failure due to page recycling.
-     * @return Handler result.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <X, R> R writePage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        PageLockListener lsnr,
-        PageHandler<X, R> h,
-        PageIO init,
-        IgniteWriteAheadLogManager wal,
-        Boolean walPlc,
-        X arg,
-        int intArg,
-        R lockFailed
-    ) throws IgniteCheckedException {
-        boolean releaseAfterWrite = true;
-        long page = pageMem.acquirePage(cacheId, pageId);
-        try {
-            long pageAddr = writeLock(pageMem, cacheId, pageId, page, lsnr, false);
-
-            if (pageAddr == 0L)
-                return lockFailed;
-
-            boolean ok = false;
-
-            try {
-                if (init != null) {
-                    // It is a new page and we have to initialize it.
-                    doInitPage(pageMem, cacheId, pageId, page, pageAddr, init, wal);
-                    walPlc = FALSE;
-                }
-                else {
-                    init = PageIO.getPageIO(pageAddr);
-                }
-
-                R res = h.run(cacheId, pageId, page, pageAddr, init, walPlc, arg, intArg);
-
-                ok = true;
-
-                return res;
-            }
-            finally {
-                assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
-
-                if (releaseAfterWrite = h.releaseAfterWrite(cacheId, pageId, page, pageAddr, arg, intArg))
-                    writeUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr, walPlc, ok);
-            }
-        }
-        finally {
-            if (releaseAfterWrite)
-                pageMem.releasePage(cacheId, pageId, page);
-        }
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param lsnr Lock listener.
-     * @param h Handler.
-     * @param init IO for new page initialization or {@code null} if it is an existing page.
-     * @param wal Write ahead log.
-     * @param walPlc Full page WAL record policy.
-     * @param arg Argument.
-     * @param intArg Argument of type {@code int}.
-     * @param lockFailed Result in case of lock failure due to page recycling.
-     * @return Handler result.
-     * @throws IgniteCheckedException If failed.
-     */
-    public static <X, R> R writePage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        PageLockListener lsnr,
-        PageHandler<X, R> h,
-        PageIO init,
-        IgniteWriteAheadLogManager wal,
-        Boolean walPlc,
-        X arg,
-        int intArg,
-        R lockFailed
-    ) throws IgniteCheckedException {
-        long pageAddr = writeLock(pageMem, cacheId, pageId, page, lsnr, false);
-
-        if (pageAddr == 0L)
-            return lockFailed;
-
-        boolean ok = false;
-
-        try {
-            if (init != null) {
-                // It is a new page and we have to initialize it.
-                doInitPage(pageMem, cacheId, pageId, page, pageAddr, init, wal);
-                walPlc = FALSE;
-            }
-            else {
-                init = PageIO.getPageIO(pageAddr);
-            }
-
-            R res = h.run(cacheId, pageId, page, pageAddr, init, walPlc, arg, intArg);
-
-            ok = true;
-
-            return res;
-        }
-        finally {
-            assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
-
-            if (h.releaseAfterWrite(cacheId, pageId, page, pageAddr, arg, intArg))
-                writeUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr, walPlc, ok);
-        }
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     * @param lsnr Lock listener.
-     * @param walPlc Full page WAL record policy.
-     * @param dirty Page is dirty.
-     */
-    public static void writeUnlock(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        long pageAddr,
-        PageLockListener lsnr,
-        Boolean walPlc,
-        boolean dirty) {
-        lsnr.onWriteUnlock(cacheId, pageId, page, pageAddr);
-
-        pageMem.writeUnlock(cacheId, pageId, page, walPlc, dirty);
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param lsnr Lock listener.
-     * @param tryLock Only try to lock without waiting.
-     * @return Page address or {@code 0} if failed to lock due to recycling.
-     */
-    public static long writeLock(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        PageLockListener lsnr,
-        boolean tryLock) {
-        lsnr.onBeforeWriteLock(cacheId, pageId, page);
-
-        long pageAddr = tryLock ? pageMem.tryWriteLock(cacheId, pageId, page) : pageMem.writeLock(cacheId, pageId, page);
-
-        lsnr.onWriteLock(cacheId, pageId, page, pageAddr);
-
-        return pageAddr;
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     * @param init Initial IO.
-     * @param wal Write ahead log.
-     * @throws IgniteCheckedException If failed.
-     */
-    private static void doInitPage(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        long pageAddr,
-        PageIO init,
-        IgniteWriteAheadLogManager wal) throws IgniteCheckedException {
-
-        assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
-
-        init.initNewPage(pageAddr, pageId, pageMem.pageSize());
-
-        // Here we should never write full page, because it is known to be new.
-        if (isWalDeltaRecordNeeded(pageMem, cacheId, pageId, page, wal, FALSE))
-            wal.log(new InitNewPageRecord(cacheId, pageId,
-                init.getType(), init.getVersion(), pageId));
-    }
-
-    /**
-     * @param pageMem Page memory.
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param wal Write ahead log.
-     * @param walPlc Full page WAL record policy.
-     * @return {@code true} If we need to make a delta WAL record for the change in this page.
-     */
-    public static boolean isWalDeltaRecordNeeded(
-        PageMemory pageMem,
-        int cacheId,
-        long pageId,
-        long page,
-        IgniteWriteAheadLogManager wal,
-        Boolean walPlc) {
-        // If the page is clean, then it is either newly allocated or just after checkpoint.
-        // In both cases we have to write full page contents to WAL.
-        return wal != null && !wal.isAlwaysWriteFullPages() && walPlc != TRUE &&
-            (walPlc == FALSE || pageMem.isDirty(cacheId, pageId, page));
-    }
-
-    /**
-     * @param src Source.
-     * @param dst Destination.
-     * @param srcOff Source offset in bytes.
-     * @param dstOff Destination offset in bytes.
-     * @param cnt Bytes count to copy.
-     */
-    public static void copyMemory(ByteBuffer src, ByteBuffer dst, long srcOff, long dstOff, long cnt) {
-        byte[] srcArr = src.hasArray() ? src.array() : null;
-        byte[] dstArr = dst.hasArray() ? dst.array() : null;
-        long srcArrOff = src.hasArray() ? src.arrayOffset() + GridUnsafe.BYTE_ARR_OFF : 0;
-        long dstArrOff = dst.hasArray() ? dst.arrayOffset() + GridUnsafe.BYTE_ARR_OFF : 0;
-
-        long srcPtr = src.isDirect() ? GridUnsafe.bufferAddress(src) : 0;
-        long dstPtr = dst.isDirect() ? GridUnsafe.bufferAddress(dst) : 0;
-
-        GridUnsafe.copyMemory(srcArr, srcPtr + srcArrOff + srcOff, dstArr, dstPtr + dstArrOff + dstOff, cnt);
-    }
-
-    /**
-     * Will zero memory in buf
-     * @param buf Buffer.
-     * @param off Offset.
-     * @param len Length.
-     */
-    public static void zeroMemory(ByteBuffer buf, int off, int len) {
-        if (buf.isDirect())
-            GridUnsafe.setMemory(GridUnsafe.bufferAddress(buf) + off, len, (byte)0);
-
-        else {
-            for (int i = off; i < off + len; i++)
-                buf.put(i, (byte)0); //TODO Optimize!
-        }
-    }
-
-    /**
-     * @param srcAddr Source.
-     * @param dstAddr Destination.
-     * @param srcOff Source offset in bytes.
-     * @param dstOff Destination offset in bytes.
-     * @param cnt Bytes count to copy.
-     */
-    public static void copyMemory(long srcAddr, long dstAddr, long srcOff, long dstOff, long cnt) {
-        GridUnsafe.copyMemory(null, srcAddr + srcOff, null, dstAddr + dstOff, cnt);
-    }
-
-    /**
-     * @param addr Address.
-     * @param off Offset.
-     * @param len Length.
-     */
-    public static void zeroMemory(long addr, int off, int len) {
-        GridUnsafe.setMemory(addr + off, len, (byte)0);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
deleted file mode 100644
index 904d217..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.processors.cache.database.tree.util;
-
-/**
- * Page lock listener.
- */
-public interface PageLockListener {
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     */
-    public void onBeforeWriteLock(int cacheId, long pageId, long page);
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     */
-    public void onWriteLock(int cacheId, long pageId, long page, long pageAddr);
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     */
-    public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr);
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     */
-    public void onBeforeReadLock(int cacheId, long pageId, long page);
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     */
-    public void onReadLock(int cacheId, long pageId, long page, long pageAddr);
-
-    /**
-     * @param cacheId Cache ID.
-     * @param pageId Page ID.
-     * @param page Page pointer.
-     * @param pageAddr Page address.
-     */
-    public void onReadUnlock(int cacheId, long pageId, long page, long pageAddr);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 4480efe..f0d5bf1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -47,7 +47,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader;
 import org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index f29c507..78ff595 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -41,7 +41,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedExceptio
 import org.apache.ignite.internal.processors.cache.GridCacheMessage;
 import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
index aabe025..cab90ae 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
@@ -42,7 +42,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheFutureAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheMessage;
 import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.near.CacheVersionedValue;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetResponse;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 2f99033..432e3f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -56,13 +56,12 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
 import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
-import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.GridCacheReturn;
 import org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult;
 import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture;