LogRecordSequence LogRecordSequence LogRecordSequence LogRecordSequence Class

定義

表示 LogStore 中儲存的記錄順序。Represents a record sequence stored in a LogStore.

public ref class LogRecordSequence sealed : IDisposable, System::IO::Log::IRecordSequence
public sealed class LogRecordSequence : IDisposable, System.IO.Log.IRecordSequence
type LogRecordSequence = class
    interface IRecordSequence
    interface IDisposable
Public NotInheritable Class LogRecordSequence
Implements IDisposable, IRecordSequence
繼承
LogRecordSequenceLogRecordSequenceLogRecordSequenceLogRecordSequence
實作

範例

這個範例會說明如何使用 LogRecordSequence 類別:This example shows how to use the LogRecordSequence class:

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.IO.Log;

namespace MyLogRecordSequence
{
    public class MyLog
    {
        string logName = "test.log";
        string logContainer = "MyExtent0";
        int containerSize = 32 * 1024;
        LogRecordSequence sequence = null;
        bool delete = true;

        // These are used in the TailPinned event handler.
        public static LogRecordSequence MySequence = null;
        public static bool AdvanceBase = true;

        public MyLog()
        {
            // Create a LogRecordSequence.
            sequence = new LogRecordSequence(this.logName,
                                              FileMode.CreateNew,
                                              FileAccess.ReadWrite,
                                              FileShare.None);

            // At least one container/extent must be added for Log Record Sequence.
            sequence.LogStore.Extents.Add(this.logContainer, this.containerSize);
     
            MySequence = sequence;

        }

        public void AddExtents()
        {
            // Add two additional extents. The extents are 
            // of the same size as the first extent.
            sequence.LogStore.Extents.Add("MyExtent1");
            sequence.LogStore.Extents.Add("MyExtent2");
        }

        public void EnumerateExtents()
        {
            LogStore store = sequence.LogStore;

            Console.WriteLine("Enumerating Log Extents...");
            Console.WriteLine("    Extent Count: {0} extents", store.Extents.Count);
            Console.WriteLine("    Extents Are...");
            foreach (LogExtent extent in store.Extents)
            {
                Console.WriteLine("      {0} ({1}, {2})",
                                  Path.GetFileName(extent.Path),
                                  extent.Size,
                                  extent.State);
            }
            Console.WriteLine("    Free Extents: {0} Free", store.Extents.FreeCount);   
        }

        public void SetLogPolicy()
        {
            Console.WriteLine();
            Console.WriteLine("Setting current log policy...");

            // SET LOG POLICY

            LogPolicy policy = sequence.LogStore.Policy;

            // Set AutoGrow policy. This enables the log to automatically grow
            // when the existing extents are full. New extents are added until
            // we reach the MaximumExtentCount extents.
            // AutoGrow policy is supported only in Windows Vista and not available in R2.
            
            //policy.AutoGrow = true;

            // Set the Growth Rate in terms of extents. This policy specifies
            // "how much" the log should grow. 
            policy.GrowthRate = new PolicyUnit(2, PolicyUnitType.Extents);

            // Set the AutoShrink policy. This enables the log to automatically
            // shrink if the available free space exceeds the shrink percentage. 
            // AutoGrow/shrink policy is supported only in Windows Vista and not available in R2.
            
            //policy.AutoShrinkPercentage = new PolicyUnit(30, PolicyUnitType.Percentage);

            // Set the PinnedTailThreshold policy.
            // A tail pinned event is triggered when there is no
            // log space available and log space may be freed by advancing the base.
            // The user must handle the tail pinned event by advancing the base of the log. 
            // If the user is not able to move the base of the log, the user should report with exception in
            // the tail pinned handler.
            // PinnedTailThreashold policy dictates the amount of space that the TailPinned event requests 
            // for advancing the base of the log. The amount of space can be in percentage or in terms of bytes 
            // which is rounded off to the nearest containers in CLFS. The default is 35 percent.

            
            policy.PinnedTailThreshold = new PolicyUnit(10, PolicyUnitType.Percentage);

            // Set the maximum extents the log can have.
            policy.MaximumExtentCount = 6;
            
            // Set the minimum extents the log can have.
            policy.MinimumExtentCount = 2;
            
            // Set the prefix for new containers that are added. 
            // when AutoGrow is enabled.
            //policy.NewExtentPrefix = "MyLogPrefix";
            
            // Set the suffix number for new containers that are added.
            // when AutoGrow is enabled. 
            policy.NextExtentSuffix = 3;

            // Commit the log policy.
            policy.Commit();

            // Refresh updates the IO.Log policy properties with current log policy 
            // set in the log. 
            policy.Refresh();

            // LOG POLICY END
            // 

            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            // Setting up IO.Log provided capabilities...
            // 

            // SET RETRY APPEND

            // IO.Log provides a mechanism similar to AutoGrow.
            // If the existing log is full and an append fails, setting RetryAppend
            // invokes the CLFS policy engine to add new extents and re-tries
            // record appends. If MaximumExtent count has been reached, 
            // a SequenceFullException is thrown. 
            // 

            sequence.RetryAppend = true;

            // RETRY APPEND END

            // REGISTER FOR TAILPINNED EVENT NOTIFICATIONS

            // Register for TailPinned Event by passing in an event handler.
            // An event is raised when the log full condition is reached.
            // The user should either advance the base sequence number to the 
            // nearest valid sequence number recommended in the tail pinned event or
            // report a failure that it is not able to advance the base sequence 
            // number. 
            //

            sequence.TailPinned += new EventHandler<TailPinnedEventArgs>(HandleTailPinned);  

            Console.WriteLine("Done...");
        }

