Skip to content

Commit 000c6c0

Browse files
committed
Logging: added the concept of KeyResolver that can format keys capture in a Log, and options to capture callstacks
- the default resolver use FdbKey.Dump(..) like before (no attempt at resolve prefix, only prettyfying) - the DirectoryKeyResolver can scrape the content of a DirectoryLayer and replace key prefix by the name of their directory subspace - logging options can enable capture callstacks, which are displayed in the log report - when displaying a callstack, try looking for the first method of interest (method if application code, not the binding) - this is a not complete or optimized yet!
1 parent 5629fbe commit 000c6c0

File tree

8 files changed

+383
-90
lines changed

8 files changed

+383
-90
lines changed

FdbShell/Program.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ private static StreamWriter GetLogFile(string name)
4343
return stream;
4444
}
4545

46-
private static IFdbDatabase GetLoggedDatabase(IFdbDatabase db, StreamWriter stream, bool autoFlush = false)
47-
{
48-
if (stream == null) return db;
49-
50-
return new FdbLoggedDatabase(db, false, false, (tr) => { stream.WriteLine(tr.Log.GetTimingsReport(true)); if (autoFlush) stream.Flush(); });
51-
}
52-
5346
public static async Task RunAsyncCommand(Func<IFdbDatabase, TextWriter, CancellationToken, Task> command, CancellationToken cancel)
5447
{
5548
TextWriter log = null;

FoundationDB.Client/Filters/FdbDatabaseFilter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public abstract class FdbDatabaseFilter : IFdbDatabase
6060

6161
#region Constructors...
6262

63-
protected FdbDatabaseFilter(IFdbDatabase database, bool forceReadOnly, bool ownsDatabase)
63+
protected FdbDatabaseFilter([NotNull] IFdbDatabase database, bool forceReadOnly, bool ownsDatabase)
6464
{
6565
if (database == null) throw new ArgumentNullException("database");
6666

@@ -296,7 +296,14 @@ public int DefaultMaxRetryDelay
296296

297297
protected void ThrowIfDisposed()
298298
{
299-
if (m_disposed) throw new ObjectDisposedException(this.GetType().Name);
299+
// this should be inlined by the caller
300+
if (m_disposed) ThrowFilterAlreadyDisposed(this);
301+
}
302+
303+
[ContractAnnotation("=> halt")]
304+
private static void ThrowFilterAlreadyDisposed([NotNull] FdbDatabaseFilter filter)
305+
{
306+
throw new ObjectDisposedException(filter.GetType().Name);
300307
}
301308

302309
public void Dispose()

FoundationDB.Client/Filters/FdbTransactionFilter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#region BSD Licence
2-
/* Copyright (c) 2013-2014, Doxense SAS
2+
/* Copyright (c) 2013-2015, Doxense SAS
33
All rights reserved.
44
55
Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,7 @@ namespace FoundationDB.Filters
3333
using System.Collections.Generic;
3434
using System.Threading;
3535
using System.Threading.Tasks;
36+
using JetBrains.Annotations;
3637

3738
/// <summary>Base class for simple transaction filters</summary>
3839
public abstract class FdbTransactionFilter : IFdbTransaction
@@ -50,7 +51,7 @@ public abstract class FdbTransactionFilter : IFdbTransaction
5051
/// <param name="trans">Underlying transaction that will be exposed as read-only</param>
5152
/// <param name="forceReadOnly">If true, force the transaction to be read-only. If false, use the read-only mode of the underlying transaction</param>
5253
/// <param name="ownsTransaction">If true, the underlying transaction will also be disposed when this instance is disposed</param>
53-
protected FdbTransactionFilter(IFdbTransaction trans, bool forceReadOnly, bool ownsTransaction)
54+
protected FdbTransactionFilter([NotNull] IFdbTransaction trans, bool forceReadOnly, bool ownsTransaction)
5455
{
5556
if (trans == null) throw new ArgumentNullException("trans");
5657

@@ -61,7 +62,14 @@ protected FdbTransactionFilter(IFdbTransaction trans, bool forceReadOnly, bool o
6162

6263
protected void ThrowIfDisposed()
6364
{
64-
if (m_disposed) throw new ObjectDisposedException(this.GetType().Name);
65+
// this should be inlined by the caller
66+
if (m_disposed) ThrowFilterAlreadyDisposed(this);
67+
}
68+
69+
[ContractAnnotation("=> halt")]
70+
private static void ThrowFilterAlreadyDisposed([NotNull] FdbTransactionFilter filter)
71+
{
72+
throw new ObjectDisposedException(filter.GetType().Name);
6573
}
6674

6775
public void Dispose()

FoundationDB.Client/Filters/Logging/FdbLoggedDatabase.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ public sealed class FdbLoggedDatabase : FdbDatabaseFilter
3939
/// <summary>Handler called everytime a transaction is successfully committed</summary>
4040
public Action<FdbLoggedTransaction> OnCommitted { get; private set; }
4141

42-
public FdbLoggedDatabase(IFdbDatabase database, bool forceReadOnly, bool ownsDatabase, Action<FdbLoggedTransaction> onCommitted)
42+
public FdbLoggingOptions LoggingOptions { get; private set; }
43+
44+
public FdbLoggedDatabase(IFdbDatabase database, bool forceReadOnly, bool ownsDatabase, Action<FdbLoggedTransaction> onCommitted, FdbLoggingOptions defaultOptions = FdbLoggingOptions.Default)
4345
: base(database, forceReadOnly, ownsDatabase)
4446
{
4547
this.OnCommitted = onCommitted;
48+
this.LoggingOptions = defaultOptions;
4649
}
4750

4851
public override IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken cancellationToken = default(CancellationToken), FdbOperationContext context = null)
4952
{
5053
return new FdbLoggedTransaction(
5154
base.BeginTransaction(mode, cancellationToken, context),
5255
true,
53-
this.OnCommitted
56+
this.OnCommitted,
57+
this.LoggingOptions
5458
);
5559
}
5660
}

0 commit comments

Comments
 (0)