You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/08/28 14:48:02 UTC

[1/8] ignite git commit: IGNITE-6101 Try to improve local scans performance

Repository: ignite
Updated Branches:
  refs/heads/ignite-6149 5a4c6f354 -> 6de99efa5


http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 675bd56..947b508 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -132,6 +132,7 @@ org.apache.ignite.compute.gridify.aop.GridifyDefaultRangeTask
 org.apache.ignite.compute.gridify.aop.GridifyDefaultTask
 org.apache.ignite.configuration.CacheConfiguration
 org.apache.ignite.configuration.CacheConfiguration$IgniteAllNodesPredicate
+org.apache.ignite.configuration.CheckpointWriteOrder
 org.apache.ignite.configuration.CollectionConfiguration
 org.apache.ignite.configuration.DataPageEvictionMode
 org.apache.ignite.configuration.DeploymentMode
@@ -303,6 +304,7 @@ org.apache.ignite.internal.executor.GridExecutorService
 org.apache.ignite.internal.executor.GridExecutorService$1
 org.apache.ignite.internal.executor.GridExecutorService$TaskTerminateListener
 org.apache.ignite.internal.igfs.common.IgfsIpcCommand
+org.apache.ignite.internal.jdbc2.JdbcBatchUpdateTask
 org.apache.ignite.internal.jdbc2.JdbcConnection$JdbcConnectionValidationTask
 org.apache.ignite.internal.jdbc2.JdbcDatabaseMetadata$UpdateMetadataTask
 org.apache.ignite.internal.jdbc2.JdbcQueryTask
@@ -347,19 +349,25 @@ org.apache.ignite.internal.processors.affinity.GridAffinityAssignment
 org.apache.ignite.internal.processors.affinity.GridAffinityMessage
 org.apache.ignite.internal.processors.affinity.GridAffinityUtils$AffinityJob
 org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$1
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$10
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$11
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$12
-org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$12$1
-org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$12$2
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$13
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$14
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$15
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$16
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$17
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$18
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$18$1
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$18$2
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$19
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$2
-org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$3
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$20
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$21
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$22
+org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$4
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$5
-org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$6
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$7
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$8
 org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager$9
@@ -411,15 +419,16 @@ org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest
 org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy
 org.apache.ignite.internal.processors.cache.ExchangeActions$1
 org.apache.ignite.internal.processors.cache.ExchangeActions$2
+org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy
 org.apache.ignite.internal.processors.cache.GridCacheAdapter
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$10
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$11
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$12
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$13
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$14
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$15$1
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$15
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$16
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$17
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$17$1
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$2
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$25$1
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$27
@@ -479,7 +488,7 @@ org.apache.ignite.internal.processors.cache.GridCacheEntryInfo
 org.apache.ignite.internal.processors.cache.GridCacheEntryRedeployException
 org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException
 org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan
-org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan$1
+org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan$2
 org.apache.ignite.internal.processors.cache.GridCacheFilterFailedException
 org.apache.ignite.internal.processors.cache.GridCacheGateway$State
 org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage
@@ -502,14 +511,15 @@ org.apache.ignite.internal.processors.cache.GridCacheMvccManager$7
 org.apache.ignite.internal.processors.cache.GridCacheMvccManager$FinishLockFuture$1
 org.apache.ignite.internal.processors.cache.GridCacheOperation
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$2
+org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$2$1
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$3
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$4
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$5
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$6
-org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$7
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeFutureSet
 org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$MessageHandler
 org.apache.ignite.internal.processors.cache.GridCacheProcessor$1
+org.apache.ignite.internal.processors.cache.GridCacheProcessor$10
 org.apache.ignite.internal.processors.cache.GridCacheProcessor$3
 org.apache.ignite.internal.processors.cache.GridCacheProcessor$4
 org.apache.ignite.internal.processors.cache.GridCacheProcessor$5
@@ -557,15 +567,15 @@ org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$7
 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$9
 org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$CacheDataStoreImpl$1
 org.apache.ignite.internal.processors.cache.IgniteCacheProxy
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$1$1
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$10
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$2
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$3
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$4
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$6
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$7
-org.apache.ignite.internal.processors.cache.IgniteCacheProxy$8
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$1
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$2
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$3
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$4
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$6
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$7
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$8
+org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl$9
 org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator
 org.apache.ignite.internal.processors.cache.KeyCacheObject
 org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl
@@ -640,6 +650,7 @@ org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactional
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$11
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$12
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$13
+org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$14
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$2
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$3
 org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter$4
@@ -748,6 +759,9 @@ org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtCol
 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$4
 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$LockTimeoutObject$1
 org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture$MiniFuture$1
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CacheGroupAffinityMessage
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysFuture$1
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse
@@ -764,11 +778,15 @@ org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPar
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplier$SupplyContextPhase
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage
-org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$1
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$2
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$3
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$4
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$5
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$6
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$7
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$8
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$8$1$1
+org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$ExchangeLocalState
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture$ExchangeType
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage
 org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage
@@ -865,10 +883,11 @@ org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$5
 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$8
 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$9
 org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter$RowData
-org.apache.ignite.internal.processors.cache.persistence.FullPageIdIterableComparator
-org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$8
+org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$6
+org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$9
 org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$CheckpointEntryType
 org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager$RebalanceIteratorAdapter
+org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager$1
 org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory
 org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory
 org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl$Segment
@@ -884,6 +903,7 @@ org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogMan
 org.apache.ignite.internal.processors.cache.persistence.wal.SegmentEofException
 org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException
 org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneWalRecordsIterator
+org.apache.ignite.internal.processors.cache.query.CacheQueryEntry
 org.apache.ignite.internal.processors.cache.query.CacheQueryType
 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture$1
 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryManager$1
@@ -898,8 +918,7 @@ org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter$1
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter$2
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$10
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$11
-org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$12
-org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$13$1
+org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$12$1
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$4$1
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$4$2
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$5
@@ -914,9 +933,9 @@ org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$Metadata
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$MetadataJob$1
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$MetadataJob$2
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$MetadataJob$3
-org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$PeekValueExpiryAwareIterator
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$RequestFutureMap
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$RequestFutureMap$1
+org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$ScanQueryIterator
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryMetricsAdapter
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryMetricsKey
 org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest
@@ -968,6 +987,7 @@ org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$14
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$15
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$16
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$17
+org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$18
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$2
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$3
 org.apache.ignite.internal.processors.cache.transactions.IgniteTxHandler$4
@@ -1010,9 +1030,9 @@ org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry
 org.apache.ignite.internal.processors.cache.version.GridCacheVersion
 org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext$State
 org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx
-org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl$UserCacheObjectByteArrayImpl
-org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl$UserCacheObjectImpl
-org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl$UserKeyCacheObjectImpl
+org.apache.ignite.internal.processors.cacheobject.UserCacheObjectByteArrayImpl
+org.apache.ignite.internal.processors.cacheobject.UserCacheObjectImpl
+org.apache.ignite.internal.processors.cacheobject.UserKeyCacheObjectImpl
 org.apache.ignite.internal.processors.closure.GridClosureProcessor$C1
 org.apache.ignite.internal.processors.closure.GridClosureProcessor$C1MLA
 org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2
@@ -1041,15 +1061,17 @@ org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$1$1
 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$2
 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$3
 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$4
-org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$6
+org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$5
+org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$7
+org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$CheckGlobalStateComputeRequest
 org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor$ClientChangeGlobalStateComputeRequest
 org.apache.ignite.internal.processors.continuous.AbstractContinuousMessage
 org.apache.ignite.internal.processors.continuous.GridContinuousHandler
 org.apache.ignite.internal.processors.continuous.GridContinuousHandler$RegisterStatus
 org.apache.ignite.internal.processors.continuous.GridContinuousMessage
 org.apache.ignite.internal.processors.continuous.GridContinuousMessageType
-org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$10$1
-org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$9
+org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$8
+org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$9$1
 org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$DiscoveryData
 org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$DiscoveryDataItem
 org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$LocalRoutineInfo
@@ -1366,6 +1388,7 @@ org.apache.ignite.internal.processors.rest.client.message.GridRouterResponse
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$2
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$3
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$4
+org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$5
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$AddCommand
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$AppendCommand
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$CacheCommand
@@ -1395,6 +1418,7 @@ org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandle
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$ReplaceCommand
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$ReplaceValueCommand
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$SizeCommand
+org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler$UpdateTllCommand
 org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheRestResponse
 org.apache.ignite.internal.processors.rest.handlers.datastructures.DataStructuresCommandHandler$1
 org.apache.ignite.internal.processors.rest.handlers.query.CacheQueryFieldsMetaResult
@@ -1991,16 +2015,18 @@ org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointData
 org.apache.ignite.spi.collision.jobstealing.JobStealingRequest
 org.apache.ignite.spi.collision.priorityqueue.PriorityQueueCollisionSpi$PriorityGridCollisionJobContextComparator
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$1
+org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$11
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$12
-org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$13
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$1
+org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$2
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosure
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosure$1
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosureNew
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$2$ConnectClosureNew$1
+org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$4
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$5
-org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$6
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeClosure
+org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeException
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeMessage
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeMessage2
 org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi$HandshakeTimeoutException

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index 0241165..6712b5b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -27,6 +27,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.eviction.EvictableEntry;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -831,6 +832,11 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
     }
 
     /** {@inheritDoc} */
