LogStore 类

定义

表示日志结构化的存储区。Represents a log-structured storage.

public ref class LogStore sealed : IDisposable
public sealed class LogStore : IDisposable
type LogStore = class
    interface IDisposable
Public NotInheritable Class LogStore
Implements IDisposable
继承
LogStore
实现

示例

下面的示例演示如何将 LogStore 存档到 XML 文档。The following example shows how to archive a LogStore to an XML document.

class LogBackup
{ 
    static void ArchiveToXML(LogStore logStore, string fileName) 
    {  
        LogArchiveSnapshot snapshot = logStore.CreateLogArchiveSnapshot();
        
        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.ASCII);
        
        writer.WriteStartElement("logArchive");
        foreach(FileRegion region in snapshot.ArchiveRegions) 
        {
            writer.WriteStartElement("fileRegion"); 
            writer.WriteElementString("path", region.Path); 
            writer.WriteElementString("length", region.FileLength.ToString()); 
            writer.WriteElementString("offset", region.Offset.ToString()); 
            using(Stream dataStream = region.GetStream()) 
            { 
                byte[] data = new byte[dataStream.Length]; 
                dataStream.Read(data, 0, data.Length); 
                writer.WriteElementString("data", Convert.ToBase64String(data)); 
            }
            writer.WriteEndElement();
        }
        writer.WriteEndElement(); 
        writer.Close(); 
        logStore.SetArchiveTail(snapshot.LastSequenceNumber); 
    }
    static void RestoreFromXML(string fileName) 
    { 
        using(XmlTextReader reader = new XmlTextReader(fileName)) 
        {
            reader.ReadStartElement("logArchive"); 
            while(reader.IsStartElement()) 
            { 
                string path = reader.ReadElementString("path"); 
                long length = Int64.Parse(reader.ReadElementString("length")); 
                long offset = Int64.Parse(reader.ReadElementString("offset")); 
                string dataString = reader.ReadElementString("data"); 
                byte[] data = Convert.FromBase64String(dataString); 
                FileStream fileStream;
                using(fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 
                { 
                    fileStream.SetLength(length); 
                    fileStream.Position = offset; fileStream.Write(data, 0, data.Length); 
                }
            } 
        reader.ReadEndElement(); 
        } 
    } 
}
Friend Class LogBackup
    Private Shared Sub ArchiveToXML(ByVal logStore As LogStore, ByVal fileName As String)
        Dim snapshot As LogArchiveSnapshot = logStore.CreateLogArchiveSnapshot()

        Dim writer As New XmlTextWriter(fileName, Encoding.ASCII)

        writer.WriteStartElement("logArchive")
        For Each region As FileRegion In snapshot.ArchiveRegions
            writer.WriteStartElement("fileRegion")
            writer.WriteElementString("path", region.Path)
            writer.WriteElementString("length", region.FileLength.ToString())
            writer.WriteElementString("offset", region.Offset.ToString())
            Using dataStream As Stream = region.GetStream()
                Dim data(dataStream.Length - 1) As Byte
                dataStream.Read(data, 0, data.Length)
                writer.WriteElementString("data", Convert.ToBase64String(data))
            End Using
            writer.WriteEndElement()
        Next region
        writer.WriteEndElement()
        writer.Close()
        logStore.SetArchiveTail(snapshot.LastSequenceNumber)

    End Sub
    Private Shared Sub RestoreFromXML(ByVal fileName As String)
        Using reader As New XmlTextReader(fileName)
            reader.ReadStartElement("logArchive")
            Do While reader.IsStartElement()
                Dim path = reader.ReadElementString("path")
                Dim length = Int64.Parse(reader.ReadElementString("length"))
                Dim offset = Int64.Parse(reader.ReadElementString("offset"))
                Dim dataString = reader.ReadElementString("data")
                Dim data() = Convert.FromBase64String(dataString)
                Dim fileStream As FileStream
                fileStream = New FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)
                Using fileStream
                    fileStream.SetLength(length)
                    fileStream.Position = offset
                    fileStream.Write(data, 0, data.Length)
                End Using
            Loop
            reader.ReadEndElement()
        End Using
    End Sub
End Class

注解

LogRecordSequence 类提供记录序列接口在公用日志文件系统 (CLFS) 日志之上的实现。The LogRecordSequence class provides an implementation of the record sequence interface on top of a Common Log File System (CLFS) log. 它与 LogStore 类一起使用,该类提供了直接操作和管理 CLFS 日志文件的接口。It works with the LogStore class, which provides an interface for directly manipulating and managing a CLFS log file. 日志存储区提供跨一组磁盘范围的仅追加存储区。A log store provides append-only storage across a set of disk extents. LogStore 类表示此存储区,并提供了添加和移除容器、设置策略以及创建存档的方法。The LogStore class represents this storage, and provides methods for adding and removing containers, setting policy, and creating archives. 它不提供从存储区中读取和写入存储区的方法;这些方法是由 LogRecordSequence 类提供的。It does not provide methods for reading from and writing to the storage; these methods are provided by the LogRecordSequence class.

