Skip to content

Commit 4e8a5ea

Browse files
authored
Add support for SourceOnly snapshot repository (#4073)
This commit adds support for SourceOnly repository. - Introduce a ResetOffset() method on JsonReader to reset the offset back to the initial offset. - Tidy up XML docs on repositories.
1 parent 169b784 commit 4e8a5ea

File tree

12 files changed

+376
-117
lines changed

12 files changed

+376
-117
lines changed

src/Elasticsearch.Net/Utf8Json/JsonReader.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ internal struct JsonReader
4040

4141
readonly byte[] bytes;
4242
int offset;
43+
int initialOffset;
4344

4445
public JsonReader(byte[] bytes)
4546
: this(bytes, 0)
@@ -60,6 +61,8 @@ public JsonReader(byte[] bytes, int offset)
6061
this.offset = offset += 3;
6162
}
6263
}
64+
65+
this.initialOffset = offset;
6366
}
6467

6568
JsonParsingException CreateParsingException(string expected)
@@ -113,11 +116,23 @@ bool IsInRange
113116
}
114117
}
115118

119+
/// <summary>
120+
/// Advances the offset by a specified amount
121+
/// </summary>
122+
/// <param name="offset">The amount to offset by</param>
116123
public void AdvanceOffset(int offset)
117124
{
118125
this.offset += offset;
119126
}
120127

