Пример #1
0
        public object GetValue(Transaction transaction)
        {
            lock (this)
            {
                if (transaction == this.pending)
                {
                    return(this.pendingvalue);
                }

                // TODO review snapshots
                if (this.snapshots.Count == 0)
                {
                    return(this.value);
                }

                long?selected = null;

                foreach (long ts in this.snapshots.Keys)
                {
                    if (!Transaction.IsPrevious(transaction.Id, ts))
                    {
                        if (!selected.HasValue || Transaction.IsPrevious(selected.Value, ts))
                        {
                            selected = ts;
                        }
                    }
                }

                if (selected.HasValue)
                {
                    return(this.snapshots[selected.Value]);
                }

                return(this.value);
            }
        }
Пример #2
0
        public void ClearSnapshots(long timestamp)
        {
            lock (this)
            {
                long?        previous = null;
                IList <long> toforgot = new List <long>();

                foreach (long ts in this.snapshots.Keys)
                {
                    if (Transaction.IsPrevious(ts, timestamp))
                    {
                        if (previous.HasValue)
                        {
                            if (Transaction.IsPrevious(previous.Value, ts))
                            {
                                toforgot.Add(previous.Value);
                                previous = ts;
                            }
                            else
                            {
                                toforgot.Add(ts);
                            }
                        }
                        else
                        {
                            previous = ts;
                        }
                    }
                }

                foreach (long ts in toforgot)
                {
                    this.snapshots.Remove(ts);
                }
            }
        }