        public void ShowLogPolicy()
        {
            Console.WriteLine();
            Console.WriteLine("Showing current log policy...");

            LogPolicy policy = sequence.LogStore.Policy;

            Console.WriteLine("    Minimum extent count:  {0}", policy.MinimumExtentCount);
            Console.WriteLine("    Maximum extent count:  {0}", policy.MaximumExtentCount);
            Console.WriteLine("    Growth rate:           {0}", policy.GrowthRate);
            Console.WriteLine("    Pinned tail threshold: {0}", policy.PinnedTailThreshold);
            Console.WriteLine("    Auto shrink percent:   {0}", policy.AutoShrinkPercentage);
            Console.WriteLine("    Auto grow enabled:     {0}", policy.AutoGrow);
            Console.WriteLine("    New extent prefix:     {0}", policy.NewExtentPrefix);
            Console.WriteLine("    Next extent suffix:    {0}", policy.NextExtentSuffix);

	}

        // Append records. Appending three records.  
        public void AppendRecords()
        {
            Console.WriteLine("Appending Log Records...");
            SequenceNumber previous = SequenceNumber.Invalid;

            previous = sequence.Append(CreateData("Hello World!"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush);
            previous = sequence.Append(CreateData("This is my first Logging App"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush);
            previous = sequence.Append(CreateData("Using LogRecordSequence..."), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush);
	    
            Console.WriteLine("Done...");
        }


        // Read the records added to the log. 
        public void ReadRecords()
        {
            Encoding enc = Encoding.Unicode;

            Console.WriteLine();

            Console.WriteLine("Reading Log Records...");
            try
            {
                foreach (LogRecord record in this.sequence.ReadLogRecords(this.sequence.BaseSequenceNumber, LogRecordEnumeratorType.Next))
                {
                    byte[] data = new byte[record.Data.Length];
                    record.Data.Read(data, 0, (int)record.Data.Length);
                    string mystr = enc.GetString(data);
                    Console.WriteLine("    {0}", mystr);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message);
            }

            Console.WriteLine();
        }

        public void FillLog()
        {
            bool append = true;

            while (append)
            {
                try
                {
                    sequence.Append(CreateData(16 * 1024), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush);
                }

                catch (SequenceFullException)
                {
                    Console.WriteLine("Log is Full...");
                    append = false;
                }
            }
        }

        // Dispose the record sequence and delete the log file. 
        public void Cleanup()
        {
            // Dispose the sequence
            sequence.Dispose();

            // Delete the log file.
            if (delete)
            {
                try
                {
                    // This deletes the base log file and all the extents associated with the log.
                    LogStore.Delete(this.logName);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message);
                }
            }
        }

        // Converts the given data to an Array of ArraySegment<byte> 
        public static IList<ArraySegment<byte>> CreateData(string str)
        {
            Encoding enc = Encoding.Unicode;

            byte[] array = enc.GetBytes(str);

            ArraySegment<byte>[] segments = new ArraySegment<byte>[1];
            segments[0] = new ArraySegment<byte>(array);

            return Array.AsReadOnly<ArraySegment<byte>>(segments);
        }

        public static IList<ArraySegment<byte>> CreateData(int size)
        {
            byte[] array = new byte[size];

            Random rnd = new Random();
            rnd.NextBytes(array);

            ArraySegment<byte>[] segments = new ArraySegment<byte>[1];
            segments[0] = new ArraySegment<byte>(array);

            return Array.AsReadOnly<ArraySegment<byte>>(segments);
        }

        public static SequenceNumber GetAdvanceBaseSeqNumber(SequenceNumber recTargetSeqNum)
        {
            SequenceNumber targetSequenceNumber = SequenceNumber.Invalid;

            Console.WriteLine("Getting actual target sequence number...");
            
            // 
            // Implement the logic for returning a valid sequence number closer to
            // recommended target sequence number. 
            //

            return targetSequenceNumber;
        }

        public static void HandleTailPinned(object arg, TailPinnedEventArgs tailPinnedEventArgs)
        {
            Console.WriteLine("TailPinned has fired");

            // Based on the implementation of a logging application, the log base can be moved
            // to free up more log space and if it is not possible to move the 
            // base, the application should report by throwing an exception.

            if(MyLog.AdvanceBase)
            {
                try
                {
                    // TailPnnedEventArgs has the recommended sequence number and its generated 
                    // based on PinnedTailThreshold policy. 
                    // This does not map to an actual sequence number in the record sequence
                    // but an approximation and potentially frees up the threshold % log space
                    // when the log base is advanced to a valid sequence number closer to the 
                    // recommended sequence number. 
                    // The user should use this sequence number to locate a closest valid sequence
                    // number to advance the base of the log.

                    SequenceNumber recommendedTargetSeqNum = tailPinnedEventArgs.TargetSequenceNumber; 
                    
                    // Get the actual Target sequence number.
                    SequenceNumber actualTargetSeqNum = MyLog.GetAdvanceBaseSeqNumber(recommendedTargetSeqNum);

                    MySequence.AdvanceBaseSequenceNumber(actualTargetSeqNum);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception thrown {0} {1}", e.GetType(), e.Message);
                }
            }
            else
            {
                // Report back Error if under some conditions the log cannot
                // advance the base sequence number.

                Console.WriteLine("Reporting Error! Unable to move the base sequence number!");
                throw new IOException();
            }
        }
    }

