Beispiel #1
0
        public SequenceNumber WriteRestartArea(
            IList <ArraySegment <byte> > data,
            SequenceNumber newBaseSeqNum,
            ReservationCollection reservationCollection)
        {
            long totalRecordSize;
            LogReservationCollection lrc;

            this.store.ValidateSequenceNumber(
                ref newBaseSeqNum,
                SequenceNumberConstraint.Arbitrary,
                "newBaseSeqNum");

            totalRecordSize = ValidateData(data);
            lrc             = ValidateReservationCollection(reservationCollection);

            EnsureMarshalContext();

            LogWriteRestartAreaState state = new LogWriteRestartAreaState();

            state.RecordSequence        = this;
            state.Data                  = data;
            state.TotalRecordSize       = totalRecordSize;
            state.ReservationCollection = lrc;
            state.NewBaseLsn            = newBaseSeqNum.High;

            state.Start();

            return(new SequenceNumber(state.ResultLsn));
        }
Beispiel #2
0
        public IAsyncResult BeginWriteRestartArea(
            IList <ArraySegment <byte> > data,
            SequenceNumber newBaseSeqNum,
            ReservationCollection reservationCollection,
            AsyncCallback callback,
            object state)
        {
            long totalRecordSize;
            LogReservationCollection lrc;

            this.store.ValidateSequenceNumber(
                ref newBaseSeqNum,
                SequenceNumberConstraint.Arbitrary,
                "newBaseSeqNum");

            totalRecordSize = ValidateData(data);
            lrc             = ValidateReservationCollection(reservationCollection);

            EnsureMarshalContext();

            LogWriteRestartAreaAsyncResult result;

            result = new LogWriteRestartAreaAsyncResult(this,
                                                        callback,
                                                        state);
            result.Data                  = data;
            result.TotalRecordSize       = totalRecordSize;
            result.NewBaseLsn            = newBaseSeqNum.High;
            result.ReservationCollection = lrc;

            result.Start();

            return(result);
        }
        public SequenceNumber ReserveAndAppend(
            IList <ArraySegment <byte> > data,
            SequenceNumber nextUndoRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservationCollection,
            params long[] reservations)
        {
            if (reservationCollection == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservationCollection"));
            }

            if (reservations == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservations"));
            }

            FileReservationCollection fileResCollection = null;

            fileResCollection = reservationCollection as FileReservationCollection;
            if (fileResCollection == null || !fileResCollection.IsMyCollection(this))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.LogRecSeq_InvalidReservationCollection));
            }

            foreach (long reservationSize in reservations)
            {
                if (reservationSize < 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("reservations"));
                }
            }

            foreach (long reservationSize in reservations)
            {
                fileResCollection.Add(reservationSize);
            }

            bool throwing = true;

            try
            {
                SequenceNumber returnValue = Append(data, nextUndoRecord, previousRecord, recordAppendOptions);
                throwing = false;
                return(returnValue);
            }
            finally
            {
                if (throwing && fileResCollection != null)
                {
                    foreach (long reservationSize in reservations)
                    {
                        fileResCollection.Remove(reservationSize);
                    }
                }
            }
        }
Beispiel #4
0
 public SequenceNumber WriteRestartArea(
     ArraySegment <byte> data,
     SequenceNumber newBaseSeqNum,
     ReservationCollection reservations)
 {
     return(WriteRestartArea(new ArraySegment <byte>[] { data },
                             newBaseSeqNum,
                             reservations));
 }
 public Enumerator(ReservationCollection parent)
 {
     this.parent          = parent;
     this.version         = parent.Version;
     this.current         = NOT_STARTED;
     this.keyIndex        = 0;
     this.numberRemaining = 0;
     this.disposed        = false;
 }
        public IAsyncResult BeginWriteRestartArea(
            IList <ArraySegment <byte> > data,
            SequenceNumber newBaseSeqNum,
            ReservationCollection reservation,
            AsyncCallback callback,
            object state)
        {
            SequenceNumber result = WriteRestartArea(data, newBaseSeqNum, reservation);

            return(new FileRecordSequenceCompletedAsyncResult(result, callback, state, Work.WriteRestartArea));
        }
        public SequenceNumber Append(
            IList <ArraySegment <byte> > data,
            SequenceNumber nextUndoRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservations)
        {
            int size = 0;

            if (reservations == null)
            {
                return(Append(data, nextUndoRecord, previousRecord, recordAppendOptions));
            }

            if (data == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("data"));
            }

            FileReservationCollection reservationCollection = reservations as FileReservationCollection;

            if (reservationCollection == null || !reservationCollection.IsMyCollection(this))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.LogRecSeq_InvalidReservationCollection));
            }

            for (int i = 0; i < data.Count; i++)
            {
                size += data[i].Count;
            }

            long reservation = reservationCollection.GetBestMatchingReservation(size);

            if (reservation < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ReservationNotFound());
            }

            bool throwing = true;

            try
            {
                SequenceNumber returnValue = this.Append(data, nextUndoRecord, previousRecord, recordAppendOptions);
                throwing = false;
                return(returnValue);
            }
            finally
            {
                if (throwing)
                {
                    reservationCollection.Add(reservation);
                }
            }
        }
