Skip to content

Commit 0d53cf5

Browse files
authored
Added Close to DataLakeOpenWriteOptions, removed RetainedUncommittedData from DataLakeUploadOptions (Azure#15140)
1 parent a1a0dd1 commit 0d53cf5

12 files changed

+1073
-436
lines changed

sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public partial class DataLakeFileOpenWriteOptions
312312
{
313313
public DataLakeFileOpenWriteOptions() { }
314314
public long? BufferSize { get { throw null; } set { } }
315+
public bool? Close { get { throw null; } set { } }
315316
public Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions OpenConditions { get { throw null; } set { } }
316317
public System.IProgress<long> ProgressHandler { get { throw null; } set { } }
317318
}
@@ -324,7 +325,6 @@ public DataLakeFileUploadOptions() { }
324325
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
325326
public string Permissions { get { throw null; } set { } }
326327
public System.IProgress<long> ProgressHandler { get { throw null; } set { } }
327-
public bool? RetainUncommittedData { get { throw null; } set { } }
328328
public Azure.Storage.StorageTransferOptions TransferOptions { get { throw null; } set { } }
329329
public string Umask { get { throw null; } set { } }
330330
}

sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,7 +4136,8 @@ private async Task<Stream> OpenWriteInternal(
41364136
bufferSize: options?.BufferSize ?? Constants.DefaultBufferSize,
41374137
position: position,
41384138
conditions: conditions,
4139-
progressHandler: options?.ProgressHandler);
4139+
progressHandler: options?.ProgressHandler,
4140+
closeEvent: options?.Close);
41404141
}
41414142
catch (Exception ex)
41424143
{
@@ -4196,7 +4197,7 @@ await client.AppendInternal(
41964197
// Flush data
41974198
return await client.FlushInternal(
41984199
position: newPosition,
4199-
retainUncommittedData: args.RetainUncommittedData,
4200+
retainUncommittedData: default,
42004201
close: args.Close,
42014202
args.HttpHeaders,
42024203
args.Conditions,
@@ -4223,7 +4224,7 @@ await client.AppendInternal(
42234224

42244225
return await client.FlushInternal(
42254226
offset + size,
4226-
retainUncommittedData: args.RetainUncommittedData,
4227+
retainUncommittedData: default,
42274228
close: args.Close,
42284229
httpHeaders: args.HttpHeaders,
42294230
conditions: args.Conditions,

sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileWriteStream.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ internal class DataLakeFileWriteStream : StorageWriteStream
1313
{
1414
private readonly DataLakeFileClient _fileClient;
1515
private readonly DataLakeRequestConditions _conditions;
16+
private readonly bool? _closeEvent;
1617
private long _writeIndex;
1718

1819
public DataLakeFileWriteStream(
1920
DataLakeFileClient fileClient,
2021
long bufferSize,
2122
long position,
2223
DataLakeRequestConditions conditions,
23-
IProgress<long> progressHandler) : base(
24+
IProgress<long> progressHandler,
25+
bool? closeEvent) : base(
2426
position,
2527
bufferSize,
2628
progressHandler)
@@ -29,6 +31,7 @@ public DataLakeFileWriteStream(
2931
_fileClient = fileClient;
3032
_conditions = conditions ?? new DataLakeRequestConditions();
3133
_writeIndex = position;
34+
_closeEvent = closeEvent;
3235
}
3336

3437
protected override async Task AppendInternal(bool async, CancellationToken cancellationToken)
@@ -59,7 +62,7 @@ protected override async Task FlushInternal(bool async, CancellationToken cancel
5962
Response<PathInfo> response = await _fileClient.FlushInternal(
6063
position: _writeIndex,
6164
retainUncommittedData: default,
62-
close: default,
65+
close: _closeEvent,
6366
httpHeaders: default,
6467
conditions: _conditions,
6568
async: async,

sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileOpenWriteOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,17 @@ public class DataLakeFileOpenWriteOptions
2727
/// progress updates about data transfers.
2828
/// </summary>
2929
public IProgress<long> ProgressHandler { get; set; }
30+
31+
/// <summary>
32+
/// Azure Storage Events allow applications to receive notifications when files change. When Azure Storage Events are enabled,
33+
/// a file changed event is raised. This event has a property indicating whether this is the final change to distinguish the
34+
/// difference between an intermediate flush to a file stream and the final close of a file stream. The close query parameter
35+
/// is valid only when the action is "flush" and change notifications are enabled. If the value of close is "true" and the
36+
/// flush operation completes successfully, the service raises a file change notification with a property indicating that
37+
/// this is the final update (the file stream has been closed). If "false" a change notification is raised indicating the
38+
/// file has changed. The default is false. This query parameter is set to true by the Hadoop ABFS driver to indicate that
39+
/// the file stream has been closed.
40+
/// </summary>
41+
public bool? Close { get; set; }
3042
}
3143
}

sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileUploadOptions.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ public class DataLakeFileUploadOptions
5050
/// </summary>
5151
public IProgress<long> ProgressHandler { get; set; }
5252

53-
/// <summary>
54-
/// If "true", uncommitted data is retained after the flush operation completes; otherwise, the uncommitted data is deleted
55-
/// after the flush operation. The default is false. Data at offsets less than the specified position are written to the
56-
/// file when flush succeeds, but this optional parameter allows data after the flush position to be retained for a future
57-
/// flush operation.
58-
/// </summary>
59-
public bool? RetainUncommittedData { get; set; }
60-
6153
/// <summary>
6254
/// Azure Storage Events allow applications to receive notifications when files change. When Azure Storage Events are enabled,
6355
/// a file changed event is raised. This event has a property indicating whether this is the final change to distinguish the

sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,7 +2878,7 @@ await file.UploadAsync(
28782878
}
28792879

28802880
[Test]
2881-
public async Task UploadAsync_CloseAndRetainData()
2881+
public async Task UploadAsync_Close()
28822882
{
28832883
// Arrange
28842884
await using DisposingFileSystem test = await GetNewFileSystem();
@@ -2889,7 +2889,6 @@ public async Task UploadAsync_CloseAndRetainData()
28892889
DataLakeFileUploadOptions options = new DataLakeFileUploadOptions
28902890
{
28912891
Close = true,
2892-
RetainUncommittedData = true
28932892
};
28942893

28952894
// Act
@@ -4201,6 +4200,7 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
42014200
openWriteStream.FlushAsync(),
42024201
e => Assert.AreEqual("ConditionNotMet", e.ErrorCode));
42034202
}
4203+
42044204
[Test]
42054205
public async Task OpenWriteAsync_ProgressReporting()
42064206
{
@@ -4337,5 +4337,30 @@ await file.OpenWriteAsync(
43374337
});
43384338
}
43394339
}
4340+
4341+
[Test]
4342+
public async Task OpenWriteAsync_Close()
4343+
{
4344+
// Arrange
4345+
await using DisposingFileSystem test = await GetNewFileSystem();
4346+
DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName()));
4347+
await file.CreateAsync();
4348+
4349+
byte[] data = GetRandomBuffer(Constants.KB);
4350+
using Stream stream = new MemoryStream(data);
4351+
4352+
DataLakeFileOpenWriteOptions options = new DataLakeFileOpenWriteOptions
4353+
{
4354+
Close = true,
4355+
BufferSize = 256
4356+
};
4357+
4358+
// Act
4359+
Stream openWriteStream = await file.OpenWriteAsync(
4360+
overwrite: false,
4361+
options);
4362+
await stream.CopyToAsync(openWriteStream);
4363+
await openWriteStream.FlushAsync();
4364+
}
43404365
}
43414366
}

0 commit comments

Comments
 (0)