    class LogSample
    {
        static void Main(string[] args)
        {
            // Create log record sequence.
            MyLog log = new MyLog();

            // Add additional extents.
            log.AddExtents();

            // Enumerate the current log extents.
            log.EnumerateExtents();

            // Set log policies and register for TailPinned event notifications. 
            log.SetLogPolicy();

            log.ShowLogPolicy();
            
            // Append a few records and read the appended records. 
            log.AppendRecords();
            log.ReadRecords();

            // Fill the Log to trigger log growth...and subsequent TailPinned notifications.
            log.FillLog();

            log.EnumerateExtents();

            log.Cleanup();
        }
    }
}


Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Text
Imports System.IO.Log

Namespace MyLogRecordSequence
	Public Class MyLog
		Private logName As String = "test.log"
		Private logContainer As String = "MyExtent0"
		Private containerSize As Integer = 32 * 1024
		Private sequence As LogRecordSequence = Nothing
		Private delete As Boolean = True

		' These are used in the TailPinned event handler.
		Public Shared MySequence As LogRecordSequence = Nothing
		Public Shared AdvanceBase As Boolean = True

		Public Sub New()
			' Create a LogRecordSequence.
			sequence = New LogRecordSequence(Me.logName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)

			' At least one container/extent must be added for Log Record Sequence.
			sequence.LogStore.Extents.Add(Me.logContainer, Me.containerSize)

			MySequence = sequence

		End Sub

		Public Sub AddExtents()
			' Add two additional extents. The extents are 
			' of the same size as the first extent.
			sequence.LogStore.Extents.Add("MyExtent1")
			sequence.LogStore.Extents.Add("MyExtent2")
		End Sub

		Public Sub EnumerateExtents()
			Dim store As LogStore = sequence.LogStore

			Console.WriteLine("Enumerating Log Extents...")
			Console.WriteLine("    Extent Count: {0} extents", store.Extents.Count)
			Console.WriteLine("    Extents Are...")
            For Each extent In store.Extents
                Console.WriteLine("      {0} ({1}, {2})", Path.GetFileName(extent.Path), extent.Size, extent.State)
            Next extent
			Console.WriteLine("    Free Extents: {0} Free", store.Extents.FreeCount)
		End Sub

		Public Sub SetLogPolicy()
			Console.WriteLine()
			Console.WriteLine("Setting current log policy...")