Beispiel #8
0
        public IAsyncResult BeginReserveAndAppend(
            IList <ArraySegment <byte> > data,
            SequenceNumber userRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservationCollection,
            long[] reservations,
            AsyncCallback callback,
            object state)
        {
            long totalRecordSize;
            LogReservationCollection lrc;

            this.store.ValidateSequenceNumber(
                ref userRecord,
                SequenceNumberConstraint.Arbitrary,
                "userRecord");
            this.store.ValidateSequenceNumber(
                ref previousRecord,
                SequenceNumberConstraint.Arbitrary,
                "previousRecord");

            if (reservationCollection == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservationCollection"));
            }
            if (reservations == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservations"));
            }
            ValidateReservations(reservations);

            totalRecordSize = ValidateData(data);
            lrc             = ValidateReservationCollection(reservationCollection);

            EnsureMarshalContext();

            LogAppendAsyncResult result = new LogAppendAsyncResult(this,
                                                                   callback,
                                                                   state);

            result.Data                  = data;
            result.TotalRecordSize       = totalRecordSize;
            result.UserLsn               = userRecord.High;
            result.PreviousLsn           = previousRecord.High;
            result.RecordAppendOptions   = recordAppendOptions;
            result.ReservationCollection = lrc;
            result.Reservations          = reservations;

            result.Start();

            return(result);
        }
Beispiel #9
0
        public IAsyncResult BeginAppend(
            IList <ArraySegment <byte> > data,
            SequenceNumber userRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservations,
            AsyncCallback callback,
            object state)
        {
            long totalRecordSize;
            LogReservationCollection lrc;

            if ((this.store.Access & FileAccess.Write) == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported(SR.NotSupported_ReadOnly));
            }

            if (recordAppendOptions > (RecordAppendOptions.ForceAppend | RecordAppendOptions.ForceFlush) ||
                recordAppendOptions < RecordAppendOptions.None)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("recordAppendOptions"));
            }

            this.store.ValidateSequenceNumber(
                ref userRecord,
                SequenceNumberConstraint.Arbitrary,
                "userRecord");
            this.store.ValidateSequenceNumber(
                ref previousRecord,
                SequenceNumberConstraint.Arbitrary,
                "previousRecord");

            totalRecordSize = ValidateData(data);
            lrc             = ValidateReservationCollection(reservations);

            EnsureMarshalContext();

            LogAppendAsyncResult result = new LogAppendAsyncResult(this,
                                                                   callback,
                                                                   state);

            result.Data                  = data;
            result.TotalRecordSize       = totalRecordSize;
            result.UserLsn               = userRecord.High;
            result.PreviousLsn           = previousRecord.High;
            result.RecordAppendOptions   = recordAppendOptions;
            result.ReservationCollection = lrc;

            result.Start();

            return(result);
        }
Beispiel #10
0
 public IAsyncResult BeginWriteRestartArea(
     ArraySegment <byte> data,
     SequenceNumber newBaseSeqNum,
     ReservationCollection reservation,
     AsyncCallback callback,
     object state)
 {
     return(BeginWriteRestartArea(new ArraySegment <byte>[] { data },
                                  newBaseSeqNum,
                                  reservation,
                                  callback,
                                  state));
 }
