Skip to content

Commit cc3193f

Browse files
committed
Merge branch 'master' into dev/versionstamps
2 parents 1cb6819 + f22e9ce commit cc3193f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1946
-886
lines changed

FdbShell/Commands/BasicCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ public static async Task Count(string[] path, ITuple extras, IFdbDatabase db, Te
220220
var copy = KeySubspace.Copy(folder);
221221
log.WriteLine("# Counting keys under {0} ...", FdbKey.Dump(copy.GetPrefix()));
222222

223-
var progress = new Progress<STuple<long, Slice>>((state) =>
223+
var progress = new Progress<(long Count, Slice Current)>((state) =>
224224
{
225-
log.Write("\r# Found {0:N0} keys...", state.Item1);
225+
log.Write("\r# Found {0:N0} keys...", state.Count);
226226
});
227227

228228
long count = await Fdb.System.EstimateCountAsync(db, copy.ToRange(), progress, ct);

FdbTop/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric cu
819819
{
820820
foreach(var role in proc.Roles)
821821
{
822-
map.Add(role.Value);
822+
map.Add(role.Role);
823823
}
824824
}
825825

@@ -860,7 +860,7 @@ private static void ShowProcessesScreen(FdbSystemStatus status, HistoryMetric cu
860860
map = new RoleMap();
861861
foreach (var role in proc.Roles)
862862
{
863-
map.Add(role.Value);
863+
map.Add(role.Role);
864864
}
865865
Console.ForegroundColor = ConsoleColor.DarkGray;
866866
WriteAt(1, y,

FoundationDB.Client/Fdb.Bulk.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace FoundationDB.Client
3131
using System;
3232
using System.Collections.Generic;
3333
using System.Diagnostics;
34+
using System.Linq;
3435
using System.Threading;
3536
using System.Threading.Tasks;
3637
using Doxense.Diagnostics.Contracts;
@@ -98,7 +99,7 @@ public static Task<long> WriteAsync([NotNull] IFdbDatabase db, [NotNull] IEnumer
9899

99100
return RunWriteOperationAsync(
100101
db,
101-
data,
102+
data.Select(x => (x.Key, x.Value)),
102103
new WriteOptions(),
103104
ct
104105
);
@@ -118,6 +119,49 @@ public static Task<long> WriteAsync([NotNull] IFdbDatabase db, [NotNull] IEnumer
118119

119120
ct.ThrowIfCancellationRequested();
120121

122+
return RunWriteOperationAsync(
123+
db,
124+
data.Select(x => (x.Key, x.Value)),
125+
options ?? new WriteOptions(),
126+
ct
127+
);
128+
}
129+
130+
/// <summary>Writes a potentially large sequence of key/value pairs into the database, by using as many transactions as necessary, and automatically scaling the size of each batch.</summary>
131+
/// <param name="db">Database used for the operation</param>
132+
/// <param name="data">Sequence of key/value pairs</param>
133+
/// <param name="ct">Token used to cancel the operation</param>
134+
/// <returns>Total number of values inserted in the database</returns>
135+
/// <remarks>In case of a non-retryable error, some of the keys may remain in the database. Other transactions running at the same time may observe only a fraction of the keys until the operation completes.</remarks>
136+
public static Task<long> WriteAsync([NotNull] IFdbDatabase db, [NotNull] IEnumerable<(Slice Key, Slice Value)> data, CancellationToken ct)
137+
{
138+
if (db == null) throw new ArgumentNullException(nameof(db));
139+
if (data == null) throw new ArgumentNullException(nameof(data));
140+
141+
ct.ThrowIfCancellationRequested();
142+
143+
return RunWriteOperationAsync(
144+
db,
145+
data,
146+
new WriteOptions(),
147+
ct
148+
);
149+
}
150+
151+
/// <summary>Writes a potentially large sequence of key/value pairs into the database, by using as many transactions as necessary, and automatically scaling the size of each batch.</summary>
152+
/// <param name="db">Database used for the operation</param>
153+
/// <param name="data">Sequence of key/value pairs</param>
154+
/// <param name="options">Custom options used to configure the behaviour of the operation</param>
155+
/// <param name="ct">Token used to cancel the operation</param>
156+
/// <returns>Total number of values inserted in the database</returns>
157+
/// <remarks>In case of a non-retryable error, some of the keys may remain in the database. Other transactions running at the same time may observe only a fraction of the keys until the operation completes.</remarks>
158+
public static Task<long> WriteAsync([NotNull] IFdbDatabase db, [NotNull] IEnumerable<(Slice Key, Slice Value)> data, WriteOptions options, CancellationToken ct)
159+
{
160+
if (db == null) throw new ArgumentNullException(nameof(db));
161+
if (data == null) throw new ArgumentNullException(nameof(data));
162+
163+
ct.ThrowIfCancellationRequested();
164+
121165
return RunWriteOperationAsync(
122166
db,
123167
data,
@@ -126,7 +170,7 @@ public static Task<long> WriteAsync([NotNull] IFdbDatabase db, [NotNull] IEnumer
126170
);
127171
}
128172

129-
internal static async Task<long> RunWriteOperationAsync([NotNull] IFdbDatabase db, [NotNull] IEnumerable<KeyValuePair<Slice, Slice>> data, WriteOptions options, CancellationToken ct)
173+
internal static async Task<long> RunWriteOperationAsync([NotNull] IFdbDatabase db, [NotNull] IEnumerable<(Slice Key, Slice Value)> data, WriteOptions options, CancellationToken ct)
130174
{
131175
Contract.Requires(db != null && data != null && options != null);
132176

@@ -145,7 +189,7 @@ internal static async Task<long> RunWriteOperationAsync([NotNull] IFdbDatabase d
145189
throw new NotImplementedException("Multiple concurrent transactions are not yet supported");
146190
}
147191

148-
var chunk = new List<KeyValuePair<Slice, Slice>>();
192+
var chunk = new List<(Slice Key, Slice Value)>();
149193

150194
long items = 0;
151195
using (var iterator = data.GetEnumerator())
@@ -960,7 +1004,6 @@ public static Task ForEachAsync<TSource, TLocal>(
9601004
/// <param name="localFinally">Lambda function that will be called after the last batch, and will be passed the last known state.</param>
9611005
/// <param name="ct">Token used to cancel the operation</param>
9621006
/// <returns>Task that completes when all the elements of <paramref name="source"/> have been processed, a non-retryable error occurs, or <paramref name="ct"/> is triggered</returns>
963-
[Obsolete("EXPERIMENTAL: do not use yet!")]
9641007
public static Task ForEachAsync<TSource, TLocal>(
9651008
[NotNull] IFdbDatabase db,
9661009
[NotNull] IEnumerable<TSource> source,

FoundationDB.Client/Fdb.System.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public static Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, KeyRange
408408
/// <param name="ct">Token used to cancel the operation</param>
409409
/// <returns>Number of keys k such that range.Begin &lt;= k &gt; range.End</returns>
410410
/// <remarks>If the range contains a large of number keys, the operation may need more than one transaction to complete, meaning that the number will not be transactionally accurate.</remarks>
411-
public static Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, KeyRange range, IProgress<STuple<long, Slice>> onProgress, CancellationToken ct)
411+
public static Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, KeyRange range, IProgress<(long Count, Slice Current)> onProgress, CancellationToken ct)
412412
{
413413
return EstimateCountAsync(db, range.Begin, range.End, onProgress, ct);
414414
//REVIEW: BUGBUG: REFACTORING: deal with null value for End!
@@ -422,7 +422,7 @@ public static Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, KeyRange
422422
/// <param name="ct">Token used to cancel the operation</param>
423423
/// <returns>Number of keys k such that <paramref name="beginInclusive"/> &lt;= k &gt; <paramref name="endExclusive"/></returns>
424424
/// <remarks>If the range contains a large of number keys, the operation may need more than one transaction to complete, meaning that the number will not be transactionally accurate.</remarks>
425-
public static async Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, Slice beginInclusive, Slice endExclusive, IProgress<STuple<long, Slice>> onProgress, CancellationToken ct)
425+
public static async Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, Slice beginInclusive, Slice endExclusive, IProgress<(long Count, Slice Current)> onProgress, CancellationToken ct)
426426
{
427427
const int INIT_WINDOW_SIZE = 1 << 8; // start at 256 //1024
428428
const int MAX_WINDOW_SIZE = 1 << 13; // never use more than 4096
@@ -538,7 +538,7 @@ public static async Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, Sli
538538
.ConfigureAwait(false);
539539

540540
counter += n;
541-
if (onProgress != null) onProgress.Report(STuple.Create(counter, end));
541+
onProgress?.Report((counter, end));
542542
#if TRACE_COUNTING
543543
++iter;
544544
#endif
@@ -552,7 +552,7 @@ public static async Task<long> EstimateCountAsync([NotNull] IFdbDatabase db, Sli
552552
// the range is not finished, advance the cursor
553553
counter += windowSize;
554554
cursor = next;
555-
if (onProgress != null) onProgress.Report(STuple.Create(counter, cursor));
555+
onProgress?.Report((counter, cursor));
556556

557557
if (!last)
558558
{ // double the size of the window if we are not in the last segment

FoundationDB.Client/FdbDatabase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ internal void ChangeRoot(IKeySubspace subspace, IFdbDirectory directory, bool re
456456
lock (this)//TODO: don't use this for locking
457457
{
458458
m_readOnly = readOnly;
459-
m_globalSpace = KeySubspace.Copy(subspace).Using(TypeSystem.Tuples);
460-
m_globalSpaceCopy = KeySubspace.Copy(subspace).Using(TypeSystem.Tuples); // keep another copy
459+
m_globalSpace = KeySubspace.Copy(subspace, TypeSystem.Tuples);
460+
m_globalSpaceCopy = KeySubspace.Copy(subspace, TypeSystem.Tuples); // keep another copy
461461
m_directory = directory == null ? null : new FdbDatabasePartition(this, directory);
462462
}
463463
}

FoundationDB.Client/FdbDatabaseExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,18 @@ public static Task SetAsync([NotNull] this IFdbRetryable db, Slice key, Slice va
318318
return db.WriteAsync((tr) => tr.Set(key, value), ct);
319319
}
320320

321-
/// <summary>Set the values of a list of keys in the database, using a dedicated transaction.</summary>
321+
/// <summary>Set the values of a sequence of keys in the database, using a dedicated transaction.</summary>
322322
/// <param name="db">Database instance</param>
323323
/// <remarks>
324324
/// Use this method only if you intend to perform a single operation inside your execution context (ex: HTTP request).
325325
/// If you need to combine multiple read or write operations, consider using on of the multiple <see cref="IFdbRetryable.WriteAsync"/> or <see cref="IFdbRetryable.ReadWriteAsync"/> overrides.
326326
/// </remarks>
327-
public static Task SetValuesAsync([NotNull] this IFdbRetryable db, KeyValuePair<Slice, Slice>[] keyValuePairs, CancellationToken ct)
327+
public static Task SetValuesAsync([NotNull] this IFdbRetryable db, IEnumerable<KeyValuePair<Slice, Slice>> items, CancellationToken ct)
328328
{
329329
Contract.NotNull(db, nameof(db));
330330
return db.WriteAsync((tr) =>
331331
{
332-
foreach (var kv in keyValuePairs)
332+
foreach (var kv in items)
333333
{
334334
tr.Set(kv.Key, kv.Value);
335335
}
@@ -342,12 +342,12 @@ public static Task SetValuesAsync([NotNull] this IFdbRetryable db, KeyValuePair<
342342
/// Use this method only if you intend to perform a single operation inside your execution context (ex: HTTP request).
343343
/// If you need to combine multiple read or write operations, consider using on of the multiple <see cref="IFdbRetryable.WriteAsync"/> or <see cref="IFdbRetryable.ReadWriteAsync"/> overrides.
344344
/// </remarks>
345-
public static Task SetValuesAsync([NotNull] this IFdbRetryable db, IEnumerable<KeyValuePair<Slice, Slice>> keyValuePairs, CancellationToken ct)
345+
public static Task SetValuesAsync([NotNull] this IFdbRetryable db, IEnumerable<(Slice Key, Slice Value)> items, CancellationToken ct)
346346
{
347347
Contract.NotNull(db, nameof(db));
348348
return db.WriteAsync((tr) =>
349349
{
350-
foreach (var kv in keyValuePairs)
350+
foreach (var kv in items)
351351
{
352352
tr.Set(kv.Key, kv.Value);
353353
}

FoundationDB.Client/FoundationDB.Client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
<LangVersion>latest</LangVersion>
3333
</PropertyGroup>
3434

35+
<ItemGroup>
36+
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
37+
</ItemGroup>
38+
3539
</Project>

FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,34 +153,29 @@ internal FdbDirectoryLayer(IDynamicKeySubspace nodeSubspace, IDynamicKeySubspace
153153
}
154154
}
155155

156-
/// <summary>Create an instance of the default Directory Layer</summary>
157-
[NotNull]
158-
public static FdbDirectoryLayer Create()
159-
{
160-
return Create(Slice.Empty);
161-
}
162-
163156
/// <summary>Create an instance of a Directory Layer located under a specific prefix and path</summary>
164157
/// <param name="prefix">Prefix for the content. The nodes will be stored under <paramref name="prefix"/> + &lt;FE&gt;</param>
165158
/// <param name="path">Optional path, if the Directory Layer is not located at the root of the database.</param>
159+
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TypeSystem.Tuples"/> type system by default.</param>
166160
[NotNull]
167-
public static FdbDirectoryLayer Create(Slice prefix, IEnumerable<string> path = null)
161+
public static FdbDirectoryLayer Create(Slice prefix, IEnumerable<string> path = null, IKeyEncoding encoding = null)
168162
{
169-
var subspace = KeySubspace.FromKey(prefix).Using(TypeSystem.Tuples);
163+
var subspace = KeySubspace.CreateDynamic(prefix, encoding ?? TypeSystem.Tuples);
170164
var location = path != null ? ParsePath(path) : STuple.Empty;
171165
return new FdbDirectoryLayer(subspace.Partition[FdbKey.Directory], subspace, location);
172166
}
173167

174168
/// <summary>Create an instance of a Directory Layer located under a specific subspace and path</summary>
175169
/// <param name="subspace">Subspace for the content. The nodes will be stored under <paramref name="subspace"/>.Key + &lt;FE&gt;</param>
176170
/// <param name="path">Optional path, if the Directory Layer is not located at the root of the database.</param>
171+
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TypeSystem.Tuples"/> type system by default.</param>
177172
[NotNull]
178-
public static FdbDirectoryLayer Create(IKeySubspace subspace, IEnumerable<string> path = null)
173+
public static FdbDirectoryLayer Create(IKeySubspace subspace, IEnumerable<string> path = null, IKeyEncoding encoding = null)
179174
{
180175
if (subspace == null) throw new ArgumentNullException(nameof(subspace));
181176

182177
var location = path != null ? ParsePath(path) : STuple.Empty;
183-
var space = subspace.Using(TypeSystem.Tuples);
178+
var space = subspace.Using(encoding ?? TypeSystem.Tuples);
184179
return new FdbDirectoryLayer(space.Partition[FdbKey.Directory], space, location);
185180
}
186181

@@ -539,14 +534,6 @@ internal static ITuple ParsePath(IEnumerable<string> path, string argName = null
539534
return STuple.FromArray<string>(pathCopy);
540535
}
541536

542-
[NotNull]
543-
internal static ITuple ParsePath([NotNull] string name, string argName = null)
544-
{
545-
if (name == null) throw new ArgumentNullException(argName ?? "name");
546-
547-
return STuple.Create<string>(name);
548-
}
549-
550537
[NotNull]
551538
internal static ITuple VerifyPath([NotNull] ITuple path, string argName = null)
552539
{

FoundationDB.Client/Layers/Tuples/Encoding/TupleCodec`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public TupleCodec(T missingValue)
5555

5656
public override Slice EncodeOrdered(T value)
5757
{
58-
return TupleEncoder.EncodeKey(value);
58+
return TupleEncoder.EncodeKey(default(Slice), value);
5959
}
6060

6161
public override void EncodeOrderedSelfTerm(ref SliceWriter output, T value)

0 commit comments

Comments
 (0)