			' SET LOG POLICY

			Dim policy As LogPolicy = sequence.LogStore.Policy

			' Set AutoGrow policy. This enables the log to automatically grow
			' when the existing extents are full. New extents are added until
			' we reach the MaximumExtentCount extents.
			' AutoGrow policy is supported only in Windows Vista and not available in R2.

			'policy.AutoGrow = true;

			' Set the Growth Rate in terms of extents. This policy specifies
			' "how much" the log should grow. 
			policy.GrowthRate = New PolicyUnit(2, PolicyUnitType.Extents)

			' Set the AutoShrink policy. This enables the log to automatically
			' shrink if the available free space exceeds the shrink percentage. 
			' AutoGrow/shrink policy is supported only in Windows Vista and not available in R2.

			'policy.AutoShrinkPercentage = new PolicyUnit(30, PolicyUnitType.Percentage);

			' Set the PinnedTailThreshold policy.
			' A tail pinned event is triggered when there is no
			' log space available and log space may be freed by advancing the base.
			' The user must handle the tail pinned event by advancing the base of the log. 
			' If the user is not able to move the base of the log, the user should report with exception in
			' the tail pinned handler.
			' PinnedTailThreashold policy dictates the amount of space that the TailPinned event requests 
			' for advancing the base of the log. The amount of space can be in percentage or in terms of bytes 
			' which is rounded off to the nearest containers in CLFS. The default is 35 percent.


			policy.PinnedTailThreshold = New PolicyUnit(10, PolicyUnitType.Percentage)

			' Set the maximum extents the log can have.
			policy.MaximumExtentCount = 6

			' Set the minimum extents the log can have.
			policy.MinimumExtentCount = 2

			' Set the prefix for new containers that are added. 
			' when AutoGrow is enabled.
			'policy.NewExtentPrefix = "MyLogPrefix";

			' Set the suffix number for new containers that are added.
			' when AutoGrow is enabled. 
			policy.NextExtentSuffix = 3

			' Commit the log policy.
			policy.Commit()

			' Refresh updates the IO.Log policy properties with current log policy 
			' set in the log. 
			policy.Refresh()

			' LOG POLICY END
			' 

			'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			' Setting up IO.Log provided capabilities...
			' 

			' SET RETRY APPEND

			' IO.Log provides a mechanism similar to AutoGrow.
			' If the existing log is full and an append fails, setting RetryAppend
			' invokes the CLFS policy engine to add new extents and re-tries
			' record appends. If MaximumExtent count has been reached, 
			' a SequenceFullException is thrown. 
			' 

			sequence.RetryAppend = True

			' RETRY APPEND END

			' REGISTER FOR TAILPINNED EVENT NOTIFICATIONS

			' Register for TailPinned Event by passing in an event handler.
			' An event is raised when the log full condition is reached.
			' The user should either advance the base sequence number to the 
			' nearest valid sequence number recommended in the tail pinned event or
			' report a failure that it is not able to advance the base sequence 
			' number. 
			'

			AddHandler sequence.TailPinned, AddressOf HandleTailPinned

			Console.WriteLine("Done...")
		End Sub

		Public Sub ShowLogPolicy()
			Console.WriteLine()
			Console.WriteLine("Showing current log policy...")

			Dim policy As LogPolicy = sequence.LogStore.Policy

			Console.WriteLine("    Minimum extent count:  {0}", policy.MinimumExtentCount)
			Console.WriteLine("    Maximum extent count:  {0}", policy.MaximumExtentCount)
			Console.WriteLine("    Growth rate:           {0}", policy.GrowthRate)
			Console.WriteLine("    Pinned tail threshold: {0}", policy.PinnedTailThreshold)
			Console.WriteLine("    Auto shrink percent:   {0}", policy.AutoShrinkPercentage)
			Console.WriteLine("    Auto grow enabled:     {0}", policy.AutoGrow)
			Console.WriteLine("    New extent prefix:     {0}", policy.NewExtentPrefix)
			Console.WriteLine("    Next extent suffix:    {0}", policy.NextExtentSuffix)

		End Sub

		' Append records. Appending three records.  
		Public Sub AppendRecords()
			Console.WriteLine("Appending Log Records...")
			Dim previous As SequenceNumber = SequenceNumber.Invalid

