internal override void Visit(SetCommitTsRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { throw new TransactionException("The specified tx does not exist."); } } while (Interlocked.CompareExchange(ref txEntry.latch, 1, 0) != 0) { ; } // read and write long commitTime = Math.Max(req.ProposedCommitTs, txEntry.CommitLowerBound); txEntry.CommitTime = commitTime; Interlocked.Exchange(ref txEntry.latch, 0); req.Result = commitTime; req.Finished = true; }
public static void CopyValue(TxTableEntry src, TxTableEntry dst) { dst.TxId = src.TxId; dst.Status = src.Status; dst.CommitTime = src.CommitTime; dst.CommitLowerBound = src.CommitLowerBound; }
internal override void Visit(RecycleTxRequest req) { // RecycleTxRequest will be called at the begining of tx, the remoteEntry is supposed to be null TxTableEntry txEntry = null; if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { txEntry = new TxTableEntry(req.TxId); if (!this.txTable.TryAdd(req.TxId, txEntry)) { req.Result = false; req.Finished = true; return; } } while (Interlocked.CompareExchange(ref txEntry.latch, 1, 0) != 0) { ; } txEntry.Reset(); Interlocked.Exchange(ref txEntry.latch, 0); req.RemoteTxEntry = txEntry; req.Result = true; req.Finished = true; }
internal override void Visit(UpdateCommitLowerBoundRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { throw new TransactionException("The specified tx does not exist."); } } while (Interlocked.CompareExchange(ref txEntry.latch, 1, 0) != 0) { ; } long commitTime = txEntry.CommitTime; if (commitTime == TxTableEntry.DEFAULT_COMMIT_TIME && txEntry.CommitLowerBound < req.CommitTsLowerBound) { txEntry.CommitLowerBound = req.CommitTsLowerBound; } Interlocked.Exchange(ref txEntry.latch, 0); req.Result = commitTime; req.Finished = true; }
public void Set(long txId, TxStatus status, TxTableEntry remoteEntry = null) { this.TxId = txId; this.SenderId = txId; this.TxStatus = status; this.RemoteTxEntry = remoteEntry; }
public void Set(long txId, long senderId, long lowerBound, TxTableEntry remoteEntry = null) { this.TxId = txId; this.SenderId = senderId; this.CommitTsLowerBound = lowerBound; this.RemoteTxEntry = remoteEntry; }
public void Set(long txId, long proposedCommitTs, TxTableEntry remoteEntry = null) { this.TxId = txId; this.SenderId = txId; this.ProposedCommitTs = proposedCommitTs; this.RemoteTxEntry = remoteEntry; }
public void Set(long txId, long senderId, TxTableEntry localEntry = null, TxTableEntry remoteEntry = null) { this.TxId = txId; this.SenderId = senderId; this.LocalTxEntry = localEntry; this.RemoteTxEntry = remoteEntry; }
internal override void Visit(NewTxIdRequest req) { TxTableEntry txEntry = new TxTableEntry(); req.Result = this.txTable.TryAdd(req.TxId, txEntry) ? true : false; req.RemoteTxEntry = txEntry; req.Finished = true; }
public override bool Equals(object obj) { TxTableEntry entry = obj as TxTableEntry; if (entry == null) { return(false); } return(this.TxId == entry.TxId && this.Status == entry.Status && this.CommitTime == entry.CommitTime && this.CommitLowerBound == entry.CommitLowerBound); }
internal override void Visit(InsertTxIdRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { txEntry = this.txTable[req.TxId]; } txEntry.Reset(req.TxId); req.Finished = true; }
internal override void Visit(UpdateTxStatusRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { txEntry = this.txTable[req.TxId]; } txEntry.Status = req.TxStatus; req.Result = null; req.Finished = true; }
internal override void Visit(RemoveTxRequest req) { TxTableEntry te = null; this.txTable.TryRemove(req.TxId, out te); if (te != null) { req.Result = true; } else { req.Result = false; } req.Finished = true; }
internal override void Visit(GetTxEntryRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { txEntry = txTable[req.TxId]; req.RemoteTxEntry = txEntry; } TxTableEntry.CopyValue(txEntry, req.LocalTxEntry); req.Result = req.LocalTxEntry; req.Finished = true; }
internal override void Visit(NewTxIdRequest req) { if (this.txTable.ContainsKey(req.TxId)) { req.Result = false; } else { TxTableEntry txEntry = new TxTableEntry(); this.txTable.Add(req.TxId, txEntry); req.RemoteTxEntry = txEntry; req.Result = true; } req.Finished = true; }
internal override void Visit(UpdateTxStatusRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { throw new TransactionException("The specified tx does not exist."); } } txEntry.Status = req.TxStatus; req.Result = null; req.Finished = true; }
internal override void Visit(GetTxEntryRequest req) { byte[][] valueBytes = req.Result as byte[][]; if (valueBytes == null || valueBytes.Length == 0) { req.Result = null; } else { TxTableEntry txEntry = req.LocalTxEntry; txEntry.Set( req.TxId, (TxStatus)BitConverter.ToInt32(valueBytes[0], 0), BitConverter.ToInt64(valueBytes[1], 0), BitConverter.ToInt64(valueBytes[2], 0)); req.Result = txEntry; } }
internal override void Visit(RecycleTxRequest req) { // RecycleTxRequest is supposed to has no remoteTxEntry reference TxTableEntry txEntry = null; this.txTable.TryGetValue(req.TxId, out txEntry); if (txEntry == null) { txEntry = new TxTableEntry(req.TxId); this.txTable.Add(req.TxId, txEntry); } else { txEntry.Reset(); req.RemoteTxEntry = txEntry; req.Result = true; req.Finished = true; } }
internal override void Visit(InsertTxIdRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { throw new TransactionException("The specified txId does not exist."); } } while (Interlocked.CompareExchange(ref txEntry.latch, 1, 0) != 0) { ; } txEntry.Reset(req.TxId); Interlocked.Exchange(ref txEntry.latch, 0); req.Finished = true; }
internal override void Visit(UpdateCommitLowerBoundRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { txEntry = this.txTable[req.TxId]; } if (txEntry.CommitTime == TxTableEntry.DEFAULT_COMMIT_TIME) { txEntry.CommitLowerBound = Math.Max(txEntry.CommitLowerBound, req.CommitTsLowerBound); req.Result = txEntry.CommitTime; } else { req.Result = txEntry.CommitTime; } req.Finished = true; }
internal override void Visit(SetCommitTsRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null) { txEntry = this.txTable[req.TxId]; } // already has a commit time if (txEntry.CommitTime != TxTableEntry.DEFAULT_COMMIT_TIME) { req.Result = -1L; } else { txEntry.CommitTime = Math.Max(txEntry.CommitLowerBound, req.ProposedCommitTs); req.Result = txEntry.CommitTime; } req.Finished = true; }
internal override void Visit(InsertTxIdRequest req) { TxTableEntry txTableEntry = new TxTableEntry(req.TxId); this.HashId = req.TxId.ToString(); byte[][] keysBytes = { Encoding.ASCII.GetBytes(TxTableEntry.STATUS_STRING), Encoding.ASCII.GetBytes(TxTableEntry.COMMIT_TIME_STRING), Encoding.ASCII.GetBytes(TxTableEntry.COMMIT_LOWER_BOUND_STRING) }; byte[][] valuesBytes = { BitConverter.GetBytes((int)txTableEntry.Status), BitConverter.GetBytes(txTableEntry.CommitTime), BitConverter.GetBytes(txTableEntry.CommitLowerBound) }; this.RedisReq = new RedisRequest(this.HashId, keysBytes, valuesBytes, RedisRequestType.HMSet) { ParentRequest = req }; }
internal override void Visit(GetTxEntryRequest req) { TxTableEntry txEntry = req.RemoteTxEntry; if (txEntry == null || req.TxId != txEntry.TxId) { if (!this.txTable.TryGetValue(req.TxId, out txEntry)) { throw new TransactionException("The specified tx does not exist."); } // return back the txEntry req.RemoteTxEntry = txEntry; } while (Interlocked.CompareExchange(ref txEntry.latch, 1, 0) != 0) { ; } TxTableEntry.CopyValue(txEntry, req.LocalTxEntry); Interlocked.Exchange(ref txEntry.latch, 0); req.Result = req.LocalTxEntry; req.Finished = true; }
public TxEntryRequest(long txId) { this.TxId = txId; this.LocalTxEntry = null; this.RemoteTxEntry = null; }
public TxEntryRequest(long txId, TxTableEntry localTxEntry, TxTableEntry remoteTxEntry) { this.TxId = txId; this.LocalTxEntry = localTxEntry; this.RemoteTxEntry = remoteTxEntry; }