Skip to content

Commit e3d6779

Browse files
KrzysFRabdullin
authored andcommitted
[BREAKING CHANGE] Remove TypeSystem completely, and add AsDynamic(..), AsTyped<T..>(..) extension methods
- Version of Using(..) and UsingEncoder(...) that took an IKeyEncoding are renamed to AsDynamic() or AsTyped<T...>() - The encoding is optional, and will use TuPack.Encoding by default - Changed the KeySubspace.Copy(...) into extension methods
1 parent 24dc02f commit e3d6779

File tree

17 files changed

+171
-168
lines changed

17 files changed

+171
-168
lines changed

FdbShell/Commands/BasicCommands.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ public static async Task Dir(string[] path, ITuple extras, DirectoryBrowseOption
7070
if (!(subfolder is FdbDirectoryPartition))
7171
{
7272
long count = await Fdb.System.EstimateCountAsync(db, subfolder.Keys.ToRange(), ct);
73-
log.WriteLine(" {0,-12} {1,-12} {3,9:N0} {2}", FdbKey.Dump(KeySubspace.Copy(subfolder).GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, count);
73+
log.WriteLine(" {0,-12} {1,-12} {3,9:N0} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, count);
7474
}
7575
else
7676
{
77-
log.WriteLine(" {0,-12} {1,-12} {3,9} {2}", FdbKey.Dump(KeySubspace.Copy(subfolder).GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, "-");
77+
log.WriteLine(" {0,-12} {1,-12} {3,9} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name, "-");
7878
}
7979
}
8080
else
8181
{
82-
log.WriteLine(" {0,-12} {1,-12} {2}", FdbKey.Dump(KeySubspace.Copy(subfolder).GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name);
82+
log.WriteLine(" {0,-12} {1,-12} {2}", FdbKey.Dump(subfolder.Copy().GetPrefix()), subfolder.Layer.IsNullOrEmpty ? "-" : ("<" + subfolder.Layer.ToUnicode() + ">"), name);
8383
}
8484
}
8585
else
@@ -217,7 +217,7 @@ public static async Task Count(string[] path, ITuple extras, IFdbDatabase db, Te
217217
return;
218218
}
219219

220-
var copy = KeySubspace.Copy(folder);
220+
var copy = folder.Copy();
221221
log.WriteLine("# Counting keys under {0} ...", FdbKey.Dump(copy.GetPrefix()));
222222

223223
var progress = new Progress<(long Count, Slice Current)>((state) =>
@@ -555,7 +555,7 @@ public static async Task Shards(string[] path, ITuple extras, IFdbDatabase db, T
555555
var folder = (await TryOpenCurrentDirectoryAsync(path, db, ct)) as FdbDirectorySubspace;
556556
if (folder != null)
557557
{
558-
var r = KeyRange.StartsWith(KeySubspace.Copy(folder).GetPrefix());
558+
var r = KeyRange.StartsWith(folder.Copy().GetPrefix());
559559
Console.WriteLine("Searching for shards that intersect with /{0} ...", String.Join("/", path));
560560
ranges = await Fdb.System.GetChunksAsync(db, r, ct);
561561
Console.WriteLine("Found {0} ranges intersecting {1}:", ranges.Count, r);
@@ -590,7 +590,7 @@ public static async Task Sampling(string[] path, ITuple extras, IFdbDatabase db,
590590
KeyRange span;
591591
if (folder is FdbDirectorySubspace)
592592
{
593-
span = KeyRange.StartsWith(KeySubspace.Copy(folder as FdbDirectorySubspace).GetPrefix());
593+
span = KeyRange.StartsWith((folder as FdbDirectorySubspace).Copy().GetPrefix());
594594
log.WriteLine("Reading list of shards for /{0} under {1} ...", String.Join("/", path), FdbKey.Dump(span.Begin));
595595
}
596596
else

FoundationDB.Client/Subspaces/Fdb.Directory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static async Task<IFdbDatabase> OpenNamedPartitionAsync(string clusterFil
8585
if (Logging.On) Logging.Verbose(typeof(Fdb.Directory), "OpenNamedPartitionAsync", $"Found named partition '{descriptor.FullName}' at prefix {descriptor}");
8686

8787
// we have to chroot the database to the new prefix, and create a new DirectoryLayer with a new '/'
88-
rootSpace = KeySubspace.Copy(descriptor); //note: create a copy of the key
88+
rootSpace = descriptor.Copy(); //note: create a copy of the key
8989
//TODO: find a nicer way to do that!
9090
db.ChangeRoot(rootSpace, FdbDirectoryLayer.Create(rootSpace, partitionPath), readOnly);
9191

FoundationDB.Client/Subspaces/KeySubspace.cs

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -141,95 +141,6 @@ public static TypedKeySubspace<T1, T2, T3, T4> CreateTyped<T1, T2, T3, T4>(Slice
141141

142142
#endregion
143143

144-
#region Copy...
145-
146-
/// <summary>Create a new copy of a subspace's prefix</summary>
147-
[Pure]
148-
internal static Slice StealPrefix([NotNull] IKeySubspace subspace)
149-
{
150-
//note: we can workaround the 'security' in top directory partition by accessing their key prefix without triggering an exception!
151-
return subspace is KeySubspace ks
152-
? ks.Key.Memoize()
153-
: subspace.GetPrefix().Memoize();
154-
}
155-
156-
/// <summary>Create a copy of a generic subspace, sharing the same binary prefix</summary>
157-
[Pure, NotNull]
158-
public static KeySubspace Copy([NotNull] IKeySubspace subspace)
159-
{
160-
Contract.NotNull(subspace, nameof(subspace));
161-
162-
var prefix = StealPrefix(subspace);
163-
164-
if (subspace is IDynamicKeySubspace dyn)
165-
{ // reuse the encoding of the original
166-
return new DynamicKeySubspace(prefix, dyn.Encoding);
167-
}
168-
169-
// no encoding
170-
return new KeySubspace(prefix);
171-
}
172-
173-
/// <summary>Create a copy of a generic subspace, sharing the same binary prefix</summary>
174-
[Pure, NotNull]
175-
public static DynamicKeySubspace Copy([NotNull] IKeySubspace subspace, IKeyEncoding encoding)
176-
{
177-
Contract.NotNull(subspace, nameof(subspace));
178-
Contract.NotNull(encoding, nameof(encoding));
179-
return new DynamicKeySubspace(StealPrefix(subspace), encoding);
180-
}
181-
182-
/// <summary>Create a copy of a generic subspace, sharing the same binary prefix</summary>
183-
[Pure, NotNull]
184-
public static DynamicKeySubspace Copy([NotNull] IKeySubspace subspace, IDynamicKeyEncoder encoder)
185-
{
186-
Contract.NotNull(subspace, nameof(subspace));
187-
Contract.NotNull(encoder, nameof(encoder));
188-
return new DynamicKeySubspace(StealPrefix(subspace), encoder);
189-
}
190-
191-
/// <summary>Create a copy of a dynamic subspace, sharing the same binary prefix and encoder</summary>
192-
[Pure, NotNull]
193-
public static DynamicKeySubspace Copy([NotNull] IDynamicKeySubspace subspace)
194-
{
195-
Contract.NotNull(subspace, nameof(subspace));
196-
return new DynamicKeySubspace(StealPrefix(subspace), subspace.Encoding);
197-
}
198-
199-
/// <summary>Create a copy of a typed subspace, sharing the same binary prefix and encoder</summary>
200-
[Pure, NotNull]
201-
public static TypedKeySubspace<T1> Copy<T1>([NotNull] ITypedKeySubspace<T1> subspace)
202-
{
203-
Contract.NotNull(subspace, nameof(subspace));
204-
return new TypedKeySubspace<T1>(StealPrefix(subspace), subspace.KeyEncoder);
205-
}
206-
207-
/// <summary>Create a copy of a typed subspace, sharing the same binary prefix and encoder</summary>
208-
[Pure, NotNull]
209-
public static TypedKeySubspace<T1, T2> Copy<T1, T2>([NotNull] ITypedKeySubspace<T1, T2> subspace)
210-
{
211-
Contract.NotNull(subspace, nameof(subspace));
212-
return new TypedKeySubspace<T1, T2>(StealPrefix(subspace), subspace.KeyEncoder);
213-
}
214-
215-
/// <summary>Create a copy of a typed subspace, sharing the same binary prefix and encoder</summary>
216-
[Pure, NotNull]
217-
public static TypedKeySubspace<T1, T2, T3> Copy<T1, T2, T3>([NotNull] ITypedKeySubspace<T1, T2, T3> subspace)
218-
{
219-
Contract.NotNull(subspace, nameof(subspace));
220-
return new TypedKeySubspace<T1, T2, T3>(StealPrefix(subspace), subspace.KeyEncoder);
221-
}
222-
223-
/// <summary>Create a copy of a typed subspace, sharing the same binary prefix and encoder</summary>
224-
[Pure, NotNull]
225-
public static TypedKeySubspace<T1, T2, T3, T4> Copy<T1, T2, T3, T4>([NotNull] ITypedKeySubspace<T1, T2, T3, T4> subspace)
226-
{
227-
Contract.NotNull(subspace, nameof(subspace));
228-
return new TypedKeySubspace<T1, T2, T3, T4>(StealPrefix(subspace), subspace.KeyEncoder);
229-
}
230-
231-
#endregion
232-
233144
internal KeySubspace(Slice prefix)
234145
{
235146
this.Key = prefix;
@@ -260,7 +171,7 @@ protected virtual Slice GetKeyPrefix()
260171

261172
/// <summary>Returns the master instance of the prefix, without any safety checks</summary>
262173
/// <remarks>This instance should NEVER be exposed to anyone else, and should ONLY be used for logging/troubleshooting</remarks>
263-
protected Slice GetPrefixUnsafe()
174+
internal Slice GetPrefixUnsafe()
264175
{
265176
return this.Key;
266177
}

0 commit comments

Comments
 (0)