			previous = sequence.Append(CreateData("Hello World!"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)
			previous = sequence.Append(CreateData("This is my first Logging App"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)
			previous = sequence.Append(CreateData("Using LogRecordSequence..."), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)

			Console.WriteLine("Done...")
		End Sub


		' Read the records added to the log. 
		Public Sub ReadRecords()
			Dim enc As Encoding = Encoding.Unicode

			Console.WriteLine()

			Console.WriteLine("Reading Log Records...")
			Try
				For Each record As LogRecord In Me.sequence.ReadLogRecords(Me.sequence.BaseSequenceNumber, LogRecordEnumeratorType.Next)
					Dim data(record.Data.Length - 1) As Byte
					record.Data.Read(data, 0, CInt(Fix(record.Data.Length)))
					Dim mystr As String = enc.GetString(data)
					Console.WriteLine("    {0}", mystr)
				Next record
			Catch e As Exception
				Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message)
			End Try

			Console.WriteLine()
		End Sub

		Public Sub FillLog()
			Dim append As Boolean = True

			Do While append
				Try
					sequence.Append(CreateData(16 * 1024), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)

				Catch e1 As SequenceFullException
					Console.WriteLine("Log is Full...")
					append = False
				End Try
			Loop
		End Sub

		' Dispose the record sequence and delete the log file. 
		Public Sub Cleanup()
			' Dispose the sequence
			sequence.Dispose()

			' Delete the log file.
			If delete Then
				Try
					' This deletes the base log file and all the extents associated with the log.
					LogStore.Delete(Me.logName)
				Catch e As Exception
					Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message)
				End Try
			End If
		End Sub

		' Converts the given data to an Array of ArraySegment<byte> 
		Public Shared Function CreateData(ByVal str As String) As IList(Of ArraySegment(Of Byte))
			Dim enc As Encoding = Encoding.Unicode

			Dim array() As Byte = enc.GetBytes(str)

			Dim segments(0) As ArraySegment(Of Byte)
			segments(0) = New ArraySegment(Of Byte)(array)

            Return System.Array.AsReadOnly(Of ArraySegment(Of Byte))(segments)
		End Function

		Public Shared Function CreateData(ByVal size As Integer) As IList(Of ArraySegment(Of Byte))
			Dim array(size - 1) As Byte

			Dim rand As New Random()
			rand.NextBytes(array)

			Dim segments(0) As ArraySegment(Of Byte)
			segments(0) = New ArraySegment(Of Byte)(array)

            Return System.Array.AsReadOnly(Of ArraySegment(Of Byte))(segments)
		End Function

		Public Shared Function GetAdvanceBaseSeqNumber(ByVal recTargetSeqNum As SequenceNumber) As SequenceNumber
			Dim targetSequenceNumber As SequenceNumber = SequenceNumber.Invalid

			Console.WriteLine("Getting actual target sequence number...")

			' 
			' Implement the logic for returning a valid sequence number closer to
			' recommended target sequence number. 
			'

			Return targetSequenceNumber
		End Function

		Public Shared Sub HandleTailPinned(ByVal arg As Object, ByVal tailPinnedEventArgs As TailPinnedEventArgs)
			Console.WriteLine("TailPinned has fired")

			' Based on the implementation of a logging application, the log base can be moved
			' to free up more log space and if it is not possible to move the 
			' base, the application should report by throwing an exception.

			If MyLog.AdvanceBase Then
				Try
					' TailPnnedEventArgs has the recommended sequence number and its generated 
					' based on PinnedTailThreshold policy. 
					' This does not map to an actual sequence number in the record sequence
					' but an approximation and potentially frees up the threshold % log space
					' when the log base is advanced to a valid sequence number closer to the 
					' recommended sequence number. 
					' The user should use this sequence number to locate a closest valid sequence
					' number to advance the base of the log.

					Dim recommendedTargetSeqNum As SequenceNumber = tailPinnedEventArgs.TargetSequenceNumber

					' Get the actual Target sequence number.
					Dim actualTargetSeqNum As SequenceNumber = MyLog.GetAdvanceBaseSeqNumber(recommendedTargetSeqNum)

					MySequence.AdvanceBaseSequenceNumber(actualTargetSeqNum)
				Catch e As Exception
					Console.WriteLine("Exception thrown {0} {1}", e.GetType(), e.Message)
				End Try
			Else
				' Report back Error if under some conditions the log cannot
				' advance the base sequence number.

				Console.WriteLine("Reporting Error! Unable to move the base sequence number!")
				Throw New IOException()
			End If
		End Sub
	End Class

	Friend Class LogSample
		Shared Sub Main(ByVal args() As String)
			' Create log record sequence.
			Dim log As New MyLog()

