ReservationCollection ReservationCollection ReservationCollection ReservationCollection Class

定义

管理在记录序列中生成的空间预留的集合。Manages the collection of space reservations made in a record sequence.

public ref class ReservationCollection abstract : System::Collections::Generic::ICollection<long>, System::Collections::Generic::IEnumerable<long>
public abstract class ReservationCollection : System.Collections.Generic.ICollection<long>, System.Collections.Generic.IEnumerable<long>
type ReservationCollection = class
    interface ICollection<int64>
    interface seq<int64>
    interface IEnumerable
Public MustInherit Class ReservationCollection
Implements ICollection(Of Long), IEnumerable(Of Long)
继承
ReservationCollectionReservationCollectionReservationCollectionReservationCollection
实现

示例

如下面的示例所示,可以通过两种方式执行预留。Reservations can be performed in two ways as shown in the following examples. 您可以采用示例中的做法可靠地进行处理。You can adopt the practices in the samples for robust processing. 请注意,只有在使用基于 CLFS 的 LogRecordSequence 类时才能执行此任务。Notice that this task can only be performed when using the CLFS-based LogRecordSequence class.

//Using the ReserveAndAppend Method  
ReservationCollection reservations = recordSequence.CreateReservationCollection();  
long[] lengthOfUndoRecords = new long[] { 1000 };  
recordSequence.ReserveAndAppend(recordData,  
                                                     userSqn,  
                                                     previousSqn,  
                                                     RecordSequenceAppendOptions.None,  
                                                     reservations,  
                                                     lengthOfUndoRecords);  
recordSequence.Append(undoRecordData,    // If necessary …  
                                    userSqn,  
                                    previousSqn,  
                                    RecordSequenceAppendOptions.ForceFlush,  
                                    reservations);  
  
// Using the Manual Approach  
ReservationCollection reservations = recordSequence.CreateReservationCollection();  
reservations.Add(lengthOfUndoRecord);  
try  
{  
   recordSequence.Append(recordData, userSqn, previousSqn, RecordAppendOptions.None);  
}  
catch (Exception)  
{  
   reservations.Remove(lengthOfUndoRecord);  
   throw;  
}  
  
recordSequence.Append(undoRecordData, userSqn, previousSqn, RecordAppendOptions.ForceFlush, reservations);  

注解

此类表示在记录序列中生成的一组预留区域。This class represents a set of reservation areas that are made in a record sequence. 向集合中添加项可分配新的预留。Adding items to the collection allocates new reservations. 从集合中移除项可释放这些预留。Removing items from the collection frees those reservations.

如果应用程序包含以后要写入日志中,但无法立即写入的数据,则会在日志中保留空间。An application reserves space in the log when it has data that is to be written to the log in the future, but cannot write it immediately. 预留可保证在能够写入数据时将其写入到日志中。Reservations provide a guarantee that the data can be written to the log when the data is available to be written. 使用日志时, 应用程序通常会在封送处理区域中保留一条或多条日志记录。When using logs, applications often reserve one or more log records in a marshaling area. 您必须在追加记录之前保留记录。You must reserve records prior to appending them.

预留可用于保证可以在提交数据之前完成操作;否则,将回滚更改。Reservations can be used to guarantee that an operation can be completed before the data is committed; otherwise, the changes are rolled back. 此外,还可以用于在日志中记录“撤消操作”。It can also be used to record an "undo action" in the log. 在回滚操作期间,如果事务资源管理器 (RM) 中断,RM 必须能够恢复其状态。During a rollback operation, a transactional resource manager (RM) must be able to recover its state if the RM is interrupted during the rollback operation. 通过使用预留区域,RM 可以在使用日志之前在其中预留空间。By using a reservation area, an RM can reserve space in a log before it is used.

ReserveAndAppend 方法可以保留空间和/或追加数据,具体取决于在进行调用时指定的参数。The ReserveAndAppend method can either reserve space or append data, or both, depending on the parameters that are specified when making the call. 随着事务中工作的进展,应用程序可以追加撤消信息并为补偿记录保留空间。As work progresses in a transaction, an application can append the undo information and reserve space for compensation records. 在回滚操作期间,创建的补偿记录指示撤消的针对磁盘的操作。During a rollback operation, compensation records that are created indicate what has been undone on the disk. 这些记录是使用以前保留的空间追加的。The records are appended using space that has been previously reserved. 这可保证在执行回滚操作时,RM 不会出现日志空间不足的问题(这是一种错误状态)。This guarantees that an RM does not run out of log space, which is a fatal condition, while performing a rollback operation. 如果在事务过程中日志填满,应用程序可以安全地回滚事务,而不会损坏持久数据。If a log fills up during a transaction, an application can safely roll back a transaction without corrupting durable data.

