diff --git a/.editorconfig b/.editorconfig
index 49f34bd03..4a9719c4b 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,5 +1,38 @@
-; 4-column tab indentation
-[*.cs]
+# Editor Config for foundationdb-dotnet-client
+
+# root
+root = true
+
+
+# Global defaults
+[*]
+end_of_line = crlf
+insert_final_newline = true
indent_style = tab
indent_size = 4
+[*.cs]
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = false
+csharp_indent_labels = one_less_than_current
+csharp_indent_switch_labels = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_prefer_braces = true
+csharp_preserve_single_line_statements = true
+csharp_space_after_cast = true
+csharp_space_after_comma = true
+csharp_space_after_keywords_in_control_flow_statements = true
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_style_conditional_delegate_call = true:suggestion
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_throw_expression = true:suggestion
+dotnet_sort_system_directives_first = true:suggestion
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_explicit_tuple_names = true:warning
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_qualification_for_method = false:suggestion
+
+csharp_style_inlined_variable_declaration = true:suggestion
diff --git a/.gitignore b/.gitignore
index 9623924d5..5f7062a2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,7 +27,7 @@ _ReSharper*/
*.vssscc
$tf*/
-nuget/
+.nuget/
packages/
*.ide/
.vs/
@@ -37,4 +37,10 @@ fdb_c.dll
# Build tools and artifacts
/build/tools/
/build/output/
+/build/.fake
+# JetBrains
+.idea
+
+# OSX
+.DS_Store
diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config
deleted file mode 100644
index 67f8ea046..000000000
--- a/.nuget/NuGet.Config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe
deleted file mode 100755
index 8dd7e45ae..000000000
Binary files a/.nuget/NuGet.exe and /dev/null differ
diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets
deleted file mode 100644
index 3f8c37b22..000000000
--- a/.nuget/NuGet.targets
+++ /dev/null
@@ -1,144 +0,0 @@
-
-
-
- $(MSBuildProjectDirectory)\..\
-
-
- false
-
-
- false
-
-
- true
-
-
- false
-
-
-
-
-
-
-
-
-
-
- $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
-
-
-
-
- $(SolutionDir).nuget
-
-
-
- $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config
- $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config
-
-
-
- $(MSBuildProjectDirectory)\packages.config
- $(PackagesProjectConfig)
-
-
-
-
- $(NuGetToolsPath)\NuGet.exe
- @(PackageSource)
-
- "$(NuGetExePath)"
- mono --runtime=v4.0.30319 "$(NuGetExePath)"
-
- $(TargetDir.Trim('\\'))
-
- -RequireConsent
- -NonInteractive
-
- "$(SolutionDir) "
- "$(SolutionDir)"
-
-
- $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)
- $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
-
-
-
- RestorePackages;
- $(BuildDependsOn);
-
-
-
-
- $(BuildDependsOn);
- BuildPackage;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Common/VersionInfo.cs b/Common/VersionInfo.cs
index 5262018c7..8c8f4ef16 100644
--- a/Common/VersionInfo.cs
+++ b/Common/VersionInfo.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2015, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -27,15 +27,13 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
#endregion
using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Doxense")]
[assembly: AssemblyProduct("FoundationDB.Client")]
-[assembly: AssemblyCopyright("Copyright Doxense SAS 2013-2015")]
+[assembly: AssemblyCopyright("Copyright Doxense SAS 2013-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("0.9.9.0")] //note: Only change this when doing breaking API changes!
-[assembly: AssemblyFileVersion("0.9.8.0")] //note: change this to "x.y.revision.build_step" in a build step of your favorite C.I. build server
-[assembly: AssemblyInformationalVersion("0.9.9-pre")] //note: this is the version seen by NuGet, add "-alpha"/"-beta"/"-rc1" at the end to create pre-release packages
+[assembly: AssemblyVersion("5.1.0.0")] //note: Only change this when doing breaking API changes!
+[assembly: AssemblyFileVersion("5.1.0.0")] //note: change this to "x.y.revision.build_step" in a build step of your favorite C.I. build server
+[assembly: AssemblyInformationalVersion("0.5.1-alpha1")] //note: this is the version seen by NuGet, add "-alpha"/"-beta"/"-rc1" at the end to create pre-release packages
diff --git a/FdbBurner/App.config b/FdbBurner/App.config
index 9c05822ff..bae5d6d81 100644
--- a/FdbBurner/App.config
+++ b/FdbBurner/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/FdbBurner/FdbBurner.csproj b/FdbBurner/FdbBurner.csproj
index e2cc1154e..3c13f4ee0 100644
--- a/FdbBurner/FdbBurner.csproj
+++ b/FdbBurner/FdbBurner.csproj
@@ -9,7 +9,7 @@
Properties
FdbBurner
FdbBurner
- v4.5.1
+ v4.6.1
512
true
diff --git a/FdbBurner/Program.cs b/FdbBurner/Program.cs
index 8e898300f..cc2a77af2 100644
--- a/FdbBurner/Program.cs
+++ b/FdbBurner/Program.cs
@@ -1,15 +1,15 @@
-using FoundationDB.Client;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
+
namespace FdbBurner
{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Globalization;
+ using System.Linq;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using FoundationDB.Client;
public class Program
{
diff --git a/FdbShell/App.config b/FdbShell/App.config
index 8e1564635..bae5d6d81 100644
--- a/FdbShell/App.config
+++ b/FdbShell/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/FdbShell/Commands/BasicCommands.cs b/FdbShell/Commands/BasicCommands.cs
index ecbeac4ab..4a340e7d1 100644
--- a/FdbShell/Commands/BasicCommands.cs
+++ b/FdbShell/Commands/BasicCommands.cs
@@ -1,19 +1,20 @@
-using FoundationDB.Client;
-using FoundationDB.Layers.Directories;
-using FoundationDB.Layers.Tuples;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
+
namespace FdbShell
{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Globalization;
+ using System.IO;
+ using System.Linq;
+ using System.Net;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Doxense.Collections.Tuples;
+ using FoundationDB.Client;
+ using FoundationDB.Layers.Directories;
+
public static class BasicCommands
{
@@ -29,7 +30,7 @@ public static async Task TryOpenCurrentDirectoryAsync(string[] pa
{
if (path != null && path.Length > 0)
{
- return await db.Directory.TryOpenAsync(path, cancellationToken: ct);
+ return await db.Directory.TryOpenAsync(path, ct: ct);
}
else
{
@@ -37,11 +38,11 @@ public static async Task TryOpenCurrentDirectoryAsync(string[] pa
}
}
- public static async Task Dir(string[] path, IFdbTuple extras, DirectoryBrowseOptions options, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Dir(string[] path, ITuple extras, DirectoryBrowseOptions options, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
if (log == null) log = Console.Out;
- log.WriteLine("# Listing {0}:", String.Join("/", path));
+ log.WriteLine("# Listing {0}:", string.Join("/", path));
var parent = await TryOpenCurrentDirectoryAsync(path, db, ct);
if (parent == null)
@@ -52,7 +53,7 @@ public static async Task Dir(string[] path, IFdbTuple extras, DirectoryBrowseOpt
if (parent.Layer.IsPresent)
{
- log.WriteLine("# Layer: {0}", parent.Layer.ToAsciiOrHexaString());
+ log.WriteLine("# Layer: {0:P}", parent.Layer);
}
var folders = await Fdb.Directory.BrowseAsync(db, parent, ct);
@@ -69,16 +70,16 @@ public static async Task Dir(string[] path, IFdbTuple extras, DirectoryBrowseOpt
if (!(subfolder is FdbDirectoryPartition))
{
long count = await Fdb.System.EstimateCountAsync(db, subfolder.Keys.ToRange(), ct);
- log.WriteLine(" {0,-12} {1,-12} {3,9:N0} {2}", FdbKey.Dump(FdbSubspace.Copy(subfolder).Key), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, count);
+ log.WriteLine(" {0,-12} {1,-12} {3,9:N0} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, count);
}
else
{
- log.WriteLine(" {0,-12} {1,-12} {3,9} {2}", FdbKey.Dump(FdbSubspace.Copy(subfolder).Key), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, "-");
+ log.WriteLine(" {0,-12} {1,-12} {3,9} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, "-");
}
}
else
{
- log.WriteLine(" {0,-12} {1,-12} {2}", FdbKey.Dump(FdbSubspace.Copy(subfolder).Key), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name);
+ log.WriteLine(" {0,-12} {1,-12} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name);
}
}
else
@@ -96,7 +97,7 @@ public static async Task Dir(string[] path, IFdbTuple extras, DirectoryBrowseOpt
}
/// Creates a new directory
- public static async Task CreateDirectory(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task CreateDirectory(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
if (log == null) log = Console.Out;
@@ -104,33 +105,33 @@ public static async Task CreateDirectory(string[] path, IFdbTuple extras, IFdbDa
log.WriteLine("# Creating directory {0} with layer '{1}'", String.Join("/", path), layer);
- var folder = await db.Directory.TryOpenAsync(path, cancellationToken: ct);
+ var folder = await db.Directory.TryOpenAsync(path, ct: ct);
if (folder != null)
{
log.WriteLine("- Directory {0} already exists!", string.Join("/", path));
return;
}
- folder = await db.Directory.TryCreateAsync(path, Slice.FromString(layer), cancellationToken: ct);
- log.WriteLine("- Created under {0} [{1}]", FdbKey.Dump(folder.Key), folder.Key.ToHexaString(' '));
+ folder = await db.Directory.TryCreateAsync(path, Slice.FromString(layer), ct: ct);
+ log.WriteLine("- Created under {0} [{1}]", FdbKey.Dump(folder.GetPrefix()), folder.GetPrefix().ToHexaString(' '));
// look if there is already stuff under there
- var stuff = await db.ReadAsync((tr) => tr.GetRange(folder.Keys.ToRange()).FirstOrDefaultAsync(), cancellationToken: ct);
+ var stuff = await db.ReadAsync((tr) => tr.GetRange(folder.Keys.ToRange()).FirstOrDefaultAsync(), ct: ct);
if (stuff.Key.IsPresent)
{
log.WriteLine("CAUTION: There is already some data under {0} !");
- log.WriteLine(" {0} = {1}", FdbKey.Dump(stuff.Key), stuff.Value.ToAsciiOrHexaString());
+ log.WriteLine(" {0} = {1:V}", FdbKey.Dump(stuff.Key), stuff.Value);
}
}
/// Remove a directory and all its data
- public static async Task RemoveDirectory(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task RemoveDirectory(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
if (log == null) log = Console.Out;
string layer = extras.Count > 0 ? extras.Get(0) : null;
- var folder = await db.Directory.TryOpenAsync(path, cancellationToken: ct);
+ var folder = await db.Directory.TryOpenAsync(path, ct: ct);
if (folder == null)
{
log.WriteLine("# Directory {0} does not exist", string.Join("/", path));
@@ -153,16 +154,16 @@ public static async Task RemoveDirectory(string[] path, IFdbTuple extras, IFdbDa
}
/// Move/Rename a directory
- public static async Task MoveDirectory(string[] srcPath, string[] dstPath, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task MoveDirectory(string[] srcPath, string[] dstPath, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
- var folder = await db.Directory.TryOpenAsync(srcPath, cancellationToken: ct);
+ var folder = await db.Directory.TryOpenAsync(srcPath, ct: ct);
if (folder == null)
{
log.WriteLine("# Source directory {0} does not exist!", string.Join("/", srcPath));
return;
}
- folder = await db.Directory.TryOpenAsync(dstPath, cancellationToken: ct);
+ folder = await db.Directory.TryOpenAsync(dstPath, ct: ct);
if (folder != null)
{
log.WriteLine("# Destination directory {0} already exists!", string.Join("/", dstPath));
@@ -173,7 +174,7 @@ public static async Task MoveDirectory(string[] srcPath, string[] dstPath, IFdbT
Console.WriteLine("Moved {0} to {1}", string.Join("/", srcPath), string.Join("/", dstPath));
}
- public static async Task ShowDirectoryLayer(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task ShowDirectoryLayer(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
var dir = await BasicCommands.TryOpenCurrentDirectoryAsync(path, db, ct);
if (dir == null)
@@ -185,13 +186,13 @@ public static async Task ShowDirectoryLayer(string[] path, IFdbTuple extras, IFd
if (dir.Layer == FdbDirectoryPartition.LayerId)
log.WriteLine("# Directory {0} is a partition", String.Join("/", path));
else if (dir.Layer.IsPresent)
- log.WriteLine("# Directory {0} has layer {1}", String.Join("/", path), dir.Layer.ToAsciiOrHexaString());
+ log.WriteLine("# Directory {0} has layer {1:P}", String.Join("/", path), dir.Layer);
else
log.WriteLine("# Directory {0} does not have a layer defined", String.Join("/", path));
}
}
- public static async Task ChangeDirectoryLayer(string[] path, string layer, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task ChangeDirectoryLayer(string[] path, string layer, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
var dir = await BasicCommands.TryOpenCurrentDirectoryAsync(path, db, ct);
if (dir == null)
@@ -201,12 +202,12 @@ public static async Task ChangeDirectoryLayer(string[] path, string layer, IFdbT
else
{
dir = await db.ReadWriteAsync((tr) => dir.ChangeLayerAsync(tr, Slice.FromString(layer)), ct);
- log.WriteLine("# Directory {0} layer changed to {1}", String.Join("/", path), dir.Layer.ToAsciiOrHexaString());
+ log.WriteLine("# Directory {0} layer changed to {1:P}", String.Join("/", path), dir.Layer);
}
}
/// Counts the number of keys inside a directory
- public static async Task Count(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Count(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
// look if there is something under there
var folder = (await TryOpenCurrentDirectoryAsync(path, db, ct)) as FdbDirectorySubspace;
@@ -216,12 +217,12 @@ public static async Task Count(string[] path, IFdbTuple extras, IFdbDatabase db,
return;
}
- var copy = FdbSubspace.Copy(folder);
- log.WriteLine("# Counting keys under {0} ...", FdbKey.Dump(copy.Key));
+ var copy = folder.Copy();
+ log.WriteLine("# Counting keys under {0} ...", FdbKey.Dump(copy.GetPrefix()));
- var progress = new Progress>((state) =>
+ var progress = new Progress<(long Count, Slice Current)>((state) =>
{
- log.Write("\r# Found {0:N0} keys...", state.Item1);
+ log.Write("\r# Found {0:N0} keys...", state.Count);
});
long count = await Fdb.System.EstimateCountAsync(db, copy.ToRange(), progress, ct);
@@ -229,7 +230,7 @@ public static async Task Count(string[] path, IFdbTuple extras, IFdbDatabase db,
}
/// Shows the first few keys of a directory
- public static async Task Show(string[] path, IFdbTuple extras, bool reverse, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Show(string[] path, ITuple extras, bool reverse, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
int count = 20;
if (extras.Count > 0)
@@ -239,23 +240,23 @@ public static async Task Show(string[] path, IFdbTuple extras, bool reverse, IFd
}
// look if there is something under there
- var folder = await db.Directory.TryOpenAsync(path, cancellationToken: ct);
+ var folder = await db.Directory.TryOpenAsync(path, ct: ct);
if (folder != null)
{
- log.WriteLine("# Content of {0} [{1}]", FdbKey.Dump(folder.Key), folder.Key.ToHexaString(' '));
+ log.WriteLine("# Content of {0} [{1}]", FdbKey.Dump(folder.GetPrefix()), folder.GetPrefix().ToHexaString(' '));
var keys = await db.QueryAsync((tr) =>
{
var query = tr.GetRange(folder.Keys.ToRange());
return reverse
? query.Reverse().Take(count)
: query.Take(count + 1);
- }, cancellationToken: ct);
+ }, ct: ct);
if (keys.Count > 0)
{
if (reverse) keys.Reverse();
foreach (var key in keys.Take(count))
{
- log.WriteLine("...{0} = {1}", FdbKey.Dump(folder.ExtractKey(key.Key)), key.Value.ToAsciiOrHexaString());
+ log.WriteLine("...{0} = {1:V}", FdbKey.Dump(folder.ExtractKey(key.Key)), key.Value);
}
if (!reverse && keys.Count == count + 1)
{
@@ -270,14 +271,14 @@ public static async Task Show(string[] path, IFdbTuple extras, bool reverse, IFd
}
/// Display a tree of a directory's children
- public static async Task Tree(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Tree(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
if (log == null) log = Console.Out;
log.WriteLine("# Tree of {0}:", String.Join("/", path));
FdbDirectorySubspace root = null;
- if (path.Length > 0) root = await db.Directory.TryOpenAsync(path, cancellationToken: ct);
+ if (path.Length > 0) root = await db.Directory.TryOpenAsync(path, ct: ct);
await TreeDirectoryWalk(root, new List(), db, log, ct);
@@ -317,7 +318,7 @@ private static async Task TreeDirectoryWalk(FdbDirectorySubspace folder, List
{
var kvs = await Task.WhenAll(
- tr.GetRange(FdbKeyRange.StartsWith(key)).FirstOrDefaultAsync(),
- tr.GetRange(FdbKeyRange.StartsWith(key)).LastOrDefaultAsync()
+ tr.GetRange(KeyRange.StartsWith(key)).FirstOrDefaultAsync(),
+ tr.GetRange(KeyRange.StartsWith(key)).LastOrDefaultAsync()
);
return new { Min = kvs[0].Key, Max = kvs[1].Key };
}, ct);
if (bounds.Min.HasValue)
{ // folder is not empty
- shards = await Fdb.System.GetChunksAsync(db, FdbKeyRange.StartsWith(key), ct);
+ shards = await Fdb.System.GetChunksAsync(db, KeyRange.StartsWith(key), ct);
//TODO: we still need to check if the first and last shard really intersect the subspace
// we need to check if the shards actually contain data
@@ -453,14 +454,14 @@ private static string FormatSize(long size, CultureInfo ci = null)
}
/// Find the DCs, machines and processes in the cluster
- public static async Task Topology(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Topology(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
var coords = await Fdb.System.GetCoordinatorsAsync(db, ct);
log.WriteLine("[Cluster] {0}", coords.Id);
var servers = await db.QueryAsync(tr => tr
.WithReadAccessToSystemKeys()
- .GetRange(FdbKeyRange.StartsWith(Fdb.System.ServerList))
+ .GetRange(KeyRange.StartsWith(Fdb.System.ServerList))
.Select(kvp => new
{
// Offsets Size Type Name Description
@@ -545,7 +546,7 @@ public static async Task Topology(string[] path, IFdbTuple extras, IFdbDatabase
log.WriteLine();
}
- public static async Task Shards(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Shards(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
var ranges = await Fdb.System.GetChunksAsync(db, FdbKey.MinValue, FdbKey.MaxValue, ct);
Console.WriteLine("Found {0} shards in the whole cluster", ranges.Count);
@@ -554,7 +555,7 @@ public static async Task Shards(string[] path, IFdbTuple extras, IFdbDatabase db
var folder = (await TryOpenCurrentDirectoryAsync(path, db, ct)) as FdbDirectorySubspace;
if (folder != null)
{
- var r = FdbKeyRange.StartsWith(FdbSubspace.Copy(folder).Key);
+ var r = KeyRange.StartsWith(folder.Copy().GetPrefix());
Console.WriteLine("Searching for shards that intersect with /{0} ...", String.Join("/", path));
ranges = await Fdb.System.GetChunksAsync(db, r, ct);
Console.WriteLine("Found {0} ranges intersecting {1}:", ranges.Count, r);
@@ -574,7 +575,7 @@ public static async Task Shards(string[] path, IFdbTuple extras, IFdbDatabase db
//TODO: shards that intersect the current directory
}
- public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
+ public static async Task Sampling(string[] path, ITuple extras, IFdbDatabase db, TextWriter log, CancellationToken ct)
{
double ratio = 0.1d;
bool auto = true;
@@ -586,16 +587,16 @@ public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase
}
var folder = await TryOpenCurrentDirectoryAsync(path, db, ct);
- FdbKeyRange span;
+ KeyRange span;
if (folder is FdbDirectorySubspace)
{
- span = FdbKeyRange.StartsWith(FdbSubspace.Copy(folder as FdbDirectorySubspace).Key);
+ span = KeyRange.StartsWith((folder as FdbDirectorySubspace).Copy().GetPrefix());
log.WriteLine("Reading list of shards for /{0} under {1} ...", String.Join("/", path), FdbKey.Dump(span.Begin));
}
else
{
log.WriteLine("Reading list of shards for the whole cluster ...");
- span = FdbKeyRange.All;
+ span = KeyRange.All;
}
// dump keyServers
@@ -603,7 +604,7 @@ public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase
log.WriteLine("> Found {0:N0} shard(s)", ranges.Count);
// take a sample
- var samples = new List();
+ var samples = new List();
if (ranges.Count <= 32)
{ // small enough to scan it all
@@ -620,7 +621,7 @@ public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase
if (sz < 32) sz = Math.Max(sz, Math.Min(32, ranges.Count));
}
- var population = new List(ranges);
+ var population = new List(ranges);
for (int i = 0; i < sz; i++)
{
int p = rnd.Next(population.Count);
@@ -667,8 +668,8 @@ public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase
long count = 0;
int iter = 0;
- var beginSelector = FdbKeySelector.FirstGreaterOrEqual(range.Begin);
- var endSelector = FdbKeySelector.FirstGreaterOrEqual(range.End);
+ var beginSelector = KeySelector.FirstGreaterOrEqual(range.Begin);
+ var endSelector = KeySelector.FirstGreaterOrEqual(range.End);
while (true)
{
FdbRangeChunk data = default(FdbRangeChunk);
@@ -707,7 +708,7 @@ public static async Task Sampling(string[] path, IFdbTuple extras, IFdbDatabase
if (!data.HasMore) break;
- beginSelector = FdbKeySelector.FirstGreaterThan(data.Last.Key);
+ beginSelector = KeySelector.FirstGreaterThan(data.Last.Key);
++iter;
}
diff --git a/FdbShell/Commands/FdbCliCommands.cs b/FdbShell/Commands/FdbCliCommands.cs
index eab5d23bb..a62fbda25 100644
--- a/FdbShell/Commands/FdbCliCommands.cs
+++ b/FdbShell/Commands/FdbCliCommands.cs
@@ -1,17 +1,13 @@
-using FoundationDB.Client;
-using FoundationDB.Layers.Directories;
-using FoundationDB.Layers.Tuples;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
+
namespace FdbShell
{
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
+
public static class FdbCliCommands
{
diff --git a/FdbShell/FdbShell.csproj b/FdbShell/FdbShell.csproj
index c065c6d3d..e626e7b5e 100644
--- a/FdbShell/FdbShell.csproj
+++ b/FdbShell/FdbShell.csproj
@@ -9,7 +9,7 @@
Properties
FdbShell
FdbShell
- v4.5
+ v4.6.1
512
..\..\W2M\
true
@@ -77,13 +77,6 @@
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
\ No newline at end of file
+
+
diff --git a/FoundationDB.Client/IFdbCluster.cs b/FoundationDB.Client/IFdbCluster.cs
index 6c14420fa..3322e1320 100644
--- a/FoundationDB.Client/IFdbCluster.cs
+++ b/FoundationDB.Client/IFdbCluster.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2014, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,12 @@ namespace FoundationDB.Client
using System.Threading.Tasks;
/// Cluster connection context.
+ [PublicAPI]
public interface IFdbCluster : IDisposable
{
/// Path to the cluster file used by this connection, or null if the default cluster file is being used
- string Path { [CanBeNull] get; }
+ [CanBeNull]
+ string Path { get; }
/// Set an option on this cluster that does not take any parameter
/// Option to set
@@ -57,10 +59,10 @@ public interface IFdbCluster : IDisposable
/// Name of the database. Must be 'DB' (as of Beta 2)
/// Subspace of keys that will be accessed.
/// If true, the database will only allow read operations.
- /// Cancellation Token (optionnal) for the connect operation
+ /// Cancellation Token (optionnal) for the connect operation
/// Task that will return an FdbDatabase, or an exception
- Task OpenDatabaseAsync(string databaseName, IFdbSubspace subspace, bool readOnly, CancellationToken cancellationToken);
- //REVIEW: we should return an IFdbDatabase instead !
+ [ItemNotNull]
+ Task OpenDatabaseAsync(string databaseName, IKeySubspace subspace, bool readOnly, CancellationToken ct);
}
}
diff --git a/FoundationDB.Client/IFdbDatabase.cs b/FoundationDB.Client/IFdbDatabase.cs
index c3eca66c4..5cc046bb0 100644
--- a/FoundationDB.Client/IFdbDatabase.cs
+++ b/FoundationDB.Client/IFdbDatabase.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2014, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -33,13 +33,16 @@ namespace FoundationDB.Client
using System.Threading;
/// Database connection context.
- public interface IFdbDatabase : IFdbReadOnlyRetryable, IFdbRetryable, IFdbDynamicSubspace, IFdbKey, IDisposable
+ [PublicAPI]
+ public interface IFdbDatabase : IFdbRetryable, IDynamicKeySubspace, IDisposable
{
/// Name of the database
- string Name { [NotNull] get; }
+ [NotNull]
+ string Name { get; }
/// Cluster of the database
- IFdbCluster Cluster { [NotNull] get; }
+ [NotNull]
+ IFdbCluster Cluster { get; }
/// Returns a cancellation token that is linked with the lifetime of this database instance
/// The token will be cancelled if the database instance is disposed
@@ -47,10 +50,12 @@ public interface IFdbDatabase : IFdbReadOnlyRetryable, IFdbRetryable, IFdbDynami
/// Returns the global namespace used by this database instance
/// Makes a copy of the subspace tuple, so you should not call this property a lot. Use any of the Partition(..) methods to create a subspace of the database
- IFdbDynamicSubspace GlobalSpace { [NotNull] get; }
+ [NotNull]
+ IDynamicKeySubspace GlobalSpace { get; }
/// Directory partition of this database instance
- FdbDatabasePartition Directory { [NotNull] get; }
+ [NotNull]
+ FdbDatabasePartition Directory { get; }
/// If true, this database instance will only allow starting read-only transactions.
bool IsReadOnly { get; }
@@ -81,7 +86,7 @@ public interface IFdbDatabase : IFdbReadOnlyRetryable, IFdbRetryable, IFdbDynami
/// Start a new transaction on this database, with the specified mode
/// Mode of the transaction (read-only, read-write, ....)
- /// Optional cancellation token that can abort all pending async operations started by this transaction.
+ /// Optional cancellation token that can abort all pending async operations started by this transaction.
/// Existing parent context, if the transaction needs to be linked with a retry loop, or a parent transaction. If null, will create a new standalone context valid only for this transaction
/// New transaction instance that can read from or write to the database.
/// You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.
@@ -93,7 +98,7 @@ public interface IFdbDatabase : IFdbReadOnlyRetryable, IFdbRetryable, IFdbDynami
/// await tr.CommitAsync();
/// }
[NotNull]
- IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken cancellationToken, FdbOperationContext context = null);
+ IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext context = null);
}
diff --git a/FoundationDB.Client/IFdbKey.cs b/FoundationDB.Client/IFdbKey.cs
deleted file mode 100644
index 1a3f2c904..000000000
--- a/FoundationDB.Client/IFdbKey.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-#region BSD Licence
-/* Copyright (c) 2013, Doxense SARL
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of Doxense nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#endregion
-
-namespace FoundationDB.Client
-{
- using System;
-
- /// Allows a layer or custom class to be used as keys in a FoundationDB database
- public interface IFdbKey
- {
- /// Returns a binary representation of this instance, to be used as a complete key in the database
- Slice ToFoundationDbKey();
- }
-
-}
diff --git a/FoundationDB.Client/IFdbReadOnlyRetryable.cs b/FoundationDB.Client/IFdbReadOnlyRetryable.cs
index d025ced09..32e1be41e 100644
--- a/FoundationDB.Client/IFdbReadOnlyRetryable.cs
+++ b/FoundationDB.Client/IFdbReadOnlyRetryable.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2014, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,7 @@ namespace FoundationDB.Client
using System.Threading.Tasks;
/// Transactional context that can execute, inside a retry loop, idempotent actions using read-only transactions.
+ [PublicAPI]
public interface IFdbReadOnlyRetryable
{
#region Important Note: Differences with Python's @transactional and Java's TransactionContext
@@ -64,29 +65,29 @@ public interface IFdbReadOnlyRetryable
/// Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
/// Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.
- /// Token used to cancel the operation
+ /// Token used to cancel the operation
///
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task ReadAsync([NotNull, InstantHandle] Func asyncHandler, CancellationToken cancellationToken);
+ Task ReadAsync([NotNull, InstantHandle] Func asyncHandler, CancellationToken ct);
/// Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
/// Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.
- /// Token used to cancel the operation
+ /// Token used to cancel the operation
///
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task ReadAsync([NotNull, InstantHandle] Func> asyncHandler, CancellationToken cancellationToken);
+ Task ReadAsync([NotNull, InstantHandle] Func> asyncHandler, CancellationToken ct);
//REVIEW: should we keep these ?
/// [EXPERIMENTAL] do not use yet!.
- Task ReadAsync([NotNull, InstantHandle] Func asyncHandler, [InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task ReadAsync([NotNull, InstantHandle] Func asyncHandler, [InstantHandle] Action onDone, CancellationToken ct);
/// [EXPERIMENTAL] do not use yet!.
- Task ReadAsync([NotNull, InstantHandle] Func> asyncHandler, [InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task ReadAsync([NotNull, InstantHandle] Func> asyncHandler, [InstantHandle] Action onDone, CancellationToken ct);
}
diff --git a/FoundationDB.Client/IFdbReadOnlyTransaction.cs b/FoundationDB.Client/IFdbReadOnlyTransaction.cs
index 19644ee81..ccc8c9218 100644
--- a/FoundationDB.Client/IFdbReadOnlyTransaction.cs
+++ b/FoundationDB.Client/IFdbReadOnlyTransaction.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2014, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@ namespace FoundationDB.Client
using System.Threading.Tasks;
/// Transaction that allows read operations
+ [PublicAPI]
public interface IFdbReadOnlyTransaction : IDisposable
{
@@ -43,7 +44,8 @@ public interface IFdbReadOnlyTransaction : IDisposable
int Id { get; }
/// Context of this transaction.
- FdbOperationContext Context { [NotNull] get; }
+ [NotNull]
+ FdbOperationContext Context { get; }
/// Isolation Level of this transaction.
FdbIsolationLevel IsolationLevel { get; }
@@ -52,7 +54,8 @@ public interface IFdbReadOnlyTransaction : IDisposable
bool IsSnapshot { get; }
/// Return a Snapshotted version of this transaction, or the transaction itself it is already operating in Snapshot mode.
- IFdbReadOnlyTransaction Snapshot { [NotNull] get; }
+ [NotNull]
+ IFdbReadOnlyTransaction Snapshot { get; }
/// Cancellation Token linked to the life time of the transaction
/// Will be triggered if the transaction is aborted or disposed
@@ -76,17 +79,19 @@ public interface IFdbReadOnlyTransaction : IDisposable
/// Reads several values from the database snapshot represented by the current transaction
/// Keys to be looked up in the database
/// Task that will return an array of values, or an exception. Each item in the array will contain the value of the key at the same index in , or Slice.Nil if that key does not exist.
+ [ItemNotNull]
Task GetValuesAsync([NotNull] Slice[] keys);
/// Resolves a key selector against the keys in the database snapshot represented by the current transaction.
/// Key selector to resolve
/// Task that will return the key matching the selector, or an exception
- Task GetKeyAsync(FdbKeySelector selector);
+ Task GetKeyAsync(KeySelector selector);
/// Resolves several key selectors against the keys in the database snapshot represented by the current transaction.
/// Key selectors to resolve
/// Task that will return an array of keys matching the selectors, or an exception
- Task GetKeysAsync([NotNull] FdbKeySelector[] selectors);
+ [ItemNotNull]
+ Task GetKeysAsync([NotNull] KeySelector[] selectors);
///
/// Reads all key-value pairs in the database snapshot represented by transaction (potentially limited by Limit, TargetBytes, or Mode)
@@ -98,7 +103,7 @@ public interface IFdbReadOnlyTransaction : IDisposable
/// Optionnal query options (Limit, TargetBytes, Mode, Reverse, ...)
/// If streaming mode is FdbStreamingMode.Iterator, this parameter should start at 1 and be incremented by 1 for each successive call while reading this range. In all other cases it is ignored.
///
- Task GetRangeAsync(FdbKeySelector beginInclusive, FdbKeySelector endExclusive, FdbRangeOptions options = null, int iteration = 0);
+ Task GetRangeAsync(KeySelector beginInclusive, KeySelector endExclusive, FdbRangeOptions options = null, int iteration = 0);
///
/// Create a new range query that will read all key-value pairs in the database snapshot represented by the transaction
@@ -107,11 +112,12 @@ public interface IFdbReadOnlyTransaction : IDisposable
/// key selector defining the end of the range
/// Optionnal query options (Limit, TargetBytes, Mode, Reverse, ...)
/// Range query that, once executed, will return all the key-value pairs matching the providing selector pair
- FdbRangeQuery> GetRange(FdbKeySelector beginInclusive, FdbKeySelector endExclusive, FdbRangeOptions options = null);
+ FdbRangeQuery> GetRange(KeySelector beginInclusive, KeySelector endExclusive, FdbRangeOptions options = null);
/// Returns a list of public network addresses as strings, one for each of the storage servers responsible for storing and its associated value
/// Name of the key whose location is to be queried.
/// Task that will return an array of strings, or an exception
+ [ItemNotNull]
Task GetAddressesForKeyAsync(Slice key);
/// Returns this transaction snapshot read version.
diff --git a/FoundationDB.Client/IFdbRetryable.cs b/FoundationDB.Client/IFdbRetryable.cs
index c0e4c1dba..5efbcb297 100644
--- a/FoundationDB.Client/IFdbRetryable.cs
+++ b/FoundationDB.Client/IFdbRetryable.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013, Doxense SARL
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,64 +34,65 @@ namespace FoundationDB.Client
using System.Threading.Tasks;
/// Transactional context that can execute, inside a retry loop, idempotent actions using read and/or write transactions.
+ [PublicAPI]
public interface IFdbRetryable : IFdbReadOnlyRetryable
{
// note: see IFdbReadOnlyRetryable for comments about the differences between the .NET binding and other binding regarding the design of Transactionals
/// Run an idempotent transaction block inside a write-only transaction, which can be executed more than once if any retryable error occurs.
/// Idempotent handler that should only call write methods on the transation, and may be retried until the transaction commits, or a non-recoverable error occurs.
- /// Token used to cancel the operation
+ /// Token used to cancel the operation
///
/// You do not need to commit the transaction inside the handler, it will be done automatically.
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task WriteAsync([NotNull, InstantHandle] Action handler, CancellationToken cancellationToken);
+ Task WriteAsync([NotNull, InstantHandle] Action handler, CancellationToken ct);
/// Run an idempotent transactional block inside a write-only transaction, which can be executed more than once if any retryable error occurs.
/// Idempotent async handler that will be retried until the transaction commits, or a non-recoverable error occurs.
- /// Token used to cancel the operation
+ /// Token used to cancel the operation
///
/// You do not need to commit the transaction inside the handler, it will be done automatically.
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task WriteAsync([NotNull, InstantHandle] Func handler, CancellationToken cancellationToken);
+ Task WriteAsync([NotNull, InstantHandle] Func handler, CancellationToken ct);
/// Run an idempotent transactional block inside a read-write transaction, which can be executed more than once if any retryable error occurs.
/// Idempotent asynchronous handler that will be retried until the transaction commits, or a non-recoverable error occurs.
- /// Token used to cancel the operation
+ /// Token used to cancel the operation
///
/// You do not need to commit the transaction inside the handler, it will be done automatically.
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task ReadWriteAsync([NotNull, InstantHandle] Func asyncHandler, CancellationToken cancellationToken);
+ Task ReadWriteAsync([NotNull, InstantHandle] Func asyncHandler, CancellationToken ct);
/// Run an idempotent transactional block that returns a value, inside a read-write transaction, which can be executed more than once if any retryable error occurs.
/// Idempotent asynchronous lambda function that will be retried until the transaction commits, or a non-recoverable error occurs. The returned value of the last call will be the result of the operation.
- /// Token used to cancel the operation
- /// Result of the lambda function if the transaction committed sucessfully.
+ /// Token used to cancel the operation
+ /// Result of the lambda function if the transaction committed successfully.
///
/// You do not need to commit the transaction inside the handler, it will be done automatically.
/// Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda!
/// You must wait for the Task to complete successfully before updating the global state of the application.
///
- Task ReadWriteAsync([NotNull, InstantHandle] Func> asyncHandler, CancellationToken cancellationToken);
+ Task ReadWriteAsync([NotNull, InstantHandle] Func> asyncHandler, CancellationToken ct);
//REVIEW: should we keep these ?
/// [EXPERIMENTAL] do not use yet!.
- Task WriteAsync([NotNull, InstantHandle] Action handler, [NotNull, InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task WriteAsync([NotNull, InstantHandle] Action handler, [NotNull, InstantHandle] Action onDone, CancellationToken ct);
/// [EXPERIMENTAL] do not use yet!.
- Task WriteAsync([NotNull, InstantHandle] Func handler, [NotNull, InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task WriteAsync([NotNull, InstantHandle] Func handler, [NotNull, InstantHandle] Action onDone, CancellationToken ct);
/// [EXPERIMENTAL] do not use yet!.
- Task ReadWriteAsync([NotNull, InstantHandle] Func asyncHandler, [NotNull, InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task ReadWriteAsync([NotNull, InstantHandle] Func asyncHandler, [NotNull, InstantHandle] Action onDone, CancellationToken ct);
/// [EXPERIMENTAL] do not use yet!.
- Task ReadWriteAsync([NotNull, InstantHandle] Func> asyncHandler, [NotNull, InstantHandle] Action onDone, CancellationToken cancellationToken);
+ Task ReadWriteAsync([NotNull, InstantHandle] Func> asyncHandler, [NotNull, InstantHandle] Action onDone, CancellationToken ct);
}
}
diff --git a/FoundationDB.Client/IFdbTransaction.cs b/FoundationDB.Client/IFdbTransaction.cs
index 7e777eeb2..98f684dd9 100644
--- a/FoundationDB.Client/IFdbTransaction.cs
+++ b/FoundationDB.Client/IFdbTransaction.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013, Doxense SARL
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,11 +28,13 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
namespace FoundationDB.Client
{
+ using JetBrains.Annotations;
using System;
using System.Threading;
using System.Threading.Tasks;
/// Transaction that allows read and write operations
+ [PublicAPI]
public interface IFdbTransaction : IFdbReadOnlyTransaction
{
/// Returns true if this transaction instance only allow read operations
@@ -110,14 +112,40 @@ public interface IFdbTransaction : IFdbReadOnlyTransaction
///
long GetCommittedVersion();
+ /// Returns the which was used by versionstamps operations in this transaction.
+ ///
+ /// The Task will be ready only after the successful completion of a call to on this transaction.
+ /// Read-only transactions do not modify the database when committed and will result in the Task completing with an error.
+ /// Keep in mind that a transaction which reads keys and then sets them to their current values may be optimized to a read-only transaction.
+ ///
+ Task GetVersionStampAsync();
+
+ /// Return a place-holder 80-bit VersionStamp, whose value is not yet known, but will be filled by the database at commit time.
+ /// This value can used to generate temporary keys or value, for use with the or mutations
+ ///
+ /// The generate placeholder will use a random value that is unique per transaction (and changes at reach retry).
+ /// If the key contains the exact 80-bit byte signature of this token, the corresponding location will be tagged and replaced with the actual VersionStamp at commit time.
+ /// If another part of the key contains (by random chance) the same exact byte sequence, then an error will be triggered, and hopefully the transaction will retry with another byte sequence.
+ ///
+ VersionStamp CreateVersionStamp();
+
+ /// Return a place-holder 96-bit VersionStamp with an attached user version, whose value is not yet known, but will be filled by the database at commit time.
+ /// This value can used to generate temporary keys or value, for use with the or mutations
+ ///
+ /// The generate placeholder will use a random value that is unique per transaction (and changes at reach retry).
+ /// If the key contains the exact 80-bit byte signature of this token, the corresponding location will be tagged and replaced with the actual VersionStamp at commit time.
+ /// If another part of the key contains (by random chance) the same exact byte sequence, then an error will be triggered, and hopefully the transaction will retry with another byte sequence.
+ ///
+ VersionStamp CreateVersionStamp(int userVersion);
+
///
/// Watch a key for any change in the database.
///
/// Key to watch
- /// CancellationToken used to abort the watch if the caller doesn't want to wait anymore. Note that you can manually cancel the watch by calling Cancel() on the returned FdbWatch instance
+ /// CancellationToken used to abort the watch if the caller doesn't want to wait anymore. Note that you can manually cancel the watch by calling Cancel() on the returned FdbWatch instance
/// FdbWatch that can be awaited and will complete when the key has changed in the database, or cancellation occurs. You can call Cancel() at any time if you are not interested in watching the key anymore. You MUST always call Dispose() if the watch completes or is cancelled, to ensure that resources are released properly.
/// You can directly await an FdbWatch, or obtain a Task<Slice> by reading the property.
- FdbWatch Watch(Slice key, CancellationToken cancellationToken);
+ FdbWatch Watch(Slice key, CancellationToken ct);
}
diff --git a/FoundationDB.Client/FdbKeyRange.cs b/FoundationDB.Client/KeyRange.cs
similarity index 53%
rename from FoundationDB.Client/FdbKeyRange.cs
rename to FoundationDB.Client/KeyRange.cs
index a66c45110..a4c72b0de 100644
--- a/FoundationDB.Client/FdbKeyRange.cs
+++ b/FoundationDB.Client/KeyRange.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013, Doxense SARL
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,254 +28,288 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
namespace FoundationDB.Client
{
- using FoundationDB.Client.Utils;
using System;
+ using System.Collections.Generic;
using System.Diagnostics;
+ using System.Runtime.CompilerServices;
+ using Doxense;
+ using Doxense.Diagnostics.Contracts;
+ using JetBrains.Annotations;
/// Represents a pair of keys defining the range 'Begin <= key > End'
[DebuggerDisplay("Begin={Begin}, End={End}")]
- public struct FdbKeyRange : IEquatable, IComparable
+ public readonly struct KeyRange : IEquatable, IComparable, IEquatable<(Slice Begin, Slice End)>, IComparable<(Slice Begin, Slice End)>
{
- /// Returns an empty pair of keys
- public static FdbKeyRange Empty { get { return default(FdbKeyRange); } }
-
- /// Returns a range that contains all the keys in the database
- public static FdbKeyRange All { get { return new FdbKeyRange(FdbKey.MinValue, FdbKey.MaxValue); } }
/// Start of the range
- public Slice Begin { get { return m_begin; } }
- private Slice m_begin; //PERF: readonly struct
+ public readonly Slice Begin;
/// End of the range
- public Slice End { get { return m_end; } }
- private Slice m_end; //PERF: readonly struct
+ public readonly Slice End;
- ///
- /// Create a new range of keys
- ///
+ /// Create a new range of keys
/// Start of range (usually included)
/// End of range (usually excluded)
- public FdbKeyRange(Slice begin, Slice end)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public KeyRange(Slice begin, Slice end)
{
- m_begin = begin;
- m_end = end;
-
- Contract.Ensures(m_begin <= m_end, "The range is inverted");
+ this.Begin = begin;
+ this.End = end;
+ Contract.Ensures(this.Begin <= this.End, "The range is inverted");
}
- public FdbKeyRange(IFdbKey begin, IFdbKey end)
+ [Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static KeyRange Create(Slice a, Slice b)
{
- if (begin == null) throw new ArgumentNullException("begin");
- if (end == null) throw new ArgumentNullException("end");
-
- m_begin = begin.ToFoundationDbKey();
- m_end = end.ToFoundationDbKey();
-
- Contract.Ensures(m_begin <= m_end, "The range is inverted");
+ return new KeyRange(a, b);
}
- public static FdbKeyRange Create(Slice a, Slice b)
- {
- return new FdbKeyRange(a, b);
- }
+ /// Returns an empty pair of keys
+ public static readonly KeyRange Empty = default(KeyRange);
+
+ /// Returns a range that contains all the keys in the database
+ public static KeyRange All => new KeyRange(FdbKey.MinValue, FdbKey.MaxValue);
/// Create a range that will return all keys starting with : ('prefix' <= k < strinc('prefix'))
- ///
- ///
- public static FdbKeyRange StartsWith(Slice prefix)
+ [Pure]
+ public static KeyRange StartsWith(Slice prefix)
{
- if (prefix.IsNull) throw Fdb.Errors.KeyCannotBeNull("prefix");
+ if (prefix.Count == 0)
+ {
+ if (prefix.IsNull) throw Fdb.Errors.KeyCannotBeNull(nameof(prefix));
+ return new KeyRange(Slice.Empty, FdbKey.MaxValue);
+ }
// prefix => [ prefix, prefix + 1 )
- return new FdbKeyRange(
+ return new KeyRange(
prefix,
FdbKey.Increment(prefix)
);
}
- public static FdbKeyRange StartsWith(TKey prefix)
- where TKey : IFdbKey
- {
- if (prefix == null) throw new ArgumentNullException("prefix");
- return StartsWith(prefix.ToFoundationDbKey());
- }
-
/// Create a range that selects all keys starting with , but not the prefix itself: ('prefix\x00' <= k < string('prefix')
/// Key prefix (that will be excluded from the range)
/// Range including all keys with the specified prefix.
- public static FdbKeyRange PrefixedBy(Slice prefix)
+ [Pure]
+ public static KeyRange PrefixedBy(Slice prefix)
{
- if (prefix.IsNull) throw Fdb.Errors.KeyCannotBeNull("prefix");
+ if (prefix.IsNull) throw Fdb.Errors.KeyCannotBeNull(nameof(prefix));
// prefix => [ prefix."\0", prefix + 1)
- return new FdbKeyRange(
+ return new KeyRange(
prefix + FdbKey.MinValue,
FdbKey.Increment(prefix)
);
}
- public static FdbKeyRange PrefixedBy(TKey prefix)
- where TKey : IFdbKey
- {
- if (prefix == null) throw new ArgumentNullException("prefix");
- return PrefixedBy(prefix.ToFoundationDbKey());
- }
-
/// Create a range that will only return itself ('key' <= k < 'key\x00')
/// Key that will be returned by the range
/// Range that only return the specified key.
- public static FdbKeyRange FromKey(Slice key)
+ [Pure]
+ public static KeyRange FromKey(Slice key)
{
- if (key.IsNull) throw Fdb.Errors.KeyCannotBeNull();
-
if (key.Count == 0)
{ // "" => [ "", "\x00" )
- return new FdbKeyRange(Slice.Empty, FdbKey.MinValue);
+ if (key.IsNull) throw Fdb.Errors.KeyCannotBeNull();
+ return new KeyRange(Slice.Empty, FdbKey.MinValue);
}
// key => [ key, key + '\0' )
- return new FdbKeyRange(
+ return new KeyRange(
key,
key + FdbKey.MinValue
);
}
- public static FdbKeyRange FromKey(TKey key)
- where TKey : IFdbKey
+ public override bool Equals(object obj)
+ {
+ if (obj is KeyRange range) return Equals(range);
+ if (obj is ValueTuple tuple) return Equals(tuple);
+ return false;
+ }
+
+ public override int GetHashCode()
{
- if (key == null) throw new ArgumentNullException("key");
- return FromKey(key.ToFoundationDbKey());
+ return HashCodes.Combine(this.Begin.GetHashCode(), this.End.GetHashCode());
}
- public override bool Equals(object obj)
+ public bool Equals(KeyRange other)
{
- return (obj is FdbKeyRange) && Equals((FdbKeyRange)obj);
+ return this.Begin.Equals(other.Begin) && this.End.Equals(other.End);
}
- public override int GetHashCode()
+ public bool Equals((Slice Begin, Slice End) other)
{
- // ReSharper disable once NonReadonlyMemberInGetHashCode
- int h1 = m_begin.GetHashCode();
- // ReSharper disable once NonReadonlyMemberInGetHashCode
- int h2 = m_end.GetHashCode();
- return ((h1 << 5) + h1) ^ h2;
+ return this.Begin.Equals(other.Begin) && this.End.Equals(other.End);
}
- public bool Equals(FdbKeyRange other)
+ public static bool operator ==(KeyRange left, KeyRange right)
{
- return m_begin.Equals(other.m_begin) && m_end.Equals(other.m_end);
+ return left.Begin.Equals(right.Begin) && left.End.Equals(right.End);
}
- public static bool operator ==(FdbKeyRange left, FdbKeyRange right)
+ public static bool operator !=(KeyRange left, KeyRange right)
{
- return left.m_begin.Equals(right.m_begin) && left.m_end.Equals(right.m_end);
+ return !left.Begin.Equals(right.Begin) || !left.End.Equals(right.End);
}
- public static bool operator !=(FdbKeyRange left, FdbKeyRange right)
+ public int CompareTo(KeyRange other)
{
- return !left.m_begin.Equals(right.m_begin) || !left.m_end.Equals(right.m_end);
+ int c = this.Begin.CompareTo(other.Begin);
+ if (c == 0) c = this.End.CompareTo(other.End);
+ return c;
}
- public int CompareTo(FdbKeyRange other)
+ public int CompareTo((Slice Begin, Slice End) other)
{
- int c = m_begin.CompareTo(other.m_begin);
- if (c == 0) c = m_end.CompareTo(other.m_end);
+ int c = this.Begin.CompareTo(other.Begin);
+ if (c == 0) c = this.End.CompareTo(other.End);
return c;
}
+ [Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator KeyRange((Slice Begin, Slice End) range)
+ {
+ return new KeyRange(range.Begin, range.End);
+ }
+
+ [Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator (Slice Begin, Slice End)(KeyRange range)
+ {
+ return (range.Begin, range.End);
+ }
+
/// Combine another range with the current range, to produce a range that includes both (and all keys in between it the ranges are disjoint)
/// Range to merge with the current range
/// New range where the Begin key is the smallest bound and the End key is the largest bound of both ranges.
/// If both range are disjoint, then the resulting range will also contain the keys in between.
- public FdbKeyRange Merge(FdbKeyRange other)
+ [Pure]
+ public KeyRange Merge(KeyRange other)
{
- Slice begin = m_begin.CompareTo(other.m_begin) <= 0 ? m_begin : other.m_begin;
- Slice end = m_end.CompareTo(other.m_end) >= 0 ? m_end : other.m_end;
- return new FdbKeyRange(begin, end);
+ Slice begin = this.Begin.CompareTo(other.Begin) <= 0 ? this.Begin : other.Begin;
+ Slice end = this.End.CompareTo(other.End) >= 0 ? this.End : other.End;
+ return new KeyRange(begin, end);
}
/// Checks whether the current and the specified range are intersecting (i.e: there exists at at least one key that belongs to both ranges)
/// Range that is being checked for interection
/// True if the other range intersects the current range.
/// Note that ranges [0, 1) and [1, 2) do not intersect, since the end is exclusive by default
- public bool Intersects(FdbKeyRange other)
+ [Pure]
+ public bool Intersects(KeyRange other)
{
- int c = m_begin.CompareTo(other.m_begin);
+ int c = this.Begin.CompareTo(other.Begin);
if (c == 0)
{ // share the same begin key
return true;
}
- else if (c < 0)
+ if (c < 0)
{ // after us
- return m_end.CompareTo(other.m_begin) > 0;
- }
- else
- { // before us
- return m_begin.CompareTo(other.m_end) < 0;
+ return this.End.CompareTo(other.Begin) > 0;
}
+ // before us
+ return this.Begin.CompareTo(other.End) < 0;
}
/// Checks whether the current and the specified range are disjoint (i.e: there exists at least one key between both ranges)
///
///
/// Note that ranges [0, 1) and [1, 2) are not disjoint because, even though they do not intersect, they are both contiguous.
- public bool Disjoint(FdbKeyRange other)
+ [Pure]
+ public bool Disjoint(KeyRange other)
{
- int c = m_begin.CompareTo(other.m_begin);
+ int c = this.Begin.CompareTo(other.Begin);
if (c == 0)
{ // share the same begin key
return false;
}
- else if (c < 0)
+ if (c < 0)
{ // after us
- return m_end.CompareTo(other.m_begin) < 0;
- }
- else
- { // before us
- return m_begin.CompareTo(other.m_end) > 0;
+ return this.End.CompareTo(other.Begin) < 0;
}
+ // before us
+ return this.Begin.CompareTo(other.End) > 0;
}
/// Returns true, if the key is contained in the range
///
///
+ [Pure]
public bool Contains(Slice key)
{
- return key.CompareTo(m_begin) >= 0 && key.CompareTo(m_end) < 0;
- }
-
- public bool Contains(TKey key)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return Contains(key.ToFoundationDbKey());
+ return key.CompareTo(this.Begin) >= 0 && key.CompareTo(this.End) < 0;
}
/// Test if is contained inside the range
/// Key that will be compared with the the range's bounds
/// If true, the End bound is inclusive, otherwise it is exclusive
/// -1 if key is less than the lower bound of the range ( < Begin), +1 if the key is greater or equal to the higher bound of the range ( >= End) or 0 if it is inside the range (Begin <= < End)
+ [Pure]
public int Test(Slice key, bool endIncluded = false)
{
// note: if the range is empty (Begin = End = Slice.Empty) then it should return 0
- if (m_begin.IsPresent && key.CompareTo(m_begin) < 0) return -1;
- if (m_end.IsPresent && key.CompareTo(m_end) >= (endIncluded ? 1 : 0)) return +1;
+ if (this.Begin.IsPresent && key.CompareTo(this.Begin) < 0) return -1;
+ if (this.End.IsPresent && key.CompareTo(this.End) >= (endIncluded ? 1 : 0)) return +1;
return 0;
}
- public int Test(TKey key, bool endIncluded = false)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return Test(key.ToFoundationDbKey(), endIncluded);
- }
-
/// Returns a printable version of the range
public override string ToString()
{
- return "{" + FdbKey.PrettyPrint(m_begin, FdbKey.PrettyPrintMode.Begin) + ", " + FdbKey.PrettyPrint(m_end, FdbKey.PrettyPrintMode.End) + "}";
+ return "{" + FdbKey.PrettyPrint(this.Begin, FdbKey.PrettyPrintMode.Begin) + ", " + FdbKey.PrettyPrint(this.End, FdbKey.PrettyPrintMode.End) + "}";
}
+ [DebuggerDisplay("Mode={m_mode}")]
+ public sealed class Comparer : IComparer, IEqualityComparer
+ {
+ private const int BOTH = 0;
+ private const int BEGIN = 1;
+ private const int END = 2;
+
+ public static readonly Comparer Default = new Comparer(BOTH);
+ public static readonly Comparer Begin = new Comparer(BEGIN);
+ public static readonly Comparer End = new Comparer(END);
+
+ private readonly int m_mode;
+
+ private Comparer(int mode)
+ {
+ Contract.Requires(mode >= BOTH && mode <= END);
+ m_mode = mode;
+ }
+
+ public int Compare(KeyRange x, KeyRange y)
+ {
+ switch (m_mode)
+ {
+ case BEGIN: return x.Begin.CompareTo(y.Begin);
+ case END: return x.End.CompareTo(y.End);
+ default: return x.CompareTo(y);
+ }
+ }
+
+ public bool Equals(KeyRange x, KeyRange y)
+ {
+ switch(m_mode)
+ {
+ case BEGIN: return x.Begin.Equals(y.Begin);
+ case END: return x.End.Equals(y.End);
+ default: return x.Equals(y);
+ }
+ }
+
+ public int GetHashCode(KeyRange obj)
+ {
+ switch(m_mode)
+ {
+ case BEGIN: return obj.Begin.GetHashCode();
+ case END: return obj.End.GetHashCode();
+ default: return obj.GetHashCode();
+ }
+ }
+ }
+
+
}
}
diff --git a/FoundationDB.Client/FdbKeySelector.cs b/FoundationDB.Client/KeySelector.cs
similarity index 56%
rename from FoundationDB.Client/FdbKeySelector.cs
rename to FoundationDB.Client/KeySelector.cs
index 4c260c918..c66564373 100644
--- a/FoundationDB.Client/FdbKeySelector.cs
+++ b/FoundationDB.Client/KeySelector.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2014, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,15 +34,12 @@ namespace FoundationDB.Client
using JetBrains.Annotations;
/// Defines a selector for a key in the database
- [DebuggerDisplay("{ToString()}")]
- public struct FdbKeySelector : IEquatable
+ [DebuggerDisplay("{ToString(),nq}")]
+ public readonly struct KeySelector : IEquatable
{
- /// Empty key selector
- public static readonly FdbKeySelector None = default(FdbKeySelector);
/// Key of the selector
- public Slice Key { get { return m_key; } }
- private Slice m_key; //PERF: readonly struct
+ public readonly Slice Key;
/// If true, the selected key can be equal to .
public readonly bool OrEqual;
@@ -51,158 +48,120 @@ public struct FdbKeySelector : IEquatable
public readonly int Offset;
/// Creates a new selector
- public FdbKeySelector(Slice key, bool orEqual, int offset)
+ public KeySelector(Slice key, bool orEqual, int offset)
{
- m_key = key;
+ Key = key;
this.OrEqual = orEqual;
this.Offset = offset;
}
- /// Creates a new selector
- public FdbKeySelector(IFdbKey key, bool orEqual, int offset)
- {
- if (key == null) throw new ArgumentNullException("key");
- m_key = key.ToFoundationDbKey();
- this.OrEqual = orEqual;
- this.Offset = offset;
- }
-
- /// Returns a displayable representation of the key selector
- [Pure]
- public string PrettyPrint(FdbKey.PrettyPrintMode mode)
- {
- var sb = new StringBuilder();
- int offset = this.Offset;
- if (offset < 1)
- {
- sb.Append(this.OrEqual ? "lLE{" : "lLT{");
- }
- else
- {
- --offset;
- sb.Append(this.OrEqual ? "fGT{" : "fGE{");
- }
- sb.Append(FdbKey.PrettyPrint(m_key, mode));
- sb.Append("}");
-
- if (offset > 0)
- sb.Append(" + ").Append(offset);
- else if (offset < 0)
- sb.Append(" - ").Append(-offset);
-
- return sb.ToString();
- }
-
- /// Converts the value of the current object into its equivalent string representation
- public override string ToString()
- {
- return PrettyPrint(FdbKey.PrettyPrintMode.Single);
- }
+ /// Empty key selector
+ public static readonly KeySelector None = default(KeySelector);
- public bool Equals(FdbKeySelector other)
+ public bool Equals(KeySelector other)
{
- return this.Offset == other.Offset && this.OrEqual == other.OrEqual && m_key.Equals(other.m_key);
+ return this.Offset == other.Offset && this.OrEqual == other.OrEqual && Key.Equals(other.Key);
}
public override bool Equals(object obj)
{
- return obj is FdbKeySelector && Equals((FdbKeySelector)obj);
+ return obj is KeySelector selector && Equals(selector);
}
public override int GetHashCode()
{
// ReSharper disable once NonReadonlyMemberInGetHashCode
- return m_key.GetHashCode() ^ this.Offset ^ (this.OrEqual ? 0 : -1);
+ return Key.GetHashCode() ^ this.Offset ^ (this.OrEqual ? 0 : -1);
}
/// Creates a key selector that will select the last key that is less than
- public static FdbKeySelector LastLessThan(Slice key)
+ public static KeySelector LastLessThan(Slice key)
{
// #define FDB_KEYSEL_LAST_LESS_THAN(k, l) k, l, 0, 0
- return new FdbKeySelector(key, false, 0);
+ return new KeySelector(key, false, 0);
}
/// Creates a key selector that will select the last key that is less than or equal to
- public static FdbKeySelector LastLessOrEqual(Slice key)
+ public static KeySelector LastLessOrEqual(Slice key)
{
// #define FDB_KEYSEL_LAST_LESS_OR_EQUAL(k, l) k, l, 1, 0
- return new FdbKeySelector(key, true, 0);
+ return new KeySelector(key, true, 0);
}
/// Creates a key selector that will select the first key that is greater than
- public static FdbKeySelector FirstGreaterThan(Slice key)
+ public static KeySelector FirstGreaterThan(Slice key)
{
// #define FDB_KEYSEL_FIRST_GREATER_THAN(k, l) k, l, 1, 1
- return new FdbKeySelector(key, true, 1);
+ return new KeySelector(key, true, 1);
}
/// Creates a key selector that will select the first key that is greater than or equal to
- public static FdbKeySelector FirstGreaterOrEqual(Slice key)
+ public static KeySelector FirstGreaterOrEqual(Slice key)
{
// #define FDB_KEYSEL_FIRST_GREATER_OR_EQUAL(k, l) k, l, 0, 1
- return new FdbKeySelector(key, false, 1);
- }
-
- /// Creates a key selector that will select the last key that is less than
- public static FdbKeySelector LastLessThan(TKey key)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return LastLessThan(key.ToFoundationDbKey());
- }
-
- /// Creates a key selector that will select the last key that is less than or equal to
- public static FdbKeySelector LastLessOrEqual(TKey key)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return LastLessOrEqual(key.ToFoundationDbKey());
- }
-
- /// Creates a key selector that will select the first key that is greater than
- public static FdbKeySelector FirstGreaterThan(TKey key)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return FirstGreaterThan(key.ToFoundationDbKey());
- }
-
- /// Creates a key selector that will select the first key that is greater than or equal to
- public static FdbKeySelector FirstGreaterOrEqual(TKey key)
- where TKey : IFdbKey
- {
- if (key == null) throw new ArgumentNullException("key");
- return FirstGreaterOrEqual(key.ToFoundationDbKey());
+ return new KeySelector(key, false, 1);
}
/// Add a value to the selector's offset
/// ex: fGE('abc')
/// ex: 7
/// fGE('abc')+7
- public static FdbKeySelector operator +(FdbKeySelector selector, int offset)
+ public static KeySelector operator +(KeySelector selector, int offset)
{
- return new FdbKeySelector(selector.m_key, selector.OrEqual, selector.Offset + offset);
+ return new KeySelector(selector.Key, selector.OrEqual, selector.Offset + offset);
}
/// Substract a value to the selector's offset
/// ex: fGE('abc')
/// ex: 7
/// fGE('abc')-7
- public static FdbKeySelector operator -(FdbKeySelector selector, int offset)
+ public static KeySelector operator -(KeySelector selector, int offset)
{
- return new FdbKeySelector(selector.m_key, selector.OrEqual, selector.Offset - offset);
+ return new KeySelector(selector.Key, selector.OrEqual, selector.Offset - offset);
}
- public static bool operator ==(FdbKeySelector left, FdbKeySelector right)
+ public static bool operator ==(KeySelector left, KeySelector right)
{
return left.Equals(right);
}
- public static bool operator !=(FdbKeySelector left, FdbKeySelector right)
+ public static bool operator !=(KeySelector left, KeySelector right)
{
return !left.Equals(right);
}
+ /// Converts the value of the current object into its equivalent string representation
+ public override string ToString()
+ {
+ return PrettyPrint(FdbKey.PrettyPrintMode.Single);
+ }
+
+ /// Returns a displayable representation of the key selector
+ [Pure]
+ public string PrettyPrint(FdbKey.PrettyPrintMode mode)
+ {
+ var sb = new StringBuilder();
+ int offset = this.Offset;
+ if (offset < 1)
+ {
+ sb.Append(this.OrEqual ? "lLE{" : "lLT{");
+ }
+ else
+ {
+ --offset;
+ sb.Append(this.OrEqual ? "fGT{" : "fGE{");
+ }
+ sb.Append(FdbKey.PrettyPrint(Key, mode));
+ sb.Append("}");
+
+ if (offset > 0)
+ sb.Append(" + ").Append(offset);
+ else if (offset < 0)
+ sb.Append(" - ").Append(-offset);
+
+ return sb.ToString();
+ }
+
}
}
diff --git a/FoundationDB.Client/FdbKeySelectorPair.cs b/FoundationDB.Client/KeySelectorPair.cs
similarity index 54%
rename from FoundationDB.Client/FdbKeySelectorPair.cs
rename to FoundationDB.Client/KeySelectorPair.cs
index 0b9b3bb78..68f881de5 100644
--- a/FoundationDB.Client/FdbKeySelectorPair.cs
+++ b/FoundationDB.Client/KeySelectorPair.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013, Doxense SARL
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -33,87 +33,65 @@ namespace FoundationDB.Client
/// Represents of pair of key selectors that range 'GetKey(Begin) <= key < GetKey(End)'
[DebuggerDisplay("[ToString()]")]
- public struct FdbKeySelectorPair
+ public readonly struct KeySelectorPair
{
/// Start of the range
- public FdbKeySelector Begin { get { return m_begin; } }
- private FdbKeySelector m_begin; //PERF: readonly struct
+ public readonly KeySelector Begin;
/// End of the range
- public FdbKeySelector End { get { return m_end; } }
- private FdbKeySelector m_end; //PERF: readonly struct
+ public readonly KeySelector End;
/// Create a new pair of key selectors
/// Selector for key from which to start iterating
/// Selector for key where to stop iterating
- public FdbKeySelectorPair(FdbKeySelector beginInclusive, FdbKeySelector endExclusive)
+ public KeySelectorPair(KeySelector beginInclusive, KeySelector endExclusive)
{
- m_begin = beginInclusive;
- m_end = endExclusive;
+ this.Begin = beginInclusive;
+ this.End = endExclusive;
}
/// Factory method for a pair of key selectors
- public static FdbKeySelectorPair Create(FdbKeySelector beginInclusive, FdbKeySelector endExclusive)
+ public static KeySelectorPair Create(KeySelector beginInclusive, KeySelector endExclusive)
{
- return new FdbKeySelectorPair(
+ return new KeySelectorPair(
beginInclusive,
endExclusive
);
}
/// Create a new pair of key selectors using FIRST_GREATER_OR_EQUAL on both keys
- public static FdbKeySelectorPair Create(Slice begin, Slice end)
+ public static KeySelectorPair Create(Slice begin, Slice end)
{
- return new FdbKeySelectorPair(
- FdbKeySelector.FirstGreaterOrEqual(begin),
- FdbKeySelector.FirstGreaterOrEqual(end)
+ return new KeySelectorPair(
+ KeySelector.FirstGreaterOrEqual(begin),
+ KeySelector.FirstGreaterOrEqual(end)
);
}
/// Create a new pair of key selectors using FIRST_GREATER_OR_EQUAL on both keys
- public static FdbKeySelectorPair Create(TKey begin, TKey end)
- where TKey : IFdbKey
+ public static KeySelectorPair Create(KeyRange range)
{
- if (begin == null) throw new ArgumentNullException("begin");
- if (end == null) throw new ArgumentNullException("end");
- return new FdbKeySelectorPair(
- FdbKeySelector.FirstGreaterOrEqual(begin.ToFoundationDbKey()),
- FdbKeySelector.FirstGreaterOrEqual(end.ToFoundationDbKey())
- );
- }
-
- /// Create a new pair of key selectors using FIRST_GREATER_OR_EQUAL on both keys
- public static FdbKeySelectorPair Create(FdbKeyRange range)
- {
- return new FdbKeySelectorPair(
- FdbKeySelector.FirstGreaterOrEqual(range.Begin),
- FdbKeySelector.FirstGreaterOrEqual(range.End)
+ return new KeySelectorPair(
+ KeySelector.FirstGreaterOrEqual(range.Begin),
+ KeySelector.FirstGreaterOrEqual(range.End)
);
}
/// Create a new pair of key selectors that will select all the keys that start with the specified prefix
- public static FdbKeySelectorPair StartsWith(Slice prefix)
+ public static KeySelectorPair StartsWith(Slice prefix)
{
- var range = FdbKeyRange.StartsWith(prefix);
+ var range = KeyRange.StartsWith(prefix);
- return new FdbKeySelectorPair(
- FdbKeySelector.FirstGreaterOrEqual(range.Begin),
- FdbKeySelector.FirstGreaterOrEqual(range.End)
+ return new KeySelectorPair(
+ KeySelector.FirstGreaterOrEqual(range.Begin),
+ KeySelector.FirstGreaterOrEqual(range.End)
);
}
- /// Create a new pair of key selectors that will select all the keys that start with the specified prefix
- public static FdbKeySelectorPair StartsWith(TKey prefix)
- where TKey : IFdbKey
- {
- if (prefix == null) throw new ArgumentNullException("prefix");
- return StartsWith(prefix.ToFoundationDbKey());
- }
-
/// Returns a printable version of the pair of key selectors
public override string ToString()
{
- return "[ " + m_begin.PrettyPrint(FdbKey.PrettyPrintMode.Begin) + ", " + m_end.PrettyPrint(FdbKey.PrettyPrintMode.End) + " )";
+ return "[ " + this.Begin.PrettyPrint(FdbKey.PrettyPrintMode.Begin) + ", " + this.End.PrettyPrint(FdbKey.PrettyPrintMode.End) + " )";
}
}
diff --git a/FoundationDB.Client/Layers/Directories/FdbDirectoryExtensions.cs b/FoundationDB.Client/Layers/Directories/FdbDirectoryExtensions.cs
index 2aea8bb71..5d08ffb13 100644
--- a/FoundationDB.Client/Layers/Directories/FdbDirectoryExtensions.cs
+++ b/FoundationDB.Client/Layers/Directories/FdbDirectoryExtensions.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2015, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -45,52 +45,52 @@ public static class FdbDirectoryExtensions
/// If the directory does not exist, it is created (creating parent directories if necessary).
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
///
- public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, Slice.Nil), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, Slice.Nil), ct);
}
/// Opens the directory with the given .
/// If the directory does not exist, it is created (creating parent directories if necessary).
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
///
- public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken cancellationToken)
+ public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), ct);
}
/// Opens the directory with the given .
/// If the directory does not exist, it is created (creating parent directories if necessary).
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
///
- public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, new [] { name }, Slice.Nil), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, new [] { name }, Slice.Nil), ct);
}
/// Opens the directory with the given .
/// If the directory does not exist, it is created (creating parent directories if necessary).
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
///
- public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken cancellationToken)
+ public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, new[] { name }, layer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, new[] { name }, layer), ct);
}
/// Opens the directory with the given .
@@ -99,9 +99,9 @@ public static Task CreateOrOpenAsync([NotNull] this IFdbDi
///
public static Task CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, Slice layer = default(Slice))
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.CreateOrOpenAsync(trans, new[] { name }, layer);
}
@@ -118,9 +118,9 @@ public static Task CreateOrOpenAsync([NotNull] this IFdbDi
///
public static Task TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, bool readOnly, Slice layer = default(Slice))
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
if (readOnly)
return directory.TryOpenAsync(trans, path, layer);
@@ -140,7 +140,7 @@ public static Task CreateOrOpenAsync([NotNull] this IFdbDi
///
public static Task TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, bool readOnly, Slice layer = default(Slice))
{
- if (name == null) throw new ArgumentNullException("name");
+ if (name == null) throw new ArgumentNullException(nameof(name));
return TryCreateOrOpenAsync(directory, trans, new[] { name }, readOnly, layer);
}
@@ -152,51 +152,51 @@ public static Task CreateOrOpenAsync([NotNull] this IFdbDi
/// Creates a directory with the given (creating parent directories if necessary).
/// An error is raised if the given directory already exists.
///
- public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, path, Slice.Nil), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, path, Slice.Nil), ct);
}
/// Creates a directory with the given (creating parent directories if necessary).
/// An error is raised if the given directory already exists.
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
///
- public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken cancellationToken)
+ public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, path, layer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, path, layer), ct);
}
/// Creates a directory with the given .
/// An error is raised if the given directory already exists.
///
- public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, new [] { name }, Slice.Nil), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, new [] { name }, Slice.Nil), ct);
}
/// Creates a directory with the given .
/// An error is raised if the given directory already exists.
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
///
- public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken cancellationToken)
+ public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, new[] { name }, layer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.CreateAsync(tr, new[] { name }, layer), ct);
}
/// Creates a directory with the given .
@@ -205,53 +205,53 @@ public static Task CreateAsync([NotNull] this IFdbDirector
///
public static Task CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, Slice layer = default(Slice))
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.CreateAsync(trans, new[] { name }, layer);
}
/// Attempts to create a directory with the given (creating parent directories if necessary).
- public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, path, Slice.Nil), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, path, Slice.Nil), ct);
}
/// Attempts to create a directory with the given (creating parent directories if necessary).
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
///
- public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken cancellationToken)
+ public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, path, layer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, path, layer), ct);
}
/// Attempts to create a directory with the given .
- public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
- return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new [] { name }, Slice.Nil), cancellationToken);
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
+ return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new [] { name }, Slice.Nil), ct);
}
/// Attempts to create a directory with the given .
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
///
- public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken cancellationToken)
+ public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
- return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new[] { name }, layer), cancellationToken);
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
+ return db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new[] { name }, layer), ct);
}
/// Attempts to create a directory with the given .
@@ -259,9 +259,9 @@ public static Task TryCreateAsync([NotNull] this IFdbDirec
///
public static Task TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, Slice layer = default(Slice))
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.TryCreateAsync(trans, new[] { name }, layer);
}
@@ -273,49 +273,49 @@ public static Task TryCreateAsync([NotNull] this IFdbDirec
/// Opens the directory with the given .
/// An error is raised if the directory does not exist.
///
- public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadAsync((tr) => directory.OpenAsync(tr, path, Slice.Nil), cancellationToken);
+ return db.ReadAsync((tr) => directory.OpenAsync(tr, path, Slice.Nil), ct);
}
/// Opens the directory with the given .
/// An error is raised if the directory does not exist, or if a layer is specified and a different layer was specified when the directory was created.
///
- public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken cancellationToken)
+ public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadAsync((tr) => directory.OpenAsync(tr, path, layer), cancellationToken);
+ return db.ReadAsync((tr) => directory.OpenAsync(tr, path, layer), ct);
}
/// Opens the sub-directory with the given .
/// An error is raised if the directory does not exist.
///
- public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.OpenAsync(tr, new[] { name }, Slice.Nil), cancellationToken);
+ return db.ReadAsync((tr) => directory.OpenAsync(tr, new[] { name }, Slice.Nil), ct);
}
/// Opens the sub-directory with the given .
/// An error is raised if the directory does not exist, or if a layer is specified and a different layer was specified when the directory was created.
///
- public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken cancellationToken)
+ public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.OpenAsync(tr, new[] { name }, layer), cancellationToken);
+ return db.ReadAsync((tr) => directory.OpenAsync(tr, new[] { name }, layer), ct);
}
/// Opens the sub-directory with the given .
@@ -323,59 +323,59 @@ public static Task OpenAsync([NotNull] this IFdbDirectory
///
public static Task OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name, Slice layer = default(Slice))
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.OpenAsync(trans, new[] { name }, layer);
}
/// Attempts to open the directory with the given .
- public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, Slice.Nil), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, Slice.Nil), ct);
}
/// Attempts to open the directory with the given .
- public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken cancellationToken)
+ public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, layer), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, layer), ct);
}
/// Attempts to open the directory with the given .
- public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.TryOpenAsync(tr, new[] { name }, Slice.Nil), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryOpenAsync(tr, new[] { name }, Slice.Nil), ct);
}
/// Attempts to open the directory with the given .
- public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, Slice layer, CancellationToken cancellationToken)
+ public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.TryOpenAsync(tr, new[] { name }, layer), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryOpenAsync(tr, new[] { name }, layer), ct);
}
/// Attempts to open the directory with the given .
public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.TryOpenAsync(trans, new[] { name }, Slice.Nil);
}
@@ -383,9 +383,9 @@ public static Task TryOpenAsync([NotNull] this IFdbDirecto
/// Attempts to open the directory with the given .
public static Task TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name, Slice layer)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.TryOpenAsync(trans, new[] { name }, layer);
}
@@ -398,27 +398,27 @@ public static Task TryOpenAsync([NotNull] this IFdbDirecto
/// There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
/// An error is raised if the old directory does not exist, a directory already exists at `new_path`, or the parent directory of `new_path` does not exist.
///
- public static Task MoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath, CancellationToken cancellationToken)
+ public static Task MoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (oldPath == null) throw new ArgumentNullException("oldPath");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (oldPath == null) throw new ArgumentNullException(nameof(oldPath));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- return db.ReadWriteAsync((tr) => directory.MoveAsync(tr, oldPath, newPath), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.MoveAsync(tr, oldPath, newPath), ct);
}
/// Attempts to move the directory found at to .
/// There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
///
- public static Task TryMoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath, CancellationToken cancellationToken)
+ public static Task TryMoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (oldPath == null) throw new ArgumentNullException("oldPath");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (oldPath == null) throw new ArgumentNullException(nameof(oldPath));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- return db.ReadWriteAsync((tr) => directory.TryMoveAsync(tr, oldPath, newPath), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.TryMoveAsync(tr, oldPath, newPath), ct);
}
#endregion
@@ -429,25 +429,25 @@ public static Task TryMoveAsync([NotNull] this IFdbDirecto
/// There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
/// An error is raised if a directory already exists at `new_path`, or if the new path points to a child of the current directory.
///
- public static Task MoveToAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, [NotNull] IEnumerable newPath, CancellationToken cancellationToken)
+ public static Task MoveToAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, [NotNull] IEnumerable newPath, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- return db.ReadWriteAsync((tr) => subspace.MoveToAsync(tr, newPath), cancellationToken);
+ return db.ReadWriteAsync((tr) => subspace.MoveToAsync(tr, newPath), ct);
}
/// Attempts to move the current directory to .
/// There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
///
- public static Task TryMoveToAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, [NotNull] IEnumerable newPath, CancellationToken cancellationToken)
+ public static Task TryMoveToAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, [NotNull] IEnumerable newPath, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- return db.ReadWriteAsync((tr) => subspace.TryMoveToAsync(tr, newPath), cancellationToken);
+ return db.ReadWriteAsync((tr) => subspace.TryMoveToAsync(tr, newPath), ct);
}
#endregion
@@ -457,34 +457,34 @@ public static Task TryMoveToAsync([NotNull] this FdbDirect
/// Removes the directory, its contents, and all subdirectories.
/// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
///
- public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, IEnumerable path, CancellationToken cancellationToken)
+ public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr, path), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr, path), ct);
}
/// Removes the directory, its contents, and all subdirectories.
/// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
///
- public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
- return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr, new [] { name }), cancellationToken);
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
+ return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr, new [] { name }), ct);
}
/// Removes the directory, its contents, and all subdirectories.
/// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
///
- public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, CancellationToken cancellationToken)
+ public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.RemoveAsync(tr), ct);
}
/// Removes the directory, its contents, and all subdirectories.
@@ -492,9 +492,9 @@ public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull]
///
public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.RemoveAsync(trans, new[] { name });
}
@@ -502,24 +502,24 @@ public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull]
/// Removes the directory, its contents, and all subdirectories.
/// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
///
- public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, IEnumerable path, CancellationToken cancellationToken)
+ public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, path), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, path), ct);
}
/// Removes the directory, its contents, and all subdirectories.
/// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
///
- public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, new [] { name }), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, new [] { name }), ct);
}
/// Removes the directory, its contents, and all subdirectories.
@@ -527,9 +527,9 @@ public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory,
///
public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.TryRemoveAsync(trans, new[] { name });
}
@@ -540,44 +540,44 @@ public static Task TryRemoveAsync([NotNull] this IFdbDirectory directory,
/// Checks if a directory already exists
/// Returns true if the directory exists, otherwise false.
- public static Task ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable path, CancellationToken cancellationToken)
+ public static Task ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadAsync((tr) => directory.ExistsAsync(tr, path), cancellationToken);
+ return db.ReadAsync((tr) => directory.ExistsAsync(tr, path), ct);
}
/// Checks if a directory already exists
/// Returns true if the directory exists, otherwise false.
- public static Task ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.ExistsAsync(tr, new[] { name }), cancellationToken);
+ return db.ReadAsync((tr) => directory.ExistsAsync(tr, new[] { name }), ct);
}
/// Checks if a directory already exists
/// Returns true if the directory exists, otherwise false.
public static Task ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.ExistsAsync(trans, new[] { name });
}
/// Checks if this directory exists
/// Returns true if the directory exists, otherwise false.
- public static Task ExistsAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken cancellationToken)
+ public static Task ExistsAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadAsync((tr) => subspace.ExistsAsync(tr), cancellationToken);
+ return db.ReadAsync((tr) => subspace.ExistsAsync(tr), ct);
}
#endregion
@@ -585,95 +585,95 @@ public static Task ExistsAsync([NotNull] this FdbDirectorySubspace subspac
#region List / TryList...
/// Returns the list of subdirectories of directory at .
- public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, CancellationToken cancellationToken)
+ public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path));
- return db.ReadAsync((tr) => directory.ListAsync(tr, path), cancellationToken);
+ return db.ReadAsync((tr) => directory.ListAsync(tr, path), ct);
}
/// Returns the list of subdirectories of the sub-directory with the given .
- public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
- return db.ReadAsync((tr) => directory.ListAsync(tr, new [] { name }), cancellationToken);
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
+ return db.ReadAsync((tr) => directory.ListAsync(tr, new [] { name }), ct);
}
/// Returns the list of subdirectories of the current directory.
- public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, CancellationToken cancellationToken)
+ public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- return db.ReadAsync((tr) => directory.ListAsync(tr), cancellationToken);
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ return db.ReadAsync((tr) => directory.ListAsync(tr), ct);
}
/// Returns the list of subdirectories of the current directory.
public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
return directory.ListAsync(trans);
}
/// Returns the list of subdirectories of the sub-directory with the given .
public static Task> ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.ListAsync(trans, new[] { name });
}
/// Returns the list of subdirectories of directory at , if it exists
- public static Task> TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable path, CancellationToken cancellationToken)
+ public static Task> TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable path, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path"); //REVIEW: or not?
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path)); //REVIEW: or not?
- return db.ReadAsync((tr) => directory.TryListAsync(tr, path), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryListAsync(tr, path), ct);
}
/// Returns the list of subdirectories of the sub-directory with the given , if it exists
- public static Task> TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken cancellationToken)
+ public static Task> TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (name == null) throw new ArgumentNullException(nameof(name));
- return db.ReadAsync((tr) => directory.TryListAsync(tr, new [] { name }), cancellationToken);
+ return db.ReadAsync((tr) => directory.TryListAsync(tr, new [] { name }), ct);
}
/// Returns the list of subdirectories of the sub-directory with the given , if it exists
public static Task> TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (trans == null) throw new ArgumentNullException("trans");
- if (name == null) throw new ArgumentNullException("name");
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (name == null) throw new ArgumentNullException(nameof(name));
return directory.TryListAsync(trans, new[] { name });
}
/// Returns the list of all the subdirectories of the current directory.
- public static Task> ListAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken cancellationToken)
+ public static Task> ListAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadAsync((tr) => subspace.ListAsync(tr), cancellationToken);
+ return db.ReadAsync((tr) => subspace.ListAsync(tr), ct);
}
/// Returns the list of all the subdirectories of the current directory, it it exists.
- public static Task> TryListAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken cancellationToken)
+ public static Task> TryListAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbReadOnlyRetryable db, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadAsync((tr) => subspace.TryListAsync(tr), cancellationToken);
+ return db.ReadAsync((tr) => subspace.TryListAsync(tr), ct);
}
#endregion
@@ -681,22 +681,22 @@ public static Task> TryListAsync([NotNull] this FdbDirectorySubspac
#region Metadata
/// Change the layer id of the directory at
- public static Task ChangeLayerAsync([NotNull] this FdbDirectoryLayer directory, [NotNull] IFdbRetryable db, IEnumerable path, Slice newLayer, CancellationToken cancellationToken)
+ public static Task ChangeLayerAsync([NotNull] this FdbDirectoryLayer directory, [NotNull] IFdbRetryable db, IEnumerable path, Slice newLayer, CancellationToken ct)
{
- if (directory == null) throw new ArgumentNullException("directory");
- if (db == null) throw new ArgumentNullException("db");
- if (path == null) throw new ArgumentNullException("path"); //REVIEW: or not?
+ if (directory == null) throw new ArgumentNullException(nameof(directory));
+ if (db == null) throw new ArgumentNullException(nameof(db));
+ if (path == null) throw new ArgumentNullException(nameof(path)); //REVIEW: or not?
- return db.ReadWriteAsync((tr) => directory.ChangeLayerAsync(tr, path, newLayer), cancellationToken);
+ return db.ReadWriteAsync((tr) => directory.ChangeLayerAsync(tr, path, newLayer), ct);
}
/// Change the layer id of this directory
- public static Task ChangeLayerAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, Slice newLayer, CancellationToken cancellationToken)
+ public static Task ChangeLayerAsync([NotNull] this FdbDirectorySubspace subspace, [NotNull] IFdbRetryable db, Slice newLayer, CancellationToken ct)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
- if (db == null) throw new ArgumentNullException("db");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
+ if (db == null) throw new ArgumentNullException(nameof(db));
- return db.ReadWriteAsync((tr) => subspace.ChangeLayerAsync(tr, newLayer), cancellationToken);
+ return db.ReadWriteAsync((tr) => subspace.ChangeLayerAsync(tr, newLayer), ct);
}
#endregion
diff --git a/FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs b/FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs
index e5be52787..2e9af0707 100644
--- a/FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs
+++ b/FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2015, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,18 +28,19 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
namespace FoundationDB.Layers.Directories
{
- using FoundationDB.Client;
- using FoundationDB.Client.Utils;
- using FoundationDB.Layers.Tuples;
- using FoundationDB.Linq;
- using FoundationDB.Filters.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
-
+ using Doxense.Collections.Tuples;
+ using Doxense.Diagnostics.Contracts;
+ using Doxense.Linq;
+ using Doxense.Memory;
+ using Doxense.Serialization.Encoders;
+ using FoundationDB.Client;
+ using FoundationDB.Filters.Logging;
/// Provides a FdbDirectoryLayer class for managing directories in FoundationDB.
/// Directories are a recommended approach for administering layers and applications. Directories work in conjunction with subspaces. Each layer or application should create or open at least one directory with which to manage its subspace(s).
@@ -52,9 +53,9 @@ public class FdbDirectoryLayer : IFdbDirectory
{
private const int SUBDIRS = 0;
internal static readonly Version LayerVersion = new Version(1, 0, 0);
- internal static readonly Slice LayerSuffix = Slice.FromAscii("layer");
- internal static readonly Slice HcaKey = Slice.FromAscii("hca");
- internal static readonly Slice VersionKey = Slice.FromAscii("version");
+ internal static readonly Slice LayerSuffix = Slice.FromStringAscii("layer");
+ internal static readonly Slice HcaKey = Slice.FromStringAscii("hca");
+ internal static readonly Slice VersionKey = Slice.FromStringAscii("version");
/// Use this flag to make the Directory Layer start annotating the transactions with a descriptions of all operations.
///
@@ -64,19 +65,19 @@ public class FdbDirectoryLayer : IFdbDirectory
public static bool AnnotateTransactions { get; set; }
/// Subspace where the content of each folder will be stored
- public IFdbDynamicSubspace ContentSubspace { [NotNull] get; private set; }
+ public IDynamicKeySubspace ContentSubspace { [NotNull] get; }
/// Subspace where all the metadata nodes for each folder will be stored
- public IFdbDynamicSubspace NodeSubspace { [NotNull] get; private set; }
+ public IDynamicKeySubspace NodeSubspace { [NotNull] get; }
/// Root node of the directory
- internal IFdbDynamicSubspace RootNode { [NotNull] get; private set; }
+ internal IDynamicKeySubspace RootNode { [NotNull] get; }
/// Allocated used to generated prefix for new content
- internal FdbHighContentionAllocator Allocator { [NotNull] get; private set; }
+ internal FdbHighContentionAllocator Allocator { [NotNull] get; }
/// Gets the path for the root node of this FdbDirectoryLayer.
- internal IFdbTuple Location { [NotNull] get; private set; }
+ internal ITuple Location { [NotNull] get; }
/// Name of root directory of this layer
/// Returns String.Empty for the root Directory Layer, or the name of the partition
@@ -101,7 +102,7 @@ public string Name
/// Convert a relative path in this Directory Layer, into an absolute path from the root of partition of the database
[NotNull]
- internal IFdbTuple PartitionSubPath(IFdbTuple path = null)
+ internal ITuple PartitionSubPath(ITuple path = null)
{
// If the DL is the root, the path is already absolute
// If the DL is used by a partition, then the path of the partition will be prepended to the path
@@ -112,7 +113,7 @@ void IFdbDirectory.CheckLayer(Slice layer)
{
if (layer.IsPresent)
{
- throw new InvalidOperationException(String.Format("The directory layer {0} is not compatible with layer {1}.", this.FullName, layer.ToAsciiOrHexaString()));
+ throw new InvalidOperationException($"The directory layer {this.FullName} is not compatible with layer {layer:K}.");
}
}
@@ -129,7 +130,7 @@ Task IFdbDirectory.ChangeLayerAsync(IFdbTransaction trans,
/// Subspace where all the node metadata will be stored ('\xFE' by default)
/// Subspace where all automatically allocated directories will be stored (empty by default)
/// Location of the root of all the directories managed by this Directory Layer. Ususally empty for the root partition of the database.
- internal FdbDirectoryLayer(IFdbDynamicSubspace nodeSubspace, IFdbDynamicSubspace contentSubspace, IFdbTuple location)
+ internal FdbDirectoryLayer(IDynamicKeySubspace nodeSubspace, IDynamicKeySubspace contentSubspace, ITuple location)
{
Contract.Requires(nodeSubspace != null && contentSubspace != null);
@@ -138,11 +139,11 @@ internal FdbDirectoryLayer(IFdbDynamicSubspace nodeSubspace, IFdbDynamicSubspace
this.NodeSubspace = nodeSubspace;
// The root node is the one whose contents are the node subspace
- this.RootNode = nodeSubspace.Partition.ByKey(nodeSubspace.Key);
+ this.RootNode = nodeSubspace.Partition.ByKey(nodeSubspace.GetPrefix());
this.Allocator = new FdbHighContentionAllocator(this.RootNode.Partition.ByKey(HcaKey));
if (location == null || location.Count == 0)
{
- this.Location = FdbTuple.Empty;
+ this.Location = STuple.Empty;
this.Path = new string[0];
}
else
@@ -152,34 +153,29 @@ internal FdbDirectoryLayer(IFdbDynamicSubspace nodeSubspace, IFdbDynamicSubspace
}
}
- /// Create an instance of the default Directory Layer
- [NotNull]
- public static FdbDirectoryLayer Create()
- {
- return Create(Slice.Empty);
- }
-
/// Create an instance of a Directory Layer located under a specific prefix and path
/// Prefix for the content. The nodes will be stored under + <FE>
/// Optional path, if the Directory Layer is not located at the root of the database.
+ /// Optional key encoding scheme. If not specified, will use the encoding by default.
[NotNull]
- public static FdbDirectoryLayer Create(Slice prefix, IEnumerable path = null)
+ public static FdbDirectoryLayer Create(Slice prefix, IEnumerable path = null, IKeyEncoding encoding = null)
{
- var subspace = FdbSubspace.CreateDynamic(prefix, TypeSystem.Tuples);
- var location = path != null ? ParsePath(path) : FdbTuple.Empty;
+ var subspace = KeySubspace.CreateDynamic(prefix, encoding ?? TuPack.Encoding);
+ var location = path != null ? ParsePath(path) : STuple.Empty;
return new FdbDirectoryLayer(subspace.Partition[FdbKey.Directory], subspace, location);
}
/// Create an instance of a Directory Layer located under a specific subspace and path
/// Subspace for the content. The nodes will be stored under .Key + <FE>
/// Optional path, if the Directory Layer is not located at the root of the database.
+ /// Optional key encoding scheme. If not specified, will use the encoding by default.
[NotNull]
- public static FdbDirectoryLayer Create(IFdbSubspace subspace, IEnumerable path = null)
+ public static FdbDirectoryLayer Create(IKeySubspace subspace, IEnumerable path = null, IKeyEncoding encoding = null)
{
- if (subspace == null) throw new ArgumentNullException("subspace");
+ if (subspace == null) throw new ArgumentNullException(nameof(subspace));
- var location = path != null ? ParsePath(path) : FdbTuple.Empty;
- var space = subspace.Using(TypeSystem.Tuples);
+ var location = path != null ? ParsePath(path) : STuple.Empty;
+ var space = subspace.AsDynamic(encoding ?? TuPack.Encoding);
return new FdbDirectoryLayer(space.Partition[FdbKey.Directory], space, location);
}
@@ -188,12 +184,12 @@ public static FdbDirectoryLayer Create(IFdbSubspace subspace, IEnumerableSubspace for the content of the Directory Layer.
/// Optional path, if the Directory Layer is not located at the root of the database
[NotNull]
- public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDynamicSubspace contentSubspace, IEnumerable path = null)
+ public static FdbDirectoryLayer Create(IDynamicKeySubspace nodeSubspace, IDynamicKeySubspace contentSubspace, IEnumerable path = null)
{
- if (nodeSubspace == null) throw new ArgumentNullException("nodeSubspace");
- if (contentSubspace == null) throw new ArgumentNullException("contentSubspace");
+ if (nodeSubspace == null) throw new ArgumentNullException(nameof(nodeSubspace));
+ if (contentSubspace == null) throw new ArgumentNullException(nameof(contentSubspace));
- var location = path != null ? ParsePath(path) : FdbTuple.Empty;
+ var location = path != null ? ParsePath(path) : STuple.Empty;
//TODO: check that nodeSubspace != contentSubspace?
return new FdbDirectoryLayer(nodeSubspace, contentSubspace, location);
}
@@ -208,10 +204,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Transaction to use for the operation
/// Path of the directory to create or open
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
+ [ItemNotNull]
public Task CreateOrOpenAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(null, trans, ParsePath(path), layer, Slice.Nil, allowCreate: true, allowOpen: true, throwOnError: true);
}
@@ -222,10 +219,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Transaction to use for the operation
/// Path of the directory to open.
/// Optional layer id of the directory. If it is different than the layer specified when creating the directory, an exception will be thrown.
+ [ItemNotNull]
public Task OpenAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(trans, null, ParsePath(path), layer, prefix: Slice.Nil, allowCreate: false, allowOpen: true, throwOnError: true);
}
@@ -236,10 +234,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Transaction to use for the operation
/// Path of the directory to create
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
+ [ItemNotNull]
public Task CreateAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(null, trans, ParsePath(path), layer, prefix: Slice.Nil, allowCreate: true, allowOpen: false, throwOnError: true);
}
@@ -248,10 +247,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Transaction to use for the operation
/// Path of the directory to open.
/// Optional layer id of the directory. If it is different than the layer specified when creating the directory, an exception will be thrown.
+ [ItemCanBeNull]
public Task TryOpenAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(trans, null, ParsePath(path), layer, prefix: Slice.Nil, allowCreate: false, allowOpen: true, throwOnError: false);
}
@@ -260,10 +260,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Transaction to use for the operation
/// Path of the directory to create
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
+ [ItemCanBeNull]
public Task TryCreateAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(null, trans, ParsePath(path), layer, prefix: Slice.Nil, allowCreate: true, allowOpen: false, throwOnError: false);
}
@@ -273,10 +274,11 @@ public static FdbDirectoryLayer Create(IFdbDynamicSubspace nodeSubspace, IFdbDyn
/// Path of the directory to create
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
/// The directory will be created with the given physical prefix; otherwise a prefix is allocated automatically.
+ [ItemNotNull]
public Task RegisterAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer, Slice prefix)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(null, trans, ParsePath(path), layer, prefix: prefix, allowCreate: true, allowOpen: false, throwOnError: true);
}
@@ -286,10 +288,11 @@ public Task RegisterAsync([NotNull] IFdbTransaction trans,
/// Path of the directory to create
/// If is specified, it is recorded with the directory and will be checked by future calls to open.
/// The directory will be created with the given physical prefix; otherwise a prefix is allocated automatically.
+ [ItemCanBeNull]
public Task TryRegisterAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer, Slice prefix)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return CreateOrOpenInternalAsync(null, trans, ParsePath(path), layer, prefix: prefix, allowCreate: true, allowOpen: false, throwOnError: false);
}
@@ -305,15 +308,16 @@ public Task TryRegisterAsync([NotNull] IFdbTransaction tra
/// Transaction to use for the operation
/// Path of the directory to move
/// New path of the directory
- public Task MoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath)
+ [ItemNotNull]
+ public Task MoveAsync(IFdbTransaction trans, IEnumerable oldPath, IEnumerable newPath)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (oldPath == null) throw new ArgumentNullException("oldPath");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (oldPath == null) throw new ArgumentNullException(nameof(oldPath));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- var oldLocation = FdbTuple.FromEnumerable(oldPath);
+ var oldLocation = STuple.FromEnumerable(oldPath);
VerifyPath(oldLocation, "oldPath");
- var newLocation = FdbTuple.FromEnumerable(newPath);
+ var newLocation = STuple.FromEnumerable(newPath);
VerifyPath(newLocation, "newPath");
return MoveInternalAsync(trans, oldLocation, newLocation, throwOnError: true);
@@ -326,15 +330,16 @@ public Task MoveAsync([NotNull] IFdbTransaction trans, [No
/// Transaction to use for the operation
/// Path of the directory to move
/// New path of the directory
- public Task TryMoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable oldPath, [NotNull] IEnumerable newPath)
+ [ItemCanBeNull]
+ public Task TryMoveAsync(IFdbTransaction trans, IEnumerable oldPath, IEnumerable newPath)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (oldPath == null) throw new ArgumentNullException("oldPath");
- if (newPath == null) throw new ArgumentNullException("newPath");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (oldPath == null) throw new ArgumentNullException(nameof(oldPath));
+ if (newPath == null) throw new ArgumentNullException(nameof(newPath));
- var oldLocation = FdbTuple.FromEnumerable(oldPath);
+ var oldLocation = STuple.FromEnumerable(oldPath);
VerifyPath(oldLocation, "oldPath");
- var newLocation = FdbTuple.FromEnumerable(newPath);
+ var newLocation = STuple.FromEnumerable(newPath);
VerifyPath(newLocation, "newPath");
return MoveInternalAsync(trans, oldLocation, newLocation, throwOnError: false);
@@ -365,8 +370,8 @@ Task IFdbDirectory.TryMoveToAsync(IFdbTransaction trans, I
/// Path of the directory to remove (including any subdirectories)
public Task RemoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return RemoveInternalAsync(trans, ParsePath(path), throwIfMissing: true);
}
@@ -378,8 +383,8 @@ public Task RemoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerablePath of the directory to remove (including any subdirectories)
public Task TryRemoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
var location = ParsePath(path);
if (location.Count == 0) throw new NotSupportedException("Cannot remove a directory layer");
@@ -396,8 +401,8 @@ public Task TryRemoveAsync([NotNull] IFdbTransaction trans, [NotNull] IEnu
/// Returns true if the directory exists, otherwise false.
public Task ExistsAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable path)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
// no reason to disallow checking for the root directory (could be used to check if a directory layer is initialized?)
var location = ParsePath(path);
@@ -413,36 +418,40 @@ public Task ExistsAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull]
/// Returns the list of subdirectories of directory at
/// Transaction to use for the operation
/// Path of the directory to list
+ [ItemNotNull]
public Task> ListAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable path)
{
- if (trans == null) throw new ArgumentNullException("trans");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
return ListInternalAsync(trans, ParsePath(path), throwIfMissing: true);
}
/// Returns the list of subdirectories of the root directory
/// Transaction to use for the operation
+ [ItemNotNull]
public Task> ListAsync([NotNull] IFdbReadOnlyTransaction trans)
{
- if (trans == null) throw new ArgumentNullException("trans");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
- return ListInternalAsync(trans, FdbTuple.Empty, throwIfMissing: true);
+ return ListInternalAsync(trans, STuple.Empty, throwIfMissing: true);
}
/// Returns the list of subdirectories of directory at , if it exists.
/// Transaction to use for the operation
/// Path of the directory to list
+ [ItemCanBeNull]
public Task> TryListAsync([NotNull] IFdbReadOnlyTransaction trans, IEnumerable path)
{
- if (trans == null) throw new ArgumentNullException("trans");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
return ListInternalAsync(trans, ParsePath(path), throwIfMissing: false);
}
+ [ItemCanBeNull]
public Task> TryListAsync([NotNull] IFdbReadOnlyTransaction trans)
{
- if (trans == null) throw new ArgumentNullException("trans");
- return ListInternalAsync(trans, FdbTuple.Empty, throwIfMissing: false);
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ return ListInternalAsync(trans, STuple.Empty, throwIfMissing: false);
}
#endregion
@@ -451,10 +460,11 @@ public Task> TryListAsync([NotNull] IFdbReadOnlyTransaction trans)
/// Transaction to use for the operation
/// Path of the directory to change
/// New layer id of the directory
+ [ItemCanBeNull]
public async Task ChangeLayerAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice newLayer)
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
var location = ParsePath(path);
@@ -467,17 +477,17 @@ public async Task ChangeLayerAsync([NotNull] IFdbTransacti
public override string ToString()
{
- return String.Format("DirectoryLayer(path={0}, contents={1}, nodes={2})", this.FullName, this.ContentSubspace.Key.ToAsciiOrHexaString(), this.NodeSubspace.Key.ToAsciiOrHexaString());
+ return $"DirectoryLayer(path={this.FullName}, contents={this.ContentSubspace.GetPrefix():K}, nodes={this.NodeSubspace.GetPrefix():K})";
}
#endregion
#region Internal Helpers...
- private struct Node
+ private readonly struct Node
{
- public Node(IFdbDynamicSubspace subspace, IFdbTuple path, IFdbTuple targetPath, Slice layer)
+ public Node(IDynamicKeySubspace subspace, ITuple path, ITuple targetPath, Slice layer)
{
this.Subspace = subspace;
this.Path = path;
@@ -485,14 +495,15 @@ public Node(IFdbDynamicSubspace subspace, IFdbTuple path, IFdbTuple targetPath,
this.Layer = layer;
}
- public readonly IFdbDynamicSubspace Subspace;
- public readonly IFdbTuple Path;
- public readonly IFdbTuple TargetPath;
- public Slice Layer; //PERF: readonly struct
+ public readonly IDynamicKeySubspace Subspace;
+ public readonly ITuple Path;
+ public readonly ITuple TargetPath;
+ public readonly Slice Layer;
- public bool Exists { get { return this.Subspace != null; } }
+ public bool Exists => this.Subspace != null;
- public IFdbTuple PartitionSubPath { [NotNull] get { return this.TargetPath.Substring(this.Path.Count); } }
+ [NotNull]
+ public ITuple PartitionSubPath => this.TargetPath.Substring(this.Path.Count);
public bool IsInPartition(bool includeEmptySubPath)
{
@@ -501,16 +512,16 @@ public bool IsInPartition(bool includeEmptySubPath)
}
- private static void SetLayer([NotNull] IFdbTransaction trans, [NotNull] IFdbDynamicSubspace subspace, Slice layer)
+ private static void SetLayer([NotNull] IFdbTransaction trans, [NotNull] IDynamicKeySubspace subspace, Slice layer)
{
if (layer.IsNull) layer = Slice.Empty;
trans.Set(subspace.Keys.Encode(LayerSuffix), layer);
}
[NotNull]
- internal static IFdbTuple ParsePath(IEnumerable path, string argName = null)
+ internal static ITuple ParsePath(IEnumerable path, string argName = null)
{
- if (path == null) return FdbTuple.Empty;
+ if (path == null) return STuple.Empty;
var pathCopy = path.ToArray();
foreach (var s in pathCopy)
@@ -520,19 +531,11 @@ internal static IFdbTuple ParsePath(IEnumerable path, string argName = n
throw new ArgumentException("The path of a directory cannot contain null elements", argName ?? "path");
}
}
- return FdbTuple.FromArray(pathCopy);
- }
-
- [NotNull]
- internal static IFdbTuple ParsePath([NotNull] string name, string argName = null)
- {
- if (name == null) throw new ArgumentNullException(argName ?? "name");
-
- return FdbTuple.Create(name);
+ return STuple.FromArray(pathCopy);
}
[NotNull]
- internal static IFdbTuple VerifyPath([NotNull] IFdbTuple path, string argName = null)
+ internal static ITuple VerifyPath([NotNull] ITuple path, string argName = null)
{
// The path should not contain any null strings
if (path == null) throw new ArgumentNullException(argName ?? "path");
@@ -548,7 +551,7 @@ internal static IFdbTuple VerifyPath([NotNull] IFdbTuple path, string argName =
}
[NotNull]
- internal IReadOnlyList ToAbsolutePath([NotNull] IFdbTuple path)
+ internal IReadOnlyList ToAbsolutePath([NotNull] ITuple path)
{
if (path.Count == 0) return this.Path;
var converted = path.ToArray();
@@ -558,15 +561,16 @@ internal IReadOnlyList ToAbsolutePath([NotNull] IFdbTuple path)
/// Maps an absolute path to a relative path within this directory layer
[NotNull]
- internal IFdbTuple ToRelativePath([NotNull] IFdbTuple path)
+ internal ITuple ToRelativePath([NotNull] ITuple path)
{
- if (path == null) throw new ArgumentNullException("path");
+ if (path == null) throw new ArgumentNullException(nameof(path));
if (!path.StartsWith(this.Location)) throw new InvalidOperationException("The path cannot be outside of this partition");
return path.Substring(this.Location.Count);
}
- internal async Task CreateOrOpenInternalAsync(IFdbReadOnlyTransaction readTrans, IFdbTransaction trans, [NotNull] IFdbTuple path, Slice layer, Slice prefix, bool allowCreate, bool allowOpen, bool throwOnError)
+ [ItemCanBeNull]
+ internal async Task CreateOrOpenInternalAsync(IFdbReadOnlyTransaction readTrans, IFdbTransaction trans, [NotNull] ITuple path, Slice layer, Slice prefix, bool allowCreate, bool allowOpen, bool throwOnError)
{
Contract.Requires(readTrans != null || trans != null, "Need at least one transaction");
Contract.Requires(path != null, "Path must be specified");
@@ -599,20 +603,20 @@ internal async Task CreateOrOpenInternalAsync(IFdbReadOnly
if (!allowOpen)
{
- if (throwOnError) throw new InvalidOperationException(string.Format("The directory {0} already exists.", path));
+ if (throwOnError) throw new InvalidOperationException($"The directory {path} already exists.");
return null;
}
if (layer.IsPresent && layer != existingNode.Layer)
{
- throw new InvalidOperationException(String.Format("The directory {0} was created with incompatible layer {1} instead of expected {2}.", path, layer.ToAsciiOrHexaString(), existingNode.Layer.ToAsciiOrHexaString()));
+ throw new InvalidOperationException($"The directory {path} was created with incompatible layer {layer:P} instead of expected {existingNode.Layer:P}.");
}
return ContentsOfNode(existingNode.Subspace, path, existingNode.Layer);
}
if (!allowCreate)
{
- if (throwOnError) throw new InvalidOperationException(string.Format("The directory {0} does not exist.", path));
+ if (throwOnError) throw new InvalidOperationException($"The directory {path} does not exist.");
return null;
}
@@ -621,16 +625,16 @@ internal async Task CreateOrOpenInternalAsync(IFdbReadOnly
await CheckWriteVersionAsync(trans).ConfigureAwait(false);
- if (prefix == null)
+ if (prefix.IsNull)
{ // automatically allocate a new prefix inside the ContentSubspace
long id = await this.Allocator.AllocateAsync(trans).ConfigureAwait(false);
prefix = this.ContentSubspace.Keys.Encode(id);
// ensure that there is no data already present under this prefix
if (FdbDirectoryLayer.AnnotateTransactions) trans.Annotate("Ensure that there is no data already present under prefix {0}", prefix);
- if (await trans.GetRange(FdbKeyRange.StartsWith(prefix)).AnyAsync().ConfigureAwait(false))
+ if (await trans.GetRange(KeyRange.StartsWith(prefix)).AnyAsync().ConfigureAwait(false))
{
- throw new InvalidOperationException(String.Format("The database has keys stored at the prefix chosen by the automatic prefix allocator: {0}", prefix.ToAsciiOrHexaString()));
+ throw new InvalidOperationException($"The database has keys stored at the prefix chosen by the automatic prefix allocator: {prefix:K}");
}
// ensure that the prefix has not already been allocated
@@ -651,17 +655,17 @@ internal async Task CreateOrOpenInternalAsync(IFdbReadOnly
}
// we need to recursively create any missing parents
- IFdbDynamicSubspace parentNode;
+ IDynamicKeySubspace parentNode;
if (path.Count > 1)
{
var parentSubspace = await CreateOrOpenInternalAsync(readTrans, trans, path.Substring(0, path.Count - 1), Slice.Nil, Slice.Nil, true, true, true).ConfigureAwait(false);
- parentNode = NodeWithPrefix(parentSubspace.Key);
+ parentNode = NodeWithPrefix(parentSubspace.GetPrefix());
}
else
{
parentNode = this.RootNode;
}
- if (parentNode == null) throw new InvalidOperationException(string.Format("The parent directory of {0} doesn't exist.", path));
+ if (parentNode == null) throw new InvalidOperationException($"The parent directory of {path} doesn't exist.");
// initialize the metadata for this new directory
var node = NodeWithPrefix(prefix);
@@ -672,7 +676,8 @@ internal async Task CreateOrOpenInternalAsync(IFdbReadOnly
return ContentsOfNode(node, path, layer);
}
- internal async Task MoveInternalAsync([NotNull] IFdbTransaction trans, [NotNull] IFdbTuple oldPath, [NotNull] IFdbTuple newPath, bool throwOnError)
+ [ItemCanBeNull]
+ internal async Task MoveInternalAsync([NotNull] IFdbTransaction trans, [NotNull] ITuple oldPath, [NotNull] ITuple newPath, bool throwOnError)
{
Contract.Requires(trans != null && oldPath != null && newPath != null);
@@ -686,7 +691,7 @@ internal async Task MoveInternalAsync([NotNull] IFdbTransa
}
if (newPath.StartsWith(oldPath))
{
- throw new InvalidOperationException(string.Format("The destination directory({0}) cannot be a subdirectory of the source directory({1}).", newPath, oldPath));
+ throw new InvalidOperationException($"The destination directory({newPath}) cannot be a subdirectory of the source directory({oldPath}).");
}
await CheckWriteVersionAsync(trans).ConfigureAwait(false);
@@ -694,7 +699,7 @@ internal async Task MoveInternalAsync([NotNull] IFdbTransa
var oldNode = await FindAsync(trans, oldPath).ConfigureAwait(false);
if (!oldNode.Exists)
{
- if (throwOnError) throw new InvalidOperationException(string.Format("The source directory '{0}' does not exist.", oldPath));
+ if (throwOnError) throw new InvalidOperationException($"The source directory '{oldPath}' does not exist.");
return null;
}
@@ -703,7 +708,7 @@ internal async Task MoveInternalAsync([NotNull] IFdbTransa
// we have already checked that old and new are under this partition path, but one of them (or both?) could be under a sub-partition..
if (oldNode.IsInPartition(false) || newNode.IsInPartition(false))
{
- if (!oldNode.IsInPartition(false) || !newNode.IsInPartition(false) || !FdbTuple.Equals(oldNode.Path, newNode.Path))
+ if (!oldNode.IsInPartition(false) || !newNode.IsInPartition(false) || !STuple.Equals(oldNode.Path, newNode.Path))
{
throw new InvalidOperationException("Cannot move between partitions.");
}
@@ -713,25 +718,25 @@ internal async Task MoveInternalAsync([NotNull] IFdbTransa
if (newNode.Exists)
{
- if (throwOnError) throw new InvalidOperationException(string.Format("The destination directory '{0}' already exists. Remove it first.", newPath));
+ if (throwOnError) throw new InvalidOperationException($"The destination directory '{newPath}' already exists. Remove it first.");
return null;
}
var parentNode = await FindAsync(trans, newPath.Substring(0, newPath.Count - 1)).ConfigureAwait(false);
if (!parentNode.Exists)
{
- if (throwOnError) throw new InvalidOperationException(string.Format("The parent of the destination directory '{0}' does not exist. Create it first.", newPath));
+ if (throwOnError) throw new InvalidOperationException($"The parent of the destination directory '{newPath}' does not exist. Create it first.");
return null;
}
- if (FdbDirectoryLayer.AnnotateTransactions) trans.Annotate("Register the prefix {0} to its new location in the folder sub-tree", oldNode.Subspace.Key);
- trans.Set(GetSubDirKey(parentNode.Subspace, newPath.Get(-1)), this.NodeSubspace.Keys.Decode(oldNode.Subspace.Key));
+ if (FdbDirectoryLayer.AnnotateTransactions) trans.Annotate("Register the prefix {0} to its new location in the folder sub-tree", oldNode.Subspace.GetPrefix());
+ trans.Set(GetSubDirKey(parentNode.Subspace, newPath.Get(-1)), this.NodeSubspace.Keys.Decode(oldNode.Subspace.GetPrefix()));
await RemoveFromParent(trans, oldPath).ConfigureAwait(false);
return ContentsOfNode(oldNode.Subspace, newPath, oldNode.Layer);
}
- internal async Task RemoveInternalAsync([NotNull] IFdbTransaction trans, [NotNull] IFdbTuple path, bool throwIfMissing)
+ internal async Task RemoveInternalAsync([NotNull] IFdbTransaction trans, [NotNull] ITuple path, bool throwIfMissing)
{
Contract.Requires(trans != null && path != null);
@@ -743,7 +748,7 @@ internal async Task RemoveInternalAsync([NotNull] IFdbTransaction trans, [
var n = await FindAsync(trans, path).ConfigureAwait(false);
if (!n.Exists)
{
- if (throwIfMissing) throw new InvalidOperationException(string.Format("The directory '{0}' does not exist.", path));
+ if (throwIfMissing) throw new InvalidOperationException($"The directory '{path}' does not exist.");
return false;
}
@@ -761,7 +766,8 @@ internal async Task RemoveInternalAsync([NotNull] IFdbTransaction trans, [
return true;
}
- internal async Task> ListInternalAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IFdbTuple path, bool throwIfMissing)
+ [ItemCanBeNull]
+ internal async Task> ListInternalAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] ITuple path, bool throwIfMissing)
{
Contract.Requires(trans != null && path != null);
@@ -771,7 +777,7 @@ internal async Task> ListInternalAsync([NotNull] IFdbReadOnlyTransa
if (!node.Exists)
{
- if (throwIfMissing) throw new InvalidOperationException(string.Format("The directory '{0}' does not exist.", path));
+ if (throwIfMissing) throw new InvalidOperationException($"The directory '{path}' does not exist.");
return null;
}
@@ -786,7 +792,7 @@ internal async Task> ListInternalAsync([NotNull] IFdbReadOnlyTransa
.ConfigureAwait(false);
}
- internal async Task ExistsInternalAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IFdbTuple path)
+ internal async Task ExistsInternalAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] ITuple path)
{
Contract.Requires(trans != null && path != null);
@@ -804,7 +810,7 @@ internal async Task ExistsInternalAsync([NotNull] IFdbReadOnlyTransaction
return true;
}
- internal async Task ChangeLayerInternalAsync([NotNull] IFdbTransaction trans, [NotNull] IFdbTuple path, Slice newLayer)
+ internal async Task ChangeLayerInternalAsync([NotNull] IFdbTransaction trans, [NotNull] ITuple path, Slice newLayer)
{
Contract.Requires(trans != null && path != null);
@@ -814,7 +820,7 @@ internal async Task ChangeLayerInternalAsync([NotNull] IFdbTransaction trans, [N
if (!node.Exists)
{
- throw new InvalidOperationException(string.Format("The directory '{0}' does not exist, or as already been removed.", path));
+ throw new InvalidOperationException($"The directory '{path}' does not exist, or as already been removed.");
}
if (node.IsInPartition(includeEmptySubPath: false))
@@ -860,8 +866,8 @@ private static void CheckVersion(Slice value, bool writeAccess)
var minor = reader.ReadFixed32();
var upgrade = reader.ReadFixed32();
- if (major > LayerVersion.Major) throw new InvalidOperationException(String.Format("Cannot load directory with version {0}.{1}.{2} using directory layer {3}", major, minor, upgrade, LayerVersion));
- if (writeAccess && minor > LayerVersion.Minor) throw new InvalidOperationException(String.Format("Directory with version {0}.{1}.{2} is read-only when opened using directory layer {3}", major, minor, upgrade, LayerVersion));
+ if (major > LayerVersion.Major) throw new InvalidOperationException($"Cannot load directory with version {major}.{minor}.{upgrade} using directory layer {FdbDirectoryLayer.LayerVersion}");
+ if (writeAccess && minor > LayerVersion.Minor) throw new InvalidOperationException($"Directory with version {major}.{minor}.{upgrade} is read-only when opened using directory layer {FdbDirectoryLayer.LayerVersion}");
}
private void InitializeDirectory([NotNull] IFdbTransaction trans)
@@ -876,7 +882,8 @@ private void InitializeDirectory([NotNull] IFdbTransaction trans)
trans.Set(this.RootNode.Keys.Encode(VersionKey), writer.ToSlice());
}
- private async Task NodeContainingKey([NotNull] IFdbReadOnlyTransaction tr, Slice key)
+ [ItemCanBeNull]
+ private async Task NodeContainingKey([NotNull] IFdbReadOnlyTransaction tr, Slice key)
{
Contract.Requires(tr != null);
@@ -909,7 +916,7 @@ private async Task NodeContainingKey([NotNull] IFdbReadOnlyTransac
/// Returns the subspace to a node metadata, given its prefix
[CanBeNull]
- private IFdbDynamicSubspace NodeWithPrefix(Slice prefix)
+ private IDynamicKeySubspace NodeWithPrefix(Slice prefix)
{
if (prefix.IsNullOrEmpty) return null;
return this.NodeSubspace.Partition.ByKey(prefix);
@@ -917,19 +924,19 @@ private IFdbDynamicSubspace NodeWithPrefix(Slice prefix)
/// Returns a new Directory Subspace given its node subspace, path and layer id
[NotNull]
- private FdbDirectorySubspace ContentsOfNode([NotNull] IFdbSubspace node, [NotNull] IFdbTuple relativePath, Slice layer)
+ private FdbDirectorySubspace ContentsOfNode([NotNull] IKeySubspace node, [NotNull] ITuple relativePath, Slice layer)
{
Contract.Requires(node != null);
var path = this.Location.Concat(relativePath);
- var prefix = this.NodeSubspace.Keys.Decode(node.Key);
+ var prefix = this.NodeSubspace.Keys.Decode(node.GetPrefix());
if (layer == FdbDirectoryPartition.LayerId)
{
- return new FdbDirectoryPartition(path, relativePath, prefix, this);
+ return new FdbDirectoryPartition(path, relativePath, prefix, this, TuPack.Encoding);
}
else
{
- return new FdbDirectorySubspace(path, relativePath, prefix, this, layer, TypeSystem.Default.GetDynamicEncoder());
+ return new FdbDirectorySubspace(path, relativePath, prefix, this, layer, TuPack.Encoding);
}
}
@@ -942,7 +949,7 @@ private FdbDirectoryPartition GetPartitionForNode(Node node)
/// Finds a node subspace, given its path, by walking the tree from the root.
/// Node if it was found, or null
- private async Task FindAsync([NotNull] IFdbReadOnlyTransaction tr, [NotNull] IFdbTuple path)
+ private async Task FindAsync([NotNull] IFdbReadOnlyTransaction tr, [NotNull] ITuple path)
{
Contract.Requires(tr != null && path != null);
@@ -953,14 +960,14 @@ private async Task FindAsync([NotNull] IFdbReadOnlyTransaction tr, [NotNul
Slice layer = Slice.Nil;
while (i < path.Count)
{
- if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Looking for child {0} under node {1}...", path.Get(i), n.Key);
+ if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Looking for child {0} under node {1}...", path.Get(i), n.GetPrefix());
n = NodeWithPrefix(await tr.GetAsync(GetSubDirKey(n, path.Get(i))).ConfigureAwait(false));
if (n == null)
{
return new Node(null, path.Substring(0, i + 1), path, Slice.Empty);
}
- if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Reading Layer value for subfolder {0} found at {1}", path, n.Key);
+ if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Reading Layer value for subfolder {0} found at {1}", path, n.GetPrefix());
layer = await tr.GetAsync(n.Keys.Encode(LayerSuffix)).ConfigureAwait(false);
if (layer == FdbDirectoryPartition.LayerId)
{ // stop when reaching a partition
@@ -974,14 +981,14 @@ private async Task FindAsync([NotNull] IFdbReadOnlyTransaction tr, [NotNul
/// Returns the list of names and nodes of all children of the specified node
[NotNull]
- private IFdbAsyncEnumerable> SubdirNamesAndNodes([NotNull] IFdbReadOnlyTransaction tr, [NotNull] IFdbDynamicSubspace node)
+ private IAsyncEnumerable> SubdirNamesAndNodes([NotNull] IFdbReadOnlyTransaction tr, [NotNull] IDynamicKeySubspace node)
{
Contract.Requires(tr != null && node != null);
var sd = node.Partition.ByKey(SUBDIRS);
return tr
.GetRange(sd.Keys.ToRange())
- .Select(kvp => new KeyValuePair(
+ .Select(kvp => new KeyValuePair(
sd.Keys.Decode(kvp.Key),
NodeWithPrefix(kvp.Value)
));
@@ -989,14 +996,14 @@ private IFdbAsyncEnumerable> SubdirNam
/// Remove an existing node from its parents
/// True if the parent node was found, otherwise false
- private async Task RemoveFromParent([NotNull] IFdbTransaction tr, [NotNull] IFdbTuple path)
+ private async Task RemoveFromParent([NotNull] IFdbTransaction tr, [NotNull] ITuple path)
{
Contract.Requires(tr != null && path != null);
var parent = await FindAsync(tr, path.Substring(0, path.Count - 1)).ConfigureAwait(false);
if (parent.Exists)
{
- if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing path {0} from its parent folder at {1}", path, parent.Subspace.Key);
+ if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing path {0} from its parent folder at {1}", path, parent.Subspace.GetPrefix());
tr.Clear(GetSubDirKey(parent.Subspace, path.Get(-1)));
return true;
}
@@ -1004,7 +1011,7 @@ private async Task RemoveFromParent([NotNull] IFdbTransaction tr, [NotNull
}
/// Resursively remove a node (including the content), all its children
- private async Task RemoveRecursive([NotNull] IFdbTransaction tr, [NotNull] IFdbDynamicSubspace node)
+ private async Task RemoveRecursive([NotNull] IFdbTransaction tr, [NotNull] IDynamicKeySubspace node)
{
Contract.Requires(tr != null && node != null);
@@ -1012,10 +1019,10 @@ private async Task RemoveRecursive([NotNull] IFdbTransaction tr, [NotNull] IFdbD
await SubdirNamesAndNodes(tr, node).ForEachAsync((kvp) => RemoveRecursive(tr, kvp.Value)).ConfigureAwait(false);
// remove ALL the contents
- if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing all content located under {0}", node.Key);
- tr.ClearRange(ContentsOfNode(node, FdbTuple.Empty, Slice.Empty).ToRange());
+ if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing all content located under {0}", node.GetPrefix());
+ tr.ClearRange(ContentsOfNode(node, STuple.Empty, Slice.Empty).ToRange());
// and all the metadata for this folder
- if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing all metadata for folder under {0}", node.Key);
+ if (FdbDirectoryLayer.AnnotateTransactions) tr.Annotate("Removing all metadata for folder under {0}", node.GetPrefix());
tr.ClearRange(node.Keys.ToRange());
}
@@ -1039,7 +1046,7 @@ private async Task IsPrefixFree([NotNull] IFdbReadOnlyTransaction tr, Slic
.ConfigureAwait(false);
}
- private static Slice GetSubDirKey([NotNull] IFdbDynamicSubspace parent, [NotNull] string path)
+ private static Slice GetSubDirKey([NotNull] IDynamicKeySubspace parent, [NotNull] string path)
{
Contract.Requires(parent != null && path != null);
@@ -1056,9 +1063,9 @@ private static Slice GetSubDirKey([NotNull] IFdbDynamicSubspace parent, [NotNull
/// Tuple that should only contain strings
/// Array of strings
[NotNull]
- public static string[] ParsePath([NotNull] IFdbTuple path)
+ public static string[] ParsePath([NotNull] ITuple path)
{
- if (path == null) throw new ArgumentNullException("path");
+ if (path == null) throw new ArgumentNullException(nameof(path));
var tmp = new string[path.Count];
for (int i = 0; i < tmp.Length; i++)
{
@@ -1070,23 +1077,23 @@ public static string[] ParsePath([NotNull] IFdbTuple path)
[NotNull]
public static string[] Combine([NotNull] IEnumerable parent, string path)
{
- if (parent == null) throw new ArgumentNullException("parent");
+ if (parent == null) throw new ArgumentNullException(nameof(parent));
return parent.Concat(new[] { path }).ToArray();
}
[NotNull]
public static string[] Combine(IEnumerable parent, params string[] paths)
{
- if (parent == null) throw new ArgumentNullException("parent");
- if (paths == null) throw new ArgumentNullException("paths");
+ if (parent == null) throw new ArgumentNullException(nameof(parent));
+ if (paths == null) throw new ArgumentNullException(nameof(paths));
return parent.Concat(paths).ToArray();
}
[NotNull]
public static string[] Combine([NotNull] IEnumerable parent, [NotNull] IEnumerable paths)
{
- if (parent == null) throw new ArgumentNullException("parent");
- if (paths == null) throw new ArgumentNullException("paths");
+ if (parent == null) throw new ArgumentNullException(nameof(parent));
+ if (paths == null) throw new ArgumentNullException(nameof(paths));
return parent.Concat(paths).ToArray();
}
@@ -1141,7 +1148,7 @@ public static string[] Parse(string path)
[NotNull]
public static string FormatPath([NotNull] IEnumerable paths)
{
- if (paths == null) throw new ArgumentNullException("paths");
+ if (paths == null) throw new ArgumentNullException(nameof(paths));
return String.Join("/", paths.Select(path =>
{
diff --git a/FoundationDB.Client/Layers/Directories/FdbDirectoryPartition.cs b/FoundationDB.Client/Layers/Directories/FdbDirectoryPartition.cs
index 7ccc2fd6a..d183be738 100644
--- a/FoundationDB.Client/Layers/Directories/FdbDirectoryPartition.cs
+++ b/FoundationDB.Client/Layers/Directories/FdbDirectoryPartition.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2015, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,41 +28,47 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
namespace FoundationDB.Layers.Directories
{
- using FoundationDB.Client;
- using FoundationDB.Layers.Tuples;
using System;
+ using Doxense.Collections.Tuples;
+ using Doxense.Serialization.Encoders;
+ using FoundationDB.Client;
+ using JetBrains.Annotations;
+
public class FdbDirectoryPartition : FdbDirectorySubspace
{
/// Returns a slice with the ASCII string "partition"
- public static Slice LayerId { get { return Slice.FromString("partition"); } }
-
- private readonly FdbDirectoryLayer m_parentDirectoryLayer;
+ public static Slice LayerId => Slice.FromString("partition");
- internal FdbDirectoryPartition(IFdbTuple location, IFdbTuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer)
- : base(location, relativeLocation, prefix, new FdbDirectoryLayer(FdbSubspace.CreateDynamic(prefix + FdbKey.Directory, TypeSystem.Tuples), FdbSubspace.CreateDynamic(prefix, TypeSystem.Tuples), location), LayerId, TypeSystem.Tuples.GetDynamicEncoder())
+ internal FdbDirectoryPartition([NotNull] ITuple location, [NotNull] ITuple relativeLocation, Slice prefix, [NotNull] FdbDirectoryLayer directoryLayer, [NotNull] IKeyEncoding keyEncoding)
+ : base(location, relativeLocation, prefix, new FdbDirectoryLayer(FromKey(prefix + FdbKey.Directory).AsDynamic(keyEncoding), FromKey(prefix).AsDynamic(keyEncoding), location), LayerId, keyEncoding)
{
- m_parentDirectoryLayer = directoryLayer;
+ this.ParentDirectoryLayer = directoryLayer;
}
- internal FdbDirectoryLayer ParentDirectoryLayer { get { return m_parentDirectoryLayer; } }
+ internal FdbDirectoryLayer ParentDirectoryLayer { get; }
protected override Slice GetKeyPrefix()
{
throw new InvalidOperationException("Cannot create keys in the root of a directory partition.");
}
+ protected override KeyRange GetKeyRange()
+ {
+ throw new InvalidOperationException("Cannot create a key range in the root of a directory partition.");
+ }
+
public override bool Contains(Slice key)
{
throw new InvalidOperationException("Cannot check whether a key belongs to the root of a directory partition.");
}
- protected override IFdbTuple ToRelativePath(IFdbTuple location)
+ protected override ITuple ToRelativePath(ITuple location)
{
- return location ?? FdbTuple.Empty;
+ return location ?? STuple.Empty;
}
- protected override FdbDirectoryLayer GetLayerForPath(IFdbTuple relativeLocation)
+ protected override FdbDirectoryLayer GetLayerForPath(ITuple relativeLocation)
{
if (relativeLocation.Count == 0)
{ // Forward all actions on the Partition itself (empty path) to its parent's DL
@@ -76,7 +82,7 @@ protected override FdbDirectoryLayer GetLayerForPath(IFdbTuple relativeLocation)
public override string ToString()
{
- return String.Format("DirectoryPartition(path={0}, prefix={1})", this.FullName, this.InternalKey.ToAsciiOrHexaString());
+ return $"DirectoryPartition(path={this.FullName}, prefix={GetPrefixUnsafe():K})";
}
}
diff --git a/FoundationDB.Client/Layers/Directories/FdbDirectorySubspace.cs b/FoundationDB.Client/Layers/Directories/FdbDirectorySubspace.cs
index 205804016..045abe205 100644
--- a/FoundationDB.Client/Layers/Directories/FdbDirectorySubspace.cs
+++ b/FoundationDB.Client/Layers/Directories/FdbDirectorySubspace.cs
@@ -1,5 +1,5 @@
#region BSD Licence
-/* Copyright (c) 2013-2015, Doxense SAS
+/* Copyright (c) 2013-2018, Doxense SAS
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,23 +28,24 @@ DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
namespace FoundationDB.Layers.Directories
{
- using FoundationDB.Client;
- using FoundationDB.Client.Utils;
- using FoundationDB.Layers.Tuples;
- using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
+ using Doxense.Collections.Tuples;
+ using Doxense.Diagnostics.Contracts;
+ using Doxense.Serialization.Encoders;
+ using FoundationDB.Client;
+ using JetBrains.Annotations;
/// A Directory Subspace represents the contents of a directory, but it also remembers the path with which it was opened and offers convenience methods to operate on the directory at that path.
/// An instance of DirectorySubspace can be used for all the usual subspace operations. It can also be used to operate on the directory with which it was opened.
- [DebuggerDisplay("Path={this.FullName}, Prefix={InternalKey}, Layer={Layer}")]
- public class FdbDirectorySubspace : FdbDynamicSubspace, IFdbDirectory
+ [DebuggerDisplay("Path={this.FullName}, Prefix={Key}, Layer={Layer}")]
+ public class FdbDirectorySubspace : DynamicKeySubspace, IFdbDirectory
{
- internal FdbDirectorySubspace(IFdbTuple location, IFdbTuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer, Slice layer, IDynamicKeyEncoder encoder)
- : base(prefix, encoder)
+ internal FdbDirectorySubspace([NotNull] ITuple location, [NotNull] ITuple relativeLocation, Slice prefix, [NotNull] FdbDirectoryLayer directoryLayer, Slice layer, [NotNull] IKeyEncoding encoding)
+ : base(prefix, encoding)
{
Contract.Requires(location != null && relativeLocation != null && prefix != null && directoryLayer != null);
if (layer.IsNull) layer = Slice.Empty;
@@ -60,10 +61,10 @@ internal FdbDirectorySubspace(IFdbTuple location, IFdbTuple relativeLocation, Sl
}
/// Absolute location of the directory
- protected IFdbTuple Location { [NotNull] get; private set; }
+ protected ITuple Location { [NotNull] get; private set; }
/// Location of the directory relative to its parent Directory Layer
- protected IFdbTuple RelativeLocation { [NotNull] get; private set; }
+ protected ITuple RelativeLocation { [NotNull] get; private set; }
/// Absolute path of this directory
public IReadOnlyList Path { [NotNull] get; private set; }
@@ -90,7 +91,7 @@ public string FullName
/// Return the DirectoryLayer instance that should be called for the given path
/// Location relative to this directory subspace
- protected virtual FdbDirectoryLayer GetLayerForPath(IFdbTuple relativeLocation)
+ protected virtual FdbDirectoryLayer GetLayerForPath(ITuple relativeLocation)
{
// for regular directories, always returns its DL.
return this.DirectoryLayer;
@@ -100,7 +101,7 @@ protected virtual FdbDirectoryLayer GetLayerForPath(IFdbTuple relativeLocation)
/// Path relative from this directory
/// Path relative to the path of the current partition
[NotNull]
- protected virtual IFdbTuple ToRelativePath(IFdbTuple location)
+ protected virtual ITuple ToRelativePath(ITuple location)
{
return location == null ? this.RelativeLocation : this.RelativeLocation.Concat(location);
}
@@ -109,9 +110,9 @@ protected virtual IFdbTuple ToRelativePath(IFdbTuple location)
/// Path relative from this directory
/// Path relative to the path of the current partition
[NotNull]
- protected IFdbTuple ToRelativePath(IEnumerable path)
+ protected ITuple ToRelativePath(IEnumerable path)
{
- return ToRelativePath(path == null ? null : FdbTuple.FromEnumerable(path));
+ return ToRelativePath(path == null ? null : STuple.FromEnumerable(path));
}
/// Ensure that this directory was registered with the correct layer id
@@ -121,16 +122,17 @@ public void CheckLayer(Slice layer)
{
if (layer.IsPresent && layer != this.Layer)
{
- throw new InvalidOperationException(String.Format("The directory {0} was created with incompatible layer {1} instead of expected {2}.", this.FullName, this.Layer.ToAsciiOrHexaString(), layer.ToAsciiOrHexaString()));
+ throw new InvalidOperationException($"The directory {this.FullName} was created with incompatible layer {this.Layer:P} instead of expected {layer:P}.");
}
}
/// Change the layer id of this directory
/// Transaction to use for the operation
/// New layer id of this directory
- public async Task ChangeLayerAsync([NotNull] IFdbTransaction trans, Slice newLayer)
+ [ItemNotNull]
+ public async Task ChangeLayerAsync(IFdbTransaction trans, Slice newLayer)
{
- if (trans == null) throw new ArgumentNullException("trans");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
if (newLayer.IsNull) newLayer = Slice.Empty;
if (this.RelativeLocation.Count == 0)
@@ -151,7 +153,7 @@ public async Task ChangeLayerAsync([NotNull] IFdbTransacti
// set the layer to the new value
await this.DirectoryLayer.ChangeLayerInternalAsync(trans, this.RelativeLocation, newLayer).ConfigureAwait(false);
// and return the new version of the subspace
- return new FdbDirectorySubspace(this.Location, this.RelativeLocation, this.InternalKey, this.DirectoryLayer, newLayer, TypeSystem.Default.GetDynamicEncoder());
+ return new FdbDirectorySubspace(this.Location, this.RelativeLocation, GetKeyPrefix(), this.DirectoryLayer, newLayer, this.Encoding);
}
/// Opens a subdirectory with the given .
@@ -160,10 +162,10 @@ public async Task ChangeLayerAsync([NotNull] IFdbTransacti
/// Transaction to use for the operation
/// Relative path of the subdirectory to create or open
/// If is specified, it is checked against the layer of an existing subdirectory or set as the layer of a new subdirectory.
- public Task CreateOrOpenAsync([NotNull] IFdbTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
+ public Task CreateOrOpenAsync(IFdbTransaction trans, IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return this.DirectoryLayer.CreateOrOpenInternalAsync(null, trans, ToRelativePath(path), layer, Slice.Nil, allowCreate: true, allowOpen: true, throwOnError: true);
}
@@ -174,10 +176,10 @@ public async Task ChangeLayerAsync([NotNull] IFdbTransacti
/// Transaction to use for the operation
/// Relative path of the subdirectory to open
/// If specified, the opened directory must have the same layer id.
- public Task OpenAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable path, Slice layer = default(Slice))
+ public Task OpenAsync(IFdbReadOnlyTransaction trans, IEnumerable path, Slice layer = default(Slice))
{
- if (trans == null) throw new ArgumentNullException("trans");
- if (path == null) throw new ArgumentNullException("path");
+ if (trans == null) throw new ArgumentNullException(nameof(trans));
+ if (path == null) throw new ArgumentNullException(nameof(path));
return this.DirectoryLayer.CreateOrOpenInternalAsync(trans, null, ToRelativePath(path), layer, prefix: Slice.Nil, allowCreate: false, allowOpen: true, throwOnError: true);
}
@@ -188,10 +190,10 @@ public async Task