			' Add additional extents.
			log.AddExtents()

			' Enumerate the current log extents.
			log.EnumerateExtents()

			' Set log policies and register for TailPinned event notifications. 
			log.SetLogPolicy()

			log.ShowLogPolicy()

			' Append a few records and read the appended records. 
			log.AppendRecords()
			log.ReadRecords()

			' Fill the Log to trigger log growth...and subsequent TailPinned notifications.
			log.FillLog()

			log.EnumerateExtents()

			log.Cleanup()
		End Sub
	End Class
End Namespace

備註

LogRecordSequence 類別會在一般記錄檔系統 (CLFS) 記錄頂端提供記錄順序介面實作。The LogRecordSequence class provides an implementation of the record sequence interface on top of a Common Log File System (CLFS) log. 除了標準的記錄導向功能之外,它還提供了一個原則模型,可用來避免記錄檔已滿狀況,以及在同一實體檔案上進行用戶端多工。In addition to the standard record-oriented features, it provides a policy model for avoiding log-full conditions, and multiplexing of clients on the same physical file. 它會搭配使用 LogStore 類別,這個類別會提供用來直接操作和管理 CLFS 記錄檔的介面。It works with the LogStore class, which provides an interface for directly manipulating and managing a CLFS log file. 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 concrete 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.

建構函式

LogRecordSequence(LogStore) LogRecordSequence(LogStore) LogRecordSequence(LogStore) LogRecordSequence(LogStore)

使用指定的記錄存放區,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with the specified log store.

LogRecordSequence(LogStore, Int32, Int32) LogRecordSequence(LogStore, Int32, Int32) LogRecordSequence(LogStore, Int32, Int32) LogRecordSequence(LogStore, Int32, Int32)

使用指定的記錄存放區、每個記錄的緩衝區大小和緩衝區數目,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with the specified log store, buffer size for each record, and buffer number.

LogRecordSequence(String, FileMode) LogRecordSequence(String, FileMode) LogRecordSequence(String, FileMode) LogRecordSequence(String, FileMode)

使用指定的記錄存放區路徑和存取模式,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with a specified path to the log store and the access mode.

LogRecordSequence(String, FileMode, FileAccess) LogRecordSequence(String, FileMode, FileAccess) LogRecordSequence(String, FileMode, FileAccess) LogRecordSequence(String, FileMode, FileAccess)

使用指定的記錄存放區路徑以及存取和共用模式,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with a specified path to the log store and the access and share modes.

LogRecordSequence(String, FileMode, FileAccess, FileShare) LogRecordSequence(String, FileMode, FileAccess, FileShare) LogRecordSequence(String, FileMode, FileAccess, FileShare) LogRecordSequence(String, FileMode, FileAccess, FileShare)

使用指定的記錄存放區路徑和存取模式,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with a specified path to the log store and the access mode.

LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32)

使用指定的記錄存放區路徑、檔案權限、存取與共用模式,以及緩衝區大小和記錄計數,初始化 LogRecordSequence 類別的新執行個體。Initializes a new instance of the LogRecordSequence class with a specified path to the log store, file permission, access and share modes, and the buffer size and count for records.

LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32, FileSecurity) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32, FileSecurity) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32, FileSecurity) LogRecordSequence(String, FileMode, FileAccess, FileShare, Int32, Int32, FileSecurity)

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

屬性

BaseSequenceNumber BaseSequenceNumber BaseSequenceNumber BaseSequenceNumber

取得目前 LogRecordSequence 中第一個有效記錄的序號。Gets the sequence number of the first valid record in the current LogRecordSequence.

LastSequenceNumber LastSequenceNumber LastSequenceNumber LastSequenceNumber

取得大於上一筆附加記錄的序號Gets the sequence number which is greater than the last record appended

LogStore LogStore LogStore LogStore

取得 LogStore,包含這個記錄順序的資料。Gets the LogStore that contains the data for this record sequence. 這個方法無法被繼承。This method cannot be inherited.

MaximumRecordLength MaximumRecordLength MaximumRecordLength MaximumRecordLength

取得可以新增至這個記錄順序的記錄大小上限。Gets the maximum size of a record that can be added to this record sequence.

ReservedBytes ReservedBytes ReservedBytes ReservedBytes

取得保留的位元組總數。Gets the total number of bytes that have been reserved.

RestartSequenceNumber RestartSequenceNumber RestartSequenceNumber RestartSequenceNumber

取得最接近記錄結尾之重新啟動區域的序號。Gets the sequence number of the restart area closest to the end of the log.

