Cloud Drive の Snapshot と CopyTo を試してみた。

ホワイトペーパーが日本語化されたので、少しずつ試してます。
Download - Windows Azure Drive-February2010_jp.docx
Snapshot を取ってそれを CopyTo するような使い方をするらしい。


※ちなみに Windows Azure 関係の資料は日本語化が進んでますね!Windows Azure Services | Windows Azure


コード一部抜粋。Cloud Drive 読み書き出来た! - お だ のスペース で載せたコードに付け足してます。

protected void btnSnapshot_Click(object sender, EventArgs e)
{
  this.CreateContainer();

  StorageCredentialsAccountAndKey credentials =
    new StorageCredentialsAccountAndKey("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");

  try
  {
    int cacheSize = 20000;

    Uri blobUri = new Uri("http://127.0.0.1:10000/devstoreaccount1/testpageblob/normal");
    LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache");

    CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);

    CloudDrive drive = new CloudDrive(blobUri, credentials);
    var snapshotUri = drive.Snapshot();
    this.lblSnapshotUri.Text = snapshotUri.ToString();
    CloudDrive snapshotDrive = new CloudDrive(snapshotUri, credentials);
    string driveLetter = snapshotDrive.Mount(cacheSize, DriveMountOptions.None);
    using (StreamReader reader = new StreamReader(driveLetter + "//hoge.txt"))
    {
      this.lblContent.Text = reader.ReadToEnd();
    }
  }
  catch (CloudDriveException ex)
  {
    Debug.WriteLine(ex.StackTrace);
    throw;
  }
}

protected void btnSnapshotWrite_Click(object sender, EventArgs e)
{
  this.CreateContainer();

  StorageCredentialsAccountAndKey credentials =
    new StorageCredentialsAccountAndKey("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");

  try
  {
    int cacheSize = 20000;

    Uri blobUri = new Uri(this.lblSnapshotUri.Text);
    LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache");

    CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);

    CloudDrive drive = new CloudDrive(blobUri, credentials);
    string driveLetter = drive.Mount(cacheSize, DriveMountOptions.None);
    using (StreamWriter writer = new StreamWriter(driveLetter + "//hoge.txt"))
    {
      writer.Write(this.txtContent.Text);
    }
    using (StreamReader reader = new StreamReader(driveLetter + "//hoge.txt"))
    {
      this.lblContent.Text = reader.ReadToEnd();
    }
  }
  catch (CloudDriveException ex)
  {
    Debug.WriteLine(ex.StackTrace);
    throw;
  }
}

protected void btnCopy_Click(object sender, EventArgs e)
{
  this.CreateContainer();

  StorageCredentialsAccountAndKey credentials =
    new StorageCredentialsAccountAndKey("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");

  try
  {
    int cacheSize = 20000;

    Uri blobUri = new Uri(this.lblSnapshotUri.Text);
    LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache");

    CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);

    CloudDrive drive = new CloudDrive(blobUri, credentials);
    var copyUri = new Uri("http://127.0.0.1:10000/devstoreaccount1/testpageblob/" + this.txtCopyUri.Text);
    drive.CopyTo(copyUri);
    CloudDrive snapshotDrive = new CloudDrive(copyUri, credentials);
    string driveLetter = snapshotDrive.Mount(cacheSize, DriveMountOptions.None);
    using (StreamReader reader = new StreamReader(driveLetter + "//hoge.txt"))
    {
      this.lblContent.Text = reader.ReadToEnd();
    }
  }
  catch (CloudDriveException ex)
  {
    Debug.WriteLine(ex.StackTrace);
    throw;
  }
}

protected void btnCopyWrite_Click(object sender, EventArgs e)
{
  this.CreateContainer();

  StorageCredentialsAccountAndKey credentials =
    new StorageCredentialsAccountAndKey("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");

  try
  {
    int cacheSize = 20000;

    Uri blobUri = new Uri("http://127.0.0.1:10000/devstoreaccount1/testpageblob/" + this.txtCopyUri.Text);
    LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache");

    CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);

    CloudDrive drive = new CloudDrive(blobUri, credentials);
    string driveLetter = drive.Mount(cacheSize, DriveMountOptions.None);
    using (StreamWriter writer = new StreamWriter(driveLetter + "//hoge.txt"))
    {
      writer.Write(this.txtContent.Text);
    }
    using (StreamReader reader = new StreamReader(driveLetter + "//hoge.txt"))
    {
      this.lblContent.Text = reader.ReadToEnd();
    }
  }
  catch (CloudDriveException ex)
  {
    Debug.WriteLine(ex.StackTrace);
    throw;
  }
}

Snapshot について思ったこと

  • URL は、Snapshot を取った Uri に ?snapshot=日時 を付加したみたいな感じでした。
http://127.0.0.1:10000/devstoreaccount1/testpageblob/normal?snapshot=2010-03-01T12:32:35.8660000Z
  • 読取専用だと思ってたんだけど、マウントしたら書き込み出来てしまった。あれ読取専用じゃなかったっけ?

2010/03/08 追記:本番環境だと読取専用でした。

あとどういう条件かはわかってないんですが、時々 ERROR_LEASE_LOCKED ってエラーがでる。もう少し検証 + ホワイトペーパーをちゃんと読まないとダメだな。