128+
/// <summary>
129+
/// Resets the offset of the reader back to the original offset
130+
/// </summary>
131+
public void ResetOffset()
132+
{
133+
this.offset = this.initialOffset;
134+
}
135+
121136
public byte[] GetBufferUnsafe()
122137
{
123138
return bytes;

src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
namespace Nest
55
{
6+
/// <summary>
7+
/// A snapshot repository that stores snapshots in an Azure storage account
8+
/// <para />
9+
/// Requires the repository-azure plugin to be installed on the cluster
10+
/// </summary>
611
public interface IAzureRepository : IRepository<IAzureRepositorySettings> { }
712

13+
/// <inheritdoc />
814
public class AzureRepository : IAzureRepository
915
{
1016
public AzureRepository() { }
@@ -16,32 +22,55 @@ public AzureRepository() { }
1622
public string Type { get; } = "azure";
1723
}
1824

25+
/// <summary>
26+
/// Snapshot repository settings for <see cref="IAzureRepository"/>
27+
/// </summary>
1928
public interface IAzureRepositorySettings : IRepositorySettings
2029
{
30+
/// <summary>
31+
/// The path within the container on which to store the snapshot data.
32+
/// </summary>
2133
[DataMember(Name ="base_path")]
2234
string BasePath { get; set; }
2335

36+
/// <summary>
37+
/// Big files can be broken down into chunks during the snapshot process, if needed.
38+
/// The chunk size can be specified in bytes or by using size value notation,
39+
/// i.e. 1g, 10m, 5k. Defaults to 64m (64m max)
40+
/// </summary>
2441
[DataMember(Name ="chunk_size")]
2542
string ChunkSize { get; set; }
2643

44+
/// <summary>
45+
/// When set to true metadata files are stored in compressed format. This setting doesn't
46+
/// affect index files that are already compressed by default. Defaults to <c>false</c>.
47+
/// </summary>
2748
[DataMember(Name ="compress")]
2849
bool? Compress { get; set; }
2950

51+
/// <summary>
52+
/// Tha name of the container
53+
/// </summary>
3054
[DataMember(Name ="container")]
3155
string Container { get; set; }
3256
}
3357

58+
/// <inheritdoc />
3459
public class AzureRepositorySettings : IAzureRepositorySettings
3560
{
61+
/// <inheritdoc />
3662
[DataMember(Name ="base_path")]
3763
public string BasePath { get; set; }
3864

65+
/// <inheritdoc />
3966
[DataMember(Name ="chunk_size")]
4067
public string ChunkSize { get; set; }
4168

69+
/// <inheritdoc />
4270
[DataMember(Name ="compress")]
4371
public bool? Compress { get; set; }
4472

73+
/// <inheritdoc />
4574
[DataMember(Name ="container")]
4675
public string Container { get; set; }
4776
}
@@ -54,42 +83,28 @@ public class AzureRepositorySettingsDescriptor
5483
bool? IAzureRepositorySettings.Compress { get; set; }
5584
string IAzureRepositorySettings.Container { get; set; }
5685

57-
/// <summary>
58-
/// Container name. Defaults to elasticsearch-snapshots
59-
/// </summary>
60-
/// <param name="container"></param>
86+
/// <inheritdoc cref="IAzureRepositorySettings.Container"/>
6187
public AzureRepositorySettingsDescriptor Container(string container) => Assign(container, (a, v) => a.Container = v);
6288

63-
/// <summary>
64-
/// Specifies the path within container to repository data. Defaults to empty (root directory).
65-
/// </summary>
66-
/// <param name="basePath"></param>
67-
/// <returns></returns>
89+
/// <inheritdoc cref="IAzureRepositorySettings.BasePath"/>
6890
public AzureRepositorySettingsDescriptor BasePath(string basePath) => Assign(basePath, (a, v) => a.BasePath = v);
6991

70-
/// <summary>
71-
/// When set to true metadata files are stored in compressed format. This setting doesn't
72-
/// affect index files that are already compressed by default. Defaults to false.
73-
/// </summary>
74-
/// <param name="compress"></param>
92+
/// <inheritdoc cref="IAzureRepositorySettings.Compress"/>
7593
public AzureRepositorySettingsDescriptor Compress(bool? compress = true) => Assign(compress, (a, v) => a.Compress = v);
7694

77-
/// <summary>
78-
/// Big files can be broken down into chunks during snapshotting if needed.
79-
/// The chunk size can be specified in bytes or by using size value notation,
80-
/// i.e. 1g, 10m, 5k. Defaults to 64m (64m max)
81-
/// </summary>
82-
/// <param name="chunkSize"></param>
95+
/// <inheritdoc cref="IAzureRepositorySettings.ChunkSize"/>
8396
public AzureRepositorySettingsDescriptor ChunkSize(string chunkSize) => Assign(chunkSize, (a, v) => a.ChunkSize = v);
8497
}
8598

99+
/// <inheritdoc cref="IAzureRepository"/>
86100
public class AzureRepositoryDescriptor
87101
: DescriptorBase<AzureRepositoryDescriptor, IAzureRepository>, IAzureRepository
88102
{
89103
IAzureRepositorySettings IRepository<IAzureRepositorySettings>.Settings { get; set; }
90104
string ISnapshotRepository.Type { get; } = "azure";
91105
object IRepositoryWithSettings.DelegateSettings => Self.Settings;
92106

107+
/// <inheritdoc cref="IAzureRepositorySettings"/>
93108
public AzureRepositoryDescriptor Settings(Func<AzureRepositorySettingsDescriptor, IAzureRepositorySettings> settingsSelector) =>
94109
Assign(settingsSelector, (a, v) => a.Settings = v?.Invoke(new AzureRepositorySettingsDescriptor()));
95110
}

src/Nest/Modules/SnapshotAndRestore/Repositories/CreateRepository/CreateRepositoryRequest.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33

44
namespace Nest
55
{
6+
/// <summary>
7+
/// Creates a snapshot repository
8+
/// </summary>
69
[MapsApi("snapshot.create_repository.json")]
710
[JsonFormatter(typeof(CreateRepositoryFormatter))]
811
public partial interface ICreateRepositoryRequest
912
{
13+
/// <summary>
14+
/// The snapshot repository
15+
/// </summary>
1016
ISnapshotRepository Repository { get; set; }
1117
}
1218

19+
/// <inheritdoc cref="ICreateRepositoryRequest" />
1320
public partial class CreateRepositoryRequest
1421
{
22+
/// <inheritdoc />
1523
public ISnapshotRepository Repository { get; set; }
1624
}
1725

26+
/// <inheritdoc cref="ICreateRepositoryRequest" />
1827
public partial class CreateRepositoryDescriptor
1928
{
2029
ISnapshotRepository ICreateRepositoryRequest.Repository { get; set; }
2130

22-
/// <summary>
23-
/// The shared file system repository ("type": "fs") is using shared file system to store snapshot.
24-
/// The path specified in the location parameter should point to the same location in the shared
25-
/// filesystem and be accessible on all data and master nodes.
26-
/// </summary>
31+
/// <inheritdoc cref="IFileSystemRepository"/>
2732
public CreateRepositoryDescriptor FileSystem(Func<FileSystemRepositoryDescriptor, IFileSystemRepository> selector) =>
2833
Assign(selector, (a, v) => a.Repository = v?.Invoke(new FileSystemRepositoryDescriptor()));
2934

30-
/// <summary>
31-
/// The URL repository ("type": "url") can be used as an alternative read-only way to access data
32-
/// created by shared file system repository is using shared file system to store snapshot.
33-
/// </summary>
35+
/// <inheritdoc cref="IReadOnlyUrlRepository" />
3436
public CreateRepositoryDescriptor ReadOnlyUrl(Func<ReadOnlyUrlRepositoryDescriptor, IReadOnlyUrlRepository> selector) =>
3537
Assign(selector, (a, v) => a.Repository = v?.Invoke(new ReadOnlyUrlRepositoryDescriptor()));
3638

37-
/// <summary>
38-
/// Specify an azure storage container to snapshot and restore to. (defaults to a container named elasticsearch-snapshots)
39-
/// </summary>
39+
/// <inheritdoc cref="IAzureRepository" />
4040
public CreateRepositoryDescriptor Azure(Func<AzureRepositoryDescriptor, IAzureRepository> selector = null) =>
4141
Assign(selector.InvokeOrDefault(new AzureRepositoryDescriptor()), (a, v) => a.Repository = v);
4242

43-
/// <summary> Create an snapshot/restore repository that points to an HDFS filesystem </summary>
43+
/// <inheritdoc cref="IHdfsRepository" />
4444
public CreateRepositoryDescriptor Hdfs(Func<HdfsRepositoryDescriptor, IHdfsRepository> selector) =>
4545
Assign(selector, (a, v) => a.Repository = v?.Invoke(new HdfsRepositoryDescriptor()));
4646

47-
/// <summary> Snapshot and restore to an Amazon S3 bucket </summary>
47+
/// <inheritdoc cref="IS3Repository" />
4848
public CreateRepositoryDescriptor S3(Func<S3RepositoryDescriptor, IS3Repository> selector) =>
4949
Assign(selector, (a, v) => a.Repository = v?.Invoke(new S3RepositoryDescriptor()));
5050

51-
/// <summary> Snapshot and restore to an Amazon S3 bucket </summary>
51+
/// <inheritdoc cref="ISourceOnlyRepository" />
5252
public CreateRepositoryDescriptor SourceOnly(Func<SourceOnlyRepositoryDescriptor, ISourceOnlyRepository> selector) =>
5353
Assign(selector, (a, v) => a.Repository = v?.Invoke(new SourceOnlyRepositoryDescriptor()));
5454

src/Nest/Modules/SnapshotAndRestore/Repositories/FileSystemRepository.cs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// A snapshot repository that uses a shared file system to store snapshot data.
9+
/// The path specified in the location parameter should point to the same location in the shared
10+
/// filesystem and be accessible on all data and master nodes.
11+
/// </summary>
712
public interface IFileSystemRepository : IRepository<IFileSystemRepositorySettings> { }
813

14+
/// <inheritdoc />
915
public class FileSystemRepository : IFileSystemRepository
1016
{
1117
public FileSystemRepository(FileSystemRepositorySettings settings) => Settings = settings;
@@ -15,29 +21,53 @@ public class FileSystemRepository : IFileSystemRepository
1521
public string Type { get; } = "fs";
1622
}
1723

24+
/// <summary>
25+
/// Repository settings for <see cref="IFileSystemRepository"/>
26+
/// </summary>
1827
public interface IFileSystemRepositorySettings : IRepositorySettings
1928
{
29+
/// <summary>
30+
/// Big files can be broken down into chunks during the snapshot process, if needed.
31+
/// The chunk size can be specified in bytes or by using size value notation, i.e. 1g, 10m, 5k.
32+
/// Defaults to null (unlimited chunk size).
33+
/// </summary>
2034
[DataMember(Name ="chunk_size")]
2135
string ChunkSize { get; set; }
2236

37+
/// <summary>
38+
/// Turns on compression of the snapshot files. Defaults to true.
39+
/// </summary>
2340
[DataMember(Name ="compress")]
2441
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
2542
bool? Compress { get; set; }
2643

44+
/// <summary>
45+
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
46+
/// </summary>
2747
[DataMember(Name ="concurrent_streams")]
2848
[JsonFormatter(typeof(NullableStringIntFormatter))]
2949
int? ConcurrentStreams { get; set; }
3050

51+
/// <summary>
52+
/// Location of the snapshots. Mandatory.
53+
/// </summary>
3154
[DataMember(Name ="location")]
3255
string Location { get; set; }
3356

57+
/// <summary>
58+
/// Throttles per node restore rate. Defaults to 20mb per second.
59+
/// </summary>
3460
[DataMember(Name ="max_restore_bytes_per_second")]
3561
string RestoreBytesPerSecondMaximum { get; set; }
3662

63+
/// <summary>
64+
/// Throttles per node snapshot rate. Defaults to 20mb per second.
65+
/// </summary>
3766
[DataMember(Name ="max_snapshot_bytes_per_second")]
3867
string SnapshotBytesPerSecondMaximum { get; set; }
3968
}
4069

70+
/// <inheritdoc cref="IFileSystemRepositorySettings"/>
4171
public class FileSystemRepositorySettings : IFileSystemRepositorySettings
4272
{
4373
internal FileSystemRepositorySettings() { }
@@ -57,6 +87,7 @@ internal FileSystemRepositorySettings() { }
5787
public string SnapshotBytesPerSecondMaximum { get; set; }
5888
}
5989

90+
/// <inheritdoc cref="IFileSystemRepositorySettings"/>
6091
public class FileSystemRepositorySettingsDescriptor
6192
: DescriptorBase<FileSystemRepositorySettingsDescriptor, IFileSystemRepositorySettings>, IFileSystemRepositorySettings
6293
{
@@ -67,55 +98,37 @@ public class FileSystemRepositorySettingsDescriptor
6798
string IFileSystemRepositorySettings.RestoreBytesPerSecondMaximum { get; set; }
6899
string IFileSystemRepositorySettings.SnapshotBytesPerSecondMaximum { get; set; }
69100

70-
/// <summary>
71-
/// Location of the snapshots. Mandatory.
72-
/// </summary>
73-
/// <param name="location"></param>
101+
/// <inheritdoc cref="IFileSystemRepositorySettings.Location"/>
74102
public FileSystemRepositorySettingsDescriptor Location(string location) => Assign(location, (a, v) => a.Location = v);
75103

76-
/// <summary>
77-
/// Turns on compression of the snapshot files. Defaults to true.
78-
/// </summary>
79-
/// <param name="compress"></param>
104+
/// <inheritdoc cref="IFileSystemRepositorySettings.Compress"/>
80105
public FileSystemRepositorySettingsDescriptor Compress(bool? compress = true) => Assign(compress, (a, v) => a.Compress = v);
81106

82-
/// <summary>
83-
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
84-
/// </summary>
85-
/// <param name="concurrentStreams"></param>
107+
/// <inheritdoc cref="IFileSystemRepositorySettings.ConcurrentStreams"/>
86108
public FileSystemRepositorySettingsDescriptor ConcurrentStreams(int? concurrentStreams) =>
87109
Assign(concurrentStreams, (a, v) => a.ConcurrentStreams = v);
88110

89-
/// <summary>
90-
/// Big files can be broken down into chunks during snapshotting if needed.
91-
/// The chunk size can be specified in bytes or by using size value notation, i.e. 1g, 10m, 5k.
92-
/// Defaults to null (unlimited chunk size).
93-
/// </summary>
94-
/// <param name="chunkSize"></param>
111+
/// <inheritdoc cref="IFileSystemRepositorySettings.ChunkSize"/>
95112
public FileSystemRepositorySettingsDescriptor ChunkSize(string chunkSize) => Assign(chunkSize, (a, v) => a.ChunkSize = v);
96113

97-
/// <summary>
98-
/// Throttles per node restore rate. Defaults to 20mb per second.
99-
/// </summary>
100-
/// <param name="maximumBytesPerSecond"></param>
114+
/// <inheritdoc cref="IFileSystemRepositorySettings.RestoreBytesPerSecondMaximum"/>
101115
public FileSystemRepositorySettingsDescriptor RestoreBytesPerSecondMaximum(string maximumBytesPerSecond) =>
102116
Assign(maximumBytesPerSecond, (a, v) => a.RestoreBytesPerSecondMaximum = v);
103117

104-
/// <summary>
105-
/// Throttles per node snapshot rate. Defaults to 20mb per second.
106-
/// </summary>
107-
/// <param name="maximumBytesPerSecond"></param>
118+
/// <inheritdoc cref="IFileSystemRepositorySettings.SnapshotBytesPerSecondMaximum"/>
108119
public FileSystemRepositorySettingsDescriptor SnapshotBytesPerSecondMaximum(string maximumBytesPerSecond) =>
109120
Assign(maximumBytesPerSecond, (a, v) => a.SnapshotBytesPerSecondMaximum = v);
110121
}
111122

123+
/// <inheritdoc cref="IFileSystemRepository"/>
112124
public class FileSystemRepositoryDescriptor
113125
: DescriptorBase<FileSystemRepositoryDescriptor, IFileSystemRepository>, IFileSystemRepository
114126
{
115127
IFileSystemRepositorySettings IRepository<IFileSystemRepositorySettings>.Settings { get; set; }
116128
object IRepositoryWithSettings.DelegateSettings => Self.Settings;
117129
string ISnapshotRepository.Type { get; } = "fs";
118130

131+
/// <inheritdoc cref="IFileSystemRepositorySettings"/>
119132
public FileSystemRepositoryDescriptor Settings(string location,
120133
Func<FileSystemRepositorySettingsDescriptor, IFileSystemRepositorySettings> settingsSelector = null
121134
) =>

src/Nest/Modules/SnapshotAndRestore/Repositories/GetRepository/GetRepositoryResponseFormatter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public GetRepositoryResponse Deserialize(ref JsonReader reader, IJsonFormatterRe
8787
var hdfs = GetRepository<HdfsRepository, HdfsRepositorySettings>(settings, formatterResolver);
8888
repositories.Add(name, hdfs);
8989
break;
90+
case "source":
91+
// reset the offset
92+
snapshotSegmentReader.ResetOffset();
93+
var source = formatterResolver.GetFormatter<ISourceOnlyRepository>()
94+
.Deserialize(ref snapshotSegmentReader, formatterResolver);
95+
repositories.Add(name, source);
96+
break;
9097
}
9198
}
9299
}

0 commit comments

Comments
 (0)