RetryAppend RetryAppend RetryAppend RetryAppend

取得或設定值,這個值表示是否在記錄已滿時自動重試附加作業。Gets or sets a value indicating whether or not appends are automatically retried if the log is full.

方法

AdvanceBaseSequenceNumber(SequenceNumber) AdvanceBaseSequenceNumber(SequenceNumber) AdvanceBaseSequenceNumber(SequenceNumber) AdvanceBaseSequenceNumber(SequenceNumber)

將記錄檔的基底序號往前移動。Moves the base sequence number of the log forward. 這個方法無法被繼承。This method cannot be inherited.

Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions)

將記錄寫入 LogRecordSequenceWrites a log record to the LogRecordSequence. 這個方法無法被繼承。This method cannot be inherited.

Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection)

使用之前在順序中保留的空間,將記錄附加到 IRecordSequenceAppends a log record to the IRecordSequence, using space previously reserved in the sequence. 這個方法無法被繼承。This method cannot be inherited.

Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions)

將記錄附加到 IRecordSequenceAppends a log record to the IRecordSequence. 這個方法無法被繼承。This method cannot be inherited.

Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection) Append(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection)

使用之前在順序中保留的空間,將記錄附加到 IRecordSequenceAppends a log record to the IRecordSequence, using space previously reserved in the sequence. 這個方法無法被繼承。This method cannot be inherited.

BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object)

開始執行非同步的附加作業。Begins an asynchronous append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object)

開始執行非同步的附加作業。Begins an asynchronous append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, AsyncCallback, Object)

開始執行非同步的附加作業。Begins an asynchronous append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object) BeginAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, AsyncCallback, Object)

開始執行非同步的附加作業。Begins an asynchronous append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginFlush(SequenceNumber, AsyncCallback, Object) BeginFlush(SequenceNumber, AsyncCallback, Object) BeginFlush(SequenceNumber, AsyncCallback, Object) BeginFlush(SequenceNumber, AsyncCallback, Object)

使用先前保留在順序中的空間,開始執行非同步的清除作業。Begins an asynchronous flush operation, using space previously reserved in the sequence. 這個方法無法被繼承。This method cannot be inherited.

BeginReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object)

開始執行非同步的保留和附加作業。Begins an asynchronous reserve and append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object) BeginReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[], AsyncCallback, Object)

開始執行非同步的保留和附加作業。Begins an asynchronous reserve and append operation. 這個方法無法被繼承。This method cannot be inherited.

BeginWriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection, AsyncCallback, Object)

使用先前保留在順序中的空間,開始執行非同步的重新啟用區域寫入作業。Begins an asynchronous restart area write operation, using space previously reserved in the sequence. 這個方法無法被繼承。This method cannot be inherited.

BeginWriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection, AsyncCallback, Object) BeginWriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection, AsyncCallback, Object)

使用先前保留在順序中的空間,開始執行非同步的重新啟用區域寫入作業。Begins an asynchronous restart area write operation, using space previously reserved in the sequence. 這個方法無法被繼承。This method cannot be inherited.

CreateReservationCollection() CreateReservationCollection() CreateReservationCollection() CreateReservationCollection()

建立新的 ReservationCollectionCreates a new ReservationCollection. 這個方法無法被繼承。This method cannot be inherited.

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

釋放由元件使用的資源。Releases the resources used by the component.

EndAppend(IAsyncResult) EndAppend(IAsyncResult) EndAppend(IAsyncResult) EndAppend(IAsyncResult)

結束執行非同步的附加作業。Ends an asynchronous append operation. 這個方法無法被繼承。This method cannot be inherited.

EndFlush(IAsyncResult) EndFlush(IAsyncResult) EndFlush(IAsyncResult) EndFlush(IAsyncResult)

結束執行非同步的清除作業。Ends an asynchronous flush operation. 這個方法無法被繼承。This method cannot be inherited.

EndReserveAndAppend(IAsyncResult) EndReserveAndAppend(IAsyncResult) EndReserveAndAppend(IAsyncResult) EndReserveAndAppend(IAsyncResult)

結束執行非同步的保留和附加作業。Ends an asynchronous reserve and append operation. 這個方法無法被繼承。This method cannot be inherited.

EndWriteRestartArea(IAsyncResult) EndWriteRestartArea(IAsyncResult) EndWriteRestartArea(IAsyncResult) EndWriteRestartArea(IAsyncResult)

