ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [48/51] [abbrv] incubator-ignite git commit: Merge branches 'ignite-96' and 'sprint-1' of https://git-wip-us.apache.org/repos/asf/incubator-ignite into ignite-96
Date Sat, 07 Feb 2015 10:53:20 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicyMBean.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicyMBean.java
index b3a8b6c,62d5ee7..0ecace5
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicyMBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicyMBean.java
@@@ -22,9 -22,17 +22,9 @@@ import org.apache.ignite.mxbean.*
  /**
   * MBean for {@code FIFO} eviction policy.
   */
- @IgniteMXBeanDescription("MBean for FIFO cache eviction policy.")
+ @MXBeanDescription("MBean for FIFO cache eviction policy.")
  public interface CacheFifoEvictionPolicyMBean {
      /**
 -     * Gets name of metadata attribute used to store eviction policy data.
 -     *
 -     * @return Name of metadata attribute used to store eviction policy data.
 -     */
 -    @MXBeanDescription("Name of metadata attribute used to store eviction policy data.")
 -    public String getMetaAttributeName();
 -
 -    /**
       * Gets maximum allowed cache size.
       *
       * @return Maximum allowed cache size.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsEvictionFilter.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsEvictionFilter.java
index 0000000,25a209f..1a17a8b
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsEvictionFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsEvictionFilter.java
@@@ -1,0 -1,34 +1,35 @@@
+ /*
+  * 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.cache.eviction.ignitefs;
+ 
 -import org.apache.ignite.cache.*;
+ import org.apache.ignite.cache.eviction.*;
+ import org.apache.ignite.internal.processors.fs.*;
+ 
++import javax.cache.Cache.*;
++
+ /**
+  * GGFS eviction filter which will not evict blocks of particular files.
+  */
+ public class CacheIgniteFsEvictionFilter implements CacheEvictionFilter {
+     /** {@inheritDoc} */
 -    @Override public boolean evictAllowed(CacheEntry entry) {
++    @Override public boolean evictAllowed(Entry entry) {
+         Object key = entry.getKey();
+ 
+         return !(key instanceof GridGgfsBlockKey && ((GridGgfsBlockKey)key).evictExclude());
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsPerBlockLruEvictionPolicy.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsPerBlockLruEvictionPolicy.java
index 0000000,80c958d..cec59ce
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsPerBlockLruEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/ignitefs/CacheIgniteFsPerBlockLruEvictionPolicy.java
@@@ -1,0 -1,353 +1,358 @@@
+ /*
+  * 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.cache.eviction.ignitefs;
+ 
+ import org.apache.ignite.*;
 -import org.apache.ignite.cache.*;
+ import org.apache.ignite.cache.eviction.*;
+ import org.apache.ignite.ignitefs.*;
++import org.apache.ignite.internal.processors.cache.*;
+ import org.apache.ignite.internal.processors.fs.*;
+ import org.jdk8.backport.*;
+ import org.jdk8.backport.ConcurrentLinkedDeque8.*;
+ import org.jetbrains.annotations.*;
+ 
+ import java.util.*;
+ import java.util.concurrent.atomic.*;
+ import java.util.regex.*;
+ 
+ /**
+  * GGFS eviction policy which evicts particular blocks.
+  */
+ public class CacheIgniteFsPerBlockLruEvictionPolicy implements CacheEvictionPolicy<GridGgfsBlockKey,
byte[]>,
+     CacheIgniteFsPerBlockLruEvictionPolicyMXBean {
 -    /** Meta denoting node in the queue. */
 -    public static final String META_NODE = "ggfs_node";
 -
+     /** Maximum size. When reached, eviction begins. */
+     private volatile long maxSize;
+ 
+     /** Maximum amount of blocks. When reached, eviction begins. */
+     private volatile int maxBlocks;
+ 
+     /** Collection of regex for paths which must not be evicted. */
+     private volatile Collection<String> excludePaths;
+ 
+     /** Exclusion patterns. */
+     private volatile Collection<Pattern> excludePatterns;
+ 
+     /** Whether patterns must be recompiled during the next call. */
+     private final AtomicBoolean excludeRecompile = new AtomicBoolean(true);
+ 
+     /** Queue. */
 -    private final ConcurrentLinkedDeque8<CacheEntry<GridGgfsBlockKey, byte[]>>
queue =
++    private final ConcurrentLinkedDeque8<EvictableEntry<GridGgfsBlockKey, byte[]>>
queue =
+         new ConcurrentLinkedDeque8<>();
+ 
+     /** Current size of all enqueued blocks in bytes. */
+     private final LongAdder curSize = new LongAdder();
+ 
+     /**
+      * Default constructor.
+      */
+     public CacheIgniteFsPerBlockLruEvictionPolicy() {
+         // No-op.
+     }
+ 
+     /**
+      * Constructor.
+      *
+      * @param maxSize Maximum size. When reached, eviction begins.
+      * @param maxBlocks Maximum amount of blocks. When reached, eviction begins.
+      */
+     public CacheIgniteFsPerBlockLruEvictionPolicy(long maxSize, int maxBlocks) {
+         this(maxSize, maxBlocks, null);
+     }
+ 
+     /**
+      * Constructor.
+      *
+      * @param maxSize Maximum size. When reached, eviction begins.
+      * @param maxBlocks Maximum amount of blocks. When reached, eviction begins.
+      * @param excludePaths Collection of regex for path which must not be evicted.
+      */
+     public CacheIgniteFsPerBlockLruEvictionPolicy(long maxSize, int maxBlocks,
+         @Nullable Collection<String> excludePaths) {
+         this.maxSize = maxSize;
+         this.maxBlocks = maxBlocks;
+         this.excludePaths = excludePaths;
+     }
+ 
+     /** {@inheritDoc} */
 -    @Override public void onEntryAccessed(boolean rmv, CacheEntry<GridGgfsBlockKey, byte[]>
entry) {
++    @Override public void onEntryAccessed(boolean rmv, EvictableEntry<GridGgfsBlockKey,
byte[]> entry) {
+         if (!rmv) {
+             if (!entry.isCached())
+                 return;
+ 
+             if (touch(entry))
+                 shrink();
+         }
+         else {
 -            MetaEntry meta = entry.removeMeta(META_NODE);
++            MetaEntry meta = entry.removeMeta();
+ 
+             if (meta != null && queue.unlinkx(meta.node()))
+                 changeSize(-meta.size());
+         }
+     }
+ 
+     /**
+      * @param entry Entry to touch.
+      * @return {@code True} if new node has been added to queue by this call.
+      */
 -    private boolean touch(CacheEntry<GridGgfsBlockKey, byte[]> entry) {
 -        byte[] val = entry.peek();
++    private boolean touch(EvictableEntry<GridGgfsBlockKey, byte[]> entry) {
++        byte[] val = peek(entry);
+ 
+         int blockSize = val != null ? val.length : 0;
+ 
 -        MetaEntry meta = entry.meta(META_NODE);
++        MetaEntry meta = entry.meta();
+ 
+         // Entry has not been enqueued yet.
+         if (meta == null) {
+             while (true) {
 -                Node<CacheEntry<GridGgfsBlockKey, byte[]>> node = queue.offerLastx(entry);
++                Node<EvictableEntry<GridGgfsBlockKey, byte[]>> node = queue.offerLastx(entry);
+ 
+                 meta = new MetaEntry(node, blockSize);
+ 
 -                if (entry.putMetaIfAbsent(META_NODE, meta) != null) {
++                if (entry.putMetaIfAbsent(meta) != null) {
+                     // Was concurrently added, need to clear it from queue.
+                     queue.unlinkx(node);
+ 
+                     // Queue has not been changed.
+                     return false;
+                 }
+                 else if (node.item() != null) {
+                     if (!entry.isCached()) {
+                         // Was concurrently evicted, need to clear it from queue.
+                         queue.unlinkx(node);
+ 
+                         return false;
+                     }
+ 
+                     // Increment current size.
+                     changeSize(blockSize);
+ 
+                     return true;
+                 }
+                 // If node was unlinked by concurrent shrink() call, we must repeat the
whole cycle.
 -                else if (!entry.removeMeta(META_NODE, node))
++                else if (!entry.removeMeta(node))
+                     return false;
+             }
+         }
+         else {
+             int oldBlockSize = meta.size();
+ 
 -            Node<CacheEntry<GridGgfsBlockKey, byte[]>> node = meta.node();
++            Node<EvictableEntry<GridGgfsBlockKey, byte[]>> node = meta.node();
+ 
+             if (queue.unlinkx(node)) {
+                 // Move node to tail.
 -                Node<CacheEntry<GridGgfsBlockKey, byte[]>> newNode = queue.offerLastx(entry);
++                Node<EvictableEntry<GridGgfsBlockKey, byte[]>> newNode = queue.offerLastx(entry);
+ 
+                 int delta = blockSize - oldBlockSize;
+ 
 -                if (!entry.replaceMeta(META_NODE, meta, new MetaEntry(newNode, blockSize)))
{
++                if (!entry.replaceMeta(meta, new MetaEntry(newNode, blockSize))) {
+                     // Was concurrently added, need to clear it from queue.
+                     if (queue.unlinkx(newNode))
+                         delta -= blockSize;
+                 }
+ 
+                 if (delta != 0) {
+                     changeSize(delta);
+ 
+                    if (delta > 0)
+                        // Total size increased, so shrinking could be needed.
+                        return true;
+                 }
+             }
+         }
+ 
+         // Entry is already in queue.
+         return false;
+     }
+ 
+     /**
++     * @param entry Entry.
++     * @return Peeked value.
++     */
++    @Nullable private byte[] peek(EvictableEntry<GridGgfsBlockKey, byte[]> entry)
{
++        return (byte[])((GridCacheEvictionEntry)entry).peek();
++    }
++
++    /**
+      * Shrinks queue to maximum allowed size.
+      */
+     private void shrink() {
+         long maxSize = this.maxSize;
+         int maxBlocks = this.maxBlocks;
+ 
+         int cnt = queue.sizex();
+ 
+         for (int i = 0; i < cnt && (maxBlocks > 0 && queue.sizex()
> maxBlocks ||
+             maxSize > 0 && curSize.longValue() > maxSize); i++) {
 -            CacheEntry<GridGgfsBlockKey, byte[]> entry = queue.poll();
++            EvictableEntry<GridGgfsBlockKey, byte[]> entry = queue.poll();
+ 
+             if (entry == null)
+                 break; // Queue is empty.
+ 
 -            byte[] val = entry.peek();
++            byte[] val = peek(entry);
+ 
+             if (val != null)
+                 changeSize(-val.length); // Change current size as we polled entry from
the queue.
+ 
+             if (!entry.evict()) {
+                 // Reorder entries which we failed to evict.
 -                entry.removeMeta(META_NODE);
++                entry.removeMeta();
+ 
+                 touch(entry);
+             }
+         }
+     }
+ 
+     /**
+      * Change current size.
+      *
+      * @param delta Delta in bytes.
+      */
+     private void changeSize(int delta) {
+         if (delta != 0)
+             curSize.add(delta);
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public long getMaxSize() {
+         return maxSize;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public void setMaxSize(long maxSize) {
+         this.maxSize = maxSize;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public int getMaxBlocks() {
+         return maxBlocks;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public void setMaxBlocks(int maxBlocks) {
+         this.maxBlocks = maxBlocks;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public Collection<String> getExcludePaths() {
+         return Collections.unmodifiableCollection(excludePaths);
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public void setExcludePaths(@Nullable Collection<String> excludePaths)
{
+         this.excludePaths = excludePaths;
+ 
+         excludeRecompile.set(true);
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public long getCurrentSize() {
+         return curSize.longValue();
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public int getCurrentBlocks() {
+         return queue.size();
+     }
+ 
+     /**
+      * Check whether provided path must be excluded from evictions.
+      *
+      * @param path Path.
+      * @return {@code True} in case non block of related file must be excluded.
+      * @throws IgniteCheckedException In case of faulty patterns.
+      */
+     public boolean exclude(IgniteFsPath path) throws IgniteCheckedException {
+         assert path != null;
+ 
+         Collection<Pattern> excludePatterns0;
+ 
+         if (excludeRecompile.compareAndSet(true, false)) {
+             // Recompile.
+             Collection<String> excludePaths0 = excludePaths;
+ 
+             if (excludePaths0 != null) {
+                 excludePatterns0 = new HashSet<>(excludePaths0.size(), 1.0f);
+ 
+                 for (String excludePath : excludePaths0) {
+                     try {
+                         excludePatterns0.add(Pattern.compile(excludePath));
+                     }
+                     catch (PatternSyntaxException ignore) {
+                         throw new IgniteCheckedException("Invalid regex pattern: " + excludePath);
+                     }
+                 }
+ 
+                 excludePatterns = excludePatterns0;
+             }
+             else
+                 excludePatterns0 = excludePatterns = null;
+         }
+         else
+             excludePatterns0 = excludePatterns;
+ 
+         if (excludePatterns0 != null) {
+             String pathStr = path.toString();
+ 
+             for (Pattern pattern : excludePatterns0) {
+                 if (pattern.matcher(pathStr).matches())
+                     return true;
+             }
+         }
+ 
+         return false;
+     }
+ 
+     /**
+      * Meta entry.
+      */
+     private static class MetaEntry {
+         /** Queue node. */
 -        private final Node<CacheEntry<GridGgfsBlockKey, byte[]>> node;
++        private final Node<EvictableEntry<GridGgfsBlockKey, byte[]>> node;
+ 
+         /** Data size. */
+         private final int size;
+ 
+         /**
+          * Constructor.
+          *
+          * @param node Queue node.
+          * @param size Data size.
+          */
 -        private MetaEntry(Node<CacheEntry<GridGgfsBlockKey, byte[]>> node, int
size) {
++        private MetaEntry(Node<EvictableEntry<GridGgfsBlockKey, byte[]>> node,
int size) {
+             assert node != null;
+             assert size >= 0;
+ 
+             this.node = node;
+             this.size = size;
+         }
+ 
+         /**
+          * @return Queue node.
+          */
 -        private Node<CacheEntry<GridGgfsBlockKey, byte[]>> node() {
++        private Node<EvictableEntry<GridGgfsBlockKey, byte[]>> node() {
+             return node;
+         }
+ 
+         /**
+          * @return Data size.
+          */
+         private int size() {
+             return size;
+         }
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicyMBean.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicyMBean.java
index 4200b7c,22f39cc..49f0dcc
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicyMBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicyMBean.java
@@@ -22,9 -22,17 +22,9 @@@ import org.apache.ignite.mxbean.*
  /**
   * MBean for {@code LRU} eviction policy.
   */
- @IgniteMXBeanDescription("MBean for LRU cache eviction policy.")
+ @MXBeanDescription("MBean for LRU cache eviction policy.")
  public interface CacheLruEvictionPolicyMBean {
      /**
 -     * Gets name of metadata attribute used to store eviction policy data.
 -     *
 -     * @return Name of metadata attribute used to store eviction policy data.
 -     */
 -    @MXBeanDescription("Name of metadata attribute used to store eviction policy data.")
 -    public String getMetaAttributeName();
 -
 -    /**
       * Gets maximum allowed cache size.
       *
       * @return Maximum allowed cache size.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6d2ed753/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java
index 0000000,4b3fef8..6a7051e
mode 000000,100644..100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java
@@@ -1,0 -1,105 +1,105 @@@
+ /*
+  * 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.configuration;
+ 
 -import org.apache.ignite.IgniteAtomicSequence;
++import org.apache.ignite.*;
+ import org.apache.ignite.cache.*;
+ import org.apache.ignite.internal.util.typedef.internal.*;
+ 
+ import static org.apache.ignite.cache.CacheMode.*;
+ 
+ /**
+  * Configuration for atomic data structures.
+  */
+ public class AtomicConfiguration {
+     /** */
+     public static final int DFLT_BACKUPS = 0;
+ 
+     /** */
+     public static final CacheMode DFLT_CACHE_MODE = PARTITIONED;
+ 
+     /** Default atomic sequence reservation size. */
+     public static final int DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE = 1000;
+ 
+     /** Default batch size for all cache's sequences. */
+     private int seqReserveSize = DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE;
+ 
+     /** Cache mode. */
+     private CacheMode cacheMode = DFLT_CACHE_MODE;
+ 
+     /** Number of backups. */
+     private int backups = DFLT_BACKUPS;
+ 
+     /**
+      * @return Number of backup nodes.
+      */
+     public int getBackups() {
+         return backups;
+     }
+ 
+     /**
+      * @param backups Number of backup nodes.
+      */
+     public void setBackups(int backups) {
+         this.backups = backups;
+     }
+ 
+     /**
+      * @return Cache mode.
+      */
+     public CacheMode getCacheMode() {
+         return cacheMode;
+     }
+ 
+     /**
+      * @param cacheMode Cache mode.
+      */
+     public void setCacheMode(CacheMode cacheMode) {
+         this.cacheMode = cacheMode;
+     }
+ 
+     /**
+      * Gets default number of sequence values reserved for {@link IgniteAtomicSequence}
instances. After
+      * a certain number has been reserved, consequent increments of sequence will happen
locally,
+      * without communication with other nodes, until the next reservation has to be made.
+      * <p>
+      * Default value is {@link #DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE}.
+      *
+      * @return Atomic sequence reservation size.
+      */
+     public int getAtomicSequenceReserveSize() {
+         return seqReserveSize;
+     }
+ 
+     /**
+      * Sets default number of sequence values reserved for {@link IgniteAtomicSequence}
instances. After a certain
+      * number has been reserved, consequent increments of sequence will happen locally,
without communication with other
+      * nodes, until the next reservation has to be made.
+      *
+      * @param seqReserveSize Atomic sequence reservation size.
+      * @see #getAtomicSequenceReserveSize()
+      */
+     public void setAtomicSequenceReserveSize(int seqReserveSize) {
+         this.seqReserveSize = seqReserveSize;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override public String toString() {
+         return S.toString(AtomicConfiguration.class, this);
+     }
+ }


Mime
View raw message