LogStore LogStore LogStore LogStore Class

定義

代表記錄結構化儲存區。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
繼承
LogStoreLogStoreLogStoreLogStore
實作

範例

下列範例示範如何將 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 物件的 RemoveLogExtentCollection 方法,這個物件可以由 Extents 屬性傳回。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. 原則是針對個別記錄檔設定的,而且是變動的 (Volatile),代表一旦關閉記錄檔的所有控制代碼,就不再會有原則存在。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(SafeFileHandle) LogStore(SafeFileHandle) LogStore(SafeFileHandle)

為指定的控制代碼初始化 LogStore 類別的新執行個體。Initializes a new instance of the LogStore class for the specified handle.

LogStore(String, FileMode) LogStore(String, FileMode) LogStore(String, FileMode) LogStore(String, FileMode)

使用指定的路徑和模式初始化 LogStore 類別的新執行個體。Initializes a new instance of the LogStore class with the specified path and mode.

LogStore(String, FileMode, FileAccess) LogStore(String, FileMode, FileAccess) LogStore(String, FileMode, FileAccess) 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(String, FileMode, FileAccess, FileShare) LogStore(String, FileMode, FileAccess, FileShare) LogStore(String, FileMode, FileAccess, FileShare)

初始化 LogStore 類別的新執行個體。Initializes a new instance of the LogStore class.

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

初始化 LogStore 類別的新執行個體。Initializes a new instance of the LogStore class.

屬性

Archivable Archivable Archivable Archivable

取得用來表示是否可以封存這個 LogStore 執行個體的值。Gets a value indicating whether this LogStore instance can be archived.

BaseSequenceNumber BaseSequenceNumber BaseSequenceNumber BaseSequenceNumber

取得對應至這個 LogStore 執行個體中有效記錄的最小序號。Gets the lowest sequence number that corresponds to a valid record in this LogStore instance.

Extents Extents Extents Extents

取得包含這個記錄存放區資料的延伸記錄區集合。Gets the collection of log extents that contain the data for this log store.

FreeBytes FreeBytes FreeBytes FreeBytes

取得記錄存放區中可用的位元組數目。Gets the number of bytes available in the log store.

Handle Handle Handle Handle

取得目前 LogStore 執行個體所封裝之記錄檔的作業系統檔案控制代碼。Gets the operating system file handle for the log file that the current LogStore instance encapsulates.

LastSequenceNumber LastSequenceNumber LastSequenceNumber LastSequenceNumber

在衍生類別中覆寫時,取得要附加至記錄存放區之下一筆記錄的序號。When overridden in a derived class, gets the sequence number of the next record to be appended to the log store.

Length Length Length Length

取得記錄存放區的大小 (以位元組為單位)。Gets the size of the log store, in bytes.

Policy Policy Policy Policy

取得與此記錄存放區相關聯的原則。Gets the policy associated with this log store.

StreamCount StreamCount StreamCount StreamCount

取得這個記錄存放區的記錄資料流數目。Gets the number of log streams in this log store.

方法

CreateLogArchiveSnapshot() CreateLogArchiveSnapshot() CreateLogArchiveSnapshot() CreateLogArchiveSnapshot()

取得記錄存放區狀態的快照 (Snapshot),以便製作備份。Takes a snapshot of the log store state for making a backup.

CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber) CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber) CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber) CreateLogArchiveSnapshot(SequenceNumber, SequenceNumber)

取得介於指定之序號間的記錄存放區狀態快照 (Snapshot),以便製作備份。Takes a snapshot of the log store state between the specified sequence numbers for making a backup.

Delete(String) Delete(String) Delete(String) Delete(String)

移除記錄存放區。Removes the log store.

Dispose() Dispose() Dispose() Dispose()

釋放 LogStore 所使用的所有資源。Releases all resources used by the LogStore.

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

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
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)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
SetArchiveTail(SequenceNumber) SetArchiveTail(SequenceNumber) SetArchiveTail(SequenceNumber) SetArchiveTail(SequenceNumber)

設定封存結尾的序號。Sets the sequence number of the archive tail.

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

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於