結束執行非同步的重新啟動區域寫入作業。Ends an asynchronous restart area write operation. 這個方法無法被繼承。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)
Flush() Flush() Flush() Flush()

確定已寫入所有附加的記錄。Ensures that all appended records have been written. 這個方法無法被繼承。This method cannot be inherited.

Flush(SequenceNumber) Flush(SequenceNumber) Flush(SequenceNumber) Flush(SequenceNumber)

確保已將內含指定序號的所有附加記錄永久寫入。Ensures that all appended records up to and including the record with the specified sequence number have been durably written. 這個方法無法被繼承。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)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ReadLogRecords(SequenceNumber, LogRecordEnumeratorType) ReadLogRecords(SequenceNumber, LogRecordEnumeratorType) ReadLogRecords(SequenceNumber, LogRecordEnumeratorType) ReadLogRecords(SequenceNumber, LogRecordEnumeratorType)

傳回順序中之記錄的可列舉集合。Returns an enumerable collection of records in the sequence. 這個方法無法被繼承。This method cannot be inherited.

ReadRestartAreas() ReadRestartAreas() ReadRestartAreas() ReadRestartAreas()

傳回序列中重新啟動區域的可列舉集合。Returns an enumerable collection of the restart areas in the sequence. 這個方法無法被繼承。This method cannot be inherited.

ReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[])

自動建立單一保留區,並將記錄附加至順序。Automatically makes a single reservation and appends a record to the sequence. 這個方法無法被繼承。This method cannot be inherited.

ReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[]) ReserveAndAppend(IList<ArraySegment<Byte>>, SequenceNumber, SequenceNumber, RecordAppendOptions, ReservationCollection, Int64[])

自動建立單一保留區,並將記錄附加至順序。Automatically makes a single reservation and appends a record to the sequence. 這個方法無法被繼承。This method cannot be inherited.

SetLastRecord(SequenceNumber) SetLastRecord(SequenceNumber) SetLastRecord(SequenceNumber) SetLastRecord(SequenceNumber)

設定 LogRecordSequence 中的最後一個記錄。Sets the last record in the LogRecordSequence.

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

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

(Inherited from Object)
WriteRestartArea(ArraySegment<Byte>) WriteRestartArea(ArraySegment<Byte>) WriteRestartArea(ArraySegment<Byte>) WriteRestartArea(ArraySegment<Byte>)

將重新啟動區域寫入 LogRecordSequenceWrites a restart area to the LogRecordSequence. 這個方法無法被繼承。This method cannot be inherited.

WriteRestartArea(ArraySegment<Byte>, SequenceNumber) WriteRestartArea(ArraySegment<Byte>, SequenceNumber) WriteRestartArea(ArraySegment<Byte>, SequenceNumber) WriteRestartArea(ArraySegment<Byte>, SequenceNumber)

將重新啟動區域寫入 LogRecordSequence,並更新基底序號。Writes a restart area to the LogRecordSequence and updates the base sequence number. 這個方法無法被繼承。This method cannot be inherited.

WriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection) WriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection) WriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection) WriteRestartArea(ArraySegment<Byte>, SequenceNumber, ReservationCollection)

使用保留區將重新啟動區域寫入 LogRecordSequence,並更新基底序號。Writes a restart area to the LogRecordSequence using a reservation, and updates the base sequence number. 這個方法無法被繼承。This method cannot be inherited.

WriteRestartArea(IList<ArraySegment<Byte>>) WriteRestartArea(IList<ArraySegment<Byte>>) WriteRestartArea(IList<ArraySegment<Byte>>) WriteRestartArea(IList<ArraySegment<Byte>>)

將重新啟動區域寫入 LogRecordSequenceWrites a restart area to the LogRecordSequence. 這個方法無法被繼承。This method cannot be inherited.

WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber)

將重新啟動區域寫入 LogRecordSequence,並更新基底序號。Writes a restart area to the LogRecordSequence and updates the base sequence number. 這個方法無法被繼承。This method cannot be inherited.

WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection) WriteRestartArea(IList<ArraySegment<Byte>>, SequenceNumber, ReservationCollection)

使用保留區將重新啟動區域寫入 LogRecordSequence,並更新基底序號。Writes a restart area to the LogRecordSequence using a reservation, and updates the base sequence number. 這個方法無法被繼承。This method cannot be inherited.

事件

TailPinned TailPinned TailPinned TailPinned

標示需要移動順序結尾。Signals the need to move the tail of the sequence.

適用於