ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] ignite git commit: 'Single get' operation optimization.
Date Tue, 17 Nov 2015 14:14:17 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-single-op-get [created] 1b9ecdc65


http://git-wip-us.apache.org/repos/asf/ignite/blob/1b9ecdc6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java
new file mode 100644
index 0000000..eedf1e6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java
@@ -0,0 +1,304 @@
+/*
+ * 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.distributed.near;
+
+import java.nio.ByteBuffer;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheDeployable;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
+import org.apache.ignite.internal.processors.cache.GridCacheMessage;
+import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+public class GridNearSingleGetResponse extends GridCacheMessage implements GridCacheDeployable
{
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    public static final int INVALID_PART_FLAG_MASK = 0x1;
+
+    /** Future ID. */
+    private IgniteUuid futId;
+
+    /** */
+    private Message res;
+
+    /** */
+    private AffinityTopologyVersion topVer;
+
+    /** Error. */
+    @GridDirectTransient
+    private IgniteCheckedException err;
+
+    /** Serialized error. */
+    private byte[] errBytes;
+
+    /** */
+    private byte flags;
+
+    /**
+     * Empty constructor required for {@link Message}.
+     */
+    public GridNearSingleGetResponse() {
+        // No-op.
+    }
+
+    /**
+     * @param cacheId Cache ID.
+     * @param futId Future ID.
+     * @param topVer Topology version.
+     * @param res Result.
+     * @param invalidPartitions {@code True} if invalid partitions error occurred.
+     * @param addDepInfo Deployment info.
+     */
+    public GridNearSingleGetResponse(
+        int cacheId,
+        IgniteUuid futId,
+        AffinityTopologyVersion topVer,
+        @Nullable Message res,
+        boolean invalidPartitions,
+        boolean addDepInfo
+    ) {
+        assert futId != null;
+
+        this.cacheId = cacheId;
+        this.futId = futId;
+        this.topVer = topVer;
+        this.res = res;
+        this.addDepInfo = addDepInfo;
+
+        if (invalidPartitions)
+            flags = (byte)(flags | INVALID_PART_FLAG_MASK);
+    }
+
+    /**
+     * @param err Error.
+     */
+    public void error(IgniteCheckedException err) {
+        this.err = err;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteCheckedException error() {
+        return err;
+    }
+
+    /**
+     * @return Topology version.
+     */
+    @Override public AffinityTopologyVersion topologyVersion() {
+        return topVer;
+    }
+
+    /**
+     * @return {@code True} if invalid partitions error occurred.
+     */
+    public boolean invalidPartitions() {
+        return (flags & INVALID_PART_FLAG_MASK) != 0;
+    }
+
+    /**
+     * @return Result.
+     */
+    public Message result() {
+        return res;
+    }
+
+    /**
+     * @return Future ID.
+     */
+    public IgniteUuid futureId() {
+        return futId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException
{
+        super.prepareMarshal(ctx);
+
+        if (res != null) {
+            GridCacheContext cctx = ctx.cacheContext(cacheId);
+
+            if (res instanceof CacheObject)
+                prepareMarshalCacheObject((CacheObject) res, cctx);
+            else if (res instanceof CacheVersionedValue)
+                ((CacheVersionedValue)res).prepareMarshal(cctx.cacheObjectContext());
+            else if (res instanceof GridCacheEntryInfo)
+                ((GridCacheEntryInfo)res).marshal(cctx);
+        }
+
+        if (err != null)
+            errBytes = ctx.marshaller().marshal(err);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws
IgniteCheckedException {
+        super.finishUnmarshal(ctx, ldr);
+
+        if (res != null) {
+            GridCacheContext cctx = ctx.cacheContext(cacheId());
+
+            if (res instanceof CacheObject)
+                ((CacheObject)res).finishUnmarshal(cctx.cacheObjectContext(), ldr);
+            else if (res instanceof CacheVersionedValue)
+                ((CacheVersionedValue)res).finishUnmarshal(cctx, ldr);
+            else if (res instanceof GridCacheEntryInfo)
+                ((GridCacheEntryInfo)res).unmarshal(cctx, ldr);
+        }
+
+        if (errBytes != null && err == null)
+            err = ctx.marshaller().unmarshal(errBytes, ldr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 3:
+                if (!writer.writeByteArray("errBytes", errBytes))
+                    return false;
+
+                writer.incrementState();
+
+            case 4:
+                if (!writer.writeByte("flags", flags))
+                    return false;
+
+                writer.incrementState();
+
+            case 5:
+                if (!writer.writeIgniteUuid("futId", futId))
+                    return false;
+
+                writer.incrementState();
+
+            case 6:
+                if (!writer.writeMessage("res", res))
+                    return false;
+
+                writer.incrementState();
+
+            case 7:
+                if (!writer.writeMessage("topVer", topVer))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 3:
+                errBytes = reader.readByteArray("errBytes");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 4:
+                flags = reader.readByte("flags");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 5:
+                futId = reader.readIgniteUuid("futId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 6:
+                res = reader.readMessage("res");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 7:
+                topVer = reader.readMessage("topVer");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return reader.afterMessageRead(GridNearSingleGetResponse.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addDeploymentInfo() {
+        return addDepInfo;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 116;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 8;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridNearSingleGetResponse.class, this);
+    }
+}


Mime
View raw message