Created consistent hierarchy of versioned entries.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6730377a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6730377a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6730377a Branch: refs/heads/ignite-117 Commit: 6730377abafd6afa7e5f02a321583b1084edfb14 Parents: 74a79bb Author: vozerov-gridgain <voze...@gridgain.com> Authored: Wed Jan 28 14:37:00 2015 +0300 Committer: vozerov-gridgain <voze...@gridgain.com> Committed: Wed Jan 28 14:37:00 2015 +0300 ---------------------------------------------------------------------- .../ignite/cache/GridCacheVersionedEntry.java | 65 ++++++ .../processors/cache/GridCacheAdapter.java | 2 +- .../version/GridCachePlainVersionedEntry.java | 114 ++++++++++ .../version/GridCacheRawVersionedEntry.java | 221 +++++++++++++++++++ .../version/GridCacheVersionedEntryEx.java | 14 ++ .../dr/GridDrDataLoadCacheUpdater.java | 3 +- .../processors/dr/GridRawVersionedEntry.java | 210 ------------------ .../processors/dr/GridVersionedEntry.java | 80 ------- 8 files changed, 417 insertions(+), 292 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/cache/GridCacheVersionedEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/GridCacheVersionedEntry.java b/modules/core/src/main/java/org/apache/ignite/cache/GridCacheVersionedEntry.java new file mode 100644 index 0000000..387e593 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/cache/GridCacheVersionedEntry.java @@ -0,0 +1,65 @@ +package org.apache.ignite.cache; + +import org.jetbrains.annotations.*; + +/** + * Cache entry along with version information. + */ +public interface GridCacheVersionedEntry<K, V> { + /** + * Gets entry's key. + * + * @return Entry's key. + */ + public K key(); + + /** + * Gets entry's value. + * + * @return Entry's value. + */ + @Nullable + public V value(); + + /** + * Gets entry's TTL. + * + * @return Entry's TTL. + */ + public long ttl(); + + /** + * Gets entry's expire time. + * + * @return Entry's expire time. + */ + public long expireTime(); + + /** + * Gets ID of initiator data center. + * + * @return ID of initiator data center. + */ + public byte dataCenterId(); + + /** + * Gets entry's topology version in initiator data center. + * + * @return Entry's topology version in initiator data center. + */ + public int topologyVersion(); + + /** + * Gets entry's order in initiator data center. + * + * @return Entry's order in initiator data center + */ + public long order(); + + /** + * Gets entry's global time in initiator data center. + * + * @return Entry's global time in initiator data center + */ + public long globalTime(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/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 f2680fe..0642925 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 @@ -5603,7 +5603,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, val = (V)ctx.marshalToPortable(val); } - GridVersionedEntry<K,V> e = new GridRawVersionedEntry<>(key, null, val, null, ttl, 0, ver); + GridCacheRawVersionedEntry<K,V> e = new GridCacheRawVersionedEntry<>(key, null, val, null, ttl, 0, ver); e.marshal(ctx.marshaller()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCachePlainVersionedEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCachePlainVersionedEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCachePlainVersionedEntry.java new file mode 100644 index 0000000..e7fe4ef --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCachePlainVersionedEntry.java @@ -0,0 +1,114 @@ +package org.apache.ignite.internal.processors.cache.version; + +import org.apache.ignite.internal.util.typedef.internal.*; +import org.jetbrains.annotations.*; + +/** + * + */ +public class GridCachePlainVersionedEntry<K, V> implements GridCacheVersionedEntryEx<K, V> { + /** Key. */ + private final K key; + + /** Value. */ + private final V val; + + /** TTL. */ + private final long ttl; + + /** Expire time. */ + private final long expireTime; + + /** Version. */ + private final GridCacheVersion ver; + + /** Start version flag. */ + private final boolean isStartVer; + + /** + * @param key Key. + * @param val Value. + * @param ttl TTL. + * @param expireTime Expire time. + * @param ver Version. + */ + public GridCachePlainVersionedEntry(K key, @Nullable V val, long ttl, long expireTime, GridCacheVersion ver) { + this(key, val, ttl, expireTime, ver, false); + } + + /** + * @param key Key. + * @param val Value. + * @param ttl TTL. + * @param expireTime Expire time. + * @param ver Version. + * @param isStartVer Start version flag. + */ + public GridCachePlainVersionedEntry(K key, V val, long ttl, long expireTime, GridCacheVersion ver, + boolean isStartVer) { + assert ver != null; + assert key != null; + + this.key = key; + this.val = val; + this.ttl = ttl; + this.expireTime = expireTime; + this.ver = ver; + this.isStartVer = isStartVer; + } + + /** {@inheritDoc} */ + @Override public K key() { + return key; + } + + /** {@inheritDoc} */ + @Override public V value() { + return val; + } + + /** {@inheritDoc} */ + @Override public long ttl() { + return ttl; + } + + /** {@inheritDoc} */ + @Override public long expireTime() { + return expireTime; + } + + /** {@inheritDoc} */ + @Override public byte dataCenterId() { + return ver.dataCenterId(); + } + + /** {@inheritDoc} */ + @Override public int topologyVersion() { + return ver.topologyVersion(); + } + + /** {@inheritDoc} */ + @Override public long order() { + return ver.order(); + } + + /** {@inheritDoc} */ + @Override public long globalTime() { + return ver.globalTime(); + } + + /** {@inheritDoc} */ + @Override public GridCacheVersion version() { + return ver; + } + + /** {@inheritDoc} */ + @Override public boolean isStartVersion() { + return isStartVer; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCachePlainVersionedEntry.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheRawVersionedEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheRawVersionedEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheRawVersionedEntry.java new file mode 100644 index 0000000..9fd15ff --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheRawVersionedEntry.java @@ -0,0 +1,221 @@ +package org.apache.ignite.internal.processors.cache.version; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.marshaller.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * + */ +public class GridCacheRawVersionedEntry<K, V> implements GridCacheVersionedEntry<K, V>, GridCacheVersionable, + Map.Entry<K, V>, Externalizable { + /** */ + private static final long serialVersionUID = 0L; + + /** Key. */ + private K key; + + /** Key bytes. */ + private byte[] keyBytes; + + /** Value. */ + private V val; + + /** Value bytes. */ + private byte[] valBytes; + + /** TTL. */ + private long ttl; + + /** Expire time. */ + private long expireTime; + + /** Version. */ + private GridCacheVersion ver; + + /** + * {@code Externalizable) support. + */ + public GridCacheRawVersionedEntry() { + // No-op. + } + + /** + * Constructor. + * + * @param key Key. + * @param keyBytes Key bytes. + * @param val Value. + * @param valBytes Value bytes. + * @param expireTime Expire time. + * @param ttl TTL. + * @param ver Version. + */ + public GridCacheRawVersionedEntry(K key, @Nullable byte[] keyBytes, @Nullable V val, @Nullable byte[] valBytes, + long ttl, long expireTime, GridCacheVersion ver) { + this.key = key; + this.keyBytes = keyBytes; + this.val = val; + this.valBytes = valBytes; + this.ttl = ttl; + this.expireTime = expireTime; + this.ver = ver; + } + + /** {@inheritDoc} */ + @Override public K key() { + assert key != null : "Entry is being improperly processed."; + + return key; + } + + /** + * @return Key bytes. + */ + public byte[] keyBytes() { + return keyBytes; + } + + /** {@inheritDoc} */ + @Override public V value() { + return val; + } + + /** + * @return Value bytes. + */ + public byte[] valueBytes() { + return valBytes; + } + + /** {@inheritDoc} */ + @Override public long ttl() { + return ttl; + } + + /** {@inheritDoc} */ + @Override public long expireTime() { + return expireTime; + } + + /** {@inheritDoc} */ + @Override public byte dataCenterId() { + return ver.dataCenterId(); + } + + /** {@inheritDoc} */ + @Override public int topologyVersion() { + return ver.topologyVersion(); + } + + /** {@inheritDoc} */ + @Override public long order() { + return ver.order(); + } + + /** {@inheritDoc} */ + @Override public long globalTime() { + return ver.globalTime(); + } + + /** {@inheritDoc} */ + @Override public GridCacheVersion version() { + return ver; + } + + /** + * Perform internal unmarshal of this entry. It must be performed after entry is deserialized and before + * its restored key/value are needed. + * + * @param marsh Marshaller. + * @throws IgniteCheckedException If failed. + */ + public void unmarshal(IgniteMarshaller marsh) throws IgniteCheckedException { + unmarshalKey(marsh); + + if (valBytes != null && val == null) + val = marsh.unmarshal(valBytes, null); + } + + /** + * Perform internal key unmarshal of this entry. It must be performed after entry is deserialized and before + * its restored key/value are needed. + * + * @param marsh Marshaller. + * @throws IgniteCheckedException If failed. + */ + public void unmarshalKey(IgniteMarshaller marsh) throws IgniteCheckedException { + if (key == null) + key = marsh.unmarshal(keyBytes, null); + } + + /** + * Perform internal marshal of this entry before it will be serialized. + * + * @param marsh Marshaller. + * @throws IgniteCheckedException If failed. + */ + public void marshal(IgniteMarshaller marsh) throws IgniteCheckedException { + if (keyBytes == null) + keyBytes = marsh.marshal(key); + + if (valBytes == null && val != null) + valBytes = marsh.marshal(val); + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + assert keyBytes != null; + + U.writeByteArray(out, keyBytes); + U.writeByteArray(out, valBytes); + + out.writeLong(ttl); + + if (ttl != 0) + out.writeLong(expireTime); + + out.writeObject(ver); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + keyBytes = U.readByteArray(in); + valBytes = U.readByteArray(in); + + ttl = in.readLong(); + + if (ttl != 0) + expireTime = in.readLong(); + + ver = (GridCacheVersion)in.readObject(); + + assert keyBytes != null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridCacheRawVersionedEntry.class, this, "keyBytesLen", + keyBytes != null ? keyBytes.length : "n/a", "valBytesLen", valBytes != null ? valBytes.length : "n/a"); + } + + /** {@inheritDoc} */ + @Override public K getKey() { + return key(); + } + + /** {@inheritDoc} */ + @Override public V getValue() { + return value(); + } + + /** {@inheritDoc} */ + @Override public V setValue(V val) { + throw new UnsupportedOperationException(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionedEntryEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionedEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionedEntryEx.java new file mode 100644 index 0000000..3971c7e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionedEntryEx.java @@ -0,0 +1,14 @@ +package org.apache.ignite.internal.processors.cache.version; + +import org.apache.ignite.cache.*; + +/** + * + */ +public interface GridCacheVersionedEntryEx<K, V> extends GridCacheVersionedEntry<K, V>, GridCacheVersionable { + /** + * + * @return + */ + public boolean isStartVersion(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridDrDataLoadCacheUpdater.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridDrDataLoadCacheUpdater.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridDrDataLoadCacheUpdater.java index 1f74de5..2ba9782 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridDrDataLoadCacheUpdater.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridDrDataLoadCacheUpdater.java @@ -22,6 +22,7 @@ import org.apache.ignite.cache.*; import org.apache.ignite.dataload.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.cache.version.*; import org.apache.ignite.lang.*; import org.apache.ignite.internal.processors.cache.dr.*; import org.apache.ignite.internal.util.typedef.*; @@ -55,7 +56,7 @@ public class GridDrDataLoadCacheUpdater<K, V> implements IgniteDataLoadCacheUpda f.get(); for (Map.Entry<K, V> entry0 : col) { - GridVersionedEntry<K, V> entry = (GridVersionedEntry<K, V>)entry0; + GridCacheRawVersionedEntry<K, V> entry = (GridCacheRawVersionedEntry<K, V>)entry0; entry.unmarshal(ctx.config().getMarshaller()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridRawVersionedEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridRawVersionedEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridRawVersionedEntry.java deleted file mode 100644 index fc89e49..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridRawVersionedEntry.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.dr; - -import org.apache.ignite.*; -import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.marshaller.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; - -/** - * - */ -public class GridRawVersionedEntry<K, V> implements GridVersionedEntry<K, V>, Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** Key. */ - private K key; - - /** Key bytes. */ - private byte[] keyBytes; - - /** Value. */ - private V val; - - /** Value bytes. */ - private byte[] valBytes; - - /** TTL. */ - private long ttl; - - /** Expire time. */ - private long expireTime; - - /** Version. */ - private GridCacheVersion ver; - - /** - * {@code Externalizable) support. - */ - public GridRawVersionedEntry() { - // No-op. - } - - /** - * Constructor. - * - * @param key Key. - * @param keyBytes Key bytes. - * @param val Value. - * @param valBytes Value bytes. - * @param expireTime Expire time. - * @param ttl TTL. - * @param ver Version. - */ - public GridRawVersionedEntry(K key, - @Nullable byte[] keyBytes, - @Nullable V val, - @Nullable byte[] valBytes, - long ttl, - long expireTime, - GridCacheVersion ver) { - this.key = key; - this.keyBytes = keyBytes; - this.val = val; - this.valBytes = valBytes; - this.ttl = ttl; - this.expireTime = expireTime; - this.ver = ver; - } - - /** {@inheritDoc} */ - @Override public K key() { - assert key != null : "Entry is being improperly processed."; - - return key; - } - - /** - * @return Key bytes. - */ - public byte[] keyBytes() { - return keyBytes; - } - - /** {@inheritDoc} */ - @Override public V value() { - return val; - } - - /** - * @return Value bytes. - */ - public byte[] valueBytes() { - return valBytes; - } - - /** {@inheritDoc} */ - @Override public long ttl() { - return ttl; - } - - /** {@inheritDoc} */ - @Override public long expireTime() { - return expireTime; - } - - /** {@inheritDoc} */ - @Override public GridCacheVersion version() { - return ver; - } - - /** {@inheritDoc} */ - @Override public void unmarshal(IgniteMarshaller marsh) throws IgniteCheckedException { - unmarshalKey(marsh); - - if (valBytes != null && val == null) - val = marsh.unmarshal(valBytes, null); - } - - /** - * Perform internal key unmarshal of this entry. It must be performed after entry is deserialized and before - * its restored key/value are needed. - * - * @param marsh Marshaller. - * @throws IgniteCheckedException If failed. - */ - private void unmarshalKey(IgniteMarshaller marsh) throws IgniteCheckedException { - if (key == null) - key = marsh.unmarshal(keyBytes, null); - } - - /** {@inheritDoc} */ - @Override public void marshal(IgniteMarshaller marsh) throws IgniteCheckedException { - if (keyBytes == null) - keyBytes = marsh.marshal(key); - - if (valBytes == null && val != null) - valBytes = marsh.marshal(val); - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - assert keyBytes != null; - - U.writeByteArray(out, keyBytes); - U.writeByteArray(out, valBytes); - - out.writeLong(ttl); - - if (ttl != 0) - out.writeLong(expireTime); - - out.writeObject(ver); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - keyBytes = U.readByteArray(in); - valBytes = U.readByteArray(in); - - ttl = in.readLong(); - - if (ttl != 0) - expireTime = in.readLong(); - - ver = (GridCacheVersion)in.readObject(); - - assert keyBytes != null; - } - - /** {@inheritDoc} */ - @Override public K getKey() { - return key(); - } - - /** {@inheritDoc} */ - @Override public V getValue() { - return value(); - } - - /** {@inheritDoc} */ - @Override public V setValue(V val) { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridRawVersionedEntry.class, this, "keyBytesLen", keyBytes != null ? keyBytes.length : "n/a", - "valBytesLen", valBytes != null ? valBytes.length : "n/a"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6730377a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridVersionedEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridVersionedEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridVersionedEntry.java deleted file mode 100644 index 93a574d..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/dr/GridVersionedEntry.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.dr; - -import org.apache.ignite.*; -import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.marshaller.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * - */ -public interface GridVersionedEntry<K, V> extends Map.Entry<K, V> { - /** - * Gets entry's key. - * - * @return Entry's key. - */ - public K key(); - - /** - * Gets entry's value. - * - * @return Entry's value. - */ - @Nullable public V value(); - - /** - * Gets entry's TTL. - * - * @return Entry's TTL. - */ - public long ttl(); - - /** - * Gets entry's expire time. - * - * @return Entry's expire time. - */ - public long expireTime(); - - /** - * @return Version. - */ - public GridCacheVersion version(); - - /** - * Perform internal marshal of this entry before it will be serialized. - * - * @param marsh Marshaller. - * @throws IgniteCheckedException If failed. - */ - public void marshal(IgniteMarshaller marsh) throws IgniteCheckedException; - - /** - * Perform internal unmarshal of this entry. It must be performed after entry is deserialized and before - * its restored key/value are needed. - * - * @param marsh Marshaller. - * @throws IgniteCheckedException If failed. - */ - public void unmarshal(IgniteMarshaller marsh) throws IgniteCheckedException; -}