+    @Override public CacheObject unswap(CacheDataRow row) throws IgniteCheckedException {
+        return null;
+    }
+
+    /** {@inheritDoc} */
     @Override public boolean hasLockCandidate(long threadId) throws GridCacheEntryRemovedException {
         return localCandidate(threadId) != null;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryTransformerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryTransformerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryTransformerSelfTest.java
index 5041690..c378b6f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryTransformerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryTransformerSelfTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.cache.query.ContinuousQuery;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.cache.query.SpiQuery;
@@ -183,6 +184,46 @@ public class GridCacheQueryTransformerSelfTest extends GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
+    public void testGetObjectFieldPartitioned() throws Exception {
+        IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
+
+        Affinity<Integer> affinity = affinity(cache);
+
+        try {
+            int [] keys = new int[50];
+
+            for (int i = 0, j = 0; i < keys.length; j++) {
+                if (affinity.partition(j) == 0)
+                    keys[i++] = j;
+            }
+
+            for (int i : keys)
+                cache.put(i, new Value("str" + i, i * 100));
+
+            IgniteClosure<Cache.Entry<Integer, Value>, Integer> transformer =
+                new IgniteClosure<Cache.Entry<Integer, Value>, Integer>() {
+                    @Override public Integer apply(Cache.Entry<Integer, Value> e) {
+                        return e.getValue().idx;
+                    }
+                };
+
+            List<Integer> res = cache.query(new ScanQuery<Integer, Value>().setPartition(0), transformer).getAll();
+
+            assertEquals(50, res.size());
+
+            Collections.sort(res);
+
+            for (int i = 0; i < keys.length; i++)
+                assertEquals(keys[i] * 100, res.get(i).intValue());
+        }
+        finally {
+            cache.destroy();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testGetObjectFieldFiltered() throws Exception {
         IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
 


[8/8] ignite git commit: ignite-6149

Posted by sb...@apache.org.
ignite-6149


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6de99efa
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6de99efa
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6de99efa

Branch: refs/heads/ignite-6149
Commit: 6de99efa547f0fcd80946c2a3b9825f4b944b439
Parents: 57b9e8d
Author: sboikov <sb...@gridgain.com>
Authored: Mon Aug 28 16:07:56 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon Aug 28 17:45:12 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/MvccTestApp.java | 369 +++++++++++++++----
 1 file changed, 307 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6de99efa/modules/core/src/main/java/org/apache/ignite/internal/MvccTestApp.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MvccTestApp.java b/modules/core/src/main/java/org/apache/ignite/internal/MvccTestApp.java
index b99e805..fe36e1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MvccTestApp.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MvccTestApp.java
@@ -37,8 +37,11 @@ import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.util.GridAtomicLong;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
@@ -53,17 +56,64 @@ public class MvccTestApp {
     /** */
     private static final boolean DEBUG_LOG = false;
 
+    public static void main0(String[] args) throws Exception {
+        final MvccTestApp.TestCluster cluster = new MvccTestApp.TestCluster(3);
+
+        final int ACCOUNTS = 3;
+
+        final int START_VAL = 100_000;
+
+        final Map<Object, Object> data = new TreeMap<>();
+
+        for (int i = 0; i < ACCOUNTS; i++)
+            data.put(i, START_VAL);
+
+        cluster.txPutAll(data);
+
+        cluster.txTransfer(0, 1, true);
+        cluster.txTransfer(0, 1, true);
+        cluster.txTransfer(0, 2, true);
+
+        Map<Object, Object> getData = cluster.getAll(data.keySet());
+
+        int sum = 0;
+
+        for (int i = 0; i < ACCOUNTS; i++) {
+            Integer val = (Integer)getData.get(i);
+
+            sum += val;
+
+            System.out.println("Val: " + val);
+        }
+
+        System.out.println("Sum: " + sum);
+
+        cluster.cleanup();
+
+        getData = cluster.getAll(data.keySet());
+
+        MvccQueryVersion ver1 = cluster.crd.queryVersion();
+        MvccQueryVersion ver2 = cluster.crd.queryVersion();
+
+        cluster.crd.queryDone(ver2.cntr);
+        cluster.crd.queryDone(ver1.cntr);
+
+    }
+
     public static void main(String[] args) throws Exception {
         final AtomicBoolean err = new AtomicBoolean();
 
-        for (int iter = 0; iter < 10; iter++) {
-            System.out.println("Iteration: " + iter);
+        final int READ_THREADS = 4;
+        final int UPDATE_THREADS = 6;
+        final int ACCOUNTS = 100;
 
-            final TestCluster cluster = new TestCluster(1);
+        final int START_VAL = 1000;
 
-            final int ACCOUNTS = 4;
+        for (int iter = 0; iter < 10; iter++) {
+            System.out.println("Iteration [readThreads=" + READ_THREADS +
+                ", updateThreads=" + UPDATE_THREADS + ", accounts=" + ACCOUNTS + ", iter=" + iter + ']');
 
-            final int START_VAL = 10;
+            final TestCluster cluster = new TestCluster(1);
 
             final Map<Object, Object> data = new TreeMap<>();
 
@@ -76,7 +126,28 @@ public class MvccTestApp {
 
             List<Thread> threads = new ArrayList<>();
 
-            for (int i = 0; i < 5; i++) {
+            Thread cleanupThread = new Thread(new Runnable() {
+                @Override public void run() {
+                    Thread.currentThread().setName("cleanup");
+
+                    try {
+                        while (!stop.get()) {
+                            cluster.cleanup();
+
+                            Thread.sleep(1);
+                        }
+                    }
+                    catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+
+            threads.add(cleanupThread);
+
+            cleanupThread.start();
+
+            for (int i = 0; i < READ_THREADS; i++) {
                 final int id = i;
 
                 Thread thread = new Thread(new Runnable() {
@@ -127,7 +198,7 @@ public class MvccTestApp {
                 thread.start();
             }
 
-            for (int i = 0; i < 2; i++) {
+            for (int i = 0; i < UPDATE_THREADS; i++) {
                 final int id = i;
 
                 Thread thread = new Thread(new Runnable() {
@@ -161,13 +232,15 @@ public class MvccTestApp {
                 thread.start();
             }
 
-            long endTime = System.currentTimeMillis() + 5000;
+            long endTime = System.currentTimeMillis() + 60_000;
 
             while (!stop.get()) {
-                Thread.sleep(100);
+                Thread.sleep(1000);
 
                 if (System.currentTimeMillis() >= endTime)
                     break;
+
+                //cluster.dumpMvccInfo();
             }
 
             stop.set(true);
@@ -195,6 +268,14 @@ public class MvccTestApp {
                 System.exit(1);
             }
 
+//            cluster.dumpMvccInfo();
+//
+//            System.out.println("Cleanup");
+//
+//            cluster.cleanup();
+//
+//            cluster.dumpMvccInfo();
+
             TestDebugLog.clear();
         }
     }
@@ -219,6 +300,13 @@ public class MvccTestApp {
                 nodes.add(new Node(i));
         }
 
+        void cleanup() {
+            CoordinatorCounter cntr = crd.cleanupVersion();
+
+            for (Node node : nodes)
+                node.dataStore.cleanup(cntr);
+        }
+
         void txPutAll(Map<Object, Object> data) {
             TxId txId = new TxId(txIdGen.incrementAndGet());
 
@@ -345,6 +433,26 @@ public class MvccTestApp {
             crd.txDone(txId);
         }
 
+        public void dumpMvccInfo() {
+            for (Node node : nodes) {
+                for (Map.Entry<Object, MvccValue> e : node.dataStore.mainIdx.entrySet()) {
+                    List<MvccValue> list = node.dataStore.mvccIdx.get(e.getKey());
+
+                    int size = 0;
+
+                    if (list != null) {
+                        synchronized (list) {
+                            size = list.size();
+                        }
+                    }
+
+                    System.out.println("Mvcc info [key=" + e.getKey() +
+                        ", val=" + e.getValue() +
+                        ", mvccVals=" + size + ']');
+                }
+            }
+        }
+
         public Map<Object, Object> getAll(Set<?> keys) {
             MvccQueryVersion ver = crd.queryVersion();
 
@@ -407,6 +515,9 @@ public class MvccTestApp {
         private final GridAtomicLong commitCntr = new GridAtomicLong(-1);
 
         /** */
+        private final ConcurrentHashMap8<Long, QueryCounter> activeQueries = new ConcurrentHashMap8<>();
+
+        /** */
         @GridToStringInclude
         private final ConcurrentHashMap8<TxId, TxId> activeTxs = new ConcurrentHashMap8<>();
 
@@ -428,15 +539,12 @@ public class MvccTestApp {
             commitCntr.setIfGreater(cntr.cntr);
         }
 
-        MvccQueryVersion queryVersion() {
-            long useCntr = commitCntr.get();
-
-            Set<TxId> txs = new HashSet<>();
-
+        private Long minActive(Set<TxId> txs) {
             Long minActive = null;
 
             for (Map.Entry<TxId, TxId> e : activeTxs.entrySet()) {
-                txs.add(e.getKey());
+                if (txs != null)
+                    txs.add(e.getKey());
 
                 TxId val = e.getValue();
 
@@ -451,14 +559,102 @@ public class MvccTestApp {
                     minActive = cntr;
             }
 
+            return minActive;
+        }
+
+        static class QueryCounter extends AtomicInteger {
+            public QueryCounter(int initialValue) {
+                super(initialValue);
+            }
+
+            boolean increment2() {
+                for (;;) {
+                    int current = get();
+                    int next = current + 1;
+
+                    if (current == 0)
+                        return false;
+
+                    if (compareAndSet(current, next))
+                        return true;
+                }
+            }
+        }
+
+        private ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+        MvccQueryVersion queryVersion() {
+            rwLock.readLock().lock();
+
+            long useCntr = commitCntr.get();
+
+            Set<TxId> txs = new HashSet<>();
+
+            Long minActive = minActive(txs);
+
             if (minActive != null && minActive < useCntr)
                 useCntr = minActive;
 
-            return new MvccQueryVersion(new CoordinatorCounter(useCntr), txs);
+            MvccQueryVersion qryVer = new MvccQueryVersion(new CoordinatorCounter(useCntr), txs);
+
+            for (;;) {
+                QueryCounter qryCnt = activeQueries.get(useCntr);
+
+                if (qryCnt != null) {
+                    boolean inc = qryCnt.increment2();
+
+                    if (!inc) {
+                        activeQueries.remove(useCntr, qryCnt);
+
+                        continue;
+                    }
+                }
+                else {
+                    qryCnt = new QueryCounter(1);
+
+                    if (activeQueries.putIfAbsent(useCntr, qryCnt) != null)
+                        continue;
+                }
+
+                break;
+            }
+
+            rwLock.readLock().unlock();
+
+            return qryVer;
         }
 
-        void queryDone(CoordinatorCounter ctr) {
+        void queryDone(CoordinatorCounter cntr) {
+            AtomicInteger qryCnt = activeQueries.get(cntr.cntr);
+
+            assert qryCnt != null : cntr.cntr;
+
+            int left = qryCnt.decrementAndGet();
+
+            assert left >= 0 : left;
+
+            if (left == 0)
+                activeQueries.remove(cntr.cntr, qryCnt);
+        }
+
+        CoordinatorCounter cleanupVersion() {
+            rwLock.writeLock().lock();
+
+            long useCntr = commitCntr.get();
+
+            Long minActive = minActive(null);
+
+            if (minActive != null && minActive < useCntr)
+                useCntr = minActive - 1;
+
+            for (Long qryCntr : activeQueries.keySet()) {
+                if (qryCntr <= useCntr)
+                    useCntr = qryCntr - 1;
+            }
+
+            rwLock.writeLock().unlock();
 
+            return new CoordinatorCounter(useCntr);
         }
 
         @Override public String toString() {
@@ -595,10 +791,46 @@ public class MvccTestApp {
         private final ConcurrentHashMap<Object, ReentrantLock> locks = new ConcurrentHashMap<>();
 
         /** */
-        private final ConcurrentHashMap<Object, MvccValue> mainIdx = new ConcurrentHashMap<>();
+        final ConcurrentHashMap<Object, MvccValue> mainIdx = new ConcurrentHashMap<>();
 
         /** */
-        private final ConcurrentHashMap<Object, List<MvccValue>> mvccIdx = new ConcurrentHashMap<>();
+        final ConcurrentHashMap<Object, List<MvccValue>> mvccIdx = new ConcurrentHashMap<>();
+
+        void cleanup(CoordinatorCounter cleanupCntr) {
+            for (Map.Entry<Object, List<MvccValue>> e : mvccIdx.entrySet()) {
+                lockEntry(e.getKey());
+
+                try {
+                    List<MvccValue> list = e.getValue();
+
+                    synchronized (list) {
+                        for (int i = list.size() - 1; i >= 0; i--) {
+                            MvccValue val = list.get(i);
+
+                            if (val.ver.cntr.compareTo(cleanupCntr) <= 0) {
+                                if (DEBUG_LOG) {
+                                    TestDebugLog.msgs.add(new TestDebugLog.Msg6_1("cleanup",
+                                        e.getKey(), val.val, val.ver, cleanupCntr.cntr, null, null));
+                                }
+
+                                mainIdx.put(e.getKey(), val);
+
+                                for (int j = 0; j <= i; j++)
+                                    list.remove(0);
+
+                                if (list.isEmpty())
+                                    mvccIdx.remove(e.getKey());
+
+                                break;
+                            }
+                        }
+                    }
+                }
+                finally {
+                    unlockEntry(e.getKey());
+                }
+            }
+        }
 
         void lockEntry(Object key) {
             ReentrantLock e = lock(key);
@@ -615,8 +847,11 @@ public class MvccTestApp {
         void updateEntry(Object key, Object val, MvccUpdateVersion ver) {
             List<MvccValue> list = mvccIdx.get(key);
 
-            if (list == null)
-                mvccIdx.put(key, list = new ArrayList<>());
+            if (list == null) {
+                Object old = mvccIdx.putIfAbsent(key, list = new ArrayList<>());
+
+                assert old == null;
+            }
 
             synchronized (list) {
                 list.add(new MvccValue(val, ver));
@@ -626,8 +861,12 @@ public class MvccTestApp {
         Object lastValue(Object key) {
             List<MvccValue> list = mvccIdx.get(key);
 
-            if (list != null)
-                return list.get(list.size() - 1).val;
+            if (list != null) {
+                synchronized (list) {
+                    if (list.size() > 0)
+                        return list.get(list.size() - 1).val;
+                }
+            }
 
             MvccValue val = mainIdx.get(key);
 
@@ -651,7 +890,7 @@ public class MvccTestApp {
                             continue;
 
                         if (DEBUG_LOG) {
-                            TestDebugLog.msgs.add(new TestDebugLog.Msg3("read val", key, val, val.ver));
+                            TestDebugLog.msgs.add(new TestDebugLog.Msg3("read mvcc val", key, val, val.ver));
                             //log("get res [key=" + key + ", val=" + val.val + ", ver=" + val.ver + ']');
                         }
 
@@ -662,6 +901,19 @@ public class MvccTestApp {
 
             MvccValue val = mainIdx.get(key);
 
+            if (val != null) {
+                int cmp = val.ver.cntr.compareTo(ver.cntr);
+
+                assert cmp <= 0 : "Committed [ver=" + val.ver + ", qryVer=" + ver.cntr + ']';
+
+                if (DEBUG_LOG)
+                    TestDebugLog.msgs.add(new TestDebugLog.Msg3("read comitted val", key, val, val.ver));
+            }
+            else {
+                if (DEBUG_LOG)
+                    TestDebugLog.msgs.add(new TestDebugLog.Msg3("read comitted null", key, null, null));
+            }
+
             return val != null ? val.val : null;
         }
 
@@ -798,7 +1050,34 @@ class TestDebugLog {
                 ", id2=" + v4 +
                 ", v2=" + v5 +
                 ", cntr=" + v6 +
-                ", msg=" + msg +
+                ", thread=" + thread +
+                ", time=" + DEBUG_DATE_FMT.format(new Date(ts)) + ']';
+        }
+    }
+    static class Msg6_1 extends Message{
+        Object v1;
+        Object v2;
+        Object v3;
+        Object v4;
+        Object v5;
+        Object v6;
+
+        public Msg6_1(String msg, Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) {
+            super(msg);
+            this.v1 = v1;
+            this.v2 = v2;
+            this.v3 = v3;
+            this.v4 = v4;
+            this.v5 = v5;
+            this.v6 = v6;
+        }
+
+        public String toString() {
+            return "Msg [msg=" + msg +
+                ", key=" + v1 +
+                ", val=" + v2 +
+                ", ver=" + v3 +
+                ", cleanupC=" + v4 +
                 ", thread=" + thread +
                 ", time=" + DEBUG_DATE_FMT.format(new Date(ts)) + ']';
         }
@@ -845,7 +1124,7 @@ class TestDebugLog {
             System.out.println(msg);
     }
 
-    public static void addEntryMessage(Object key, Object val, Object arg, String msg) {
+    public static void addEntryMessage(Object key, Object val, String msg) {
         if (key instanceof KeyCacheObject)
             key = ((KeyCacheObject)key).value(null, false);
 
@@ -906,10 +1185,8 @@ class TestDebugLog {
                 if (msg instanceof Message) {
                     String msg0 = ((Message) msg).msg;
 
-                    if (msg0.equals("tx done") || msg0.equals("update"))
-
-                    w.println(msg.toString());
-
+                    if (msg0.equals("tx done") || msg0.equals("update") || msg0.equals("cleanup"))
+                        w.println(msg.toString());
                 }
             }
 
@@ -1014,37 +1291,5 @@ class TestDebugLog {
                 it.remove();
         }
     }
-    public static void main0(String[] args) throws Exception {
-        final MvccTestApp.TestCluster cluster = new MvccTestApp.TestCluster(3);
-
-        final int ACCOUNTS = 3;
-
-        final int START_VAL = 100_000;
-
-        final Map<Object, Object> data = new TreeMap<>();
-
-        for (int i = 0; i < ACCOUNTS; i++)
-            data.put(i, START_VAL);
-
-        cluster.txPutAll(data);
-
-        cluster.txTransfer(0, 1, true);
-        cluster.txTransfer(0, 1, true);
-        cluster.txTransfer(0, 2, true);
-
-        Map<Object, Object> getData = cluster.getAll(data.keySet());
-
-        int sum = 0;
-
-        for (int i = 0; i < ACCOUNTS; i++) {
-            Integer val = (Integer)getData.get(i);
-
-            sum += val;
-
-            System.out.println("Val: " + val);
-        }
-
-        System.out.println("Sum: " + sum);
-    }
 
 }
\ No newline at end of file


[3/8] ignite git commit: IGNITE-6178 Make CheckpointWriteOrder.SEQUENTIAL and checkpointingThreads=4 default in persistent store confguration

Posted by sb...@apache.org.
IGNITE-6178 Make CheckpointWriteOrder.SEQUENTIAL and checkpointingThreads=4 default in persistent store confguration


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f279b00
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f279b00
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f279b00

Branch: refs/heads/ignite-6149
Commit: 6f279b004990d4a21436a80dd4bbf21c5210c282
Parents: 1c9d80a
Author: Ivan Rakov <iv...@gmail.com>
Authored: Thu Aug 24 18:18:31 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Fri Aug 25 13:19:19 2017 +0300

----------------------------------------------------------------------
 .../ignite/configuration/PersistentStoreConfiguration.java    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6f279b00/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
index 5b902ac..888bf42 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/PersistentStoreConfiguration.java
@@ -16,12 +16,11 @@
  */
 package org.apache.ignite.configuration;
 
+import java.io.Serializable;
 import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
 import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
 import org.apache.ignite.internal.util.typedef.internal.S;
 
-import java.io.Serializable;
-
 /**
  * Configures Apache Ignite Persistent store.
  */
@@ -45,10 +44,10 @@ public class PersistentStoreConfiguration implements Serializable {
     public static final int DFLT_RATE_TIME_INTERVAL_MILLIS = 60_000;
 
     /** Default number of checkpointing threads. */
-    public static final int DFLT_CHECKPOINTING_THREADS = 1;
+    public static final int DFLT_CHECKPOINTING_THREADS = 4;
 
     /** Default checkpoint write order. */
-    public static final CheckpointWriteOrder DFLT_CHECKPOINT_WRITE_ORDER = CheckpointWriteOrder.RANDOM;
+    public static final CheckpointWriteOrder DFLT_CHECKPOINT_WRITE_ORDER = CheckpointWriteOrder.SEQUENTIAL;
 
     /** Default number of checkpoints to be kept in WAL after checkpoint is finished */
     public static final int DFLT_WAL_HISTORY_SIZE = 20;


[2/8] ignite git commit: IGNITE-6101 Try to improve local scans performance

Posted by sb...@apache.org.
IGNITE-6101 Try to improve local scans performance


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1c9d80a5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1c9d80a5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1c9d80a5

Branch: refs/heads/ignite-6149
Commit: 1c9d80a540cbce0a9d9a65e3fac2e06f53b73f43
Parents: 79d47f8
Author: Igor Seliverstov <gv...@gmail.com>
Authored: Fri Aug 25 12:22:44 2017 +0300
Committer: Yakov Zhdanov <yz...@gridgain.com>
Committed: Fri Aug 25 12:22:44 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryUtils.java     |  26 +
 .../processors/cache/CacheObjectUtils.java      |  65 ++-
 .../processors/cache/GridCacheAdapter.java      |   6 +-
 .../processors/cache/GridCacheEntryEx.java      |  10 +
 .../processors/cache/GridCacheMapEntry.java     |  27 +-
 .../processors/cache/IgniteCacheProxyImpl.java  |  26 +-
 .../colocated/GridDhtDetachedCacheEntry.java    |   4 +-
 .../distributed/near/GridNearCacheEntry.java    |   4 +-
 .../processors/cache/query/CacheQueryEntry.java |  58 +++
 .../query/GridCacheDistributedQueryManager.java |  16 +-
 .../cache/query/GridCacheQueryAdapter.java      |  53 ++-
 .../cache/query/GridCacheQueryManager.java      | 470 +++++++++----------
 .../IgniteCacheObjectProcessorImpl.java         | 164 -------
 .../UserCacheObjectByteArrayImpl.java           |  59 +++
 .../cacheobject/UserCacheObjectImpl.java        |  82 ++++
 .../cacheobject/UserKeyCacheObjectImpl.java     | 101 ++++
 .../service/GridServiceProcessor.java           |   6 +-
 .../resources/META-INF/classnames.properties    |  88 ++--
 .../processors/cache/GridCacheTestEntryEx.java  |   6 +
 .../GridCacheQueryTransformerSelfTest.java      |  41 ++
 20 files changed, 788 insertions(+), 524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index 74d1730..8970a4e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -60,6 +60,12 @@ import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
+import org.apache.ignite.internal.processors.cacheobject.UserCacheObjectByteArrayImpl;
+import org.apache.ignite.internal.processors.cacheobject.UserCacheObjectImpl;
+import org.apache.ignite.internal.processors.cacheobject.UserKeyCacheObjectImpl;
 import org.apache.ignite.internal.util.MutableSingletonList;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -707,6 +713,26 @@ public class BinaryUtils {
     }
 
     /**
+     * @param obj Object to check.
+     * @return True if this is an object of a known type.
+     */
+    public static boolean knownCacheObject(Object obj) {
+        if (obj == null)
+            return false;
+
+        Class<?> cls= obj.getClass();
+
+        return cls == KeyCacheObjectImpl.class ||
+            cls == BinaryObjectImpl.class ||
+            cls == CacheObjectImpl.class ||
+            cls == CacheObjectByteArrayImpl.class ||
+            cls == BinaryEnumObjectImpl.class ||
+            cls == UserKeyCacheObjectImpl.class ||
+            cls == UserCacheObjectImpl.class ||
+            cls == UserCacheObjectByteArrayImpl.class;
+    }
+
+    /**
      * @param arr Array to check.
      * @return {@code true} if this array is of a known type.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
index 5afa751..aeca79e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectUtils.java
@@ -17,15 +17,14 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.util.MutableSingletonList;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
 /**
  * Cache object utility methods.
  */
@@ -36,10 +35,35 @@ public class CacheObjectUtils {
      * @param cpy Copy value flag.
      * @return Unwrapped object.
      */
+    public static Object unwrapBinaryIfNeeded(CacheObjectValueContext ctx, CacheObject o, boolean keepBinary, boolean cpy) {
+        return unwrapBinary(ctx, o, keepBinary, cpy);
+    }
+
+    /**
+     * @param o Object to unwrap.
+     * @param keepBinary Keep binary flag.
+     * @param cpy Copy value flag.
+     * @return Unwrapped object.
+     */
     public static Object unwrapBinaryIfNeeded(CacheObjectValueContext ctx, Object o, boolean keepBinary, boolean cpy) {
         if (o == null)
             return null;
 
+        // TODO has to be overloaded
+        if (o instanceof Map.Entry) {
+            Map.Entry entry = (Map.Entry)o;
+
+            Object key = entry.getKey();
+
+            Object uKey = unwrapBinary(ctx, key, keepBinary, cpy);
+
+            Object val = entry.getValue();
+
+            Object uVal = unwrapBinary(ctx, val, keepBinary, cpy);
+
+            return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
+        }
+
         return unwrapBinary(ctx, o, keepBinary, cpy);
     }
 
@@ -86,7 +110,10 @@ public class CacheObjectUtils {
         Map<Object, Object> map0 = BinaryUtils.newMap(map);
 
         for (Map.Entry<Object, Object> e : map.entrySet())
-            map0.put(unwrapBinary(ctx, e.getKey(), false, cpy), unwrapBinary(ctx, e.getValue(), false, cpy));
+            // TODO why don't we use keepBinary parameter here?
+            map0.put(
+                unwrapBinary(ctx, e.getKey(), false, cpy),
+                unwrapBinary(ctx, e.getValue(), false, cpy));
 
         return map0;
     }
@@ -105,7 +132,7 @@ public class CacheObjectUtils {
             col0 = new ArrayList<>(col.size());
 
         for (Object obj : col)
-            col0.add(unwrapBinary(ctx, obj, keepBinary, cpy));
+            col0.add(unwrapBinaryIfNeeded(ctx, obj, keepBinary, cpy));
 
         return col0;
     }
@@ -137,31 +164,25 @@ public class CacheObjectUtils {
      */
     @SuppressWarnings("unchecked")
     private static Object unwrapBinary(CacheObjectValueContext ctx, Object o, boolean keepBinary, boolean cpy) {
-        if (o instanceof Map.Entry) {
-            Map.Entry entry = (Map.Entry)o;
-
-            Object key = entry.getKey();
-
-            Object uKey = unwrapBinary(ctx, key, keepBinary, cpy);
+        if (o == null)
+            return o;
 
-            Object val = entry.getValue();
+        while (BinaryUtils.knownCacheObject(o)) {
+            CacheObject co = (CacheObject)o;
 
-            Object uVal = unwrapBinary(ctx, val, keepBinary, cpy);
+            if (!co.isPlatformType() && keepBinary)
+                return o;
 
-            return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
+            // It may be a collection of binaries
+            o = co.value(ctx, cpy);
         }
-        else if (BinaryUtils.knownCollection(o))
+
+        if (BinaryUtils.knownCollection(o))
             return unwrapKnownCollection(ctx, (Collection<Object>)o, keepBinary, cpy);
         else if (BinaryUtils.knownMap(o))
             return unwrapBinariesIfNeeded(ctx, (Map<Object, Object>)o, keepBinary, cpy);
         else if (o instanceof Object[])
             return unwrapBinariesInArrayIfNeeded(ctx, (Object[])o, keepBinary, cpy);
-        else if (o instanceof CacheObject) {
-            CacheObject co = (CacheObject)o;
-
-            if (!keepBinary || co.isPlatformType())
-                return unwrapBinary(ctx, co.value(ctx, cpy), keepBinary, cpy);
-        }
 
         return o;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index fed716c..8e346ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -83,13 +83,13 @@ import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException
 import org.apache.ignite.internal.cluster.IgniteClusterEx;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl;
-import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
@@ -3916,7 +3916,9 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         return ctx.itHolder().iterator(iter, new CacheIteratorConverter<Cache.Entry<K, V>, Map.Entry<K, V>>() {
             @Override protected Cache.Entry<K, V> convert(Map.Entry<K, V> e) {
-                return new CacheEntryImpl<>(e.getKey(), e.getValue());
+                // Actually Scan Query returns Iterator<CacheQueryEntry> by default,
+                // CacheQueryEntry implements both Map.Entry and Cache.Entry interfaces.
+                return (Cache.Entry<K, V>) e;
             }
 
             @Override protected void remove(Cache.Entry<K, V> item) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index e2bc7ff..b2cabac 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicAbstractUpdateFuture;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -934,6 +935,15 @@ public interface GridCacheEntryEx {
         throws IgniteCheckedException, GridCacheEntryRemovedException;
 
     /**
+     * @param row Already extracted value.
+     * @return Value.
+     * @throws IgniteCheckedException If failed to read from swap storage.
+     * @throws GridCacheEntryRemovedException If entry was removed.
+     */
+    @Nullable public CacheObject unswap(CacheDataRow row)
+        throws IgniteCheckedException, GridCacheEntryRemovedException;
+
+    /**
      * Unswap ignoring flags.
      *
      * @param needVal If {@code false} then do not need to deserialize value during unswap.

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index d991c86..61f6fb4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -342,9 +342,16 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
     }
 
     /** {@inheritDoc} */
+    @Override public final CacheObject unswap(CacheDataRow row) throws IgniteCheckedException, GridCacheEntryRemovedException {
+        row = unswap(row, true);
+
+        return row != null ? row.value() : null;
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public final CacheObject unswap(boolean needVal)
         throws IgniteCheckedException, GridCacheEntryRemovedException {
-        CacheDataRow row = unswap(needVal, true);
+        CacheDataRow row = unswap(null, true);
 
         return row != null ? row.value() : null;
     }
@@ -352,13 +359,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
     /**
      * Unswaps an entry.
      *
-     * @param needVal If {@code false} then do not to deserialize value during unswap.
+     * @param row Already extracted cache data.
      * @param checkExpire If {@code true} checks for expiration, as result entry can be obsoleted or marked deleted.
      * @return Value.
      * @throws IgniteCheckedException If failed.
      * @throws GridCacheEntryRemovedException If entry was removed.
      */
-    @Nullable protected CacheDataRow unswap(boolean needVal, boolean checkExpire)
+    @Nullable protected CacheDataRow unswap(@Nullable CacheDataRow row, boolean checkExpire)
         throws IgniteCheckedException, GridCacheEntryRemovedException {
         boolean obsolete = false;
         boolean deferred = false;
@@ -368,7 +375,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
             checkObsolete();
 
             if (isStartVersion() && ((flags & IS_UNSWAPPED_MASK) == 0)) {
-                CacheDataRow read = cctx.offheap().read(this);
+                assert row == null || row.key() == key: "Unexpected row key";
+
+                CacheDataRow read = row == null ? cctx.offheap().read(this) : row;
 
                 flags |= IS_UNSWAPPED_MASK;
 
@@ -572,7 +581,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
 
                 if (val == null) {
                     if (isStartVersion()) {
-                        unswap(true, false);
+                        unswap(null, false);
 
                         val = this.val;
                     }
@@ -1322,7 +1331,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
 
             // Load and remove from swap if it is new.
             if (isNew())
-                oldRow = unswap(retval, false);
+                oldRow = unswap(null, false);
 
             old = val;
 
@@ -2408,7 +2417,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                     return null;
 
                 if (val == null && offheap)
-                    unswap(true, false);
+                    unswap(null, false);
 
                 if (checkExpired()) {
                     if (cctx.deferredDelete()) {
@@ -2645,7 +2654,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
         boolean isNew = isStartVersion();
 
         if (isNew)
-            unswap(true, false);
+            unswap(null, false);
 
         CacheObject val = this.val;
 
@@ -2949,7 +2958,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                 checkObsolete();
 
                 if (isStartVersion())
-                    unswap(true, false);
+                    unswap(null, false);
 
                 long expireTime = expireTimeExtras();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
index 54fcafa..bc486e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
@@ -375,31 +375,7 @@ public class IgniteCacheProxyImpl<K, V> extends AsyncSupportAdapter<IgniteCache<
         final GridCloseableIterator<R> iter = ctx.kernalContext().query().executeQuery(GridCacheQueryType.SCAN,
             ctx.name(), ctx, new IgniteOutClosureX<GridCloseableIterator<R>>() {
                 @Override public GridCloseableIterator<R> applyx() throws IgniteCheckedException {
-                    final GridCloseableIterator iter0 = qry.executeScanQuery();
-
-                    final boolean needToConvert = transformer == null;
-
-                    return new GridCloseableIteratorAdapter<R>() {
-                        @Override protected R onNext() throws IgniteCheckedException {
-                            Object next = iter0.nextX();
-
-                            if (needToConvert) {
-                                Map.Entry<K, V> entry = (Map.Entry<K, V>)next;
-
-                                return (R)new CacheEntryImpl<>(entry.getKey(), entry.getValue());
-                            }
-
-                            return (R)next;
-                        }
-
-                        @Override protected boolean onHasNext() throws IgniteCheckedException {
-                            return iter0.hasNextX();
-                        }
-
-                        @Override protected void onClose() throws IgniteCheckedException {
-                            iter0.close();
-                        }
-                    };
+                    return qry.executeScanQuery();
                 }
             }, true);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
index 7da3d4f..5566bb4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
@@ -22,8 +22,8 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.jetbrains.annotations.Nullable;
@@ -53,7 +53,7 @@ public class GridDhtDetachedCacheEntry extends GridDistributedCacheEntry {
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public CacheDataRow unswap(boolean needVal, boolean checkExpire) throws IgniteCheckedException {
+    @Nullable @Override public CacheDataRow unswap(CacheDataRow row, boolean checkExpire) throws IgniteCheckedException {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
index 6e606bf..ce728b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
@@ -30,9 +30,9 @@ import org.apache.ignite.internal.processors.cache.GridCacheMvcc;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.typedef.F;
@@ -443,7 +443,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry {
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public CacheDataRow unswap(boolean needVal, boolean checkExpire) {
+    @Nullable @Override public CacheDataRow unswap(CacheDataRow row, boolean checkExpire) {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQueryEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQueryEntry.java
new file mode 100644
index 0000000..4787464
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQueryEntry.java
@@ -0,0 +1,58 @@
+/*
+ * 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.query;
+
+import javax.cache.Cache;
+import org.apache.ignite.cache.CacheEntry;
+import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
+import org.apache.ignite.internal.processors.cache.CacheEntryImplEx;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+
+/** */
+final class CacheQueryEntry<K,V> extends IgniteBiTuple<K,V> implements Cache.Entry<K,V> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    public CacheQueryEntry() {
+        // No-op.
+    }
+
+    /**
+     * @param key Key.
+     * @param val Value.
+     */
+    CacheQueryEntry(@Nullable K key, @Nullable V val) {
+        super(key, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T unwrap(Class<T> cls) {
+        if (cls != null && cls.isAssignableFrom(getClass()))
+            return cls.cast(this);
+
+        if (cls.isAssignableFrom(CacheEntryImpl.class))
+            return (T)new CacheEntryImpl<>(getKey(), getValue());
+
+        if (cls.isAssignableFrom(CacheEntry.class))
+            return (T)new CacheEntryImplEx<>(getKey(), getValue(), null);
+
+        throw new IllegalArgumentException("Unwrapping to class is not supported: " + cls);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
index 7f859a2..b860f02 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
@@ -42,7 +42,6 @@ import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.CI2;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.P1;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -632,7 +631,20 @@ public class GridCacheDistributedQueryManager<K, V> extends GridCacheQueryManage
                 if (locIter != null && locIter.hasNextX())
                     cur = locIter.nextX();
 
-                return cur != null || (cur = fut.next()) != null;
+                return cur != null || (cur = convert(fut.next())) != null;
+            }
+
+            /**
+             * @param obj Entry to convert.
+             * @return Cache entry
+             */
+            private Object convert(Object obj) {
+                if(qry.transform() != null)
+                    return obj;
+
+                Map.Entry e = (Map.Entry)obj;
+
+                return e == null ? null : new CacheQueryEntry(e.getKey(), e.getValue());
             }
 
             @Override protected void onClose() throws IgniteCheckedException {

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
index 023c03c..c4eae8c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryAdapter.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache.query;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Deque;
@@ -517,7 +518,8 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
     @Override public GridCloseableIterator executeScanQuery() throws IgniteCheckedException {
         assert type == SCAN : "Wrong processing of qyery: " + type;
 
-        Collection<ClusterNode> nodes = nodes();
+        // Affinity nodes snapshot.
+        Collection<ClusterNode> nodes = new ArrayList<>(nodes());
 
         cctx.checkSecurity(SecurityPermission.CACHE_READ);
 
@@ -537,13 +539,15 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
 
         final GridCacheQueryManager qryMgr = cctx.queries();
 
-        if (part != null && !cctx.isLocal())
-            return new ScanQueryFallbackClosableIterator(part, this, qryMgr, cctx);
-        else {
-            boolean loc = nodes.size() == 1 && F.first(nodes).id().equals(cctx.localNodeId());
+        boolean loc = nodes.size() == 1 && F.first(nodes).id().equals(cctx.localNodeId());
 
-            return loc ? qryMgr.scanQueryLocal(this, true) : qryMgr.scanQueryDistributed(this, nodes);
-        }
+        if (loc)
+            return qryMgr.scanQueryLocal(this, true);
+
+        if (part != null)
+            return new ScanQueryFallbackClosableIterator(part, this, qryMgr, cctx);
+        else
+            return qryMgr.scanQueryDistributed(this, nodes);
     }
 
     /**
@@ -621,12 +625,12 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
     /**
      * Wrapper for queries with fallback.
      */
-    private static class ScanQueryFallbackClosableIterator extends GridCloseableIteratorAdapter<Map.Entry> {
+    private static class ScanQueryFallbackClosableIterator extends GridCloseableIteratorAdapter {
         /** */
         private static final long serialVersionUID = 0L;
 
         /** Query future. */
-        private volatile T2<GridCloseableIterator<Map.Entry>, GridCacheQueryFutureAdapter> tuple;
+        private volatile T2<GridCloseableIterator<Object>, GridCacheQueryFutureAdapter> tuple;
 
         /** Backups. */
         private volatile Queue<ClusterNode> nodes;
@@ -653,7 +657,7 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
         private boolean firstItemReturned;
 
         /** */
-        private Map.Entry cur;
+        private Object cur;
 
         /**
          * @param part Partition.
@@ -726,7 +730,7 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
                 }
             }
             else {
-                final GridCacheQueryBean bean = new GridCacheQueryBean(qry, null, null, null);
+                final GridCacheQueryBean bean = new GridCacheQueryBean(qry, null, qry.transform, null);
 
                 GridCacheQueryFutureAdapter fut =
                     (GridCacheQueryFutureAdapter)qryMgr.queryDistributed(bean, Collections.singleton(node));
@@ -736,13 +740,13 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
         }
 
         /** {@inheritDoc} */
-        @Override protected Map.Entry onNext() throws IgniteCheckedException {
+        @Override protected Object onNext() throws IgniteCheckedException {
             if (!onHasNext())
                 throw new NoSuchElementException();
 
             assert cur != null;
 
-            Map.Entry e = cur;
+            Object e = cur;
 
             cur = null;
 
@@ -755,9 +759,9 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
                 if (cur != null)
                     return true;
 
-                T2<GridCloseableIterator<Map.Entry>, GridCacheQueryFutureAdapter> t = tuple;
+                T2<GridCloseableIterator<Object>, GridCacheQueryFutureAdapter> t = tuple;
 
-                GridCloseableIterator<Map.Entry> iter = t.get1();
+                GridCloseableIterator<Object> iter = t.get1();
 
                 if (iter != null) {
                     boolean hasNext = iter.hasNext();
@@ -773,14 +777,14 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
                     assert fut != null;
 
                     if (firstItemReturned)
-                        return (cur = (Map.Entry)fut.next()) != null;
+                        return (cur = convert(fut.next())) != null;
 
                     try {
                         fut.awaitFirstPage();
 
                         firstItemReturned = true;
 
-                        return (cur = (Map.Entry)fut.next()) != null;
+                        return (cur = convert(fut.next())) != null;
                     }
                     catch (IgniteClientDisconnectedCheckedException e) {
                         throw CU.convertToCacheException(e);
@@ -793,6 +797,19 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
         }
 
         /**
+         * @param obj Entry to convert.
+         * @return Cache entry
+         */
+        private Object convert(Object obj) {
+            if(qry.transform() != null)
+                return obj;
+
+            Map.Entry e = (Map.Entry)obj;
+
+            return e == null ? null : new CacheQueryEntry(e.getKey(), e.getValue());
+        }
+
+        /**
          * @param e Exception for query run.
          */
         private void retryIfPossible(IgniteCheckedException e) {
@@ -847,7 +864,7 @@ public class GridCacheQueryAdapter<T> implements CacheQuery<T> {
         @Override protected void onClose() throws IgniteCheckedException {
             super.onClose();
 
-            T2<GridCloseableIterator<Map.Entry>, GridCacheQueryFutureAdapter> t = tuple;
+            T2<GridCloseableIterator<Object>, GridCacheQueryFutureAdapter> t = tuple;
 
             if (t != null && t.get1() != null)
                 t.get1().close();

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 3e772cd..3e27720 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -40,10 +40,10 @@ import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentMap;
 import javax.cache.Cache;
-import javax.cache.expiry.ExpiryPolicy;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.cache.QueryIndexType;
 import org.apache.ignite.cache.query.QueryMetrics;
@@ -63,7 +63,9 @@ import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheMetricsImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectUtils;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
+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.GridCacheInternal;
@@ -71,10 +73,10 @@ import org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter;
 import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-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.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor;
 import org.apache.ignite.internal.processors.datastructures.GridSetQueryPredicate;
@@ -821,22 +823,22 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      * @throws IgniteCheckedException If failed to get iterator.
      */
     @SuppressWarnings({"unchecked"})
-    private GridCloseableIterator<IgniteBiTuple<K, V>> scanIterator(final GridCacheQueryAdapter<?> qry, boolean locNode)
+    private GridCloseableIterator scanIterator(final GridCacheQueryAdapter<?> qry, boolean locNode)
         throws IgniteCheckedException {
         final IgniteBiPredicate<K, V> keyValFilter = qry.scanFilter();
 
         try {
             injectResources(keyValFilter);
 
-            Integer part = qry.partition();
-
-            if (cctx.isLocal())
-                part = null;
+            Integer part = cctx.isLocal() ? null : qry.partition();
 
             if (part != null && (part < 0 || part >= cctx.affinity().partitions()))
-                return new GridEmptyCloseableIterator<>();
-
-            final ExpiryPolicy plc = cctx.expiry();
+                return new GridEmptyCloseableIterator() {
+                    @Override public void close() throws IgniteCheckedException {
+                        closeScanFilter(keyValFilter);
+                        super.close();
+                    }
+                };
 
             AffinityTopologyVersion topVer = GridQueryProcessor.getRequestAffinityTopologyVersion();
 
@@ -858,13 +860,6 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                     throw new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(),
                         "Partition can not be reserved");
 
-                if (locPart0.state() != OWNING) {
-                    locPart0.release();
-
-                    throw new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(),
-                        "Partition can not be reserved");
-                }
-
                 locPart = locPart0;
 
                 it = cctx.offheap().cachePartitionIterator(cctx.cacheId(), part);
@@ -872,19 +867,11 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
             else {
                 locPart = null;
 
+                // TODO shouldn't we reserve all involved partitions?
                 it = cctx.offheap().cacheIterator(cctx.cacheId(), true, backups, topVer);
             }
 
-            return new PeekValueExpiryAwareIterator(it, plc, topVer, keyValFilter, qry.keepBinary(), locNode) {
-                @Override protected void onClose() {
-                    super.onClose();
-
-                    if (locPart != null)
-                        locPart.release();
-
-                    closeScanFilter(keyValFilter);
-                }
-            };
+            return new ScanQueryIterator(it, qry, topVer, locPart, keyValFilter, locNode, cctx, log);
         }
         catch (IgniteCheckedException | RuntimeException e) {
             closeScanFilter(keyValFilter);
@@ -1189,9 +1176,16 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
                 final boolean readEvt = cctx.gridEvents().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
 
-                while (!Thread.currentThread().isInterrupted() && iter.hasNext()) {
+                CacheObjectContext objCtx = cctx.cacheObjectContext();
+
+                while (!Thread.currentThread().isInterrupted()) {
                     long start = statsEnabled ? System.nanoTime() : 0L;
 
+                    // Need to call it after gathering start time because
+                    // actual row extracting may happen inside this method.
+                    if(!iter.hasNext())
+                        break;
+
                     IgniteBiTuple<K, V> row = iter.next();
 
                     // Query is cancelled.
@@ -1249,8 +1243,8 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                     V val0 = null;
 
                     if (readEvt && cctx.gridEvents().hasListener(EVT_CACHE_QUERY_OBJECT_READ)) {
-                        key0 = (K)cctx.unwrapBinaryIfNeeded(key, qry.keepBinary());
-                        val0 = (V)cctx.unwrapBinaryIfNeeded(val, qry.keepBinary());
+                        key0 = (K)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, key, qry.keepBinary(), false);
+                        val0 = (V)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, val, qry.keepBinary(), false);
 
                         switch (type) {
                             case SQL:
@@ -1320,9 +1314,9 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
                     if (rdc != null || trans != null) {
                         if (key0 == null)
-                            key0 = (K)cctx.unwrapBinaryIfNeeded(key, qry.keepBinary());
+                            key0 = (K)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, key, qry.keepBinary(), false);
                         if (val0 == null)
-                            val0 = (V)cctx.unwrapBinaryIfNeeded(val, qry.keepBinary());
+                            val0 = (V)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, val, qry.keepBinary(), false);
 
                         Cache.Entry<K, V> entry = new CacheEntryImpl(key0, val0);
 
@@ -1422,22 +1416,24 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
      * Process local scan query.
      *
      * @param qry Query.
-     * @param updStatisticsIfNeeded Update statistics flag.
+     * @param updateStatistics Update statistics flag.
      */
     @SuppressWarnings({"unchecked", "serial"})
     protected GridCloseableIterator scanQueryLocal(final GridCacheQueryAdapter qry,
-        final boolean updStatisticsIfNeeded) throws IgniteCheckedException {
+        boolean updateStatistics) throws IgniteCheckedException {
         if (!enterBusy())
             throw new IllegalStateException("Failed to process query request (grid is stopping).");
 
         final boolean statsEnabled = cctx.config().isStatisticsEnabled();
 
-        boolean needUpdStatistics = updStatisticsIfNeeded && statsEnabled;
+        updateStatistics &= statsEnabled;
 
         long startTime = U.currentTimeMillis();
 
         final String namex = cctx.name();
 
+        final IgniteBiPredicate<K, V> scanFilter = qry.scanFilter();
+
         try {
             assert qry.type() == SCAN;
 
@@ -1445,7 +1441,6 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                 log.debug("Running local SCAN query: " + qry);
 
             final String taskName = cctx.kernalContext().task().resolveTaskName(qry.taskHash());
-            final IgniteBiPredicate filter = qry.scanFilter();
             final ClusterNode locNode = cctx.localNode();
             final UUID subjId = qry.subjectId();
 
@@ -1458,80 +1453,23 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                     namex,
                     null,
                     null,
-                    filter,
+                    scanFilter,
                     null,
                     null,
                     subjId,
                     taskName));
             }
 
-            final GridCloseableIterator<IgniteBiTuple<K, V>> iter = scanIterator(qry, true);
+            GridCloseableIterator it = scanIterator(qry, true);
 
-            if (updStatisticsIfNeeded)
-                needUpdStatistics = false;
-
-            final boolean readEvt = cctx.gridEvents().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
-
-            return new GridCloseableIteratorAdapter<Object>() {
-                @Override protected Object onNext() throws IgniteCheckedException {
-                    long start = statsEnabled ? System.nanoTime() : 0L;
+            updateStatistics = false;
 
-                    IgniteBiTuple<K, V> next = iter.nextX();
-
-                    if (statsEnabled) {
-                        CacheMetricsImpl metrics = cctx.cache().metrics0();
-
-                        metrics.onRead(true);
-
-                        metrics.addGetTimeNanos(System.nanoTime() - start);
-                    }
-
-                    if (readEvt && cctx.gridEvents().hasListener(EVT_CACHE_QUERY_OBJECT_READ)) {
-                        cctx.gridEvents().record(new CacheQueryReadEvent<>(
-                            cctx.localNode(),
-                            "Scan query entry read.",
-                            EVT_CACHE_QUERY_OBJECT_READ,
-                            CacheQueryType.SCAN.name(),
-                            namex,
-                            null,
-                            null,
-                            filter,
-                            null,
-                            null,
-                            subjId,
-                            taskName,
-                            next.getKey(),
-                            next.getValue(),
-                            null,
-                            null));
-                    }
-
-                    IgniteClosure transform = qry.transform();
-
-                    if (transform == null)
-                        return next;
-
-                    Cache.Entry<K, V> entry;
-
-                    if (qry.keepBinary())
-                        entry = cctx.cache().keepBinary().getEntry(next.getKey());
-                    else
-                        entry = cctx.cache().getEntry(next.getKey());
-
-                    return transform.apply(entry);
-                }
-
-                @Override protected boolean onHasNext() throws IgniteCheckedException {
-                    return iter.hasNextX();
-                }
-
-                @Override protected void onClose() throws IgniteCheckedException {
-                    iter.close();
-                }
-            };
+            return it;
         }
         catch (Exception e) {
-            if (needUpdStatistics)
+            closeScanFilter(scanFilter);
+
+            if (updateStatistics)
                 cctx.queries().collectMetrics(GridCacheQueryType.SCAN, namex, startTime,
                     U.currentTimeMillis() - startTime, true);
 
@@ -2047,8 +1985,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         private static final long serialVersionUID = 0L;
 
         /**
-         * Number of fields to report when no fields defined.
-         * Includes _key and _val columns.
+         * Number of fields to report when no fields defined. Includes _key and _val columns.
          */
         private static final int NO_FIELDS_COLUMNS_COUNT = 2;
 
@@ -2862,14 +2799,68 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
     }
 
     /**
-     *
+     * The map prevents put to the map in case the specified request has been removed previously.
      */
-    private class PeekValueExpiryAwareIterator extends GridCloseableIteratorAdapter<IgniteBiTuple<K, V>> {
+    private class RequestFutureMap extends LinkedHashMap<Long, GridFutureAdapter<QueryResult<K, V>>> {
         /** */
         private static final long serialVersionUID = 0L;
 
+        /** Count of canceled keys */
+        private static final int CANCELED_COUNT = 128;
+
+        /**
+         * The ID of the canceled request is stored to the set in case remove(reqId) is called before put(reqId,
+         * future).
+         */
+        private Set<Long> canceled;
+
+        /** {@inheritDoc} */
+        @Override public GridFutureAdapter<QueryResult<K, V>> remove(Object key) {
+            if (containsKey(key))
+                return super.remove(key);
+            else {
+                if (canceled == null) {
+                    canceled = Collections.newSetFromMap(
+                        new LinkedHashMap<Long, Boolean>() {
+                            @Override protected boolean removeEldestEntry(Map.Entry<Long, Boolean> eldest) {
+                                return size() > CANCELED_COUNT;
+                            }
+                        });
+                }
+
+                canceled.add((Long)key);
+
+                return null;
+            }
+        }
+
+        /**
+         * @return true if the key is canceled
+         */
+        boolean isCanceled(Long key) {
+            return canceled != null && canceled.contains(key);
+        }
+    }
+
+    /** */
+    private static final class ScanQueryIterator<K, V> extends GridCloseableIteratorAdapter<Object> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final GridDhtCacheAdapter dht;
+
+        /** */
+        private final GridDhtLocalPartition locPart;
+
         /** */
-        private final ExpiryPolicy plc;
+        private final IgniteBiPredicate<K, V> scanFilter;
+
+        /** */
+        private final boolean statsEnabled;
+
+        /** */
+        private final GridIterator<CacheDataRow> it;
 
         /** */
         private final GridCacheAdapter cache;
@@ -2878,73 +2869,94 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         private final AffinityTopologyVersion topVer;
 
         /** */
-        private final GridDhtCacheAdapter dht;
+        private final boolean keepBinary;
 
         /** */
-        private final IgniteBiPredicate<K, V> keyValFilter;
+        private final boolean readEvt;
 
         /** */
-        private boolean locNode;
+        private final String cacheName;
 
         /** */
-        private final boolean keepBinary;
+        private final UUID subjId;
 
         /** */
-        private IgniteBiTuple<K, V> next;
+        private final String taskName;
 
         /** */
-        private IgniteCacheExpiryPolicy expiryPlc;
+        private final IgniteClosure transform;
+
+        /** */
+        private final CacheObjectContext objCtx;
+
+        /** */
+        private final GridCacheContext cctx;
+
+        /** */
+        private final IgniteLogger log;
 
         /** */
-        private GridIterator<CacheDataRow> it;
+        private Object next;
 
-        /** Need advance. */
+        /** */
         private boolean needAdvance;
 
+        /** */
+        private IgniteCacheExpiryPolicy expiryPlc;
+
         /**
          * @param it Iterator.
-         * @param plc Expiry policy.
+         * @param qry Query.
          * @param topVer Topology version.
-         * @param keyValFilter Key-value filter.
-         * @param keepBinary Keep binary flag from the query.
-         * @param locNode Local node.
+         * @param locPart Local partition.
+         * @param scanFilter Scan filter.
+         * @param locNode Local node flag.
+         * @param cctx Cache context.
+         * @param log Logger.
          */
-        private PeekValueExpiryAwareIterator(
+        ScanQueryIterator(
             GridIterator<CacheDataRow> it,
-            ExpiryPolicy plc,
+            GridCacheQueryAdapter qry,
             AffinityTopologyVersion topVer,
-            IgniteBiPredicate<K, V> keyValFilter,
-            boolean keepBinary,
-            boolean locNode
-        ) {
+            GridDhtLocalPartition locPart,
+            IgniteBiPredicate<K, V> scanFilter,
+            boolean locNode,
+            GridCacheContext cctx,
+            IgniteLogger log) {
             this.it = it;
-            this.plc = plc;
             this.topVer = topVer;
-            this.keyValFilter = keyValFilter;
-            this.locNode = locNode;
+            this.locPart = locPart;
+            this.scanFilter = scanFilter;
+            this.cctx = cctx;
+            this.log = log;
 
-            dht = cctx.isLocal() ? null : (cctx.isNear() ? cctx.near().dht() : cctx.dht());
-            cache = dht != null ? dht : cctx.cache();
+            statsEnabled = locNode && cctx.config().isStatisticsEnabled();
 
-            this.keepBinary = keepBinary;
-            expiryPlc = cctx.cache().expiryPolicy(plc);
+            readEvt = locNode && cctx.gridEvents().isRecordable(EVT_CACHE_QUERY_OBJECT_READ);
 
-            needAdvance = true;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean onHasNext() {
-            if (needAdvance) {
-                advance();
-
-                needAdvance = false;
+            if(readEvt){
+                taskName = cctx.kernalContext().task().resolveTaskName(qry.taskHash());
+                subjId = qry.subjectId();
+            }
+            else {
+                taskName = null;
+                subjId = null;
             }
 
-            return next != null;
+            // keep binary for remote scans if possible
+            keepBinary = (!locNode && scanFilter == null) || qry.keepBinary();
+            transform = qry.transform();
+            dht = cctx.isLocal() ? null : (cctx.isNear() ? cctx.near().dht() : cctx.dht());
+            cache = dht != null ? dht : cctx.cache();
+            objCtx = cctx.cacheObjectContext();
+            cacheName = cctx.name();
+
+            needAdvance = true;
+            expiryPlc = this.cctx.cache().expiryPolicy(null);
         }
 
         /** {@inheritDoc} */
-        @Override public IgniteBiTuple<K, V> onNext() {
+        @Override protected Object onNext() {
             if (needAdvance)
                 advance();
             else
@@ -2957,26 +2969,64 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         }
 
         /** {@inheritDoc} */
+        @Override protected boolean onHasNext() {
+            if (needAdvance) {
+                advance();
+
+                needAdvance = false;
+            }
+
+            return next != null;
+        }
+
+        /** {@inheritDoc} */
         @Override protected void onClose() {
-            sendTtlUpdate();
+            if (expiryPlc != null && dht != null) {
+                dht.sendTtlUpdateRequest(expiryPlc);
+
+                expiryPlc = null;
+            }
+
+            if (locPart != null)
+                locPart.release();
+
+            closeScanFilter(scanFilter);
         }
 
         /**
          * Moves the iterator to the next cache entry.
          */
         private void advance() {
-            IgniteBiTuple<K, V> next0 = null;
+            long start = statsEnabled ? System.nanoTime() : 0L;
+
+            Object next = null;
 
             while (it.hasNext()) {
                 CacheDataRow row = it.next();
 
                 KeyCacheObject key = row.key();
-
                 CacheObject val;
 
                 if (expiryPlc != null) {
                     try {
-                        val = value(key);
+                        CacheDataRow tmp = row;
+
+                        while (true) {
+                            try {
+                                GridCacheEntryEx entry = cache.entryEx(key);
+
+                                entry.unswap(tmp);
+
+                                val = entry.peek(true, true, topVer, expiryPlc);
+
+                                cctx.evicts().touch(entry, topVer);
+
+                                break;
+                            }
+                            catch (GridCacheEntryRemovedException ignore) {
+                                tmp = null;
+                            }
+                        }
                     }
                     catch (IgniteCheckedException e) {
                         if (log.isDebugEnabled())
@@ -2985,126 +3035,58 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                         val = null;
                     }
 
-                    if (dht != null && expiryPlc.readyToFlush(100)) {
+                    if (dht != null && expiryPlc.readyToFlush(100))
                         dht.sendTtlUpdateRequest(expiryPlc);
-
-                        expiryPlc = cctx.cache().expiryPolicy(plc);
-                    }
                 }
                 else
                     val = row.value();
 
                 if (val != null) {
-                    boolean keepBinary0 = !locNode || keepBinary;
+                    K key0 = (K)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, key, keepBinary, false);
+                    V val0 = (V)CacheObjectUtils.unwrapBinaryIfNeeded(objCtx, val, keepBinary, false);
 
-                    next0 = F.t(
-                        (K)cctx.unwrapBinaryIfNeeded(key, keepBinary0),
-                        (V)cctx.unwrapBinaryIfNeeded(val, keepBinary0));
+                    if (statsEnabled) {
+                        CacheMetricsImpl metrics = cctx.cache().metrics0();
 
-                    boolean passPred = true;
+                        metrics.onRead(true);
 
-                    if (keyValFilter != null) {
-                        Object key0 = next0.getKey();
-                        Object val0 = next0.getValue();
+                        metrics.addGetTimeNanos(System.nanoTime() - start);
+                    }
 
-                        if (keepBinary0 && !keepBinary) {
-                            key0 = (K)cctx.unwrapBinaryIfNeeded(key0, keepBinary);
-                            val0 = (V)cctx.unwrapBinaryIfNeeded(val0, keepBinary);
+                    if (scanFilter == null || scanFilter.apply(key0, val0)) {
+                        if (readEvt && cctx.gridEvents().hasListener(EVT_CACHE_QUERY_OBJECT_READ)) {
+                            cctx.gridEvents().record(new CacheQueryReadEvent<>(
+                                cctx.localNode(),
+                                "Scan query entry read.",
+                                EVT_CACHE_QUERY_OBJECT_READ,
+                                CacheQueryType.SCAN.name(),
+                                cacheName,
+                                null,
+                                null,
+                                scanFilter,
+                                null,
+                                null,
+                                subjId,
+                                taskName,
+                                key0,
+                                val0,
+                                null,
+                                null));
                         }
 
-                        passPred = keyValFilter.apply((K)key0, (V)val0);
-                    }
+                        next = transform == null ? new CacheQueryEntry<>(key0, val0)
+                            : transform.apply(new CacheQueryEntry<>(key0, val0));
 
-                    if (passPred)
                         break;
-                    else
-                        next0 = null;
+                    }
                 }
             }
 
-            next = next0;
-
-            if (next == null)
-                sendTtlUpdate();
-        }
-
-        /**
-         * Sends TTL update.
-         */
-        private void sendTtlUpdate() {
-            if (dht != null && expiryPlc != null) {
+            if ((this.next = next) == null && expiryPlc != null && dht != null) {
                 dht.sendTtlUpdateRequest(expiryPlc);
 
                 expiryPlc = null;
             }
         }
-
-        /**
-         * @param key Key.
-         * @return Value.
-         * @throws IgniteCheckedException If failed to peek value.
-         */
-        private CacheObject value(KeyCacheObject key) throws IgniteCheckedException {
-            while (true) {
-                try {
-                    GridCacheEntryEx entry = cache.entryEx(key);
-
-                    entry.unswap();
-
-                    CacheObject cacheObj = entry.peek(true, true, topVer, expiryPlc);
-
-                    cctx.evicts().touch(entry, topVer);
-
-                    return cacheObj;
-                }
-                catch (GridCacheEntryRemovedException ignore) {
-                    // No-op.
-                }
-            }
-        }
-    }
-
-    /**
-     * The map prevents put to the map in case the specified request has been removed previously.
-     */
-    private class RequestFutureMap extends LinkedHashMap<Long, GridFutureAdapter<QueryResult<K, V>>> {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Count of canceled keys */
-        private static final int CANCELED_COUNT = 128;
-
-        /**
-         * The ID of the canceled request is stored to the set in case
-         * remove(reqId) is called before put(reqId, future).
-         */
-        private Set<Long> canceled;
-
-        /** {@inheritDoc} */
-        @Override public GridFutureAdapter<QueryResult<K, V>> remove(Object key) {
-            if (containsKey(key))
-                return super.remove(key);
-            else {
-                if (canceled == null) {
-                    canceled = Collections.newSetFromMap(
-                        new LinkedHashMap<Long, Boolean>() {
-                            @Override protected boolean removeEldestEntry(Map.Entry<Long, Boolean> eldest) {
-                                return size() > CANCELED_COUNT;
-                            }
-                        });
-                }
-
-                canceled.add((Long)key);
-
-                return null;
-            }
-        }
-
-        /**
-         * @return true if the key is canceled
-         */
-        boolean isCanceled(Long key) {
-            return canceled != null && canceled.contains(key);
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index 70711e5..17be90f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cacheobject;
 
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.UUID;
@@ -40,7 +39,6 @@ import org.apache.ignite.internal.processors.cache.IncompleteCacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
 import org.apache.ignite.internal.processors.query.QueryUtils;
-import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteUuid;
@@ -341,166 +339,4 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
         return false;
     }
 
-    /**
-     * Wraps key provided by user, must be serialized before stored in cache.
-     */
-    private static class UserKeyCacheObjectImpl extends KeyCacheObjectImpl {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /**
-         *
-         */
-        public UserKeyCacheObjectImpl() {
-            //No-op.
-        }
-
-        /**
-         * @param key Key.
-         * @param part Partition.
-         */
-        UserKeyCacheObjectImpl(Object key, int part) {
-            super(key, null, part);
-        }
-
-        /**
-         * @param key Key.
-         * @param valBytes Marshalled key.
-         * @param part Partition.
-         */
-        UserKeyCacheObjectImpl(Object key, byte[] valBytes, int part) {
-            super(key, valBytes, part);
-        }
-
-        /** {@inheritDoc} */
-        @Override public KeyCacheObject copy(int part) {
-            if (this.partition() == part)
-                return this;
-
-            return new UserKeyCacheObjectImpl(val, valBytes, part);
-        }
-
-        /** {@inheritDoc} */
-        @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-            try {
-                IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
-
-                if (!proc.immutable(val)) {
-                    if (valBytes == null)
-                        valBytes = proc.marshal(ctx, val);
-
-                    boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
-
-                    ClassLoader ldr = p2pEnabled ?
-                        IgniteUtils.detectClassLoader(IgniteUtils.detectClass(this.val)) : U.gridClassLoader();
-
-                    Object val = proc.unmarshal(ctx, valBytes, ldr);
-
-                    KeyCacheObject key = new KeyCacheObjectImpl(val, valBytes, partition());
-
-                    key.partition(partition());
-
-                    return key;
-                }
-
-                KeyCacheObject key = new KeyCacheObjectImpl(val, valBytes, partition());
-
-                key.partition(partition());
-
-                return key;
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException("Failed to marshal object: " + val, e);
-            }
-        }
-    }
-
-    /**
-     * Wraps value provided by user, must be serialized before stored in cache.
-     */
-    private static class UserCacheObjectImpl extends CacheObjectImpl {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /**
-         *
-         */
-        public UserCacheObjectImpl() {
-            //No-op.
-        }
-
-        /**
-         * @param val Value.
-         * @param valBytes Value bytes.
-         */
-        public UserCacheObjectImpl(Object val, byte[] valBytes) {
-            super(val, valBytes);
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
-            return super.value(ctx, false); // Do not need copy since user value is not in cache.
-        }
-
-        /** {@inheritDoc} */
-        @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-            try {
-                IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
-
-                if (valBytes == null)
-                    valBytes = proc.marshal(ctx, val);
-
-                if (ctx.storeValue()) {
-                    boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
-
-                    ClassLoader ldr = p2pEnabled ?
-                        IgniteUtils.detectClass(this.val).getClassLoader() : val.getClass().getClassLoader();
-
-                    Object val = this.val != null && proc.immutable(this.val) ? this.val :
-                        proc.unmarshal(ctx, valBytes, ldr);
-
-                    return new CacheObjectImpl(val, valBytes);
-                }
-
-                return new CacheObjectImpl(null, valBytes);
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException("Failed to marshal object: " + val, e);
-            }
-        }
-    }
-
-    /**
-     * Wraps value provided by user, must be copied before stored in cache.
-     */
-    private static class UserCacheObjectByteArrayImpl extends CacheObjectByteArrayImpl {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /**
-         *
-         */
-        public UserCacheObjectByteArrayImpl() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        public UserCacheObjectByteArrayImpl(byte[] val) {
-            super(val);
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
-            return super.value(ctx, false); // Do not need copy since user value is not in cache.
-        }
-
-        /** {@inheritDoc} */
-        @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-            byte[] valCpy = Arrays.copyOf(val, val.length);
-
-            return new CacheObjectByteArrayImpl(valCpy);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectByteArrayImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectByteArrayImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectByteArrayImpl.java
new file mode 100644
index 0000000..aa4d5f5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectByteArrayImpl.java
@@ -0,0 +1,59 @@
+/*
+ * 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.cacheobject;
+
+import java.util.Arrays;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wraps value provided by user, must be copied before stored in cache.
+ */
+public class UserCacheObjectByteArrayImpl extends CacheObjectByteArrayImpl {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     *
+     */
+    public UserCacheObjectByteArrayImpl() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public UserCacheObjectByteArrayImpl(byte[] val) {
+        super(val);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
+        return super.value(ctx, false); // Do not need copy since user value is not in cache.
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        byte[] valCpy = Arrays.copyOf(val, val.length);
+
+        return new CacheObjectByteArrayImpl(valCpy);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectImpl.java
new file mode 100644
index 0000000..241c12b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserCacheObjectImpl.java
@@ -0,0 +1,82 @@
+/*
+ * 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.cacheobject;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wraps value provided by user, must be serialized before stored in cache.
+ */
+public class UserCacheObjectImpl extends CacheObjectImpl {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     *
+     */
+    public UserCacheObjectImpl() {
+        //No-op.
+    }
+
+    /**
+     * @param val Value.
+     * @param valBytes Value bytes.
+     */
+    public UserCacheObjectImpl(Object val, byte[] valBytes) {
+        super(val, valBytes);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
+        return super.value(ctx, false); // Do not need copy since user value is not in cache.
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        try {
+            IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
+
+            if (valBytes == null)
+                valBytes = proc.marshal(ctx, val);
+
+            if (ctx.storeValue()) {
+                boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
+
+                ClassLoader ldr = p2pEnabled ?
+                    IgniteUtils.detectClass(this.val).getClassLoader() : val.getClass().getClassLoader();
+
+                Object val = this.val != null && proc.immutable(this.val) ? this.val :
+                    proc.unmarshal(ctx, valBytes, ldr);
+
+                return new CacheObjectImpl(val, valBytes);
+            }
+
+            return new CacheObjectImpl(null, valBytes);
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException("Failed to marshal object: " + val, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserKeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserKeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserKeyCacheObjectImpl.java
new file mode 100644
index 0000000..de57667
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/UserKeyCacheObjectImpl.java
@@ -0,0 +1,101 @@
+/*
+ * 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.cacheobject;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ * Wraps key provided by user, must be serialized before stored in cache.
+ */
+public class UserKeyCacheObjectImpl extends KeyCacheObjectImpl {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     *
+     */
+    public UserKeyCacheObjectImpl() {
+        //No-op.
+    }
+
+    /**
+     * @param key Key.
+     * @param part Partition.
+     */
+    UserKeyCacheObjectImpl(Object key, int part) {
+        super(key, null, part);
+    }
+
+    /**
+     * @param key Key.
+     * @param valBytes Marshalled key.
+     * @param part Partition.
+     */
+    UserKeyCacheObjectImpl(Object key, byte[] valBytes, int part) {
+        super(key, valBytes, part);
+    }
+
+    /** {@inheritDoc} */
+    @Override public KeyCacheObject copy(int part) {
+        if (this.partition() == part)
+            return this;
+
+        return new UserKeyCacheObjectImpl(val, valBytes, part);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        try {
+            IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
+
+            if (!proc.immutable(val)) {
+                if (valBytes == null)
+                    valBytes = proc.marshal(ctx, val);
+
+                boolean p2pEnabled = ctx.kernalContext().config().isPeerClassLoadingEnabled();
+
+                ClassLoader ldr = p2pEnabled ?
+                    IgniteUtils.detectClassLoader(IgniteUtils.detectClass(this.val)) : U.gridClassLoader();
+
+                Object val = proc.unmarshal(ctx, valBytes, ldr);
+
+                KeyCacheObject key = new KeyCacheObjectImpl(val, valBytes, partition());
+
+                key.partition(partition());
+
+                return key;
+            }
+
+            KeyCacheObject key = new KeyCacheObjectImpl(val, valBytes, partition());
+
+            key.partition(partition());
+
+            return key;
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException("Failed to marshal object: " + val, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9d80a5/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
index 46fcfea..1d8720c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
@@ -26,7 +26,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
@@ -61,7 +60,6 @@ import org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage;
-import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheIteratorConverter;
 import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
@@ -1309,7 +1307,9 @@ public class GridServiceProcessor extends GridProcessorAdapter implements Ignite
             return cache.context().itHolder().iterator(iter,
                 new CacheIteratorConverter<Cache.Entry<Object, Object>, Map.Entry<Object, Object>>() {
                     @Override protected Cache.Entry<Object, Object> convert(Map.Entry<Object, Object> e) {
-                        return new CacheEntryImpl<>(e.getKey(), e.getValue());
+                        // Actually Scan Query returns Iterator<CacheQueryEntry> by default,
+                        // CacheQueryEntry implements both Map.Entry and Cache.Entry interfaces.
+                        return (Cache.Entry<Object, Object>)e;
                     }
 
                     @Override protected void remove(Cache.Entry<Object, Object> item) {


[5/8] ignite git commit: ignite-6180: restoring marshaller mappings on node start is implemented

Posted by sb...@apache.org.
ignite-6180: restoring marshaller mappings on node start is implemented

Signed-off-by: Andrey Gura <ag...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/418c4388
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/418c4388
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/418c4388

Branch: refs/heads/ignite-6149
Commit: 418c43889aac293cef8bcd6c5e4b90f85fc30e7c
Parents: 02801f8
Author: Ilya Lantukh <il...@gridgain.com>
Authored: Fri Aug 25 13:12:32 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Fri Aug 25 16:32:49 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  |   3 +
 .../internal/MarshallerMappingFileStore.java    |  76 +++++++++++-
 ...MarshallerMappingRestoreOnNodeStartTest.java | 116 +++++++++++++++++++
 .../IgnitePdsWithIndexingCoreTestSuite.java     |   2 +
 4 files changed, 196 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/418c4388/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index bb93354..d133676 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -517,6 +517,9 @@ public class MarshallerContextImpl implements MarshallerContext {
         this.transport = transport;
         closProc = ctx.closure();
         clientNode = ctx.clientNode();
+
+        if (ctx.config().isPersistentStoreEnabled())
+            fileStore.restoreMappings(this);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/418c4388/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
index 03f79c9..e4a844e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerMappingFileStore.java
@@ -34,6 +34,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.util.GridStripedLock;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContext;
 
 /**
  * File-based persistence provider for {@link MarshallerContextImpl}.
@@ -53,6 +54,9 @@ final class MarshallerMappingFileStore {
     /** */
     private final File workDir;
 
+    /** */
+    private final String FILE_EXTENSION = ".classname";
+
     /**
      * @param log Logger.
      */
@@ -137,11 +141,81 @@ final class MarshallerMappingFileStore {
     }
 
     /**
+     * Restores all mappings available in file system to marshaller context.
+     * This method should be used only on node startup.
+     *
+     * @param marshCtx Marshaller context to register mappings.
+     */
+    void restoreMappings(MarshallerContext marshCtx) throws IgniteCheckedException {
+        for (File file : workDir.listFiles()) {
+            String name = file.getName();
+
+            byte platformId = getPlatformId(name);
+
+            int typeId = getTypeId(name);
+
+            try (FileInputStream in = new FileInputStream(file)) {
+                try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
+                    String className = reader.readLine();
+
+                    marshCtx.registerClassNameLocally(platformId, typeId, className);
+                }
+            }
+            catch (IOException e) {
+                throw new IgniteCheckedException("Reading marshaller mapping from file "
+                    + name
+                    + " failed."
+                    , e);
+            }
+        }
+    }
+
+    /**
+     * @param fileName Name of file with marshaller mapping information.
+     * @throws IgniteCheckedException If file name format is broken.
+     */
+    private byte getPlatformId(String fileName) throws IgniteCheckedException {
+        String lastSymbol = fileName.substring(fileName.length() - 1);
+
+        byte platformId;
+
+        try {
+            platformId = Byte.parseByte(lastSymbol);
+        }
+        catch (NumberFormatException e) {
+            throw new IgniteCheckedException("Reading marshaller mapping from file "
+                + fileName
+                + " failed; last symbol of file name is expected to be numeric.", e);
+        }
+
+        return platformId;
+    }
+
+    /**
+     * @param fileName Name of file with marshaller mapping information.
+     * @throws IgniteCheckedException If file name format is broken.
+     */
+    private int getTypeId(String fileName) throws IgniteCheckedException {
+        int typeId;
+
+        try {
+            typeId = Integer.parseInt(fileName.substring(0, fileName.indexOf(FILE_EXTENSION)));
+        }
+        catch (NumberFormatException e) {
+            throw new IgniteCheckedException("Reading marshaller mapping from file "
+                + fileName
+                + " failed; type ID is expected to be numeric.", e);
+        }
+
+        return typeId;
+    }
+
+    /**
      * @param platformId Platform id.
      * @param typeId Type id.
      */
     private String getFileName(byte platformId, int typeId) {
-        return typeId + ".classname" + platformId;
+        return typeId + FILE_EXTENSION + platformId;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/418c4388/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
new file mode 100644
index 0000000..517b9ea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.persistence;
+
+import java.nio.file.Paths;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePdsMarshallerMappingRestoreOnNodeStartTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        int gridIndex = getTestIgniteInstanceIndex(gridName);
+
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        String tmpDir = System.getProperty("java.io.tmpdir");
+
+        cfg.setWorkDirectory(Paths.get(tmpDir, "srv" + gridIndex).toString());
+
+        cfg.setPersistentStoreConfiguration(
+            new PersistentStoreConfiguration()
+        );
+
+        cfg.setCacheConfiguration(new CacheConfiguration()
+            .setName(DEFAULT_CACHE_NAME)
+            .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
+            .setCacheMode(CacheMode.REPLICATED));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        String tmpDir = System.getProperty("java.io.tmpdir");
+
+        deleteRecursively(Paths.get(tmpDir, "srv0").toFile());
+        deleteRecursively(Paths.get(tmpDir, "srv1").toFile());
+    }
+
+    /**
+     * Test verifies that binary metadata from regular java classes is saved and restored correctly
+     * on cluster restart.
+     */
+    public void testStaticMetadataIsRestoredOnRestart() throws Exception {
+        startGrids(1);
+
+        Ignite ignite0 = grid(0);
+
+        ignite0.active(true);
+
+        IgniteCache<Object, Object> cache0 = ignite0.cache(DEFAULT_CACHE_NAME);
+
+        cache0.put(0, new TestValue1(0));
+
+        stopAllGrids();
+
+        startGrids(1);
+
+        ignite0 = grid(0);
+
+        ignite0.active(true);
+
+        Ignite ignite1 = startGrid(1);
+
+        awaitPartitionMapExchange();
+
+        ignite1.cache(DEFAULT_CACHE_NAME).get(0);
+    }
+
+    /**
+     *
+     */
+    private static class TestValue1 {
+        /** */
+        @AffinityKeyMapped
+        private final int val;
+
+        /**
+         * @param val Value.
+         */
+        TestValue1(int val) {
+            this.val = val;
+        }
+
+        /** */
+        int getValue() {
+            return val;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/418c4388/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
index bb9c9d1..ae8ea18 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePdsWithIndexingCoreTestSuite.java
@@ -19,6 +19,7 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsAtomicCacheRebalancingTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsBinaryMetadataOnClusterRestartTest;
+import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsMarshallerMappingRestoreOnNodeStartTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTxCacheRebalancingTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePersistentStoreCacheGroupsTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsMultiNodePutGetRestartTest;
@@ -51,6 +52,7 @@ public class IgnitePdsWithIndexingCoreTestSuite extends TestSuite {
         suite.addTestSuite(IgnitePdsTxCacheRebalancingTest.class);
 
         suite.addTestSuite(IgnitePdsBinaryMetadataOnClusterRestartTest.class);
+        suite.addTestSuite(IgnitePdsMarshallerMappingRestoreOnNodeStartTest.class);
 
         return suite;
     }


[4/8] ignite git commit: Fixed "IGNITE-6168 Need SSL client authentication during discovery". This closes #2505.

Posted by sb...@apache.org.
Fixed "IGNITE-6168 Need SSL client authentication during discovery". This closes #2505.

Signed-off-by: nikolay_tikhonov <nt...@gridgain.com>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/02801f8f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/02801f8f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/02801f8f

Branch: refs/heads/ignite-6149
Commit: 02801f8f28e4936b2770a7a96d9d3809cce16d42
Parents: 6f279b0
Author: Ilya Kasnacheev <il...@gmail.com>
Authored: Fri Aug 25 15:32:05 2017 +0300
Committer: nikolay_tikhonov <nt...@gridgain.com>
Committed: Fri Aug 25 15:32:05 2017 +0300

----------------------------------------------------------------------
 modules/clients/src/test/keystore/ca/node01.jks | Bin 0 -> 3719 bytes
 modules/clients/src/test/keystore/ca/node02.jks | Bin 0 -> 4598 bytes
 modules/clients/src/test/keystore/ca/node03.jks | Bin 0 -> 3754 bytes
 modules/clients/src/test/keystore/ca/oneca.cnf  |  15 ++
 modules/clients/src/test/keystore/ca/oneca.key  |  28 ++++
 .../clients/src/test/keystore/ca/oneindex.txt   |   1 +
 .../src/test/keystore/ca/oneindex.txt.attr      |   1 +
 modules/clients/src/test/keystore/ca/oneserial  |   1 +
 .../clients/src/test/keystore/ca/trust-both.jks | Bin 0 -> 1718 bytes
 .../clients/src/test/keystore/ca/trust-one.jks  | Bin 0 -> 877 bytes
 .../clients/src/test/keystore/ca/trust-two.jks  | Bin 0 -> 891 bytes
 modules/clients/src/test/keystore/ca/twoca.cnf  |  15 ++
 modules/clients/src/test/keystore/ca/twoca.key  |  28 ++++
 .../clients/src/test/keystore/ca/twoindex.txt   |   2 +
 .../src/test/keystore/ca/twoindex.txt.attr      |   1 +
 modules/clients/src/test/keystore/ca/twoserial  |   1 +
 .../ignite/spi/discovery/tcp/ServerImpl.java    |  11 +-
 modules/core/src/test/config/tests.properties   |   8 ++
 .../tcp/TcpDiscoverySslTrustedSelfTest.java     |  42 ++++++
 .../TcpDiscoverySslTrustedUntrustedTest.java    | 140 +++++++++++++++++++
 .../ignite/testframework/GridTestUtils.java     |  20 +++
 .../IgniteSpiDiscoverySelfTestSuite.java        |   4 +
 22 files changed, 316 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/node01.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/node01.jks b/modules/clients/src/test/keystore/ca/node01.jks
new file mode 100644
index 0000000..23c0643
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/node01.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/node02.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/node02.jks b/modules/clients/src/test/keystore/ca/node02.jks
new file mode 100644
index 0000000..26da4b5
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/node02.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/node03.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/node03.jks b/modules/clients/src/test/keystore/ca/node03.jks
new file mode 100644
index 0000000..831ca24
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/node03.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/oneca.cnf
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/oneca.cnf b/modules/clients/src/test/keystore/ca/oneca.cnf
new file mode 100644
index 0000000..2da42ca
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/oneca.cnf
@@ -0,0 +1,15 @@
+[ ca ]
+default_ca = oneca
+
+[ oneca ]
+certificate = ./oneca.pem
+database = ./oneindex.txt
+private_key = ./oneca.key
+new_certs_dir = ./
+default_md = sha1
+serial = ./oneserial
+default_days = 365
+policy = policy_match
+
+[policy_match]
+commonName = supplied

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/oneca.key
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/oneca.key b/modules/clients/src/test/keystore/ca/oneca.key
new file mode 100644
index 0000000..8815206
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/oneca.key
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDw4NjQ0YkcVbBo
+jvaXpcIB6fay0saNihfQ85anbxI63fvnOnUZrXnfwruUP5Az57WHi2+qzHLujytE
+QqCqo/PlSQ5jJ7s2HJVPgDVCM6qlc9/wXaYHTfGmurbf3DCGY8+qDBNcs2M5Kztj
+Pb0RIn++idVUBiiVlgrj+Tqy6AatNT6r70EBLQnVmR6aU+z/iuDNzj4M/DA35C61
+Fug4zYQIJEENSRNtNtp5VDfMaopAwZTg0ENCz5nhSAv6d0NHDsZWtK60P9nuOFsJ
+16Hmlv/RyHaVSf+OvxZjZDcWhEorlHA5mhF/RU/8iczstE2JMk6vOQ0LwKO+05gL
+2/9oJKYrAgMBAAECggEBAOf8xRQoGdMuO94Xgir/O2A4gp4rHYsHqnRVhYzwDjCf
+xpIl3M3EI5J7q8jVhv5WdKB8jCmFClPzkwoE2VQ+3xC+UZrxkv5EfRC6O5DszbbX
+aJ/IsbRrPwcC4EmteRaVXlU5mBQ5uKBAoMutlD/CaCGMAecQn1mhzg9N41iW2odI
+2AxK8ATSogCyNdVe82bedVXauBW8Kbsr5TCOxpUTrnLFhCl2aDvqFzmJFop+13E7
+V25Xz6DzrsCrWhw8Ghjh5YAYTq8RatAx53/DBYuOFlMLuSxbBcISEXjzSmNtIgsY
+BgVMPltzbIVgkzvdNDtr0JMXPdHgX9aJ1lR2Obod+zECgYEA/XxcqmWq/mY+DbXf
+5ZPXf26bms1Mx9FAK5t4hF8GGOO63HMH5n84tUKhWTJCSFo8rjsGc/b+amj1oY6J
+BJtTLUP8sJSdYQzC2SybOrFT5XskHv4NgIdVX9zNbJS+Z5BYoLfwTyziSMjay6B7
+5kE8QbBzK6MyhyBYoItMQDZMwicCgYEA80R5ArTGCMsTK0YNFlS2Y5XKORRunwEM
+1Mm741P9ejhf/NUiwez8TrcRB+i7BjjC68idhP0zUKEsKEedAP4uWpic2wbBYOuH
+7BsNxXLQ3XJeLJ066fhqOdPA3pz3NP82EBp65g41RxpzlW74LpfnE4/kxk1pi4UP
+LpJpzqeFsl0CgYEA1ICWOq9Cm0ThTqMjERZQuV7jifIEJRtR3XzXmrkCpoj7VOYG
+QIB07Nfv5ZPRp1AmwLVw4nS0skZNbWPNkBQatb7iLrJYAU0uZ9wSQjD4sU/7ZxP6
+A77wno2/lQBZYv7Knem1xtpM1VG0wrJGTDByMGuZEYMdz9QZGHXOtaIP1U8CgYAy
+ZJTMwrXjTG4EINbFMXc22eiyOlFQDt+hlMifJt7zWopHzb8NfRInHDUi9ksH1upJ
+/Zzj16+xnDGRhoQ3mG/xxHt5w8R7V08o0dHgfRBXT0HC7C8wGI2ovPzPIKT1DYkd
+fN7ImVjgCdK3ue0fecgcfUpe6dpbVIz4kMvqSzme4QKBgQDjUk7m8szM4C8BIYQH
+1yo5kSPYQUZuc2UFYozd5ZNj791iAptrSSd2Mmck8MkT3oDAbH+SWg4Qw7UA/kNe
+264vVvNIzss7bw8UFcHT6JN9gdk08EsrW+IT3vopt3QlB/wYCHCqr47VviVneqWn
+og1hf+rw1WNr3atLP/NLnWWN7g==
+-----END PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/oneindex.txt
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/oneindex.txt b/modules/clients/src/test/keystore/ca/oneindex.txt
new file mode 100644
index 0000000..8d347d0
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/oneindex.txt
@@ -0,0 +1 @@
+V	180824104710Z		01	unknown	/CN=node01

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/oneindex.txt.attr
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/oneindex.txt.attr b/modules/clients/src/test/keystore/ca/oneindex.txt.attr
new file mode 100644
index 0000000..8f7e63a
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/oneindex.txt.attr
@@ -0,0 +1 @@
+unique_subject = yes

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/oneserial
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/oneserial b/modules/clients/src/test/keystore/ca/oneserial
new file mode 100644
index 0000000..9e22bcb
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/oneserial
@@ -0,0 +1 @@
+02

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/trust-both.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/trust-both.jks b/modules/clients/src/test/keystore/ca/trust-both.jks
new file mode 100644
index 0000000..1d8ccc2
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/trust-both.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/trust-one.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/trust-one.jks b/modules/clients/src/test/keystore/ca/trust-one.jks
new file mode 100644
index 0000000..0b91ca7
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/trust-one.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/trust-two.jks
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/trust-two.jks b/modules/clients/src/test/keystore/ca/trust-two.jks
new file mode 100644
index 0000000..1939287
Binary files /dev/null and b/modules/clients/src/test/keystore/ca/trust-two.jks differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/twoca.cnf
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/twoca.cnf b/modules/clients/src/test/keystore/ca/twoca.cnf
new file mode 100644
index 0000000..1efa25a
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/twoca.cnf
@@ -0,0 +1,15 @@
+[ ca ]
+default_ca = twoca
+ 
+[ twoca ]
+certificate = ./twoca.pem
+database = ./twoindex.txt
+private_key = ./twoca.key
+new_certs_dir = ./
+default_md = sha1
+policy = policy_match
+serial = ./twoserial
+default_days = 365
+ 
+[policy_match]
+commonName = supplied

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/twoca.key
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/twoca.key b/modules/clients/src/test/keystore/ca/twoca.key
new file mode 100644
index 0000000..4053881
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/twoca.key
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCvv6fLWOIk9Hhn
+JMsfoySItogO+hhV4kREDEGi8SfAblHEKCiY4GxvtgtxS3EWyoYFynI8HK7GQNma
+tAQ49QtUP5FA36VRx3/9eh85je4AqXVgF/4qX0PdygMuSFOIxWYshj9CIwVHmiS2
++IiVthe6OsAUSMnfIFzIxlEygpi6/I2N2WchkOlWiWo1G9E4RQOjKrwCGM/mWy6Y
+KIB2u3dSaNpfNZy2+sxBRXrtDUQzDxbVv9lCQ3DkZwVr2HnfMxZ9oFP5x8HoPyJi
+uS4qLUWypnbvIuBLnlR4LX/VSONCg6PzkafQdSvoYX5XPYDF32PUiSZS+U7URHzN
+nqC7nn97AgMBAAECggEAdEvHlfjoFHotXltrijDjkQ/wMrDt/47ti3XszQz1OBII
+S1wjmR4Qw09cfQjl+aXkT9qqAvsb8BajqAptLN+CMqqpzJrxg48XM71nAifYEVoR
+UJgv2QwXFaGCv1Ke7EdrmBTxsSsJaFso5mbJwv+u7c3IouOTqfF5VGZe/qSKulgh
+/swDJTFCo+JwISTJlVppR6xUVTtLpl4JFyWWExfGpOFmCfy818lhpJLV9HZzh142
+zssJCBevpaKng4DsHVmhvhi1f8zNV674C0cJ8yCBCVFAVw5WufaWRSh8PnHT9AR8
++dqrGh+0EtmjJR9qy88LLEayWZKxE4oQLSUcDSe6OQKBgQDUK8/gZPzsepq0AOTD
+qL21nkMmA00J5u4USgB5S27PrYQB1p4uf1wfwVfmXC21Pyrwl+/mx9ukkQB907jG
+5vQTF81YEV1Z9eT5gCjE0XeCK40kYNdvfhlTPeuJteqEnrFDWZQ3WGD+6/TQoEfj
+BibgaAroKvlGF8mLWfAC9qqcrQKBgQDUDbkdUtthgZdDVoAzMS9kWB37pj1io3+8
+dOZ9i8farzTW3FcX9T504YPvazoNllKVaiO/q1sODI+7gtixYVKriZsqqE/h7ndS
+mc7OVfxqxoy5bW2XZUHNbefG/JTJvy4Zj8ANnes7Cb5fJtNtB3xa3JaGRFo91te6
+2M/6v2MpxwKBgG1Hf5MpEKhQYbwStcEc+VFBCX7btmNCQR/MGcBfnNx0l4hG3UQ/
+rthgQgDRO22d8mTnLNYl3Dg/wwwL76DqtY3b9ZTFpNo/70aevuDYroAqJFE3W97+
+CNc6DkXon7jc75or2k5DQ/oo1/hYhY4lzgJJNEzuTWPPvqv6j8dG+wslAoGAY+tn
+e8LMLuDihs9er0CQ5UaEMkz+Bdmm2gV3ilbwQEJosom23EoqOOb+xTUQcNCRb2hJ
+GgrDaBZRL/kS5FpImx3HKM2QfpRgU2K4SQ/JVgLi0okWp80Fuaf9HA1uirX0IgVT
+aNctvW707l8cJvbtCN+CahgRMaxnkNqS/cNrFYcCgYBBzR2qDcTn48gs7LvrlzMO
+RwamzD0LEibRUvw17rcmf4x2tFqx8hnyh4ahpPxlcB5SRSKhs2RKFf4AONGHMFAW
+IU/pxQJdk32NX1Xg5TjiNS+khW2Yp7voytvYyP7JMbSlp1NZbgNVYA4voikFNZ/O
+63NWew8dD+Gx5ZEWXg2Nvw==
+-----END PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/twoindex.txt
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/twoindex.txt b/modules/clients/src/test/keystore/ca/twoindex.txt
new file mode 100644
index 0000000..00b7307
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/twoindex.txt
@@ -0,0 +1,2 @@
+V	180824104716Z		01	unknown	/CN=node02
+V	180824104719Z		02	unknown	/CN=node03

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/twoindex.txt.attr
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/twoindex.txt.attr b/modules/clients/src/test/keystore/ca/twoindex.txt.attr
new file mode 100644
index 0000000..8f7e63a
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/twoindex.txt.attr
@@ -0,0 +1 @@
+unique_subject = yes

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/clients/src/test/keystore/ca/twoserial
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/keystore/ca/twoserial b/modules/clients/src/test/keystore/ca/twoserial
new file mode 100644
index 0000000..75016ea
--- /dev/null
+++ b/modules/clients/src/test/keystore/ca/twoserial
@@ -0,0 +1 @@
+03

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index ca7dd4d..5d7e39e 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -57,6 +57,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLServerSocket;
 import javax.net.ssl.SSLSocket;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
@@ -5578,8 +5579,14 @@ class ServerImpl extends TcpDiscoveryImpl {
 
             for (port = spi.locPort; port <= lastPort; port++) {
                 try {
-                    if (spi.isSslEnabled())
-                        srvrSock = spi.sslSrvSockFactory.createServerSocket(port, 0, spi.locHost);
+                    if (spi.isSslEnabled()) {
+                        SSLServerSocket sslSock = (SSLServerSocket)spi.sslSrvSockFactory
+                            .createServerSocket(port, 0, spi.locHost);
+
+                        sslSock.setNeedClientAuth(true);
+
+                        srvrSock = sslSock;
+                    }
                     else
                         srvrSock = new ServerSocket(port, 0, spi.locHost);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/test/config/tests.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/tests.properties b/modules/core/src/test/config/tests.properties
index 3275c3c..1ea5b3d 100644
--- a/modules/core/src/test/config/tests.properties
+++ b/modules/core/src/test/config/tests.properties
@@ -135,6 +135,14 @@ ssh.password=passwd
 ssl.keystore.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/server.jks
 ssl.keystore.password=123456
 
+# node01 signed with trust-one, node02 and node03 by trust-two, trust-both contains both CAs
+ssl.keystore.node01.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/node01.jks
+ssl.keystore.node02.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/node02.jks
+ssl.keystore.node03.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/node03.jks
+ssl.keystore.trustone.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/trust-one.jks
+ssl.keystore.trusttwo.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/trust-two.jks
+ssl.keystore.trustboth.path=@{IGNITE_HOME}/modules/clients/src/test/keystore/ca/trust-both.jks
+
 # Hadoop home directory.
 hadoop.home=@{HADOOP_HOME}
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedSelfTest.java
new file mode 100644
index 0000000..56567f9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedSelfTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.spi.discovery.tcp;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+
+/**
+ * Test for {@link TcpDiscoverySpi} with SSL.
+ */
+public class TcpDiscoverySslTrustedSelfTest extends TcpDiscoverySelfTest {
+    /**
+     * @throws Exception If fails.
+     */
+    public TcpDiscoverySslTrustedSelfTest() throws Exception {
+        super();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setSslContextFactory(GridTestUtils.sslTrustedFactory("node02", "trustboth"));
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedUntrustedTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedUntrustedTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedUntrustedTest.java
new file mode 100644
index 0000000..e1c6755
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslTrustedUntrustedTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.spi.discovery.tcp;
+
+import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests cases when node connects to cluster with different SSL configuration.
+ * Exception with meaningful message should be thrown.
+ */
+public class TcpDiscoverySslTrustedUntrustedTest extends GridCommonAbstractTest {
+    /** */
+    private volatile String keyStore;
+    /** */
+    private volatile String trustStore;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSslContextFactory(GridTestUtils.sslTrustedFactory(keyStore, trustStore));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSameKey() throws Exception {
+        checkDiscoverySuccess("node01", "trustone", "node01", "trustone");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDifferentKeys() throws Exception {
+        checkDiscoverySuccess("node02", "trusttwo", "node03", "trusttwo");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBothTrusts() throws Exception {
+        checkDiscoverySuccess("node01", "trustboth", "node02", "trustboth", "node03", "trustboth");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDifferentCa() throws Exception {
+        checkDiscoveryFailure("node01", "trustone", "node02", "trusttwo");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWrongCa() throws Exception {
+        checkDiscoveryFailure("node02", "trustone", "node03", "trustone");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMismatchingCaSecond() throws Exception {
+        checkDiscoveryFailure("node01", "trustboth", "node03", "trusttwo");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMismatchingCaFirst() throws Exception {
+        checkDiscoveryFailure("node02", "trusttwo", "node01", "trustboth");
+    }
+
+    /**
+     * @param keysTrusts Pairs of key store, trust store.
+     * @throws Exception If failed.
+     */
+    private void checkDiscoverySuccess(String... keysTrusts) throws Exception {
+        if (keysTrusts.length % 2 != 0)
+            fail("Wrong parameters");
+
+        for (int i = 0; i < keysTrusts.length / 2; i++) {
+            keyStore = keysTrusts[2 * i];
+            trustStore = keysTrusts[2 * i + 1];
+
+            startGrid(i);
+        }
+    }
+
+    /**
+     * @param keyStoreOk Key store of first instance.
+     * @param trustStoreOk Trust store of first instance.
+     * @param keyStoreFail Key store of second (failing) instance.
+     * @param trustStoreFail Trust store of second (failing) instance.
+     * @throws Exception If failed.
+     */
+    private void checkDiscoveryFailure(String keyStoreOk, String trustStoreOk,
+        final String keyStoreFail, final String trustStoreFail) throws Exception {
+        keyStore = keyStoreOk;
+        trustStore = trustStoreOk;
+
+        startGrid(0);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                keyStore = keyStoreFail;
+                trustStore = trustStoreFail;
+
+                startGrid(1);
+
+                return null;
+            }
+        }, IgniteCheckedException.class, "Unable to establish secure connection.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 585c759..abae97c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -1700,6 +1700,26 @@ public final class GridTestUtils {
     }
 
     /**
+     * Creates test-purposed SSL context factory from specified key store and trust store.
+     *
+     * @param keyStore Key store name.
+     * @param trustStore Trust store name.
+     * @return SSL context factory used in test.
+     */
+    public static Factory<SSLContext> sslTrustedFactory(String keyStore, String trustStore) {
+        SslContextFactory factory = new SslContextFactory();
+
+        factory.setKeyStoreFilePath(U.resolveIgnitePath(GridTestProperties.getProperty(
+            "ssl.keystore." + keyStore + ".path")).getAbsolutePath());
+        factory.setKeyStorePassword(GridTestProperties.getProperty("ssl.keystore.password").toCharArray());
+        factory.setTrustStoreFilePath(U.resolveIgnitePath(GridTestProperties.getProperty(
+            "ssl.keystore." + trustStore + ".path")).getAbsolutePath());
+        factory.setTrustStorePassword(GridTestProperties.getProperty("ssl.keystore.password").toCharArray());
+
+        return factory;
+    }
+
+    /**
      * @param o1 Object 1.
      * @param o2 Object 2.
      * @return Equals or not.

http://git-wip-us.apache.org/repos/asf/ignite/blob/02801f8f/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
index c506ca7..3335797 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSpiDiscoverySelfTestSuite.java
@@ -40,6 +40,8 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpiSelfTest;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpiStartStopSelfTest;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySslSecuredUnsecuredTest;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySslSelfTest;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySslTrustedSelfTest;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySslTrustedUntrustedTest;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.jdbc.TcpDiscoveryJdbcIpFinderSelfTest;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinderSelfTest;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinderSelfTest;
@@ -98,7 +100,9 @@ public class IgniteSpiDiscoverySelfTestSuite extends TestSuite {
 
         // SSL.
         suite.addTest(new TestSuite(TcpDiscoverySslSelfTest.class));
+        suite.addTest(new TestSuite(TcpDiscoverySslTrustedSelfTest.class));
         suite.addTest(new TestSuite(TcpDiscoverySslSecuredUnsecuredTest.class));
+        suite.addTest(new TestSuite(TcpDiscoverySslTrustedUntrustedTest.class));
 
         return suite;
     }


[6/8] ignite git commit: IGNITE-6183 Make "Node crashed in the middle of checkpoint" message softer and more informative

Posted by sb...@apache.org.
IGNITE-6183 Make "Node crashed in the middle of checkpoint" message softer and more informative

Signed-off-by: Andrey Gura <ag...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a1fab62c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a1fab62c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a1fab62c

Branch: refs/heads/ignite-6149
Commit: a1fab62c2d44730204e657ea25d1002669df90b1
Parents: 418c438
Author: Ivan Rakov <iv...@gmail.com>
Authored: Fri Aug 25 20:09:43 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Fri Aug 25 20:09:43 2017 +0300

----------------------------------------------------------------------
 .../cache/persistence/GridCacheDatabaseSharedManager.java        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a1fab62c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
index 9f2e4a0..b4502d2 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
@@ -1333,8 +1333,8 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
         boolean apply = status.needRestoreMemory();
 
         if (apply) {
-            U.quietAndWarn(log, "Ignite node crashed in the middle of checkpoint. Will restore memory state and " +
-                "enforce checkpoint on node start.");
+            U.quietAndWarn(log, "Ignite node stopped in the middle of checkpoint. Will restore memory state and " +
+                "finish checkpoint on node start.");
 
             cctx.pageStore().beginRecover();
         }


[7/8] ignite git commit: Merge remote-tracking branch 'remotes/origin/master' into ignite-6149

Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into ignite-6149


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/57b9e8db
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/57b9e8db
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/57b9e8db

Branch: refs/heads/ignite-6149
Commit: 57b9e8dbd0ec1e71fc36df6fff8804cc6275e591
Parents: 5a4c6f3 a1fab62
Author: sboikov <sb...@gridgain.com>
Authored: Mon Aug 28 11:04:01 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon Aug 28 11:04:01 2017 +0300

----------------------------------------------------------------------
 modules/clients/src/test/keystore/ca/node01.jks | Bin 0 -> 3719 bytes
 modules/clients/src/test/keystore/ca/node02.jks | Bin 0 -> 4598 bytes
 modules/clients/src/test/keystore/ca/node03.jks | Bin 0 -> 3754 bytes
 modules/clients/src/test/keystore/ca/oneca.cnf  |  15 +
 modules/clients/src/test/keystore/ca/oneca.key  |  28 ++
 .../clients/src/test/keystore/ca/oneindex.txt   |   1 +
 .../src/test/keystore/ca/oneindex.txt.attr      |   1 +
 modules/clients/src/test/keystore/ca/oneserial  |   1 +
 .../clients/src/test/keystore/ca/trust-both.jks | Bin 0 -> 1718 bytes
 .../clients/src/test/keystore/ca/trust-one.jks  | Bin 0 -> 877 bytes
 .../clients/src/test/keystore/ca/trust-two.jks  | Bin 0 -> 891 bytes
 modules/clients/src/test/keystore/ca/twoca.cnf  |  15 +
 modules/clients/src/test/keystore/ca/twoca.key  |  28 ++
 .../clients/src/test/keystore/ca/twoindex.txt   |   2 +
 .../src/test/keystore/ca/twoindex.txt.attr      |   1 +
 modules/clients/src/test/keystore/ca/twoserial  |   1 +
 .../PersistentStoreConfiguration.java           |   7 +-
 .../ignite/internal/MarshallerContextImpl.java  |   3 +
 .../internal/MarshallerMappingFileStore.java    |  76 ++-
 .../ignite/internal/binary/BinaryUtils.java     |  26 +
 .../processors/cache/CacheObjectUtils.java      |  65 ++-
 .../processors/cache/GridCacheAdapter.java      |   6 +-
 .../processors/cache/GridCacheEntryEx.java      |  10 +
 .../processors/cache/GridCacheMapEntry.java     |  27 +-
 .../processors/cache/IgniteCacheProxyImpl.java  |  26 +-
 .../colocated/GridDhtDetachedCacheEntry.java    |   4 +-
 .../distributed/near/GridNearCacheEntry.java    |   4 +-
 .../GridCacheDatabaseSharedManager.java         |   4 +-
 .../processors/cache/query/CacheQueryEntry.java |  58 +++
 .../query/GridCacheDistributedQueryManager.java |  16 +-
 .../cache/query/GridCacheQueryAdapter.java      |  53 ++-
 .../cache/query/GridCacheQueryManager.java      | 470 +++++++++----------
 .../IgniteCacheObjectProcessorImpl.java         | 164 -------
 .../UserCacheObjectByteArrayImpl.java           |  59 +++
 .../cacheobject/UserCacheObjectImpl.java        |  82 ++++
 .../cacheobject/UserKeyCacheObjectImpl.java     | 101 ++++
 .../service/GridServiceProcessor.java           |   6 +-
 .../ignite/spi/discovery/tcp/ServerImpl.java    |  11 +-
 .../resources/META-INF/classnames.properties    |  88 ++--
 modules/core/src/test/config/tests.properties   |   8 +
 .../processors/cache/GridCacheTestEntryEx.java  |   6 +
 ...MarshallerMappingRestoreOnNodeStartTest.java | 116 +++++
 .../GridCacheQueryTransformerSelfTest.java      |  41 ++
 .../tcp/TcpDiscoverySslTrustedSelfTest.java     |  42 ++
 .../TcpDiscoverySslTrustedUntrustedTest.java    | 140 ++++++
 .../ignite/testframework/GridTestUtils.java     |  20 +
 .../IgniteSpiDiscoverySelfTestSuite.java        |   4 +
 .../IgnitePdsWithIndexingCoreTestSuite.java     |   2 +
 48 files changed, 1305 insertions(+), 533 deletions(-)
----------------------------------------------------------------------