internal override void Visit(ReplaceVersionRequest req)
        {
            VersionEntry verEntry = req.RemoteVerEntry;

            if (verEntry == null)
            {
                Dictionary <long, VersionEntry> versionList = null;
                if (!this.dict.TryGetValue(req.RecordKey, out versionList) ||
                    !versionList.TryGetValue(req.VersionKey, out verEntry))
                {
                    throw new TransactionException("The specified version does not exist.");
                }
            }

            if (verEntry.TxId == req.SenderId && verEntry.EndTimestamp == req.ExpectedEndTs)
            {
                verEntry.BeginTimestamp = req.BeginTs;
                verEntry.EndTimestamp   = req.EndTs;
                verEntry.TxId           = req.TxId;
            }
            VersionEntry.CopyValue(verEntry, req.LocalVerEntry);

            req.Result   = req.LocalVerEntry;
            req.Finished = true;
        }
示例#2
0
        internal override void Visit(ReplaceVersionRequest req)
        {
            VersionEntry entry = req.RemoteVerEntry;

            if (entry == null)
            {
                throw new TransactionException("The version entry should be referenced for main-memory k-v.");
            }

            if (entry.TxId == req.SenderId &&
                entry.EndTimestamp == req.ExpectedEndTs &&
                entry.VersionKey == req.VersionKey)
            {
                while (Interlocked.CompareExchange(ref entry.latch, 1, 0) != 0)
                {
                    ;
                }

                entry.BeginTimestamp = req.BeginTs;
                entry.EndTimestamp   = req.EndTs;
                entry.TxId           = req.TxId;
                VersionEntry.CopyValue(entry, req.LocalVerEntry);

                Interlocked.Exchange(ref entry.latch, 0);
            }

            req.Result   = req.LocalVerEntry;
            req.Finished = true;
        }
        internal override void Visit(ReplaceVersionRequest req)
        {
            string sha1   = this.redisLuaManager.GetLuaScriptSha1(LuaScriptName.REPLACE_VERSION_ENTRY);
            string hashId = req.RecordKey.ToString();

            if (this.redisVersionDbMode == RedisVersionDbMode.Cluster)
            {
                hashId = RedisVersionDb.PACK_KEY(RedisVersionDb.VER_KEY_PREFIX, hashId);
            }

            byte[][] keysAndArgs =
            {
                Encoding.ASCII.GetBytes(hashId),
                BitConverter.GetBytes(req.VersionKey),
                BitConverter.GetBytes(req.BeginTs),
                BitConverter.GetBytes(req.EndTs),
                BitConverter.GetBytes(req.TxId),
                BitConverter.GetBytes(req.SenderId),
                BitConverter.GetBytes(req.ExpectedEndTs),
                RedisVersionDb.NEGATIVE_ONE_BYTES,
            };

            RedisRequest redisReq = this.NextRedisRequest();

            redisReq.Set(keysAndArgs, sha1, 1, RedisRequestType.EvalSha);
            redisReq.ParentRequest = req;
        }
 internal override void Visit(ReplaceVersionRequest req)
 {
     byte[][] returnBytes = req.Result as byte[][];
     req.Result = returnBytes == null || returnBytes.Length == 0 ?
                  null :
                  VersionEntry.Deserialize(
         req.VersionKey,
         returnBytes.ValueBytes(), req.LocalVerEntry);
 }
        internal override void Visit(ReplaceVersionRequest req)
        {
            this.CQLExecuteWithIfApplied(string.Format(CassandraVersionTable.CQL_REPLACE_VERSION,
                                                       req.TableId, req.BeginTs, req.EndTs, req.TxId,
                                                       req.RecordKey.ToString(), req.VersionKey,
                                                       req.SenderId, req.ExpectedEndTs));

            req.Result   = this.GetVersionEntryByKey(req.TableId, req.RecordKey, req.VersionKey);
            req.Finished = true;
        }
示例#6
0
        internal override void Visit(ReplaceVersionRequest req)
        {
            // read first
            VersionEntry ve = this.GetVersionEntryByKey(req.TableId, req.RecordKey, req.VersionKey, req.LocalVerEntry);

            if (ve.TxId == req.SenderId && ve.EndTimestamp == req.ExpectedEndTs)
            {
                this.CQLExecute(string.Format(PartitionedCassandraVersionTable.CQL_REPLACE_VERSION,
                                              req.TableId, req.BeginTs, req.EndTs, req.TxId,
                                              req.RecordKey.ToString(), req.VersionKey));
                ve.BeginTimestamp = req.BeginTs;
                ve.EndTimestamp   = req.EndTs;
                ve.TxId           = req.TxId;
            }

            req.Result   = ve;
            req.Finished = true;
        }
示例#7
0
        internal override void Visit(ReplaceVersionRequest req)
        {
            VersionEntry entry = req.RemoteVerEntry;

            if (entry == null)
            {
                ConcurrentDictionary <long, VersionEntry> versionList = null;
                if (!this.dict.TryGetValue(req.RecordKey, out versionList))
                {
                    throw new TransactionException("The specified record does not exist.");
                }

                if (!versionList.TryGetValue(req.VersionKey, out entry))
                {
                    throw new TransactionException("The specified version does not exist.");
                }
            }

            Debug.Assert(entry.VersionKey == req.VersionKey);
            // Debug Assertion
            // if (!entry.RecordKey.Equals(req.RecordKey))
            // {
            //     throw new Exception("Inconsistent record key");
            // }

            //int ticket = entry.EnterQueuedLatch();
            entry.WriteLock();
            if (Interlocked.Read(ref entry.TxId) == req.SenderId &&
                Interlocked.Read(ref entry.EndTimestamp) == req.ExpectedEndTs)
            {
                Interlocked.Exchange(ref entry.BeginTimestamp, req.BeginTs);
                Interlocked.Exchange(ref entry.EndTimestamp, req.EndTs);
                Interlocked.Exchange(ref entry.TxId, req.TxId);
                VersionEntry.CopyFromRemote(entry, req.LocalVerEntry);
                // req.LocalVerEntry.RecordKey = req.RecordKey;
            }
            //entry.ExitQueuedLatch(ticket);
            entry.UnWriteLock();

            req.Result   = req.LocalVerEntry;
            req.Finished = true;
        }
        internal override void Visit(ReplaceVersionRequest req)
        {
            string sha1 = this.redisLuaScriptManager.GetLuaScriptSha1(LuaScriptName.REPLACE_VERSION_ENTRY);

            this.HashId = req.RecordKey as string;

            byte[][] keysAndArgs =
            {
                Encoding.ASCII.GetBytes(this.HashId),
                BitConverter.GetBytes(req.VersionKey),
                BitConverter.GetBytes(req.BeginTs),
                BitConverter.GetBytes(req.EndTs),
                BitConverter.GetBytes(req.TxId),
                BitConverter.GetBytes(req.SenderId),
                BitConverter.GetBytes(req.ExpectedEndTs),
                RedisVersionDb.NEGATIVE_ONE_BYTES,
            };

            this.RedisReq = new RedisRequest(keysAndArgs, sha1, 1, RedisRequestType.EvalSha)
            {
                ParentRequest = req
            };
        }
示例#9
0
 internal virtual void Visit(ReplaceVersionRequest req)
 {
 }