Skip to content

Commit

Permalink
ignite-96 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakov Zhdanov committed Feb 6, 2015
1 parent 4fcea52 commit a6a57ab
Show file tree
Hide file tree
Showing 78 changed files with 345 additions and 1,507 deletions.
6 changes: 3 additions & 3 deletions modules/core/src/main/java/org/apache/ignite/Ignite.java
Expand Up @@ -21,11 +21,11 @@
import org.apache.ignite.cache.affinity.*; import org.apache.ignite.cache.affinity.*;
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.fs.IgniteFsConfiguration; import org.apache.ignite.fs.*;
import org.apache.ignite.plugin.*;
import org.apache.ignite.internal.product.*; import org.apache.ignite.internal.product.*;
import org.apache.ignite.plugin.security.*;
import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.plugin.*;
import org.apache.ignite.plugin.security.*;
import org.jetbrains.annotations.*; import org.jetbrains.annotations.*;


import java.util.*; import java.util.*;
Expand Down
Expand Up @@ -17,8 +17,6 @@


package org.apache.ignite; package org.apache.ignite;


import org.apache.ignite.*;

import java.io.*; import java.io.*;
import java.util.concurrent.*; import java.util.concurrent.*;


Expand Down
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite; package org.apache.ignite;


import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.jetbrains.annotations.*;


import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
Expand Down
Expand Up @@ -19,6 +19,8 @@


import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;


import javax.cache.Cache.*;

/** /**
* Eviction filter to specify which entries should not be evicted. Not applicable when * Eviction filter to specify which entries should not be evicted. Not applicable when
* calling explicit evict via {@link org.apache.ignite.cache.Entry#evict()}. * calling explicit evict via {@link org.apache.ignite.cache.Entry#evict()}.
Expand Down
Expand Up @@ -17,8 +17,6 @@


package org.apache.ignite.cache.eviction; package org.apache.ignite.cache.eviction;


import org.apache.ignite.cache.*;

/** /**
* Pluggable cache eviction policy. Usually, implementations will internally order * Pluggable cache eviction policy. Usually, implementations will internally order
* cache entries based on {@link #onEntryAccessed(boolean, org.apache.ignite.cache.Entry)} notifications and * cache entries based on {@link #onEntryAccessed(boolean, org.apache.ignite.cache.Entry)} notifications and
Expand Down
Expand Up @@ -28,20 +28,56 @@
* @version @java.version * @version @java.version
*/ */
public interface EvictableEntry<K, V> extends Cache.Entry<K, V> { public interface EvictableEntry<K, V> extends Cache.Entry<K, V> {
public boolean evict();

public boolean isCached();

/**
* Gets metadata by name.
*
* @return Metadata value or {@code null}.
*/
@Nullable public <T> T meta();

/**
* Adds a new metadata.
*
* @param val Metadata value.
* @return Metadata previously associated with given name, or
* {@code null} if there was none.
*/
@Nullable public <T> T addMeta(T val);

/**
* Adds given metadata value only if it was absent.
*
* @param val Value to add if it's not attached already.
* @return {@code null} if new value was put, or current value if put didn't happen.
*/
@Nullable public <T> T putMetaIfAbsent(T val);

/**
* Replaces given metadata with new {@code newVal} value only if its current value
* is equal to {@code curVal}. Otherwise, it is no-op.
*
* @param curVal Current value to check.
* @param newVal New value.
* @return {@code true} if replacement occurred, {@code false} otherwise.
*/
public <T> boolean replaceMeta(T curVal, T newVal);

/** /**
* Attaches metadata to the entry. * Removes metadata by name.
* *
* @param meta Metadata to attach. Pass {@code null} to remove previous value. * @return Value of removed metadata or {@code null}.
* @return Previous metadata value.
*/ */
public <T> T attachMeta(@Nullable Object meta); @Nullable public <T> T removeMeta();


/** /**
* Replaces entry metadata. * Removes metadata only if its current value is equal to {@code val} passed in.
* *
* @param oldMeta Old metadata value, possibly {@code null}. * @param val Value to compare.
* @param newMeta New metadata value, possibly {@code null}. * @return {@code True} if value was removed, {@code false} otherwise.
* @return {@code True} if metadata value was replaced.
*/ */
public boolean replaceMeta(@Nullable Object oldMeta, @Nullable Object newMeta); public <T> boolean removeMeta(T val);
} }
Expand Up @@ -17,16 +17,12 @@


package org.apache.ignite.cache.eviction.fifo; package org.apache.ignite.cache.eviction.fifo;


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*; import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.typedef.internal.*;
import org.jdk8.backport.*; import org.jdk8.backport.*;
import org.jdk8.backport.ConcurrentLinkedDeque8.*; import org.jdk8.backport.ConcurrentLinkedDeque8.*;


import javax.cache.Cache.*;
import java.util.*; import java.util.*;