CLFS 是符合 ARIES 的日志记录系统,用于进行预写日志记录。CLFS is an ARIES-compliant logging system, meant for write-ahead logging. 在预写日志记录中,应用程序在执行操作之前先写入撤消记录,从而保留它在日志中写入补偿记录(可能在回滚期间使用)所占用的空间量。In write-ahead logging, an application writes an undo record before it performs the operation, reserving the amount of space it takes in the log to write a compensating record, which may be used during rollback. 以后,在实际写入补偿记录时,将使用保留的空间。Later, the reserved space is used when the compensation record is actually written.

应用程序可以在任意给定时间保留或访问较长的空间(它们是互相排斥的操作)。Applications can either reserve or access long space at any given time (they are mutually exclusive operations). 将提交记录写入到日志中后,应用程序可以释放为补偿记录预留的空间。After a commit record is written to the log, an application can free up the reservations for the compensation records. 可通过调用 FreeReservationReserveAndAppend 方法来完成此操作。This action can be done by calling either the FreeReservation or ReserveAndAppend method. 调用 ReserveAndAppend 方法可保证操作是原子操作;而调用 FreeReservation 方法则无法保证操作是原子操作。Calling the ReserveAndAppend method guarantees that the operation is atomic, while calling the FreeReservation method does not.

在释放记录时,释放的记录必须与上次调用 ReserveAndAppend 方法时保留的记录相同。When you free records, you must free the same records that you reserved together in a previous call to the ReserveAndAppend method.

备注

IRecordSequence 实现必须实现 MakeReservationFreeReservation 方法才能执行实际的预留分配和释放。Your implementation of IRecordSequence must implement the MakeReservation and FreeReservation methods to perform the actual reservation allocation and deallocation. 此外,在将记录写入保留空间时,该实现还必须调用 ReservationFreedIn addition, your implementation must also call ReservationFreed when a record is written into a reserved space.

构造函数

ReservationCollection() ReservationCollection() ReservationCollection() ReservationCollection()

初始化 ReservationCollection 类的新实例。Initializes a new instance of the ReservationCollection class.

属性

Count Count Count Count

获取此集合中的预留数。Gets the number of reservations in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,指示集合是否为只读集合。Gets a value that indicates whether the collection is read-only.

方法

Add(Int64) Add(Int64) Add(Int64) Add(Int64)

分配预留并将其添加到集合中。Allocates a reservation and adds it to the collection. 不能继承此方法。This method cannot be inherited.

Clear() Clear() Clear() Clear()

释放集合中的所有预留。Releases all of the reservations in the collection. 不能继承此方法。This method cannot be inherited.

Contains(Int64) Contains(Int64) Contains(Int64) Contains(Int64)

确定是否已生成指定大小的预留。Determines whether a reservation of the specified size has been made. 不能继承此方法。This method cannot be inherited.

CopyTo(Int64[], Int32) CopyTo(Int64[], Int32) CopyTo(Int64[], Int32) CopyTo(Int64[], Int32)

从目标数组的指定索引处开始,将整个集合复制到一维数组。Copies the entire collection to a one-dimensional array, starting at the specified index of the target array. 不能继承此方法。This method cannot be inherited.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

允许 ReservationCollection 在垃圾收集器销毁资源之前将这些资源释放。Allows the ReservationCollection to free resources before it is destroyed by the garbage collector.

FreeReservation(Int64) FreeReservation(Int64) FreeReservation(Int64) FreeReservation(Int64)

在派生类中重写时,释放指定大小的预留。When overridden in a derived class, releases a reservation of the specified size.

GetBestMatchingReservation(Int64) GetBestMatchingReservation(Int64) GetBestMatchingReservation(Int64) GetBestMatchingReservation(Int64)

在派生类中重写时,获取给定大小的最佳匹配预留。When overridden in a derived class, gets the best matching reservation for a given size.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回一个可以循环访问 ReservationCollection 的枚举器。Returns an enumerator that can iterate through the ReservationCollection. 不能继承此方法。This method cannot be inherited.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MakeReservation(Int64) MakeReservation(Int64) MakeReservation(Int64) MakeReservation(Int64)

在派生类中重写时,分配指定大小的预留。When overridden in a derived class, allocates a reservation of the specified size.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Int64) Remove(Int64) Remove(Int64) Remove(Int64)

释放指定大小的预留(如果已生成)。Releases a reservation of the specified size, if one has been made. 不能继承此方法。This method cannot be inherited.

ReservationFreed(Int64) ReservationFreed(Int64) ReservationFreed(Int64) ReservationFreed(Int64)

在派生类中重写时,指示已释放了预留。When overridden in a derived class, indicates that a reservation has been released.

ReservationMade(Int64) ReservationMade(Int64) ReservationMade(Int64) ReservationMade(Int64)

在派生类中重写时,指示已生成了预留。When overridden in a derived class, indicates that a reservation has been made.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回一个可以循环访问 ReservationCollection 的枚举器。Returns an enumerator that can iterate through the ReservationCollection. 不能继承此方法。This method cannot be inherited.

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于