LogStore 类和 LogRecordSequence 类之间的关系类似于磁盘文件和 FileStream 对象之间的关系。The relationship between the LogStore class and the LogRecordSequence class is similar to the relationship between a disk file and a FileStream object. 磁盘文件提供实际存储区,并具有诸如长度和上次访问时间这样的属性,而 FileStream 对象提供文件的视图,利用该视图可以从实际存储区中读取以及向其中写入数据。The disk file provides the actual storage and has attributes such as length and last access time, while the FileStream object provides a view on the file that can be used to read from it and write to it. 与之类似,LogStore 类具有诸如策略和磁盘范围集合这样的属性,LogRecordSequence 类提供面向记录的机制,用于读取和写入数据。Similarly, the LogStore class has attributes like a policy and a collection of disk extents, and the LogRecordSequence class provides a record-oriented mechanism for reading and writing data.

FileRecordSequence 类表示的文件记录序列不同,LogStore 实例将其数据存储在 LogExtent 实例表示的磁盘范围的集合中。Unlike the file record sequence represented by the FileRecordSequence class, a LogStore instance stores its data in a collection of disk extents, represented by LogExtent instances. 给定 LogStore 实例中的所有范围都具有统一的大小,空间以范围增量的形式添加到 LogStore 实例中及从其中移除。The extents in a given LogStore instance are all of uniform size, and space is added to and removed from a LogStore instance in extent increments. 若要添加和移除日志范围,请使用可由 Add 属性返回的 Remove 对象的 LogExtentCollectionExtents 方法。To add and remove log extents, use the Add and Remove methods of the LogExtentCollection object, which can be returned by the Extents property.

LogStore 实例可以具有与自己关联的策略。A LogStore instance can have policies associated with it. 这些策略由 LogPolicy 实例表示,这些实例可由 Policy 属性返回。These are represented by LogPolicy instances that can be returned by the Policy property. 策略定义日志应遵循的规则(例如最大范围数和最小大小),以及对在特定条件下扩大或缩小 LogStore 的指令。A policy dictates rules that the log will attempt to follow, such as maximum number of extents and minimum size, and instructions on growing or shrinking the LogStore under certain conditions. 此外,还可以指定是否能够存档 LogStore 实例。In addition, you can specify whether a LogStore instance can be archived. 策略针对每个日志设置,而且是可变的。这表示,一旦日志的每个句柄都关闭了,策略也就不再存在了。Policies are set per log and are volatile, which means that once every handle to the log is closed, the policy no longer exists.

构造函数

LogStore(SafeFileHandle)

为指定的句柄初始化 LogStore 类的新实例。Initializes a new instance of the LogStore class for the specified handle.

LogStore(String, FileMode)

使用指定的路径和模式初始化 LogStore 类的新实例。Initializes a new instance of the LogStore class with the specified path and mode.

LogStore(String, FileMode, FileAccess)

使用指定的路径、模式和访问权限初始化 LogStore 类的新实例。Initializes a new instance of the LogStore class with the specified path, mode, and access.

LogStore(String, FileMode, FileAccess, FileShare)

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

LogStore(String, FileMode, FileAccess, FileShare, FileSecurity)

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

属性

Archivable

获取指示是否可对 LogStore 实例进行存档的值。Gets a value indicating whether this LogStore instance can be archived.

BaseSequenceNumber

获取与此 LogStore 实例中有效记录对应的最低序列号。Gets the lowest sequence number that corresponds to a valid record in this LogStore instance.

Extents

获取一个日志范围集合,这些日志范围包含此日志存储区的数据。Gets the collection of log extents that contain the data for this log store.

FreeBytes

获取日志存储区中的可用字节数。Gets the number of bytes available in the log store.

Handle

获取当前 LogStore 实例封装的日志文件的操作系统文件句柄。Gets the operating system file handle for the log file that the current LogStore instance encapsulates.

LastSequenceNumber

在派生类中被重写时,获取要追加到日志存储区中的下一条记录的序列号。When overridden in a derived class, gets the sequence number of the next record to be appended to the log store.

Length

获取日志存储区的大小(以字节为单位)。Gets the size of the log store, in bytes.

Policy

获取与此日志存储区关联的策略。Gets the policy associated with this log store.

StreamCount

获取此日志存储区中日志流的数量。Gets the number of log streams in this log store.

方法

CreateLogArchiveSnapshot()

拍摄日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state for making a backup.

CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber)

拍摄指定序列号之间的日志存储区状态的快照,以制作备份。Takes a snapshot of the log store state between the specified sequence numbers for making a backup.

Delete(String)

移除日志存储区。Removes the log store.

Dispose()

释放由 LogStore 使用的所有资源。Releases all resources used by the LogStore.

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
SetArchiveTail(SequenceNumber)

设置存档尾数据的序列号。Sets the sequence number of the archive tail.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于