/** /**
Expand All @@ -37,14 +33,11 @@
*/ */
public class CacheFifoEvictionPolicy<K, V> implements CacheEvictionPolicy<K, V>, public class CacheFifoEvictionPolicy<K, V> implements CacheEvictionPolicy<K, V>,
CacheFifoEvictionPolicyMBean { CacheFifoEvictionPolicyMBean {
/** Tag. */
private final String meta = UUID.randomUUID().toString();

/** Maximum size. */ /** Maximum size. */
private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE; private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;


/** FIFO queue. */ /** FIFO queue. */
private final ConcurrentLinkedDeque8<Entry<K, V>> queue = private final ConcurrentLinkedDeque8<EvictableEntry<K, V>> queue =
new ConcurrentLinkedDeque8<>(); new ConcurrentLinkedDeque8<>();


/** /**
Expand Down Expand Up @@ -90,22 +83,17 @@ public CacheFifoEvictionPolicy(int max) {
return queue.size(); return queue.size();
} }


/** {@inheritDoc} */
@Override public String getMetaAttributeName() {
return meta;
}

/** /**
* Gets read-only view on internal {@code FIFO} queue in proper order. * Gets read-only view on internal {@code FIFO} queue in proper order.
* *
* @return Read-only view ono internal {@code 'FIFO'} queue. * @return Read-only view ono internal {@code 'FIFO'} queue.
*/ */
public Collection<Entry<K, V>> queue() { public Collection<EvictableEntry<K, V>> queue() {
return Collections.unmodifiableCollection(queue); return Collections.unmodifiableCollection(queue);
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public void onEntryAccessed(boolean rmv, Entry<K, V> entry) { @Override public void onEntryAccessed(boolean rmv, EvictableEntry<K, V> entry) {
if (!rmv) { if (!rmv) {
if (!entry.isCached()) if (!entry.isCached())
return; return;
Expand All @@ -115,7 +103,7 @@ public Collection<Entry<K, V>> queue() {
shrink(); shrink();
} }
else { else {
Node<Entry<K, V>> node = entry.removeMeta(meta); Node<EvictableEntry<K, V>> node = entry.removeMeta();


if (node != null) if (node != null)
queue.unlinkx(node); queue.unlinkx(node);
Expand All @@ -126,15 +114,15 @@ public Collection<Entry<K, V>> queue() {
* @param entry Entry to touch. * @param entry Entry to touch.
* @return {@code True} if queue has been changed by this call. * @return {@code True} if queue has been changed by this call.
*/ */
private boolean touch(Entry<K, V> entry) { private boolean touch(EvictableEntry<K, V> entry) {
Node<Entry<K, V>> node = entry.meta(meta); Node<EvictableEntry<K, V>> node = entry.meta();


// Entry has not been enqueued yet. // Entry has not been enqueued yet.
if (node == null) { if (node == null) {
while (true) { while (true) {
node = queue.offerLastx(entry); node = queue.offerLastx(entry);


if (entry.putMetaIfAbsent(meta, node) != null) { if (entry.putMetaIfAbsent(node) != null) {
// Was concurrently added, need to clear it from queue. // Was concurrently added, need to clear it from queue.
queue.unlinkx(node); queue.unlinkx(node);


Expand All @@ -152,7 +140,7 @@ else if (node.item() != null) {
return true; return true;
} }
// If node was unlinked by concurrent shrink() call, we must repeat the whole cycle. // If node was unlinked by concurrent shrink() call, we must repeat the whole cycle.
else if (!entry.removeMeta(meta, node)) else if (!entry.removeMeta(node))
return false; return false;
} }
} }
Expand All @@ -170,38 +158,19 @@ private void shrink() {
int startSize = queue.sizex(); int startSize = queue.sizex();


for (int i = 0; i < startSize && queue.sizex() > max; i++) { for (int i = 0; i < startSize && queue.sizex() > max; i++) {
Entry<K, V> entry = queue.poll(); EvictableEntry<K, V> entry = queue.poll();


if (entry == null) if (entry == null)
break; break;


if (!entry.evict()) { if (!entry.evict()) {
entry.removeMeta(meta); entry.removeMeta();


touch(entry); touch(entry);
} }
} }
} }


/**
* Checks entry for empty value.
*
* @param entry Entry to check.
* @return {@code True} if entry is empty.
*/
private boolean empty(Entry<K, V> entry) {
try {
return entry.peek(F.asList(GridCachePeekMode.GLOBAL)) == null;
}
catch (IgniteCheckedException e) {
U.error(null, e.getMessage(), e);

assert false : "Should never happen: " + e;

return false;
}
}

/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public String toString() { @Override public String toString() {
return S.toString(CacheFifoEvictionPolicy.class, this); return S.toString(CacheFifoEvictionPolicy.class, this);
Expand Down
Expand Up @@ -24,14 +24,6 @@
*/ */
@IgniteMXBeanDescription("MBean for FIFO cache eviction policy.") @IgniteMXBeanDescription("MBean for FIFO cache eviction policy.")
public interface CacheFifoEvictionPolicyMBean { 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.
*/
@IgniteMXBeanDescription("Name of metadata attribute used to store eviction policy data.")
public String getMetaAttributeName();

/** /**
* Gets maximum allowed cache size. * Gets maximum allowed cache size.
* *
Expand Down
Expand Up @@ -17,10 +17,11 @@


package org.apache.ignite.cache.eviction.ggfs; package org.apache.ignite.cache.eviction.ggfs;


import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*; import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.internal.processors.fs.*; import org.apache.ignite.internal.processors.fs.*;


import javax.cache.Cache.*;

/** /**
* GGFS eviction filter which will not evict blocks of particular files. * GGFS eviction filter which will not evict blocks of particular files.
*/ */
Expand Down

0 comments on commit a6a57ab

Please sign in to comment.