Beispiel #1
0
  public void Commit( CommitStage c )
  {
    if ( Saved ) return;

    if ( c == CommitStage.Prepare )
    {
      // Save the pages to the underlying stream.
      foreach ( G.KeyValuePair<long,IndexPage> pair in PageMap )
      {
        IndexPage p = pair.Value;
        if ( !p.Saved )
        {
          p.WriteHeader();
          F.Position = (long)p.PageId * IndexPage.PageSize;
        
          // For last page, only write the amount actually used (so file size is minimised)
          F.Write( p.Data, 0, p.PageId == PageAlloc-1 ? p.Size() : IndexPage.PageSize );
          p.Saved = true;
        }
      }
    }
    else if ( c == CommitStage.Rollback )
    {
      PageMap.Clear();
      Initialise();
    }
    else F.Commit( c );
    if ( c >= CommitStage.Flush ) Saved = true;
  }
 public void PrepareToCommit() // Writes pages to the underlying file ( which will be fully buffered ).
 {
   if ( Saved ) return;
   // Save the pages.
   foreach ( G.KeyValuePair<long,IndexPage> pair in PageMap )
   {
     IndexPage p = pair.Value;
     if ( !p.Saved )
     {
       p.WriteHeader();
       F.Position = (long)p.PageId * IndexPage.PageSize;
       
       // For last page, only write the amount actually used (so file size is minimised)
       F.Write( p.Data, 0, p.PageId == PageAlloc-1 ? p.Size() : IndexPage.PageSize );
       p.Saved = true;
     }
   }
   Saved = true;
 }