Beispiel #11
0
 public SequenceNumber Append(
     ArraySegment <byte> data,
     SequenceNumber nextUndoRecord,
     SequenceNumber previousRecord,
     RecordAppendOptions recordAppendOptions,
     ReservationCollection reservations)
 {
     return(Append(new ArraySegment <byte>[] { data },
                   nextUndoRecord,
                   previousRecord,
                   recordAppendOptions,
                   reservations));
 }
Beispiel #12
0
        public IAsyncResult BeginAppend(
            IList <ArraySegment <byte> > data,
            SequenceNumber nextUndoRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservations,
            AsyncCallback callback,
            object state)
        {
            SequenceNumber result = Append(data, nextUndoRecord, previousRecord, recordAppendOptions, reservations);

            return(new FileRecordSequenceCompletedAsyncResult(result, callback, state, Work.Append));
        }
Beispiel #13
0
        public SequenceNumber WriteRestartArea(
            IList <ArraySegment <byte> > data,
            SequenceNumber newBaseSeqNum,
            ReservationCollection reservations)
        {
            long size = 0;

            if (data == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("data"));
            }

            if (reservations == null)
            {
                return(WriteRestartArea(data, newBaseSeqNum));
            }

            FileReservationCollection reservationCollection = reservations as FileReservationCollection;

            if (reservationCollection == null || !reservationCollection.IsMyCollection(this))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.LogRecSeq_InvalidReservationCollection));
            }

            for (int i = 0; i < data.Count; i++)
            {
                size = checked (size + data[i].Count);
            }
            long reservation = reservationCollection.GetBestMatchingReservation(size);

            if (reservation < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ReservationNotFound());
            }

            bool throwing = true;

            try
            {
                SequenceNumber returnValue = WriteRestartArea(data, newBaseSeqNum);
                throwing = false;
                return(returnValue);
            }
            finally
            {
                if (throwing)
                {
                    reservationCollection.Add(reservation);
                }
            }
        }
Beispiel #14
0
        public SequenceNumber ReserveAndAppend(
            IList <ArraySegment <byte> > data,
            SequenceNumber userRecord,
            SequenceNumber previousRecord,
            RecordAppendOptions recordAppendOptions,
            ReservationCollection reservationCollection,
            params long[] reservations)
        {
            long totalRecordSize;
            LogReservationCollection lrc;

            this.store.ValidateSequenceNumber(
                ref userRecord,
                SequenceNumberConstraint.Arbitrary,
                "userRecord");
            this.store.ValidateSequenceNumber(
                ref previousRecord,
                SequenceNumberConstraint.Arbitrary,
                "previousRecord");

            totalRecordSize = ValidateData(data);
            lrc             = ValidateReservationCollection(reservationCollection);
            if (lrc == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservationCollection"));
            }
            if (reservations == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("reservations"));
            }
            ValidateReservations(reservations);

            EnsureMarshalContext();

            LogReserveAndAppendState state = new LogReserveAndAppendState();

            state.RecordSequence        = this;
            state.Data                  = data;
            state.TotalRecordSize       = totalRecordSize;
            state.UserLsn               = userRecord.High;
            state.PreviousLsn           = previousRecord.High;
            state.RecordAppendOptions   = recordAppendOptions;
            state.ReservationCollection = lrc;
            state.Reservations          = reservations;

            state.Start();

            return(new SequenceNumber(state.ResultLsn));
        }
Beispiel #15
0
 public IAsyncResult BeginAppend(
     ArraySegment <byte> data,
     SequenceNumber nextUndoRecord,
     SequenceNumber previousRecord,
     RecordAppendOptions recordAppendOptions,
     ReservationCollection reservations,
     AsyncCallback callback,
     object state)
 {
     return(BeginAppend(new ArraySegment <byte>[] { data },
                        nextUndoRecord,
                        previousRecord,
                        recordAppendOptions,
                        reservations,
                        callback,
                        state));
 }
Beispiel #16
0
        LogReservationCollection ValidateReservationCollection(
            ReservationCollection reservations)
        {
            LogReservationCollection lrc = null;

            if (reservations != null)
            {
                lrc = reservations as LogReservationCollection;
                if (lrc == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              Error.ArgumentInvalid(SR.LogRecSeq_InvalidReservationCollection));
                }

                if (lrc.RecordSequence != this)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              Error.ArgumentInvalid(SR.LogRecSeq_InvalidReservationCollection));
                }
            }

            return(lrc);
        }